#include <algorithm>
#include <functional>
-#include <log4cpp/Category.hh>
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
AbstractDOMCachingXMLObject::~AbstractDOMCachingXMLObject()
void AbstractDOMCachingXMLObject::releaseDOM() const
{
if (m_dom) {
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".DOM");
- if (log.isDebugEnabled()) {
+ if (m_log.isDebugEnabled()) {
string qname=getElementQName().toString();
- log.debug("releasing cached DOM representation for (%s)", qname.empty() ? "unknown" : qname.c_str());
+ m_log.debug("releasing cached DOM representation for (%s)", qname.empty() ? "unknown" : qname.c_str());
}
setDOM(NULL);
}
void AbstractDOMCachingXMLObject::releaseParentDOM(bool propagateRelease) const
{
if (getParent() && getParent()->getDOM()) {
- Category::getInstance(XMLTOOLING_LOGCAT".DOM").debug(
+ m_log.debug(
"releasing cached DOM representation for parent object with propagation set to %s",
propagateRelease ? "true" : "false"
);
void AbstractDOMCachingXMLObject::releaseChildrenDOM(bool propagateRelease) const
{
if (hasChildren()) {
- Category::getInstance(XMLTOOLING_LOGCAT".DOM").debug(
+ m_log.debug(
"releasing cached DOM representation for children with propagation set to %s",
propagateRelease ? "true" : "false"
);
const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(domCopy);
if (!b) {
auto_ptr<QName> q(XMLHelper::getNodeQName(domCopy));
- Category::getInstance(XMLTOOLING_LOGCAT".DOM").error(
+ m_log.error(
"DOM clone failed, unable to locate builder for element (%s)", q->toString().c_str()
);
domCopy->getOwnerDocument()->release();
using namespace xmltooling;
AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
- : m_log(&log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL),
+ : m_log(log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL),
m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL)
{
addNamespace(Namespace(nsURI, prefix));
* An abstract implementation of XMLObject.
*/
-#if !defined(__xmltooling_abstractxmlobj_h__)
+#ifndef __xmltooling_abstractxmlobj_h__
#define __xmltooling_abstractxmlobj_h__
#include <xmltooling/XMLObject.h>
#include <xmltooling/util/DateTime.h>
+#include <log4cpp/Category.hh>
+
#if defined (_MSC_VER)
#pragma warning( push )
#pragma warning( disable : 4250 4251 )
/**
* Logging object.
*/
- void* m_log;
+ log4cpp::Category& m_log;
/**
* Stores off xsi:schemaLocation attribute.
#ifdef _DEBUG
xmltooling::NDC ndc("getBuilder");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObjectBuilder");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject.Builder");
auto_ptr<QName> schemaType(XMLHelper::getXSIType(domElement));
const XMLObjectBuilder* xmlObjectBuilder = schemaType.get() ? getBuilder(*(schemaType.get())) : NULL;
#include "util/NDC.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
XMLObject* AnyElementImpl::clone() const {
#ifdef _DEBUG
xmltooling::NDC ndc("releaseDOM");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".UnknownElementImpl");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject");
log.debug("releasing DOM for unknown content, preserving current DOM in XML form");
// We're losing our DOM, so assuming we have one, we preserve it.
xmltooling::NDC ndc("marshall");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject");
log.debug("marshalling unknown content");
DOMElement* cachedDOM=getDOM();
xmltooling::NDC ndc("marshall");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject");
log.debug("marshalling unknown content");
DOMElement* cachedDOM=getDOM();
}
XMLObject* UnknownElementBuilder::buildObject(
- const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
- ) const {
- return new UnknownElementImpl(nsURI,localName,prefix);
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
+ ) const {
+ return new UnknownElementImpl(nsURI,localName,prefix);
}
#include <algorithm>
#include <functional>
#include <xercesc/util/XMLUniDefs.hpp>
-#include <log4cpp/Category.hh>
#ifndef XMLTOOLING_NO_XMLSEC
using namespace xmlsignature;
#endif
using namespace xmlconstants;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
-#define XT_log (*static_cast<Category*>(m_log))
-
DOMElement* AbstractXMLObjectMarshaller::marshall(
DOMDocument* document
#ifndef XMLTOOLING_NO_XMLSEC
xmltooling::NDC ndc("marshall");
#endif
- if (XT_log.isDebugEnabled()) {
- XT_log.debug("starting to marshal %s", getElementQName().toString().c_str());
+ if (m_log.isDebugEnabled()) {
+ m_log.debug("starting to marshal %s", getElementQName().toString().c_str());
}
DOMElement* cachedDOM=getDOM();
if (cachedDOM) {
if (!document || document==cachedDOM->getOwnerDocument()) {
- XT_log.debug("XMLObject has a usable cached DOM, reusing it");
+ m_log.debug("XMLObject has a usable cached DOM, reusing it");
if (document)
setDocumentElement(cachedDOM->getOwnerDocument(),cachedDOM);
releaseParentDOM(true);
XercesJanitor<DOMDocument> janitor(bindDocument ? document : NULL);
- XT_log.debug("creating root element to marshall");
+ m_log.debug("creating root element to marshall");
DOMElement* domElement = document->createElementNS(
getElementQName().getNamespaceURI(), getElementQName().getLocalPart()
);
marshallInto(domElement);
#endif
//Recache the DOM.
- XT_log.debug("caching DOM for XMLObject (document is %sbound)", bindDocument ? "" : "not ");
+ m_log.debug("caching DOM for XMLObject (document is %sbound)", bindDocument ? "" : "not ");
setDOM(domElement, bindDocument);
janitor.release(); // safely transferred
releaseParentDOM(true);
xmltooling::NDC ndc("marshall");
#endif
- if (XT_log.isDebugEnabled()) {
- XT_log.debug("starting to marshalling %s", getElementQName().toString().c_str());
+ if (m_log.isDebugEnabled()) {
+ m_log.debug("starting to marshalling %s", getElementQName().toString().c_str());
}
DOMElement* cachedDOM=getDOM();
if (cachedDOM) {
if (parentElement->getOwnerDocument()==cachedDOM->getOwnerDocument()) {
- XT_log.debug("XMLObject has a usable cached DOM, reusing it");
+ m_log.debug("XMLObject has a usable cached DOM, reusing it");
if (parentElement!=cachedDOM->getParentNode()) {
parentElement->appendChild(cachedDOM);
releaseParentDOM(true);
}
// If we get here, we didn't have a usable DOM (and/or we released the one we had).
- XT_log.debug("creating root element to marshall");
+ m_log.debug("creating root element to marshall");
DOMElement* domElement = parentElement->getOwnerDocument()->createElementNS(
getElementQName().getNamespaceURI(), getElementQName().getLocalPart()
);
#endif
//Recache the DOM.
- XT_log.debug("caching DOM for XMLObject");
+ m_log.debug("caching DOM for XMLObject");
setDOM(domElement, false);
releaseParentDOM(true);
{
const QName* type = getSchemaType();
if (type) {
- XT_log.debug("setting xsi:type attribute for XMLObject");
+ m_log.debug("setting xsi:type attribute for XMLObject");
const XMLCh* typeLocalName = type->getLocalPart();
if (!typeLocalName || !*typeLocalName) {
if (xsivalue != typeLocalName)
XMLString::release(&xsivalue);
- XT_log.debug("Adding XSI namespace to list of namespaces used by XMLObject");
+ m_log.debug("Adding XSI namespace to list of namespaces used by XMLObject");
addNamespace(Namespace(XSI_NS, XSI_PREFIX));
}
}
void AbstractXMLObjectMarshaller::marshallNamespaces(DOMElement* domElement) const
{
- XT_log.debug("marshalling namespace attributes for XMLObject");
+ m_log.debug("marshalling namespace attributes for XMLObject");
const set<Namespace>& namespaces = getNamespaces();
for_each(namespaces.begin(),namespaces.end(),bind1st(_addns(),domElement));
}
void AbstractXMLObjectMarshaller::marshallContent(DOMElement* domElement) const
{
- XT_log.debug("marshalling text and child elements for XMLObject");
+ m_log.debug("marshalling text and child elements for XMLObject");
const XMLCh* val;
unsigned int pos=0;
#include "util/XMLHelper.h"
#include <xercesc/util/XMLUniDefs.hpp>
-#include <log4cpp/Category.hh>
using namespace xmlconstants;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
-#define XT_log (*static_cast<Category*>(m_log))
XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool bindDocument)
{
throw UnmarshallingException("Unrecognized element supplied to implementation for unmarshalling.");
}
- if (XT_log.isDebugEnabled()) {
+ if (m_log.isDebugEnabled()) {
auto_ptr_char dname(element->getNodeName());
- XT_log.debug("unmarshalling DOM element (%s)", dname.get());
+ m_log.debug("unmarshalling DOM element (%s)", dname.get());
}
if (element->hasAttributes()) {
xmltooling::NDC ndc("unmarshallAttributes");
#endif
- if (XT_log.isDebugEnabled()) {
+ if (m_log.isDebugEnabled()) {
auto_ptr_char dname(domElement->getNodeName());
- XT_log.debug("unmarshalling attributes for DOM element (%s)", dname.get());
+ m_log.debug("unmarshalling attributes for DOM element (%s)", dname.get());
}
DOMNamedNodeMap* attributes = domElement->getAttributes();
if (!attributes) {
- XT_log.debug("no attributes to unmarshall");
+ m_log.debug("no attributes to unmarshall");
return;
}
// The child node should always be an attribute, but just in case
if (childNode->getNodeType() != DOMNode::ATTRIBUTE_NODE) {
- XT_log.debug("encountered child node of type %d in attribute list, ignoring it", childNode->getNodeType());
+ m_log.debug("encountered child node of type %d in attribute list, ignoring it", childNode->getNodeType());
continue;
}
const XMLCh* nsuri=attribute->getNamespaceURI();
if (XMLString::equals(nsuri,XMLNS_NS)) {
if (XMLString::equals(attribute->getLocalName(),XMLNS_PREFIX)) {
- XT_log.debug("found default namespace declaration, adding it to the list of namespaces on the XMLObject");
+ m_log.debug("found default namespace declaration, adding it to the list of namespaces on the XMLObject");
addNamespace(Namespace(attribute->getValue(), NULL, true));
continue;
}
else {
- XT_log.debug("found namespace declaration, adding it to the list of namespaces on the XMLObject");
+ m_log.debug("found namespace declaration, adding it to the list of namespaces on the XMLObject");
addNamespace(Namespace(attribute->getValue(), attribute->getLocalName(), true));
continue;
}
static const XMLCh type[]= UNICODE_LITERAL_4(t,y,p,e);
static const XMLCh schemaLocation[]= UNICODE_LITERAL_14(s,c,h,e,m,a,L,o,c,a,t,i,o,n);
if (XMLString::equals(attribute->getLocalName(),type)) {
- XT_log.debug("skipping xsi:type declaration");
+ m_log.debug("skipping xsi:type declaration");
continue;
}
else if (XMLString::equals(attribute->getLocalName(),schemaLocation)) {
- XT_log.debug("storing off xsi:schemaLocation attribute");
+ m_log.debug("storing off xsi:schemaLocation attribute");
if (m_schemaLocation)
XMLString::release(&m_schemaLocation);
m_schemaLocation=XMLString::replicate(attribute->getValue());
}
}
else if (nsuri && !XMLString::equals(nsuri,XML_NS)) {
- XT_log.debug("found namespace-qualified attribute, adding prefix to the list of namespaces on the XMLObject");
+ m_log.debug("found namespace-qualified attribute, adding prefix to the list of namespaces on the XMLObject");
addNamespace(Namespace(nsuri, attribute->getPrefix()));
}
- XT_log.debug("processing generic attribute");
+ m_log.debug("processing generic attribute");
processAttribute(attribute);
}
}
xmltooling::NDC ndc("unmarshallContent");
#endif
- if (XT_log.isDebugEnabled()) {
+ if (m_log.isDebugEnabled()) {
auto_ptr_char dname(domElement->getNodeName());
- XT_log.debug("unmarshalling child nodes of DOM element (%s)", dname.get());
+ m_log.debug("unmarshalling child nodes of DOM element (%s)", dname.get());
}
DOMNode* childNode = domElement->getFirstChild();
if (!childNode) {
- XT_log.debug("element had no children");
+ m_log.debug("element had no children");
return;
}
const XMLObjectBuilder* builder = XMLObjectBuilder::getBuilder(static_cast<DOMElement*>(childNode));
if (!builder) {
auto_ptr<QName> cname(XMLHelper::getNodeQName(childNode));
- XT_log.error("no default builder installed, found unknown child element (%s)", cname->toString().c_str());
+ m_log.error("no default builder installed, found unknown child element (%s)", cname->toString().c_str());
throw UnmarshallingException("Unmarshaller found unknown child element, but no default builder was found.");
}
- if (XT_log.isDebugEnabled()) {
+ if (m_log.isDebugEnabled()) {
auto_ptr<QName> cname(XMLHelper::getNodeQName(childNode));
- XT_log.debug("unmarshalling child element (%s)", cname->toString().c_str());
+ m_log.debug("unmarshalling child element (%s)", cname->toString().c_str());
}
// Retain ownership of the unmarshalled child until it's processed by the parent.
++position;
}
else if (childNode->getNodeType() == DOMNode::TEXT_NODE) {
- XT_log.debug("processing text content at position (%d)", position);
+ m_log.debug("processing text content at position (%d)", position);
setTextContent(childNode->getNodeValue(), position);
}
xmltooling::NDC ndc("marshall");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Signature");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject.Signature");
log.debug("marshalling ds:Signature");
DOMElement* cachedDOM=getDOM();
xmltooling::NDC ndc("marshall");
#endif
- Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Signature");
+ Category& log=Category::getInstance(XMLTOOLING_LOGCAT".XMLObject.Signature");
log.debug("marshalling ds:Signature");
DOMElement* cachedDOM=getDOM();
XMLObject* XMLSecSignatureImpl::unmarshall(DOMElement* element, bool bindDocument)
{
- Category::getInstance(XMLTOOLING_LOGCAT".Signature").debug("unmarshalling ds:Signature");
+ Category::getInstance(XMLTOOLING_LOGCAT".XMLObject.Signature").debug("unmarshalling ds:Signature");
try {
m_signature=XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->newSignatureFromDOM(
log.debug("asked to resolve %s with baseURI %s",sysId.get(),base.get() ? base.get() : "(null)");
}
- // Find well-known schemas in the specified location.
#ifdef HAVE_GOOD_STL
+ // Find well-known schemas in the specified location.
map<xstring,xstring>::const_iterator i=m_schemaLocMap.find(systemId);
if (i!=m_schemaLocMap.end())
- return new Wrapper4InputSource(new LocalFileInputSource(NULL,i->second.c_str()));
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,i->second.c_str()));
+
+ // We'll allow anything without embedded slashes.
+ if (XMLString::indexOf(systemId, chForwardSlash)==-1)
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,systemId));
+
+ // Check for entity as a value in the map.
+ for (i=m_schemaLocMap.begin(); i!=m_schemaLocMap.end(); ++i) {
+ if (XMLString::endsWith(i->second.c_str(), systemId))
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,i->second.c_str()));
+ }
#else
+ // Find well-known schemas in the specified location.
auto_ptr_char temp(systemId);
map<string,string>::const_iterator i=m_schemaLocMap.find(temp.get());
if (i!=m_schemaLocMap.end()) {
auto_ptr_XMLCh temp2(i->second.c_str());
- return new Wrapper4InputSource(new LocalFileInputSource(NULL,temp2.get()));
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,temp2.get()));
+ }
+
+ // We'll allow anything without embedded slashes.
+ if (XMLString::indexOf(systemId, chForwardSlash)==-1)
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,systemId));
+
+ // Check for entity as a value in the map.
+ for (i=m_schemaLocMap.begin(); i!=m_schemaLocMap.end(); ++i) {
+ if (XMLString::endsWith(i->second.c_str(), temp.get())) {
+ auto_ptr_XMLCh temp2(i->second.c_str());
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI,temp2.get()));
+ }
}
#endif
// Shortcircuit the request.
- auto_ptr_char sysId(systemId);
- log.warn("unauthorized entity request (%s), blocking it", sysId.get() ? sysId.get() : "no systemId");
+#ifdef HAVE_GOOD_STL
+ auto_ptr_char temp(systemId);
+#endif
+ log.warn("unauthorized entity request (%s), blocking it", temp.get());
static const XMLByte nullbuf[] = {0};
return new Wrapper4InputSource(new MemBufInputSource(nullbuf,0,systemId));
}