* limitations under the License.\r
*/\r
\r
-/* NDC.cpp\r
+/**\r
+ * @file NDC.cpp\r
* \r
* Diagnostic context for logging \r
- * \r
- * $Id:$\r
*/\r
\r
#include "internal.h"\r
\r
#include <log4cpp/NDC.hh>\r
\r
-using namespace std;\r
using namespace xmltooling;\r
\r
NDC::NDC(const char* context)\r
log4cpp::NDC::push(context);\r
}\r
\r
-NDC::NDC(const string& context)\r
+NDC::NDC(const std::string& context)\r
{\r
log4cpp::NDC::push(context);\r
}\r
*/\r
~NDC();\r
\r
- private:\r
- NDC(const NDC&);\r
- NDC& operator=(const NDC&);\r
+ MAKE_NONCOPYABLE(NDC);\r
};\r
\r
};\r
--- /dev/null
+/*\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 XMLConstants.cpp\r
+ * \r
+ * Fundamental XML namespace constants \r
+ */\r
+\r
+\r
+#include "internal.h"\r
+#include "util/XMLConstants.h"\r
+#include <xercesc/util/XMLUniDefs.hpp>\r
+\r
+using namespace xercesc;\r
+using namespace xmltooling;\r
+ \r
+const XMLCh XMLConstants::XML_NS[] = // http://www.w3.org/XML/1998/namespace\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chLatin_X, chLatin_M, chLatin_L, chForwardSlash, chDigit_1, chDigit_9, chDigit_9, chDigit_8, chForwardSlash,\r
+ chLatin_n, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XMLNS_NS[] = // http://www.w3.org/2000/xmlns/\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chDigit_2, chDigit_0, chDigit_0, chDigit_0, chForwardSlash,\r
+ chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chForwardSlash, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XMLNS_PREFIX[] = { chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull };\r
+\r
+const XMLCh XMLConstants::XSD_NS[] = // http://www.w3.org/2001/XMLSchema\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chDigit_2, chDigit_0, chDigit_0, chDigit_1, chForwardSlash,\r
+ chLatin_X, chLatin_M, chLatin_L, chLatin_S, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XSD_PREFIX[] = { chLatin_x, chLatin_s, chNull };\r
+\r
+const XMLCh XMLConstants::XSI_NS[] = // http://www.w3.org/2001/XMLSchema-instance\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chDigit_2, chDigit_0, chDigit_0, chDigit_1, chForwardSlash,\r
+ chLatin_X, chLatin_M, chLatin_L, chLatin_S, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chDash,\r
+ chLatin_i, chLatin_n, chLatin_s, chLatin_t, chLatin_a, chLatin_n, chLatin_c, chLatin_e, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XSI_PREFIX[] = { chLatin_x, chLatin_s, chLatin_i, chNull };\r
+\r
+const XMLCh XMLConstants::XMLSIG_NS[] = // http://www.w3.org/2000/09/xmldsig#\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chDigit_2, chDigit_0, chDigit_0, chDigit_0, chForwardSlash, chDigit_0, chDigit_9, chForwardSlash,\r
+ chLatin_x, chLatin_m, chLatin_l, chLatin_d, chLatin_s, chLatin_i, chLatin_g, chPound, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XMLSIG_PREFIX[] = { chLatin_d, chLatin_s, chNull };\r
+\r
+const XMLCh XMLConstants::XMLENC_NS[] = // http://www.w3.org/2001/04/xmlenc#\r
+{ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
+ chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
+ chDigit_2, chDigit_0, chDigit_0, chDigit_1, chForwardSlash, chDigit_0, chDigit_4, chForwardSlash,\r
+ chLatin_x, chLatin_m, chLatin_l, chLatin_e, chLatin_n, chLatin_c, chPound, chNull\r
+};\r
+\r
+const XMLCh XMLConstants::XMLENC_PREFIX[] = { chLatin_x, chLatin_e, chLatin_n, chLatin_c, chNull };\r
--- /dev/null
+/*\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 XMLConstants.h\r
+ * \r
+ * Fundamental XML namespace constants \r
+ */\r
+\r
+#if !defined(__xmltooling_xmlconstants_h__)\r
+#define __xmltooling_xmlconstants_h__\r
+\r
+#include <xmltooling/unicode.h>\r
+\r
+namespace xmltooling {\r
+ \r
+ /**\r
+ * XML related constants.\r
+ */\r
+ struct XMLTOOL_API XMLConstants\r
+ {\r
+ /** XML core namespace ("http://www.w3.org/XML/1998/namespace") */\r
+ static const XMLCh XML_NS[]; \r
+ \r
+ /** XML namespace for xmlns attributes ("http://www.w3.org/2000/xmlns/") */\r
+ static const XMLCh XMLNS_NS[];\r
+ \r
+ /** XML namespace prefix for xmlns attributes ("xmlns") */\r
+ static const XMLCh XMLNS_PREFIX[];\r
+ \r
+ /** XML Schema namespace ("http://www.w3.org/2001/XMLSchema") */\r
+ static const XMLCh XSD_NS[];\r
+ \r
+ /** XML Schema QName prefix ("xs") */\r
+ static const XMLCh XSD_PREFIX[];\r
+ \r
+ /** XML Schema Instance namespace ("http://www.w3.org/2001/XMLSchema-instance") */\r
+ static const XMLCh XSI_NS[];\r
+ \r
+ /** XML Schema Instance QName prefix ("xsi") */\r
+ static const XMLCh XSI_PREFIX[];\r
+ \r
+ /** XML Signature namespace ("http://www.w3.org/2000/09/xmldsig#") */\r
+ static const XMLCh XMLSIG_NS[];\r
+ \r
+ /** XML Signature QName prefix ("ds") */\r
+ static const XMLCh XMLSIG_PREFIX[];\r
+ \r
+ /** XML Encryption namespace ("http://www.w3.org/2001/04/xmlenc#") */\r
+ static const XMLCh XMLENC_NS[];\r
+ \r
+ /** XML Encryption QName prefix ("xenc") */\r
+ static const XMLCh XMLENC_PREFIX[];\r
+ };\r
+\r
+};\r
+\r
+#endif /* __xmltooling_xmlconstants_h__ */\r
--- /dev/null
+/*\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.cpp\r
+ * \r
+ * A helper class for working with W3C DOM objects. \r
+ */\r
+\r
+#include "internal.h"\r
+#include "util/XMLHelper.h"\r
+#include "util/XMLConstants.h"\r
+\r
+#include <xercesc/util/XMLUniDefs.hpp>\r
+\r
+using namespace xmltooling;\r
+\r
+static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull };\r
+ \r
+bool XMLHelper::hasXSIType(DOMElement* e)\r
+{\r
+ if (e) {\r
+ if (e->hasAttributeNS(XMLConstants::XSI_NS, type)) {\r
+ return true;\r
+ }\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+QName* XMLHelper::getXSIType(DOMElement* e)\r
+{\r
+ DOMAttr* attribute = e->getAttributeNodeNS(XMLConstants::XSI_NS, type);\r
+ if (attribute) {\r
+ int i;\r
+ const XMLCh* attributeValue = attribute->getTextContent();\r
+ if (attributeValue && (i=XMLString::indexOf(attributeValue,chColon))>0) {\r
+ XMLCh* prefix=new XMLCh[i+1];\r
+ XMLString::subString(prefix,attributeValue,0,i);\r
+ prefix[i]=chNull;\r
+ QName* ret=new QName(e->lookupNamespaceURI(prefix), attributeValue + i + 1, prefix);\r
+ delete[] prefix;\r
+ return ret;\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+DOMAttr* XMLHelper::getIdAttribute(DOMElement* domElement)\r
+{\r
+ if(!domElement->hasAttributes()) {\r
+ return NULL;\r
+ }\r
+ \r
+ DOMNamedNodeMap* attributes = domElement->getAttributes();\r
+ DOMAttr* attribute;\r
+ for(XMLSize_t i = 0; i < attributes->getLength(); i++) {\r
+ attribute = static_cast<DOMAttr*>(attributes->item(i));\r
+ if(attribute->isId()) {\r
+ return attribute;\r
+ }\r
+ }\r
+ \r
+ return NULL;\r
+}\r
+\r
+QName* XMLHelper::getNodeQName(DOMNode* domNode)\r
+{\r
+ if (domNode)\r
+ return new QName(domNode->getNamespaceURI(), domNode->getLocalName(), domNode->getPrefix());\r
+ return NULL; \r
+}\r
+\r
+QName* XMLHelper::getAttributeValueAsQName(DOMAttr* attribute)\r
+{\r
+ if (!attribute)\r
+ return NULL;\r
+ \r
+ int i;\r
+ const XMLCh* attributeValue=attribute->getTextContent();\r
+ if (attributeValue && (i=XMLString::indexOf(attributeValue,chColon))>0) {\r
+ XMLCh* prefix=new XMLCh[i+1];\r
+ XMLString::subString(prefix,attributeValue,0,i);\r
+ prefix[i]=chNull;\r
+ QName* ret=new QName(attribute->lookupNamespaceURI(prefix), attributeValue + i + 1, prefix);\r
+ delete[] prefix;\r
+ return ret;\r
+ }\r
+ \r
+ return new QName(attribute->lookupNamespaceURI(NULL), attributeValue);\r
+}\r
+\r
+DOMElement* XMLHelper::appendChildElement(DOMElement* parentElement, DOMElement* childElement)\r
+{\r
+ DOMDocument* parentDocument = parentElement->getOwnerDocument();\r
+ if (childElement->getOwnerDocument() != parentDocument) {\r
+ childElement = static_cast<DOMElement*>(parentDocument->importNode(childElement, true));\r
+ }\r
+\r
+ parentElement->appendChild(childElement);\r
+ return childElement;\r
+}\r
--- /dev/null
+/*\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
+#if !defined(__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
+ * 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(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(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(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(DOMNode* domNode);\r
+\r
+ /**\r
+ * Constructs a QName from an attributes value.\r
+ * \r
+ * @param attribute the attribute with a QName value\r
+ * @return a QName from an attributes value, or null if the given attribute is null\r
+ */\r
+ static QName* getAttributeValueAsQName(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
+};\r
+\r
+#endif /* __xmltooling_xmlhelper_h__ */\r