Class XMLSignatureLocation
java.lang.Object
se.idsec.signservice.security.sign.xml.XMLSignatureLocation
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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enum for indicating the point within a selected parent node. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor setting up the signature location to "the last child of the document root element".XMLSignatureLocation
(String parentXPath, XMLSignatureLocation.ChildPosition childPosition) Constructor accepting an XPath expression for finding the parent element of where we should insert/find the signature element.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
. -
Method Summary
Modifier and TypeMethodDescriptiongetSignature
(Document document) Finds a signature element based on this object's settings.void
insertSignature
(Element signature, Document document) Inserts the givenSignature
element into the document according to this object's configuration.void
testInsert
(Document document) Method that can be used to verify that the supplied XPath expression can be used for the supplied document.
-
Constructor Details
-
XMLSignatureLocation
public XMLSignatureLocation()Constructor setting up the signature location to "the last child of the document root element". -
XMLSignatureLocation
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)
orgetSignature(Document)
may be created using a namespace aware parser and you may want to use thelocal-name()
XPath construct.- Parameters:
parentXPath
- the XPath expression for locating the parent node of the signature elementchildPosition
- 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
Inserts the givenSignature
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 thedocument
paramater, the element is imported into this document.- Parameters:
signature
- the element to insertdocument
- the document to which the signature element should be inserted- Throws:
XPathExpressionException
- for XPath selection errors
-
getSignature
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
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)
-