Class XMLSignatureLocation

java.lang.Object
se.idsec.signservice.security.sign.xml.XMLSignatureLocation

public class XMLSignatureLocation extends Object
Tells where in an XML document the signature should be inserted or found.
Author:
Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
  • Constructor Details

    • XMLSignatureLocation

      public XMLSignatureLocation()
      Constructor setting up the signature location to "the last child of the document root element".
    • XMLSignatureLocation

      public XMLSignatureLocation(XMLSignatureLocation.ChildPosition childPosition)
      Constructor setting of the signature location to "the first child of the document root element" (childPosition == XMLSignatureLocation.ChildPosition.FIRST or "the last child of the document root element" (childPosition == XMLSignatureLocation.ChildPosition.LAST.
      Parameters:
      childPosition - first of last child of the document root element
    • XMLSignatureLocation

      public XMLSignatureLocation(String parentXPath, XMLSignatureLocation.ChildPosition childPosition) throws XPathExpressionException
      Constructor accepting an XPath expression for finding the parent element of where we should insert/find the signature element. Note that the result of evaluating the XPath expression MUST be one single node.

      Note: Beware of that the document supplied to insertSignature(Element, Document) or getSignature(Document) may be created using a namespace aware parser and you may want to use the local-name() XPath construct.

      Parameters:
      parentXPath - the XPath expression for locating the parent node of the signature element
      childPosition - whether to insert/find the signature as the first or last child of the given parent node
      Throws:
      XPathExpressionException - for illegal XPath expressions
  • Method Details

    • insertSignature

      public void insertSignature(Element signature, Document document) throws XPathExpressionException
      Inserts the given Signature element into the document according to this object's configuration.

      Note: If the owner document of the given Signature element is not the same as the document paramater, the element is imported into this document.

      Parameters:
      signature - the element to insert
      document - the document to which the signature element should be inserted
      Throws:
      XPathExpressionException - for XPath selection errors
    • getSignature

      public Element getSignature(Document document) throws XPathExpressionException
      Finds a signature element based on this object's settings.
      Parameters:
      document - the document to locate the signature element
      Returns:
      the signature element or null if no Signature element is found
      Throws:
      XPathExpressionException - for XPath selection errors
    • testInsert

      public void testInsert(Document document) throws XPathExpressionException
      Method that can be used to verify that the supplied XPath expression can be used for the supplied document.
      Parameters:
      document - the document to evaluate the XPath expression against
      Throws:
      XPathExpressionException - if the XPath expression is incorrect (does not find a node)