-/*\r
- * Copyright 2001-2006 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * @file XMLHelper.h\r
- * \r
- * A helper class for working with W3C DOM objects. \r
- */\r
-\r
-#ifndef __xmltooling_xmlhelper_h__\r
-#define __xmltooling_xmlhelper_h__\r
-\r
-#include <xmltooling/QName.h>\r
-#include <xercesc/dom/DOM.hpp>\r
-\r
-using namespace xercesc;\r
-\r
-namespace xmltooling {\r
- \r
- /**\r
- * RAII wrapper for Xerces resources.\r
- */\r
- template<class T> class XercesJanitor\r
- {\r
- MAKE_NONCOPYABLE(XercesJanitor);\r
- T* m_held;\r
- public:\r
- XercesJanitor(T* resource) : m_held(resource) {}\r
- \r
- ~XercesJanitor() {\r
- if (m_held)\r
- m_held->release();\r
- }\r
- \r
- /**\r
- * Returns resource held by this object and releases it to the caller.\r
- * \r
- * @return the resource held or NULL\r
- */\r
- T* release() {\r
- T* ret=m_held;\r
- m_held=NULL;\r
- return ret;\r
- }\r
- };\r
- \r
- /**\r
- * A helper class for working with W3C DOM objects. \r
- */\r
- class XMLTOOL_API XMLHelper\r
- {\r
- public:\r
- /**\r
- * Checks if the given element has an xsi:type defined for it\r
- * \r
- * @param e the DOM element\r
- * @return true if there is a type, false if not\r
- */\r
- static bool hasXSIType(const DOMElement* e);\r
-\r
- /**\r
- * Gets the XSI type for a given element if it has one.\r
- * \r
- * @param e the element\r
- * @return the type or null\r
- */\r
- static QName* getXSIType(const DOMElement* e);\r
-\r
- /**\r
- * Gets the ID attribute of a DOM element.\r
- * \r
- * @param domElement the DOM element\r
- * @return the ID attribute or null if there isn't one\r
- */\r
- static DOMAttr* getIdAttribute(const DOMElement* domElement);\r
-\r
- /**\r
- * Gets the QName for the given DOM node.\r
- * \r
- * @param domNode the DOM node\r
- * @return the QName for the element or null if the element was null\r
- */\r
- static QName* getNodeQName(const DOMNode* domNode);\r
-\r
- /**\r
- * Constructs a QName from an attribute's value.\r
- * \r
- * @param attribute the attribute with a QName value\r
- * @return a QName from an attribute's value, or null if the given attribute is null\r
- */\r
- static QName* getAttributeValueAsQName(const DOMAttr* attribute);\r
-\r
- /**\r
- * Appends the child Element to the parent Element,\r
- * importing the child Element into the parent's Document if needed.\r
- * \r
- * @param parentElement the parent Element\r
- * @param childElement the child Element\r
- * @return the child Element that was added (may be an imported copy)\r
- */\r
- static DOMElement* appendChildElement(DOMElement* parentElement, DOMElement* childElement);\r
- \r
- /**\r
- * Checks the qualified name of a node.\r
- * \r
- * @param n node to check\r
- * @param ns namespace to compare with\r
- * @param local local name to compare with\r
- * @return true iff the node's qualified name matches the other parameters\r
- */\r
- static bool isNodeNamed(const DOMNode* n, const XMLCh* ns, const XMLCh* local) {\r
- return (n && XMLString::equals(local,n->getLocalName()) && XMLString::equals(ns,n->getNamespaceURI()));\r
- }\r
-\r
- /**\r
- * Returns the first matching child element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param localName local name to compare with or NULL for any match\r
- * @return the first matching child node of type Element, or NULL\r
- */\r
- static DOMElement* getFirstChildElement(const DOMNode* n, const XMLCh* localName=NULL);\r
- \r
- /**\r
- * Returns the last matching child element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param localName local name to compare with or NULL for any match\r
- * @return the last matching child node of type Element, or NULL\r
- */\r
- static DOMElement* getLastChildElement(const DOMNode* n, const XMLCh* localName=NULL);\r
- \r
- /**\r
- * Returns the next matching sibling element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param localName local name to compare with or NULL for any match\r
- * @return the next matching sibling node of type Element, or NULL\r
- */\r
- static DOMElement* getNextSiblingElement(const DOMNode* n, const XMLCh* localName=NULL);\r
- \r
- /**\r
- * Returns the previous matching sibling element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param localName local name to compare with or NULL for any match\r
- * @return the previous matching sibling node of type Element, or NULL\r
- */\r
- static DOMElement* getPreviousSiblingElement(const DOMNode* n, const XMLCh* localName=NULL);\r
- \r
- /**\r
- * Returns the first matching child element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param ns namespace to compare with\r
- * @param localName local name to compare with\r
- * @return the first matching child node of type Element, or NULL\r
- */\r
- static DOMElement* getFirstChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);\r
- \r
- /**\r
- * Returns the last matching child element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param ns namespace to compare with\r
- * @param localName local name to compare with\r
- * @return the last matching child node of type Element, or NULL\r
- */\r
- static DOMElement* getLastChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);\r
- \r
- /**\r
- * Returns the next matching sibling element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param ns namespace to compare with\r
- * @param localName local name to compare with\r
- * @return the next matching sibling node of type Element, or NULL\r
- */\r
- static DOMElement* getNextSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);\r
- \r
- /**\r
- * Returns the previous matching sibling element of the node if any.\r
- * \r
- * @param n node to check\r
- * @param ns namespace to compare with\r
- * @param localName local name to compare with\r
- * @return the previous matching sibling node of type Element, or NULL\r
- */\r
- static DOMElement* getPreviousSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);\r
-\r
- /**\r
- * Returns the content of the first Text node found in the element, if any.\r
- * This is roughly similar to the DOM getTextContent function, but only\r
- * examples the immediate children of the element.\r
- *\r
- * @param e element to examine\r
- * @return the content of the first Text node found, or NULL\r
- */\r
- static const XMLCh* getTextContent(const DOMElement* e);\r
-\r
- /**\r
- * Serializes the DOM Element provided into a buffer using UTF-8 encoding and\r
- * the default XML serializer available. No manipulation or formatting is applied.\r
- * \r
- * @param e element to serialize\r
- * @param buf buffer to serialize element into\r
- */\r
- static void serialize(const DOMElement* e, std::string& buf);\r
- };\r
-\r
-};\r
-\r
-#endif /* __xmltooling_xmlhelper_h__ */\r
+/*
+ * Copyright 2001-2006 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file XMLHelper.h
+ *
+ * A helper class for working with W3C DOM objects.
+ */
+
+#ifndef __xmltooling_xmlhelper_h__
+#define __xmltooling_xmlhelper_h__
+
+#include <xmltooling/QName.h>
+#include <xercesc/dom/DOM.hpp>
+
+using namespace xercesc;
+
+namespace xmltooling {
+
+ /**
+ * RAII wrapper for Xerces resources.
+ */
+ template<class T> class XercesJanitor
+ {
+ MAKE_NONCOPYABLE(XercesJanitor);
+ T* m_held;
+ public:
+ XercesJanitor(T* resource) : m_held(resource) {}
+
+ ~XercesJanitor() {
+ if (m_held)
+ m_held->release();
+ }
+
+ /**
+ * Returns resource held by this object and releases it to the caller.
+ *
+ * @return the resource held or NULL
+ */
+ T* release() {
+ T* ret=m_held;
+ m_held=NULL;
+ return ret;
+ }
+ };
+
+ /**
+ * A helper class for working with W3C DOM objects.
+ */
+ class XMLTOOL_API XMLHelper
+ {
+ public:
+ /**
+ * Checks if the given element has an xsi:type defined for it
+ *
+ * @param e the DOM element
+ * @return true if there is a type, false if not
+ */
+ static bool hasXSIType(const DOMElement* e);
+
+ /**
+ * Gets the XSI type for a given element if it has one.
+ *
+ * @param e the element
+ * @return the type or null
+ */
+ static QName* getXSIType(const DOMElement* e);
+
+ /**
+ * Gets the ID attribute of a DOM element.
+ *
+ * @param domElement the DOM element
+ * @return the ID attribute or null if there isn't one
+ */
+ static DOMAttr* getIdAttribute(const DOMElement* domElement);
+
+ /**
+ * Gets the QName for the given DOM node.
+ *
+ * @param domNode the DOM node
+ * @return the QName for the element or null if the element was null
+ */
+ static QName* getNodeQName(const DOMNode* domNode);
+
+ /**
+ * Constructs a QName from an attribute's value.
+ *
+ * @param attribute the attribute with a QName value
+ * @return a QName from an attribute's value, or null if the given attribute is null
+ */
+ static QName* getAttributeValueAsQName(const DOMAttr* attribute);
+
+ /**
+ * Appends the child Element to the parent Element,
+ * importing the child Element into the parent's Document if needed.
+ *
+ * @param parentElement the parent Element
+ * @param childElement the child Element
+ * @return the child Element that was added (may be an imported copy)
+ */
+ static DOMElement* appendChildElement(DOMElement* parentElement, DOMElement* childElement);
+
+ /**
+ * Checks the qualified name of a node.
+ *
+ * @param n node to check
+ * @param ns namespace to compare with
+ * @param local local name to compare with
+ * @return true iff the node's qualified name matches the other parameters
+ */
+ static bool isNodeNamed(const DOMNode* n, const XMLCh* ns, const XMLCh* local) {
+ return (n && XMLString::equals(local,n->getLocalName()) && XMLString::equals(ns,n->getNamespaceURI()));
+ }
+
+ /**
+ * Returns the first matching child element of the node if any.
+ *
+ * @param n node to check
+ * @param localName local name to compare with or NULL for any match
+ * @return the first matching child node of type Element, or NULL
+ */
+ static DOMElement* getFirstChildElement(const DOMNode* n, const XMLCh* localName=NULL);
+
+ /**
+ * Returns the last matching child element of the node if any.
+ *
+ * @param n node to check
+ * @param localName local name to compare with or NULL for any match
+ * @return the last matching child node of type Element, or NULL
+ */
+ static DOMElement* getLastChildElement(const DOMNode* n, const XMLCh* localName=NULL);
+
+ /**
+ * Returns the next matching sibling element of the node if any.
+ *
+ * @param n node to check
+ * @param localName local name to compare with or NULL for any match
+ * @return the next matching sibling node of type Element, or NULL
+ */
+ static DOMElement* getNextSiblingElement(const DOMNode* n, const XMLCh* localName=NULL);
+
+ /**
+ * Returns the previous matching sibling element of the node if any.
+ *
+ * @param n node to check
+ * @param localName local name to compare with or NULL for any match
+ * @return the previous matching sibling node of type Element, or NULL
+ */
+ static DOMElement* getPreviousSiblingElement(const DOMNode* n, const XMLCh* localName=NULL);
+
+ /**
+ * Returns the first matching child element of the node if any.
+ *
+ * @param n node to check
+ * @param ns namespace to compare with
+ * @param localName local name to compare with
+ * @return the first matching child node of type Element, or NULL
+ */
+ static DOMElement* getFirstChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);
+
+ /**
+ * Returns the last matching child element of the node if any.
+ *
+ * @param n node to check
+ * @param ns namespace to compare with
+ * @param localName local name to compare with
+ * @return the last matching child node of type Element, or NULL
+ */
+ static DOMElement* getLastChildElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);
+
+ /**
+ * Returns the next matching sibling element of the node if any.
+ *
+ * @param n node to check
+ * @param ns namespace to compare with
+ * @param localName local name to compare with
+ * @return the next matching sibling node of type Element, or NULL
+ */
+ static DOMElement* getNextSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);
+
+ /**
+ * Returns the previous matching sibling element of the node if any.
+ *
+ * @param n node to check
+ * @param ns namespace to compare with
+ * @param localName local name to compare with
+ * @return the previous matching sibling node of type Element, or NULL
+ */
+ static DOMElement* getPreviousSiblingElement(const DOMNode* n, const XMLCh* ns, const XMLCh* localName);
+
+ /**
+ * Returns the content of the first Text node found in the element, if any.
+ * This is roughly similar to the DOM getTextContent function, but only
+ * examples the immediate children of the element.
+ *
+ * @param e element to examine
+ * @return the content of the first Text node found, or NULL
+ */
+ static const XMLCh* getTextContent(const DOMElement* e);
+
+ /**
+ * Serializes the DOM Element provided into a buffer using UTF-8 encoding and
+ * the default XML serializer available. No manipulation or formatting is applied.
+ *
+ * @param e element to serialize
+ * @param buf buffer to serialize element into
+ */
+ static void serialize(const DOMElement* e, std::string& buf);
+ };
+
+};
+
+#endif /* __xmltooling_xmlhelper_h__ */