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 enumOptions for handling output of XMLObject cloning. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 XMLObjectProviderRegistryObtain 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 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.
-
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(@Nonnull 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
@Nonnull public static <T extends XMLObject> T cloneXMLObject(@Nonnull 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
-
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(@Nonnull XMLObject xmlObject, @Nonnull 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(@Nonnull QName attributeName, @Nonnull List<String> attributeValues, @Nonnull 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(@Nonnull QName attributeName, @Nullable String attributeValue, @Nonnull 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(@Nonnull AttributeMap attributeMap, @Nonnull 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(@Nonnull AttributeMap attributeMap, @Nonnull 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(@Nonnull AttributeMap attributeMap, @Nonnull Attr attribute) 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
@Nonnull public static XMLObject buildXMLObject(@Nonnull QName elementName, @Nullable 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
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
-