Package org.opensaml.core.xml.util
Class XMLObjectSupport
java.lang.Object
org.opensaml.core.xml.util.XMLObjectSupport
A helper class for working with XMLObjects.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Options for handling output of XMLObject cloning. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic XMLObject
buildXMLObject
(QName elementName) Build an XMLObject based on the element name.static XMLObject
buildXMLObject
(QName elementName, QName typeName) Build an XMLObject based on the element nane and xsi:type.static <T extends XMLObject>
TcloneXMLObject
(T originalXMLObject) Clone an XMLObject by brute force:static <T extends XMLObject>
TcloneXMLObject
(T originalXMLObject, XMLObjectSupport.CloneOutputOption cloneOutputOption) Clone an XMLObject by brute force:static XMLObjectBuilder<?>
getBuilder
(QName typeOrName) Obtain an XMLObject builder for the given QName.static Marshaller
getMarshaller
(QName typeOrName) Obtain an XMLObject marshaller for the given QName.static Marshaller
getMarshaller
(XMLObject xmlObject) Obtain an XMLObject marshaller for the given XMLObject.private static XMLObjectProviderRegistry
Obtain the XMLObject provider registry.static Unmarshaller
getUnmarshaller
(QName typeOrName) Obtain an XMLObject unmarshaller for the given QName.static Unmarshaller
getUnmarshaller
(Element element) Obtain an XMLObject unmarshaller for the given DOM Element.static String
lookupNamespacePrefix
(XMLObject xmlObject, String namespaceURI) Get the prefix bound to the specified namespace URI within the scope of the specified XMLObject.static String
lookupNamespaceURI
(XMLObject xmlObject, String prefix) Get the namespace URI bound to the specified prefix within the scope of the specified XMLObject.static Element
Marshall an XMLObject.static void
marshallAttribute
(QName attributeName, String attributeValue, Element domElement, boolean isIDAttribute) Marshall an attribute name and value to a DOM Element.static void
marshallAttribute
(QName attributeName, List<String> attributeValues, Element domElement, boolean isIDAttribute) Marshall an attribute name and value to a DOM Element.static void
marshallAttributeIDness
(String namespaceURI, String localPart, Element domElement, boolean isIDAttribute) Marshall the ID-ness of an attribute into the indicated DOM Element.static void
marshallAttributeIDness
(QName attributeName, Element domElement, boolean isIDAttribute) Marshall the ID-ness of an attribute into the indicated DOM Element.static void
marshallAttributeMap
(AttributeMap attributeMap, Element domElement) Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.static void
marshallAttributeMapIDness
(AttributeMap attributeMap, Element domElement) Marshall the ID-ness of attributes represented by the indicated AttributeMap into the indicated DOM Element.static void
marshallToOutputStream
(XMLObject xmlObject, OutputStream outputStream) Marshall an XMLObject to an OutputStream.static XMLObject
unmarshallFromInputStream
(ParserPool parserPool, InputStream inputStream) Unmarshall a Document from an InputSteam.static XMLObject
unmarshallFromReader
(ParserPool parserPool, Reader reader) Unmarshall a Document from a Reader.static void
unmarshallToAttributeMap
(AttributeMap attributeMap, Attr attribute) Unmarshall a DOM Attr to an AttributeMap.
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGLogger.
-
-
Constructor Details
-
XMLObjectSupport
private XMLObjectSupport()Constructor.
-
-
Method Details
-
cloneXMLObject
public static <T extends XMLObject> T cloneXMLObject(T originalXMLObject) throws MarshallingException, UnmarshallingException Clone an XMLObject by brute force:1) Marshall the original object if necessary 2) Clone the resulting DOM Element 3) Unmarshall a new XMLObject tree around it.
This method variant is equivalent to
cloneXMLObject(originalXMLObject, CloneOutputOption.DropDOM).
- Type Parameters:
T
- the type of object being cloned- Parameters:
originalXMLObject
- the object to be cloned- Returns:
- a clone of the original object
- Throws:
MarshallingException
- if original object can not be marshalledUnmarshallingException
- if cloned object tree can not be unmarshalled
-
cloneXMLObject
@Nullable public static <T extends XMLObject> T cloneXMLObject(@Nullable T originalXMLObject, @Nonnull XMLObjectSupport.CloneOutputOption cloneOutputOption) throws MarshallingException, UnmarshallingException Clone an XMLObject by brute force:1) Marshall the original object if necessary 2) Clone the resulting DOM Element 3) Unmarshall a new XMLObject tree around it.
- Type Parameters:
T
- the type of object being cloned- Parameters:
originalXMLObject
- the object to be clonedcloneOutputOption
- the option for handling the cloned object output- Returns:
- a clone of the original object
- Throws:
MarshallingException
- if original object can not be marshalledUnmarshallingException
- if cloned object tree can not be unmarshalled
-
unmarshallFromInputStream
public static XMLObject unmarshallFromInputStream(ParserPool parserPool, InputStream inputStream) throws XMLParserException, UnmarshallingException Unmarshall a Document from an InputSteam.- Parameters:
parserPool
- the ParserPool instance to useinputStream
- the InputStream to unmarshall- Returns:
- the unmarshalled XMLObject
- Throws:
XMLParserException
- if there is a problem parsing the input dataUnmarshallingException
- if there is a problem unmarshalling the parsed DOM
-
unmarshallFromReader
public static XMLObject unmarshallFromReader(ParserPool parserPool, Reader reader) throws XMLParserException, UnmarshallingException Unmarshall a Document from a Reader.- Parameters:
parserPool
- the ParserPool instance to usereader
- the Reader to unmarshall- Returns:
- the unmarshalled XMLObject
- Throws:
XMLParserException
- if there is a problem parsing the input dataUnmarshallingException
- if there is a problem unmarshalling the parsed DOM
-
marshall
Marshall an XMLObject. If the XMLObject already has a cached DOM viaXMLObject.getDOM()
, that Element will be returned. Otherwise the object will be fully marshalled and that Element returned.- Parameters:
xmlObject
- the XMLObject to marshall- Returns:
- the marshalled Element
- Throws:
MarshallingException
- if there is a problem marshalling the XMLObject
-
marshallToOutputStream
public static void marshallToOutputStream(XMLObject xmlObject, OutputStream outputStream) throws MarshallingException Marshall an XMLObject to an OutputStream.- Parameters:
xmlObject
- the XMLObject to marshalloutputStream
- the OutputStream to which to marshall- Throws:
MarshallingException
- if there is a problem marshalling the object
-
lookupNamespaceURI
Get the namespace URI bound to the specified prefix within the scope of the specified XMLObject.- Parameters:
xmlObject
- the XMLObject from which to searchprefix
- the prefix to search- Returns:
- the namespace URI bound to the prefix, or none if not found
-
lookupNamespacePrefix
Get the prefix bound to the specified namespace URI within the scope of the specified XMLObject.- Parameters:
xmlObject
- the XMLObject from which to searchnamespaceURI
- the namespace URI to search- Returns:
- the prefix bound to the namespace URI, or none if not found
-
marshallAttribute
public static void marshallAttribute(QName attributeName, List<String> attributeValues, Element domElement, boolean isIDAttribute) Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names appear in namespace-qualified form.- Parameters:
attributeName
- the attribute name in QName formattributeValues
- the attribute valuesdomElement
- the target element to which to marshallisIDAttribute
- flag indicating whether the attribute being marshalled should be handled as an ID-typed attribute
-
marshallAttribute
public static void marshallAttribute(QName attributeName, String attributeValue, Element domElement, boolean isIDAttribute) Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names appear in namespace-qualified form.- Parameters:
attributeName
- the attribute name in QName formattributeValue
- the attribute valuedomElement
- the target element to which to marshallisIDAttribute
- flag indicating whether the attribute being marshalled should be handled as an ID-typed attribute
-
marshallAttributeMap
Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.- Parameters:
attributeMap
- the AttributeMapdomElement
- the target Element
-
marshallAttributeMapIDness
Marshall the ID-ness of attributes represented by the indicated AttributeMap into the indicated DOM Element.- Parameters:
attributeMap
- the AttributeMapdomElement
- the target Element
-
marshallAttributeIDness
public static void marshallAttributeIDness(QName attributeName, Element domElement, boolean isIDAttribute) Marshall the ID-ness of an attribute into the indicated DOM Element.- Parameters:
attributeName
- the attribute QNamedomElement
- the target ElementisIDAttribute
- true if attribute is an ID attribute, false if not
-
marshallAttributeIDness
public static void marshallAttributeIDness(String namespaceURI, String localPart, Element domElement, boolean isIDAttribute) Marshall the ID-ness of an attribute into the indicated DOM Element.- Parameters:
namespaceURI
- the attribute name's namespace URIlocalPart
- the attribute name's local partdomElement
- the target ElementisIDAttribute
- true if attribute is an ID attribute, false if not
-
unmarshallToAttributeMap
Unmarshall a DOM Attr to an AttributeMap.- Parameters:
attributeMap
- the target AttributeMapattribute
- the target DOM Attr
-
buildXMLObject
Build an XMLObject based on the element name.- Parameters:
elementName
- the element name- Returns:
- an XMLObject
- Throws:
XMLRuntimeException
- if the required builder can not be obtained
-
buildXMLObject
Build an XMLObject based on the element nane and xsi:type.- Parameters:
elementName
- the element nametypeName
- the xsi:type- Returns:
- an XMLObject
- Throws:
XMLRuntimeException
- if the required builder can not be obtained
-
getBuilder
Obtain an XMLObject builder for the given QName.- Parameters:
typeOrName
- the element name or type- Returns:
- an XMLObject builder, or null if no provider registered
-
getMarshaller
Obtain an XMLObject marshaller for the given QName.- Parameters:
typeOrName
- the element name or type- Returns:
- an XMLObject marshaller, or null if no provider registered
-
getMarshaller
Obtain an XMLObject marshaller for the given XMLObject.- Parameters:
xmlObject
- the XMLObject to be marshalled- Returns:
- an XMLObject marshaller, or null if no provider registered
-
getUnmarshaller
Obtain an XMLObject unmarshaller for the given QName.- Parameters:
typeOrName
- the element name or type- Returns:
- an XMLObject unmarshaller, or null if no provider registered
-
getUnmarshaller
Obtain an XMLObject unmarshaller for the given DOM Element.- Parameters:
element
- the DOM element- Returns:
- an XMLObject unmarshaller, or null if no provider registered
-
getProviderRegistry
Obtain the XMLObject provider registry.- Returns:
- the configured XMLObject provider registry
- Throws:
XMLRuntimeException
- if the registry is not available
-