Package org.opensaml.core.xml.util
Class XMLObjectSupport
- java.lang.Object
-
- org.opensaml.core.xml.util.XMLObjectSupport
-
public final class XMLObjectSupport extends Object
A helper class for working with XMLObjects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXMLObjectSupport.CloneOutputOptionOptions for handling output of XMLObject cloning.
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerLOGLogger.
-
Constructor Summary
Constructors Modifier Constructor Description privateXMLObjectSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XMLObjectbuildXMLObject(QName elementName)Build an XMLObject based on the element name.static XMLObjectbuildXMLObject(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 MarshallergetMarshaller(QName typeOrName)Obtain an XMLObject marshaller for the given QName.static MarshallergetMarshaller(XMLObject xmlObject)Obtain an XMLObject marshaller for the given XMLObject.private static XMLObjectProviderRegistrygetProviderRegistry()Obtain the XMLObject provider registry.static UnmarshallergetUnmarshaller(QName typeOrName)Obtain an XMLObject unmarshaller for the given QName.static UnmarshallergetUnmarshaller(Element element)Obtain an XMLObject unmarshaller for the given DOM Element.static StringlookupNamespacePrefix(XMLObject xmlObject, String namespaceURI)Get the prefix bound to the specified namespace URI within the scope of the specified XMLObject.static StringlookupNamespaceURI(XMLObject xmlObject, String prefix)Get the namespace URI bound to the specified prefix within the scope of the specified XMLObject.static Elementmarshall(XMLObject xmlObject)Marshall an XMLObject.static voidmarshallAttribute(QName attributeName, String attributeValue, Element domElement, boolean isIDAttribute)Marshall an attribute name and value to a DOM Element.static voidmarshallAttribute(QName attributeName, List<String> attributeValues, Element domElement, boolean isIDAttribute)Marshall an attribute name and value to a DOM Element.static voidmarshallAttributeIDness(String namespaceURI, String localPart, Element domElement, boolean isIDAttribute)Marshall the ID-ness of an attribute into the indicated DOM Element.static voidmarshallAttributeIDness(QName attributeName, Element domElement, boolean isIDAttribute)Marshall the ID-ness of an attribute into the indicated DOM Element.static voidmarshallAttributeMap(AttributeMap attributeMap, Element domElement)Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.static voidmarshallAttributeMapIDness(AttributeMap attributeMap, Element domElement)Marshall the ID-ness of attributes represented by the indicated AttributeMap into the indicated DOM Element.static voidmarshallToOutputStream(XMLObject xmlObject, OutputStream outputStream)Marshall an XMLObject to an OutputStream.static XMLObjectunmarshallFromInputStream(ParserPool parserPool, InputStream inputStream)Unmarshall a Document from an InputSteam.static XMLObjectunmarshallFromReader(ParserPool parserPool, Reader reader)Unmarshall a Document from a Reader.static voidunmarshallToAttributeMap(AttributeMap attributeMap, Attr attribute)Unmarshall a DOM Attr to an AttributeMap.
-
-
-
Method Detail
-
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
@Nonnull public static Element marshall(@Nonnull XMLObject xmlObject) throws MarshallingException
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
public static String lookupNamespaceURI(XMLObject xmlObject, String prefix)
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
public static String lookupNamespacePrefix(XMLObject xmlObject, String namespaceURI)
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
public static void marshallAttributeMap(AttributeMap attributeMap, Element domElement)
Marshall the attributes represented by the indicated AttributeMap into the indicated DOM Element.- Parameters:
attributeMap- the AttributeMapdomElement- the target Element
-
marshallAttributeMapIDness
public static void marshallAttributeMapIDness(AttributeMap attributeMap, Element domElement)
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
public static void unmarshallToAttributeMap(AttributeMap attributeMap, Attr attribute)
Unmarshall a DOM Attr to an AttributeMap.- Parameters:
attributeMap- the target AttributeMapattribute- the target DOM Attr
-
buildXMLObject
public static XMLObject buildXMLObject(QName elementName)
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
public static XMLObject buildXMLObject(QName elementName, QName typeName)
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
public static XMLObjectBuilder<?> getBuilder(QName typeOrName)
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
public static Marshaller getMarshaller(QName typeOrName)
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
public static Marshaller getMarshaller(XMLObject xmlObject)
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
public static Unmarshaller getUnmarshaller(QName typeOrName)
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
public static Unmarshaller getUnmarshaller(Element element)
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
private static XMLObjectProviderRegistry getProviderRegistry()
Obtain the XMLObject provider registry.- Returns:
- the configured XMLObject provider registry
- Throws:
XMLRuntimeException- if the registry is not available
-
-