Added Xerces-C++ 3.1.2

This commit is contained in:
sippeangelo
2015-12-01 10:23:50 +01:00
parent 65d3f3bc31
commit 1b478d3159
815 changed files with 262638 additions and 0 deletions
@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/framework/XMLElementDecl.hpp>
#include <xercesc/validators/DTD/DTDAttDef.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DTDAttDef: Constructors and Destructor
// ---------------------------------------------------------------------------
DTDAttDef::DTDAttDef(MemoryManager* const manager) :
XMLAttDef(XMLAttDef::CData, XMLAttDef::Implied, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fName(0)
{
}
DTDAttDef::DTDAttDef(const XMLCh* const attName
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, MemoryManager* const manager) :
XMLAttDef(type, defType, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fName(0)
{
fName = XMLString::replicate(attName, getMemoryManager());
}
DTDAttDef::DTDAttDef( const XMLCh* const attName
, const XMLCh* const attValue
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, const XMLCh* const enumValues
, MemoryManager* const manager) :
XMLAttDef(attValue, type, defType, enumValues, manager)
, fElemId(XMLElementDecl::fgInvalidElemId)
, fName(0)
{
fName = XMLString::replicate(attName, getMemoryManager());
}
DTDAttDef::~DTDAttDef()
{
getMemoryManager()->deallocate(fName); //delete [] fName;
}
// ---------------------------------------------------------------------------
// DTDAttDef: Setter methods
// ---------------------------------------------------------------------------
void DTDAttDef::setName(const XMLCh* const newName)
{
getMemoryManager()->deallocate(fName); //delete [] fName;
fName = XMLString::replicate(newName, getMemoryManager());
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(DTDAttDef)
void DTDAttDef::serialize(XSerializeEngine& serEng)
{
XMLAttDef::serialize(serEng);
if (serEng.isStoring())
{
serEng.writeSize (fElemId);
serEng.writeString(fName);
}
else
{
serEng.readSize (fElemId);
serEng.readString(fName);
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,141 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDAttDef.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDATTDEF_HPP)
#define XERCESC_INCLUDE_GUARD_DTDATTDEF_HPP
#include <xercesc/framework/XMLAttDef.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This class is a derivative of the core XMLAttDef class. This class adds
// any DTD specific data members and provides DTD specific implementations
// of any underlying attribute def virtual methods.
//
// In the DTD we don't do namespaces, so the attribute names are just the
// QName literally from the DTD. This is what we return as the full name,
// which is what is used to key these in any name keyed collections.
//
class VALIDATORS_EXPORT DTDAttDef : public XMLAttDef
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructors
// -----------------------------------------------------------------------
DTDAttDef(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
DTDAttDef
(
const XMLCh* const attName
, const XMLAttDef::AttTypes type = CData
, const XMLAttDef::DefAttTypes defType = Implied
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
DTDAttDef
(
const XMLCh* const attName
, const XMLCh* const attValue
, const XMLAttDef::AttTypes type
, const XMLAttDef::DefAttTypes defType
, const XMLCh* const enumValues = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~DTDAttDef();
// -----------------------------------------------------------------------
// Implementation of the XMLAttDef interface
// -----------------------------------------------------------------------
virtual const XMLCh* getFullName() const;
//does nothing currently
virtual void reset() {};
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
XMLSize_t getElemId() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setElemId(const XMLSize_t newId);
void setName(const XMLCh* const newName);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(DTDAttDef)
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDAttDef(const DTDAttDef &);
DTDAttDef& operator = (const DTDAttDef&);
// -----------------------------------------------------------------------
// Private data members
//
// fElemId
// This is the id of the element (the id is into the element decl
// pool) of the element this attribute def said it belonged to.
// This is used later to link back to the element, mostly for
// validation purposes.
//
// fName
// This is the name of the attribute. Since we don't do namespaces
// in the DTD, its just the fully qualified name.
// -----------------------------------------------------------------------
XMLSize_t fElemId;
XMLCh* fName;
};
// ---------------------------------------------------------------------------
// DTDAttDef: Implementation of the XMLAttDef interface
// ---------------------------------------------------------------------------
inline const XMLCh* DTDAttDef::getFullName() const
{
return fName;
}
// ---------------------------------------------------------------------------
// DTDAttDef: Getter methods
// ---------------------------------------------------------------------------
inline XMLSize_t DTDAttDef::getElemId() const
{
return fElemId;
}
// ---------------------------------------------------------------------------
// DTDAttDef: Setter methods
// ---------------------------------------------------------------------------
inline void DTDAttDef::setElemId(const XMLSize_t newId)
{
fElemId = newId;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,188 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/DTD/DTDAttDefList.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DTDAttDefList: Constructors and Destructor
// ---------------------------------------------------------------------------
DTDAttDefList::DTDAttDefList(RefHashTableOf<DTDAttDef>* const listToUse, MemoryManager* const manager)
: XMLAttDefList(manager)
,fEnum(0)
,fList(listToUse)
,fArray(0)
,fSize(0)
,fCount(0)
{
fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(listToUse, false, manager);
fArray = (DTDAttDef **)(manager->allocate( sizeof(DTDAttDef*) << 1));
fSize = 2;
}
DTDAttDefList::~DTDAttDefList()
{
delete fEnum;
(getMemoryManager())->deallocate(fArray);
}
// ---------------------------------------------------------------------------
// DTDAttDefList: Implementation of the virtual interface
// ---------------------------------------------------------------------------
bool DTDAttDefList::isEmpty() const
{
return fList->isEmpty();
}
XMLAttDef* DTDAttDefList::findAttDef(const unsigned int
, const XMLCh* const attName)
{
// We don't use the URI, so we just look up the name
return fList->get(attName);
}
const XMLAttDef*
DTDAttDefList::findAttDef( const unsigned int
, const XMLCh* const attName) const
{
// We don't use the URI, so we just look up the name
return fList->get(attName);
}
XMLAttDef* DTDAttDefList::findAttDef( const XMLCh* const
, const XMLCh* const attName)
{
// We don't use the URI, so we just look up the name
return fList->get(attName);
}
const XMLAttDef*
DTDAttDefList::findAttDef( const XMLCh* const
, const XMLCh* const attName) const
{
// We don't use the URI, so we just look up the name
return fList->get(attName);
}
/**
* return total number of attributes in this list
*/
XMLSize_t DTDAttDefList::getAttDefCount() const
{
return fCount;
}
/**
* return attribute at the index-th position in the list.
*/
XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index)
{
if(index >= fCount)
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
return *(fArray[index]);
}
/**
* return attribute at the index-th position in the list.
*/
const XMLAttDef &DTDAttDefList::getAttDef(XMLSize_t index) const
{
if(index >= fCount)
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
return *(fArray[index]);
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(DTDAttDefList)
void DTDAttDefList::serialize(XSerializeEngine& serEng)
{
XMLAttDefList::serialize(serEng);
if (serEng.isStoring())
{
/***
*
* Serialize RefHashTableOf<DTDAttDef>
*
***/
XTemplateSerializer::storeObject(fList, serEng);
serEng.writeSize (fCount);
// do not serialize fEnum
}
else
{
/***
*
* Deserialize RefHashTableOf<DTDAttDef>
*
***/
XTemplateSerializer::loadObject(&fList, 29, true, serEng);
// assume empty so we can size fArray just right
serEng.readSize (fSize);
if (!fEnum && fList)
{
fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(fList, false, getMemoryManager());
}
if(fSize)
{
(getMemoryManager())->deallocate(fArray);
fArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize));
fCount = 0;
while(fEnum->hasMoreElements())
{
fArray[fCount++] = &fEnum->nextElement();
}
}
}
}
DTDAttDefList::DTDAttDefList(MemoryManager* const manager)
: XMLAttDefList(manager)
,fEnum(0)
,fList(0)
,fArray(0)
,fSize(0)
,fCount(0)
{
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,161 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDAttDefList.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDATTDEFLIST_HPP)
#define XERCESC_INCLUDE_GUARD_DTDATTDEFLIST_HPP
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This is a derivative of the framework abstract class which defines the
// interface to a list of attribute defs that belong to a particular
// element. The scanner needs to be able to get a list of the attributes
// that an element supports, for use during the validation process and for
// fixed/default attribute processing.
//
// Since each validator can store attributes differently, this abstract
// interface allows each validator to provide an implementation of this
// data structure that works best for it.
//
// For us, we just wrap the RefHashTableOf collection that the DTDElementDecl
// class uses to store the attributes that belong to it.
//
// This clss does not adopt the hash table, it just references it. The
// hash table is owned by the element decl it is a member of.
//
class VALIDATORS_EXPORT DTDAttDefList : public XMLAttDefList
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDAttDefList
(
RefHashTableOf<DTDAttDef>* const listToUse,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~DTDAttDefList();
// -----------------------------------------------------------------------
// Implementation of the virtual interface
// -----------------------------------------------------------------------
virtual bool isEmpty() const;
virtual XMLAttDef* findAttDef
(
const unsigned int uriID
, const XMLCh* const attName
);
virtual const XMLAttDef* findAttDef
(
const unsigned int uriID
, const XMLCh* const attName
) const;
virtual XMLAttDef* findAttDef
(
const XMLCh* const attURI
, const XMLCh* const attName
);
virtual const XMLAttDef* findAttDef
(
const XMLCh* const attURI
, const XMLCh* const attName
) const;
/**
* return total number of attributes in this list
*/
virtual XMLSize_t getAttDefCount() const ;
/**
* return attribute at the index-th position in the list.
*/
virtual XMLAttDef &getAttDef(XMLSize_t index) ;
/**
* return attribute at the index-th position in the list.
*/
virtual const XMLAttDef &getAttDef(XMLSize_t index) const ;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(DTDAttDefList)
DTDAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private :
void addAttDef(DTDAttDef *toAdd);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDAttDefList(const DTDAttDefList &);
DTDAttDefList& operator = (const DTDAttDefList&);
// -----------------------------------------------------------------------
// Private data members
//
// fEnum
// This is an enerator for the list that we use to do the enumerator
// type methods of this class.
//
// fList
// The list of DTDAttDef objects that represent the attributes that
// a particular element supports.
// fArray
// vector of pointers to the DTDAttDef objects contained in this list
// fSize
// size of fArray
// fCount
// number of DTDAttDef objects currently stored in this list
// -----------------------------------------------------------------------
RefHashTableOfEnumerator<DTDAttDef>* fEnum;
RefHashTableOf<DTDAttDef>* fList;
DTDAttDef** fArray;
XMLSize_t fSize;
XMLSize_t fCount;
friend class DTDElementDecl;
};
inline void DTDAttDefList::addAttDef(DTDAttDef *toAdd)
{
if(fCount == fSize)
{
// need to grow fArray
fSize <<= 1;
DTDAttDef** newArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize ));
memcpy(newArray, fArray, fCount * sizeof(DTDAttDef *));
(getMemoryManager())->deallocate(fArray);
fArray = newArray;
}
fArray[fCount++] = toAdd;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,437 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDElementDecl.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/validators/common/DFAContentModel.hpp>
#include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/common/MixedContentModel.hpp>
#include <xercesc/validators/common/SimpleContentModel.hpp>
#include <xercesc/validators/DTD/DTDAttDefList.hpp>
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DTDElementDecl: Constructors and Destructor
// ---------------------------------------------------------------------------
DTDElementDecl::DTDElementDecl(MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(Any)
, fAttDefs(0)
, fAttList(0)
, fContentSpec(0)
, fContentModel(0)
, fFormattedModel(0)
{
}
DTDElementDecl::DTDElementDecl( const XMLCh* const elemRawName
, const unsigned int uriId
, const DTDElementDecl::ModelTypes type
, MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(type)
, fAttDefs(0)
, fAttList(0)
, fContentSpec(0)
, fContentModel(0)
, fFormattedModel(0)
{
setElementName(elemRawName, uriId);
}
DTDElementDecl::DTDElementDecl( QName* const elementName
, const DTDElementDecl::ModelTypes type
, MemoryManager* const manager) :
XMLElementDecl(manager)
, fModelType(type)
, fAttDefs(0)
, fAttList(0)
, fContentSpec(0)
, fContentModel(0)
, fFormattedModel(0)
{
setElementName(elementName);
}
DTDElementDecl::~DTDElementDecl()
{
delete fAttDefs;
delete fAttList;
delete fContentSpec;
delete fContentModel;
getMemoryManager()->deallocate(fFormattedModel);//delete [] fFormattedModel;
}
// ---------------------------------------------------------------------------
// The virtual element decl interface
// ---------------------------------------------------------------------------
XMLAttDefList& DTDElementDecl::getAttDefList() const
{
if (!fAttList)
{
// If the att def list is not made yet, then fault it in too
if (!fAttDefs)
faultInAttDefList();
((DTDElementDecl*)this)->fAttList = new (getMemoryManager()) DTDAttDefList(fAttDefs,getMemoryManager());
}
return *fAttList;
}
XMLElementDecl::CharDataOpts DTDElementDecl::getCharDataOpts() const
{
XMLElementDecl::CharDataOpts retVal;
switch(fModelType)
{
case Children :
retVal = XMLElementDecl::SpacesOk;
break;
case Empty :
retVal = XMLElementDecl::NoCharData;
break;
default :
retVal = XMLElementDecl::AllCharData;
break;
}
return retVal;
}
bool DTDElementDecl::hasAttDefs() const
{
// If the collection hasn't been faulted in, then no att defs
if (!fAttDefs)
return false;
return !fAttDefs->isEmpty();
}
void
DTDElementDecl::setContentSpec(ContentSpecNode* toAdopt)
{
delete fContentSpec;
fContentSpec = toAdopt;
//reset Content Model
setContentModel(0);
}
const XMLCh*
DTDElementDecl::getFormattedContentModel() const
{
//
// If its not already built, then call the protected virtual method
// to allow the derived class to build it (since only it knows.)
// Otherwise, just return the previously formatted methods.
//
// Since we are faulting this in, within a const getter, we have to
// cast off the const-ness.
//
if (!fFormattedModel)
((DTDElementDecl*)this)->fFormattedModel = formatContentModel();
return fFormattedModel;
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Getter methods
// ---------------------------------------------------------------------------
const DTDAttDef* DTDElementDecl::getAttDef(const XMLCh* const attName) const
{
// If no list, then return a null
if (!fAttDefs)
return 0;
return fAttDefs->get(attName);
}
DTDAttDef* DTDElementDecl::getAttDef(const XMLCh* const attName)
{
// If no list, then return a null
if (!fAttDefs)
return 0;
return fAttDefs->get(attName);
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Implementation of the protected virtual interface
// ---------------------------------------------------------------------------
void DTDElementDecl::addAttDef(DTDAttDef* const toAdd)
{
// Fault in the att list if required
if (!fAttDefs)
faultInAttDefList();
// Tell this guy the element id of its parent (us)
toAdd->setElemId(getId());
fAttDefs->put((void*)(toAdd->getFullName()), toAdd);
// update and/or create fAttList
if(!fAttList)
((DTDElementDecl*)this)->fAttList = new (getMemoryManager()) DTDAttDefList(fAttDefs,getMemoryManager());
fAttList->addAttDef(toAdd);
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Private helper methods
// ---------------------------------------------------------------------------
XMLCh* DTDElementDecl::formatContentModel() const
{
XMLCh* newValue = 0;
if (fModelType == Any)
{
newValue = XMLString::replicate(XMLUni::fgAnyString, getMemoryManager());
}
else if (fModelType == Empty)
{
newValue = XMLString::replicate(XMLUni::fgEmptyString, getMemoryManager());
}
else
{
//
// Use a temp XML buffer to format into. Content models could be
// pretty long, but very few will be longer than one K. The buffer
// will expand to handle the more pathological ones.
//
XMLBuffer bufFmt(1023, getMemoryManager());
getContentSpec()->formatSpec(bufFmt);
newValue = XMLString::replicate(bufFmt.getRawBuffer(), getMemoryManager());
}
return newValue;
}
XMLContentModel* DTDElementDecl::makeContentModel()
{
XMLContentModel* cmRet = 0;
if (fModelType == Mixed_Simple)
{
//
// Just create a mixel content model object. This type of
// content model is optimized for mixed content validation.
//
cmRet = new (getMemoryManager()) MixedContentModel(true, this->getContentSpec(), false, getMemoryManager());
}
else if (fModelType == Children)
{
//
// This method will create an optimal model for the complexity
// of the element's defined model. If its simple, it will create
// a SimpleContentModel object. If its a simple list, it will
// create a SimpleListContentModel object. If its complex, it
// will create a DFAContentModel object.
//
cmRet = createChildModel();
}
else
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren, getMemoryManager());
}
return cmRet;
}
XMLContentModel* DTDElementDecl::createChildModel()
{
// Get the content spec node of the element
ContentSpecNode* specNode = getContentSpec();
if(!specNode)
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, getMemoryManager());
//
// Do a sanity check that the node does not have a PCDATA id. Since,
// if it was, it should have already gotten taken by the Mixed model.
//
if (specNode->getElement()) {
if (specNode->getElement()->getURI() == XMLElementDecl::fgPCDataElemId)
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_NoPCDATAHere, getMemoryManager());
}
//
// According to the type of node, we will create the correct type of
// content model.
//
if (specNode->getType() == ContentSpecNode::Leaf)
{
// Create a simple content model
return new (getMemoryManager()) SimpleContentModel
(
true
, specNode->getElement()
, 0
, ContentSpecNode::Leaf
, getMemoryManager()
);
}
else if ((specNode->getType() == ContentSpecNode::Choice)
|| (specNode->getType() == ContentSpecNode::Sequence))
{
//
// Lets see if both of the children are leafs. If so, then it has to
// be a simple content model
//
if ((specNode->getFirst()->getType() == ContentSpecNode::Leaf)
&& (specNode->getSecond()->getType() == ContentSpecNode::Leaf))
{
return new (getMemoryManager()) SimpleContentModel
(
true
, specNode->getFirst()->getElement()
, specNode->getSecond()->getElement()
, specNode->getType()
, getMemoryManager()
);
}
}
else if ((specNode->getType() == ContentSpecNode::OneOrMore)
|| (specNode->getType() == ContentSpecNode::ZeroOrMore)
|| (specNode->getType() == ContentSpecNode::ZeroOrOne))
{
//
// Its a repetition, so see if its one child is a leaf. If so its a
// repetition of a single element, so we can do a simple content
// model for that.
//
if (specNode->getFirst()->getType() == ContentSpecNode::Leaf)
{
return new (getMemoryManager()) SimpleContentModel
(
true
, specNode->getFirst()->getElement()
, 0
, specNode->getType()
, getMemoryManager()
);
}
}
else
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, getMemoryManager());
}
// Its not any simple type of content, so create a DFA based content model
return new (getMemoryManager()) DFAContentModel
(
true
, this->getContentSpec()
, getMemoryManager()
);
}
void DTDElementDecl::faultInAttDefList() const
{
// Use a hash modulus of 29 and tell it owns its elements
((DTDElementDecl*)this)->fAttDefs = new (getMemoryManager()) RefHashTableOf<DTDAttDef>(29, true, getMemoryManager());
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(DTDElementDecl)
void DTDElementDecl::serialize(XSerializeEngine& serEng)
{
XMLElementDecl::serialize(serEng);
if (serEng.isStoring())
{
serEng<<(int) fModelType;
/***
*
* Serialize RefHashTableOf<DTDAttDef>
*
***/
XTemplateSerializer::storeObject(fAttDefs, serEng);
serEng<<fAttList;
serEng<<fContentSpec;
/***
* don't serialize
*
* XMLContentModel* fContentModel;
* XMLCh* fFormattedModel;
*
***/
}
else
{
int i;
serEng>>i;
fModelType=(ModelTypes)i;
/***
*
* Deserialize RefHashTableOf<DTDAttDef>
*
***/
XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);
serEng>>fAttList;
serEng>>fContentSpec;
/***
* don't deserialize
*
* XMLContentModel* fContentModel;
* XMLCh* fFormattedModel;
*
***/
fContentModel = 0;
fFormattedModel = 0;
}
}
XMLElementDecl::objectType DTDElementDecl::getObjectType() const
{
return DTD;
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,247 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDElementDecl.hpp 932887 2010-04-11 13:04:59Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDELEMENTDECL_HPP)
#define XERCESC_INCLUDE_GUARD_DTDELEMENTDECL_HPP
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/QName.hpp>
#include <xercesc/framework/XMLElementDecl.hpp>
#include <xercesc/framework/XMLContentModel.hpp>
#include <xercesc/validators/DTD/DTDAttDef.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class ContentSpecNode;
class DTDAttDefList;
//
// This class is a derivative of the basic element decl. This one implements
// the virtuals so that they work for a DTD. The big difference is that
// they don't live in any URL in the DTD. The names are just stored as full
// QNames, so they are not split out and element decls don't live within
// URL namespaces or anything like that.
//
class VALIDATORS_EXPORT DTDElementDecl : public XMLElementDecl
{
public :
// -----------------------------------------------------------------------
// Class specific types
//
// ModelTypes
// Indicates the type of content model that an element has. This
// indicates how the content model is represented and validated.
// -----------------------------------------------------------------------
enum ModelTypes
{
Empty
, Any
, Mixed_Simple
, Children
, ModelTypes_Count
};
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
DTDElementDecl
(
const XMLCh* const elemRawName
, const unsigned int uriId
, const ModelTypes modelType
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
DTDElementDecl
(
QName* const elementName
, const ModelTypes modelType = Any
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
~DTDElementDecl();
// -----------------------------------------------------------------------
// The virtual element decl interface
// -----------------------------------------------------------------------
virtual XMLAttDefList& getAttDefList() const;
virtual CharDataOpts getCharDataOpts() const;
virtual bool hasAttDefs() const;
virtual const ContentSpecNode* getContentSpec() const;
virtual ContentSpecNode* getContentSpec();
virtual void setContentSpec(ContentSpecNode* toAdopt);
virtual XMLContentModel* getContentModel();
virtual void setContentModel(XMLContentModel* const newModelToAdopt);
virtual const XMLCh* getFormattedContentModel () const;
// -----------------------------------------------------------------------
// Support keyed collections
//
// This method allows objects of this type be placed into one of the
// standard keyed collections. This method will return the full name of
// the element, which will vary depending upon the type of the grammar.
// -----------------------------------------------------------------------
const XMLCh* getKey() const;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const DTDAttDef* getAttDef(const XMLCh* const attName) const;
DTDAttDef* getAttDef(const XMLCh* const attName);
ModelTypes getModelType() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void addAttDef(DTDAttDef* const toAdd);
void setModelType(const DTDElementDecl::ModelTypes toSet);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(DTDElementDecl)
virtual XMLElementDecl::objectType getObjectType() const;
private :
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void faultInAttDefList() const;
XMLContentModel* createChildModel() ;
XMLContentModel* makeContentModel() ;
XMLCh* formatContentModel () const ;
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDElementDecl(const DTDElementDecl &);
DTDElementDecl& operator = (const DTDElementDecl&);
// -----------------------------------------------------------------------
// Private data members
//
// fAttDefs
// The list of attributes that are defined for this element. Each
// element is its own little 'namespace' for attributes, so each
// element maintains its own list of owned attribute defs. It is
// faulted in when an attribute is actually added.
//
// fAttList
// We have to return a view of our att defs via the abstract view
// that the scanner understands. It may or may not ever be asked
// for so we fault it in as needed.
//
// fContentSpec
// This is the content spec for the node. It contains the original
// content spec that was read from the DTD, as a tree of nodes. This
// one is always set up, and is used to build the fContentModel
// version if we are validating.
//
// fModelType
// The content model type of this element. This tells us what kind
// of content model to create.
//
// fContentModel
// The content model object for this element. It is stored here via
// its abstract interface.
//
// fFormattedModel
// This is a faulted in member. When the outside world asks for
// our content model as a string, we format it and fault it into
// this field (to avoid doing the formatted over and over.)
// -----------------------------------------------------------------------
ModelTypes fModelType;
RefHashTableOf<DTDAttDef>* fAttDefs;
DTDAttDefList* fAttList;
ContentSpecNode* fContentSpec;
XMLContentModel* fContentModel;
XMLCh* fFormattedModel;
};
// ---------------------------------------------------------------------------
// DTDElementDecl: XMLElementDecl virtual interface implementation
// ---------------------------------------------------------------------------
inline ContentSpecNode* DTDElementDecl::getContentSpec()
{
return fContentSpec;
}
inline const ContentSpecNode* DTDElementDecl::getContentSpec() const
{
return fContentSpec;
}
inline XMLContentModel* DTDElementDecl::getContentModel()
{
if (!fContentModel)
fContentModel = makeContentModel();
return fContentModel;
}
inline void
DTDElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
{
delete fContentModel;
fContentModel = newModelToAdopt;
// reset formattedModel
if (fFormattedModel)
{
getMemoryManager()->deallocate(fFormattedModel);
fFormattedModel = 0;
}
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Miscellaneous methods
// ---------------------------------------------------------------------------
inline const XMLCh* DTDElementDecl::getKey() const
{
return getFullName();
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Getter methods
// ---------------------------------------------------------------------------
inline DTDElementDecl::ModelTypes DTDElementDecl::getModelType() const
{
return fModelType;
}
// ---------------------------------------------------------------------------
// DTDElementDecl: Setter methods
// ---------------------------------------------------------------------------
inline void
DTDElementDecl::setModelType(const DTDElementDecl::ModelTypes toSet)
{
fModelType = toSet;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDEntityDecl.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(DTDEntityDecl)
void DTDEntityDecl::serialize(XSerializeEngine& serEng)
{
XMLEntityDecl::serialize(serEng);
if (serEng.isStoring())
{
serEng<<fDeclaredInIntSubset;
serEng<<fIsParameter;
serEng<<fIsSpecialChar;
}
else
{
serEng>>fDeclaredInIntSubset;
serEng>>fIsParameter;
serEng>>fIsSpecialChar;
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,204 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDEntityDecl.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDENTITYDECL_HPP)
#define XERCESC_INCLUDE_GUARD_DTDENTITYDECL_HPP
#include <xercesc/framework/XMLEntityDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This is a derivative of the abstract version of an entity decl in the
// framework directory. We just need to provide implementation of a couple
// of methods.
//
class VALIDATORS_EXPORT DTDEntityDecl : public XMLEntityDecl
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDEntityDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
DTDEntityDecl
(
const XMLCh* const entName
, const bool fromIntSubset = false
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
DTDEntityDecl
(
const XMLCh* const entName
, const XMLCh* const value
, const bool fromIntSubset = false
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
DTDEntityDecl
(
const XMLCh* const entName
, const XMLCh value
, const bool fromIntSubset = false
, const bool specialChar = false
);
~DTDEntityDecl();
// -----------------------------------------------------------------------
// Implementation of the virtual XMLEntityDecl interface
// -----------------------------------------------------------------------
virtual bool getDeclaredInIntSubset() const;
virtual bool getIsParameter() const;
virtual bool getIsSpecialChar() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setDeclaredInIntSubset(const bool newValue);
void setIsParameter(const bool newValue);
void setIsSpecialChar(const bool newValue);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(DTDEntityDecl)
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDEntityDecl(const DTDEntityDecl&);
DTDEntityDecl& operator=(DTDEntityDecl&);
// -----------------------------------------------------------------------
// Private data members
//
// fDeclaredInIntSubset
// Indicates whether the entity was declared in the internal subset
// or not. If not, it cannot be referred to from a standalone
// document.
//
// fIsParameter
// Indicates whether this is a parameter entity or a general entity.
//
// fIsSpecialChar
// This indicates that its one of the special character entities,
// e.g. lt or gt or amp. We need to know this because there are
// places where only a numeric char ref or special char ref is valid
// and all others are ignored or illegal.
// -----------------------------------------------------------------------
bool fDeclaredInIntSubset;
bool fIsParameter;
bool fIsSpecialChar;
};
// ---------------------------------------------------------------------------
// DTDEntityDecl: Constructors and Destructor
// ---------------------------------------------------------------------------
inline DTDEntityDecl::DTDEntityDecl(MemoryManager* const manager) :
XMLEntityDecl(manager)
, fDeclaredInIntSubset(false)
, fIsParameter(false)
, fIsSpecialChar(false)
{
}
inline DTDEntityDecl::DTDEntityDecl( const XMLCh* const entName
, const bool fromIntSubset
, MemoryManager* const manager) :
XMLEntityDecl(entName, manager)
, fDeclaredInIntSubset(fromIntSubset)
, fIsParameter(false)
, fIsSpecialChar(false)
{
}
inline DTDEntityDecl::DTDEntityDecl( const XMLCh* const entName
, const XMLCh* const value
, const bool fromIntSubset
, MemoryManager* const manager) :
XMLEntityDecl(entName, value, manager)
, fDeclaredInIntSubset(fromIntSubset)
, fIsParameter(false)
, fIsSpecialChar(false)
{
}
inline DTDEntityDecl::DTDEntityDecl(const XMLCh* const entName
, const XMLCh value
, const bool fromIntSubset
, const bool specialChar) :
XMLEntityDecl(entName, value, XMLPlatformUtils::fgMemoryManager)
, fDeclaredInIntSubset(fromIntSubset)
, fIsParameter(false)
, fIsSpecialChar(specialChar)
{
}
inline DTDEntityDecl::~DTDEntityDecl()
{
}
// ---------------------------------------------------------------------------
// DTDEntityDecl: Getter methods
// ---------------------------------------------------------------------------
inline bool DTDEntityDecl::getDeclaredInIntSubset() const
{
return fDeclaredInIntSubset;
}
inline bool DTDEntityDecl::getIsParameter() const
{
return fIsParameter;
}
inline bool DTDEntityDecl::getIsSpecialChar() const
{
return fIsSpecialChar;
}
// ---------------------------------------------------------------------------
// DTDEntityDecl: Setter methods
// ---------------------------------------------------------------------------
inline void DTDEntityDecl::setDeclaredInIntSubset(const bool newValue)
{
fDeclaredInIntSubset = newValue;
}
inline void DTDEntityDecl::setIsParameter(const bool newValue)
{
fIsParameter = newValue;
}
inline void DTDEntityDecl::setIsSpecialChar(const bool newValue)
{
fIsSpecialChar = newValue;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,263 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDGrammar.cpp 676911 2008-07-15 13:27:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <xercesc/validators/DTD/DTDGrammar.hpp>
#include <xercesc/validators/DTD/XMLDTDDescriptionImpl.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DTDGrammar: Static member data
// ---------------------------------------------------------------------------
NameIdPool<DTDEntityDecl>* DTDGrammar::fDefaultEntities = 0;
void XMLInitializer::initializeDTDGrammar()
{
DTDGrammar::fDefaultEntities = new NameIdPool<DTDEntityDecl>(11, 12);
// Add the default entity entries for the character refs that must
// always be present. We indicate that they are from the internal
// subset. They aren't really, but they have to look that way so
// that they are still valid for use within a standalone document.
//
// We also mark them as special char entities, which allows them
// to be used in places whether other non-numeric general entities
// cannot.
//
if (DTDGrammar::fDefaultEntities)
{
DTDGrammar::fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgAmp, chAmpersand, true, true));
DTDGrammar::fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgLT, chOpenAngle, true, true));
DTDGrammar::fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgGT, chCloseAngle, true, true));
DTDGrammar::fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgQuot, chDoubleQuote, true, true));
DTDGrammar::fDefaultEntities->put(new DTDEntityDecl(XMLUni::fgApos, chSingleQuote, true, true));
}
}
void XMLInitializer::terminateDTDGrammar()
{
delete DTDGrammar::fDefaultEntities;
DTDGrammar::fDefaultEntities = 0;
}
//---------------------------------------------------------------------------
// DTDGrammar: Constructors and Destructor
// ---------------------------------------------------------------------------
DTDGrammar::DTDGrammar(MemoryManager* const manager) :
fMemoryManager(manager)
, fElemDeclPool(0)
, fElemNonDeclPool(0)
, fEntityDeclPool(0)
, fNotationDeclPool(0)
, fGramDesc(0)
, fValidated(false)
{
//
// Init all the pool members.
//
// <TBD> Investigate what the optimum values would be for the various
// pools.
//
fElemDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(109, 128, fMemoryManager);
// should not need this in the common situation where grammars
// are built once and then read - NG
//fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager);
fEntityDeclPool = new (fMemoryManager) NameIdPool<DTDEntityDecl>(109, 128, fMemoryManager);
fNotationDeclPool = new (fMemoryManager) NameIdPool<XMLNotationDecl>(109, 128, fMemoryManager);
//REVISIT: use grammarPool to create
fGramDesc = new (fMemoryManager) XMLDTDDescriptionImpl(XMLUni::fgDTDEntityString, fMemoryManager);
}
DTDGrammar::~DTDGrammar()
{
delete fElemDeclPool;
if(fElemNonDeclPool)
{
delete fElemNonDeclPool;
}
delete fEntityDeclPool;
delete fNotationDeclPool;
delete fGramDesc;
}
// -----------------------------------------------------------------------
// Virtual methods
// -----------------------------------------------------------------------
XMLElementDecl* DTDGrammar::findOrAddElemDecl (const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const
, const XMLCh* const qName
, unsigned int scope
, bool& wasAdded )
{
// See it it exists
DTDElementDecl* retVal = (DTDElementDecl*) getElemDecl(uriId, baseName, qName, scope);
// if not, then add this in
if (!retVal)
{
retVal = new (fMemoryManager) DTDElementDecl
(
qName
, uriId
, DTDElementDecl::Any
, fMemoryManager
);
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager);
const XMLSize_t elemId = fElemNonDeclPool->put(retVal);
retVal->setId(elemId);
wasAdded = true;
}
else
{
wasAdded = false;
}
return retVal;
}
XMLElementDecl* DTDGrammar::putElemDecl (const unsigned int uriId
, const XMLCh* const
, const XMLCh* const
, const XMLCh* const qName
, unsigned int
, const bool notDeclared)
{
DTDElementDecl* retVal = new (fMemoryManager) DTDElementDecl
(
qName
, uriId
, DTDElementDecl::Any
, fMemoryManager
);
if(notDeclared)
{
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager);
retVal->setId(fElemNonDeclPool->put(retVal));
} else
{
retVal->setId(fElemDeclPool->put(retVal));
}
return retVal;
}
void DTDGrammar::reset()
{
//
// We need to reset all of the pools.
//
fElemDeclPool->removeAll();
// now that we have this, no point in deleting it...
if(fElemNonDeclPool)
fElemNonDeclPool->removeAll();
fNotationDeclPool->removeAll();
fEntityDeclPool->removeAll();
fValidated = false;
}
void DTDGrammar::setGrammarDescription( XMLGrammarDescription* gramDesc)
{
if ((!gramDesc) ||
(gramDesc->getGrammarType() != Grammar::DTDGrammarType))
return;
if (fGramDesc)
delete fGramDesc;
//adopt the grammar Description
fGramDesc = (XMLDTDDescription*) gramDesc;
}
XMLGrammarDescription* DTDGrammar::getGrammarDescription() const
{
return fGramDesc;
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(DTDGrammar)
void DTDGrammar::serialize(XSerializeEngine& serEng)
{
Grammar::serialize(serEng);
//don't serialize fDefaultEntities
if (serEng.isStoring())
{
/***
*
* Serialize NameIdPool<DTDElementDecl>* fElemDeclPool;
* Serialize NameIdPool<DTDEntityDecl>* fEntityDeclPool;
* Serialize NameIdPool<XMLNotationDecl>* fNotationDeclPool;
***/
XTemplateSerializer::storeObject(fElemDeclPool, serEng);
XTemplateSerializer::storeObject(fEntityDeclPool, serEng);
XTemplateSerializer::storeObject(fNotationDeclPool, serEng);
/***
* serialize() method shall be used to store object
* which has been created in ctor
***/
fGramDesc->serialize(serEng);
serEng<<fValidated;
}
else
{
/***
*
* Deserialize NameIdPool<DTDElementDecl>* fElemDeclPool;
* Deserialize NameIdPool<DTDEntityDecl>* fEntityDeclPool;
* Deerialize NameIdPool<XMLNotationDecl>* fNotationDeclPool;
***/
XTemplateSerializer::loadObject(&fElemDeclPool, 109, 128, serEng);
fElemNonDeclPool = 0;
XTemplateSerializer::loadObject(&fEntityDeclPool, 109, 128, serEng);
XTemplateSerializer::loadObject(&fNotationDeclPool, 109, 128, serEng);
/***
* serialize() method shall be used to load object
* which has been created in ctor
***/
fGramDesc->serialize(serEng);
serEng>>fValidated;
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,391 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDGrammar.hpp 883368 2009-11-23 15:28:19Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDGRAMMAR_HPP)
#define XERCESC_INCLUDE_GUARD_DTDGRAMMAR_HPP
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/NameIdPool.hpp>
#include <xercesc/util/StringPool.hpp>
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
#include <xercesc/framework/XMLDTDDescription.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This class stores the DTD information
// NOTE: DTDs are not namespace aware, so we just use regular NameIdPool
// data structures to store element and attribute decls. They are all set
// to be in the global namespace and the full QName is used as the base name
// of the decl. This means that all the URI parameters below are expected
// to be null pointers (and anything else will cause an exception.)
//
class VALIDATORS_EXPORT DTDGrammar : public Grammar
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDGrammar(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
virtual ~DTDGrammar();
// -----------------------------------------------------------------------
// Implementation of Virtual Interface
// -----------------------------------------------------------------------
virtual Grammar::GrammarType getGrammarType() const;
virtual const XMLCh* getTargetNamespace() const;
// this method should only be used while the grammar is being
// constructed, not while it is being used
// in a validation episode!
virtual XMLElementDecl* findOrAddElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const qName
, unsigned int scope
, bool& wasAdded
) ;
virtual XMLSize_t getElemId
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
) const ;
virtual const XMLElementDecl* getElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
) const ;
virtual XMLElementDecl* getElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const qName
, unsigned int scope
);
virtual const XMLElementDecl* getElemDecl
(
const unsigned int elemId
) const;
virtual XMLElementDecl* getElemDecl
(
const unsigned int elemId
);
virtual const XMLNotationDecl* getNotationDecl
(
const XMLCh* const notName
) const;
virtual XMLNotationDecl* getNotationDecl
(
const XMLCh* const notName
);
virtual bool getValidated() const;
virtual XMLElementDecl* putElemDecl
(
const unsigned int uriId
, const XMLCh* const baseName
, const XMLCh* const prefixName
, const XMLCh* const qName
, unsigned int scope
, const bool notDeclared = false
);
virtual XMLSize_t putElemDecl
(
XMLElementDecl* const elemDecl
, const bool notDeclared = false
) ;
virtual XMLSize_t putNotationDecl
(
XMLNotationDecl* const notationDecl
) const;
virtual void setValidated(const bool newState);
virtual void reset();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const DTDEntityDecl* getEntityDecl(const XMLCh* const entName) const;
DTDEntityDecl* getEntityDecl(const XMLCh* const entName);
NameIdPool<DTDEntityDecl>* getEntityDeclPool();
const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const;
NameIdPoolEnumerator<DTDElementDecl> getElemEnumerator() const;
NameIdPoolEnumerator<DTDEntityDecl> getEntityEnumerator() const;
NameIdPoolEnumerator<XMLNotationDecl> getNotationEnumerator() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
virtual void setGrammarDescription( XMLGrammarDescription*);
virtual XMLGrammarDescription* getGrammarDescription() const;
// -----------------------------------------------------------------------
// Content management methods
// -----------------------------------------------------------------------
XMLSize_t putEntityDecl(DTDEntityDecl* const entityDecl) const;
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(DTDGrammar)
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDGrammar(const DTDGrammar &);
DTDGrammar& operator = (const DTDGrammar&);
// -----------------------------------------------------------------------
// Private data members
//
// fElemDeclPool
// This is the element decl pool. It contains all of the elements
// declared in the DTD (and their associated attributes.)
//
// fElemNonDeclPool
// This is the element decl pool that is is populated as new elements
// are seen in the XML document (not declared in the DTD), and they
// are given default characteristics.
//
// fEntityDeclPool
// This is a pool of EntityDecl objects, which contains all of the
// general entities that are declared in the DTD subsets, plus the
// default entities (such as &gt; &lt; ...) defined by the XML Standard.
//
// fNotationDeclPool
// This is a pool of NotationDecl objects, which contains all of the
// notations declared in the DTD subsets.
//
// fValidated
// Indicates if the content of the Grammar has been pre-validated
// or not. When using a cached grammar, no need for pre content
// validation.
//
// fGramDesc: adopted
//
// -----------------------------------------------------------------------
static NameIdPool<DTDEntityDecl>* fDefaultEntities;
MemoryManager* fMemoryManager;
NameIdPool<DTDElementDecl>* fElemDeclPool;
NameIdPool<DTDElementDecl>* fElemNonDeclPool;
NameIdPool<DTDEntityDecl>* fEntityDeclPool;
NameIdPool<XMLNotationDecl>* fNotationDeclPool;
XMLDTDDescription* fGramDesc;
bool fValidated;
friend class XMLInitializer;
};
// ---------------------------------------------------------------------------
// DTDGrammar: Getter methods
// ---------------------------------------------------------------------------
inline NameIdPoolEnumerator<DTDElementDecl>
DTDGrammar::getElemEnumerator() const
{
return NameIdPoolEnumerator<DTDElementDecl>(fElemDeclPool, fMemoryManager);
}
inline NameIdPoolEnumerator<DTDEntityDecl>
DTDGrammar::getEntityEnumerator() const
{
return NameIdPoolEnumerator<DTDEntityDecl>(fEntityDeclPool, fMemoryManager);
}
inline NameIdPoolEnumerator<XMLNotationDecl>
DTDGrammar::getNotationEnumerator() const
{
return NameIdPoolEnumerator<XMLNotationDecl>(fNotationDeclPool, fMemoryManager);
}
inline const DTDEntityDecl*
DTDGrammar::getEntityDecl(const XMLCh* const entName) const
{
DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
if (!decl)
return fEntityDeclPool->getByKey(entName);
return decl;
}
inline DTDEntityDecl* DTDGrammar::getEntityDecl(const XMLCh* const entName)
{
DTDEntityDecl* decl = fDefaultEntities->getByKey(entName);
if (!decl)
return fEntityDeclPool->getByKey(entName);
return decl;
}
inline NameIdPool<DTDEntityDecl>* DTDGrammar::getEntityDeclPool()
{
return fEntityDeclPool;
}
inline const NameIdPool<DTDEntityDecl>* DTDGrammar::getEntityDeclPool() const
{
return fEntityDeclPool;
}
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
inline XMLSize_t DTDGrammar::putEntityDecl(DTDEntityDecl* const entityDecl) const
{
return fEntityDeclPool->put(entityDecl);
}
// ---------------------------------------------------------------------------
// DTDGrammar: Virtual methods
// ---------------------------------------------------------------------------
inline Grammar::GrammarType DTDGrammar::getGrammarType() const {
return Grammar::DTDGrammarType;
}
inline const XMLCh* DTDGrammar::getTargetNamespace() const {
return XMLUni::fgZeroLenString;
}
// Element Decl
inline XMLSize_t DTDGrammar::getElemId (const unsigned int
, const XMLCh* const
, const XMLCh* const qName
, unsigned int) const
{
//
// In this case, we don't return zero to mean 'not found', so we have to
// map it to the official not found value if we don't find it.
//
const DTDElementDecl* decl = fElemDeclPool->getByKey(qName);
if (!decl)
return XMLElementDecl::fgInvalidElemId;
return decl->getId();
}
inline const XMLElementDecl* DTDGrammar::getElemDecl( const unsigned int
, const XMLCh* const
, const XMLCh* const qName
, unsigned int) const
{
const XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName);
if (!elemDecl && fElemNonDeclPool)
elemDecl = fElemNonDeclPool->getByKey(qName);
return elemDecl;
}
inline XMLElementDecl* DTDGrammar::getElemDecl (const unsigned int
, const XMLCh* const
, const XMLCh* const qName
, unsigned int)
{
XMLElementDecl* elemDecl = fElemDeclPool->getByKey(qName);
if (!elemDecl && fElemNonDeclPool)
elemDecl = fElemNonDeclPool->getByKey(qName);
return elemDecl;
}
inline const XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId) const
{
// Look up this element decl by id
return fElemDeclPool->getById(elemId);
}
inline XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId)
{
// Look up this element decl by id
return fElemDeclPool->getById(elemId);
}
inline XMLSize_t
DTDGrammar::putElemDecl(XMLElementDecl* const elemDecl,
const bool notDeclared)
{
if (notDeclared)
{
if(!fElemNonDeclPool)
fElemNonDeclPool = new (fMemoryManager) NameIdPool<DTDElementDecl>(29, 128, fMemoryManager);
return fElemNonDeclPool->put((DTDElementDecl*) elemDecl);
}
return fElemDeclPool->put((DTDElementDecl*) elemDecl);
}
// Notation Decl
inline const XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName) const
{
return fNotationDeclPool->getByKey(notName);
}
inline XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName)
{
return fNotationDeclPool->getByKey(notName);
}
inline XMLSize_t DTDGrammar::putNotationDecl(XMLNotationDecl* const notationDecl) const
{
return fNotationDeclPool->put(notationDecl);
}
inline bool DTDGrammar::getValidated() const
{
return fValidated;
}
inline void DTDGrammar::setValidated(const bool newState)
{
fValidated = newState;
}
XERCES_CPP_NAMESPACE_END
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,277 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDScanner.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP)
#define XERCESC_INCLUDE_GUARD_DTDSCANNER_HPP
#include <xercesc/validators/DTD/DTDGrammar.hpp>
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLScanner;
/*
* Default implementation of an XML DTD scanner.
*/
class DocTypeHandler;
class VALIDATORS_EXPORT DTDScanner : public XMemory
{
public:
// -----------------------------------------------------------------------
// Class specific types
//
// EntityExpRes
// Returned from scanEntityRef() to indicate how the expanded text
// was treated.
//
// IDTypes
// Type of the ID
// -----------------------------------------------------------------------
enum EntityExpRes
{
EntityExp_Failed
, EntityExp_Pushed
, EntityExp_Returned
};
enum IDTypes
{
IDType_Public
, IDType_External
, IDType_Either
};
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDScanner
(
DTDGrammar* dtdGrammar
, DocTypeHandler* const docTypeHandler
, MemoryManager* const grammarPoolMemoryManager
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
virtual ~DTDScanner();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
DocTypeHandler* getDocTypeHandler();
const DocTypeHandler* getDocTypeHandler() const;
// -----------------------------------------------------------------------
// Setter methods
//
// setScannerInfo() is called by the scanner to tell the DTDScanner
// about the stuff it needs to have access to.
// -----------------------------------------------------------------------
void setScannerInfo
(
XMLScanner* const owningScanner
, ReaderMgr* const readerMgr
, XMLBufferMgr* const bufMgr
);
void setDocTypeHandler
(
DocTypeHandler* const handlerToSet
);
void scanExtSubsetDecl(const bool inIncludeSect, const bool isDTD);
bool scanInternalSubset();
bool scanId
(
XMLBuffer& pubIdToFill
, XMLBuffer& sysIdToFill
, const IDTypes whatKind
);
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDScanner(const DTDScanner &);
DTDScanner& operator = (const DTDScanner&);
// -----------------------------------------------------------------------
// Private DTD scanning methods. These are all in XMLValidator2.cpp
// -----------------------------------------------------------------------
bool checkForPERef
(
const bool inLiteral
, const bool inMarkup
);
bool expandPERef
(
const bool scanExternal
, const bool inLiteral
, const bool inMarkup
, const bool throwEndOfExt = false
);
bool getQuotedString(XMLBuffer& toFill);
XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse);
bool scanAttValue
(
const XMLCh* const attrName
, XMLBuffer& toFill
, const XMLAttDef::AttTypes type
);
void scanAttListDecl();
ContentSpecNode* scanChildren
(
const DTDElementDecl& elemDecl
, XMLBuffer& bufToUse
);
bool scanCharRef(XMLCh& toFill, XMLCh& second);
void scanComment();
bool scanContentSpec(DTDElementDecl& toFill);
void scanDefaultDecl(DTDAttDef& toFill);
void scanElementDecl();
void scanEntityDecl();
bool scanEntityDef();
bool scanEntityLiteral(XMLBuffer& toFill);
bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl);
EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped);
bool scanEnumeration
(
const DTDAttDef& attDef
, XMLBuffer& toFill
, const bool notation
);
bool scanEq();
void scanIgnoredSection();
void scanMarkupDecl(const bool parseTextDecl);
bool scanMixed(DTDElementDecl& toFill);
void scanNotationDecl();
void scanPI();
bool scanPublicLiteral(XMLBuffer& toFill);
bool scanSystemLiteral(XMLBuffer& toFill);
void scanTextDecl();
bool isReadingExternalEntity();
// -----------------------------------------------------------------------
// Private data members
//
// fDocTypeHandler
// This holds the optional doc type handler that can be installed
// and used to call back for all markup events. It is DTD specific.
//
// fDumAttDef
// fDumElemDecl
// fDumEntityDecl
// These are dummy objects into which mark decls are parsed when
// they are just overrides of previously declared markup decls. In
// such situations, the first one wins but we need to have somewhere
// to parse them into. So these are lazily created and used as needed
// when such markup decls are seen.
//
// fInternalSubset
// This is used to track whether we are in the internal subset or not,
// in which case we are in the external subset.
//
// fNextAttrId
// Since att defs are per-element, we don't have a validator wide
// attribute def pool. So we use a simpler data structure in each
// element decl to store its att defs, and we use this simple counter
// to apply a unique id to each new attribute.
//
// fDTDGrammar
// The DTD information we scanned like element decl, attribute decl
// are stored in this Grammar.
//
// fBufMgr
// This is the buffer manager of the scanner. This is provided as a
// convenience so that the DTDScanner doesn't have to create its own
// buffer manager during the parse process.
//
// fReaderMgr
// This is a pointer to the reader manager that is being used by the scanner.
//
// fScanner
// The pointer to the scanner to which this DTDScanner belongs
//
// fPEntityDeclPool
// This is a pool of EntityDecl objects, which contains all of the
// parameter entities that are declared in the DTD subsets.
//
// fEmptyNamespaceId
// The uri for all DTD decls
//
// fDocTypeReaderId
// The original reader in the fReaderMgr - to be compared against the
// current reader to decide whether we are processing an external/internal
// declaration
// -----------------------------------------------------------------------
MemoryManager* fMemoryManager;
MemoryManager* fGrammarPoolMemoryManager;
DocTypeHandler* fDocTypeHandler;
DTDAttDef* fDumAttDef;
DTDElementDecl* fDumElemDecl;
DTDEntityDecl* fDumEntityDecl;
bool fInternalSubset;
unsigned int fNextAttrId;
DTDGrammar* fDTDGrammar;
XMLBufferMgr* fBufMgr;
ReaderMgr* fReaderMgr;
XMLScanner* fScanner;
NameIdPool<DTDEntityDecl>* fPEntityDeclPool;
unsigned int fEmptyNamespaceId;
XMLSize_t fDocTypeReaderId;
};
// ---------------------------------------------------------------------------
// DTDScanner: Getter methods
// ---------------------------------------------------------------------------
inline DocTypeHandler* DTDScanner::getDocTypeHandler()
{
return fDocTypeHandler;
}
inline const DocTypeHandler* DTDScanner::getDocTypeHandler() const
{
return fDocTypeHandler;
}
// ---------------------------------------------------------------------------
// DTDScanner: Setter methods
// ---------------------------------------------------------------------------
inline void DTDScanner::setDocTypeHandler(DocTypeHandler* const handlerToSet)
{
fDocTypeHandler = handlerToSet;
}
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
inline bool DTDScanner::isReadingExternalEntity() {
return (fDocTypeReaderId != fReaderMgr->getCurrentReaderNum());
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,657 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDValidator.cpp 729944 2008-12-29 17:03:32Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/internal/ReaderMgr.hpp>
#include <xercesc/internal/XMLScanner.hpp>
#include <xercesc/validators/DTD/DTDValidator.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// DTDValidator: Constructors and Destructor
// ---------------------------------------------------------------------------
DTDValidator::DTDValidator(XMLErrorReporter* const errReporter) :
XMLValidator(errReporter)
, fDTDGrammar(0)
{
reset();
}
DTDValidator::~DTDValidator()
{
}
// ---------------------------------------------------------------------------
// DTDValidator: Implementation of the XMLValidator interface
// ---------------------------------------------------------------------------
bool DTDValidator::checkContent(XMLElementDecl* const elemDecl
, QName** const children
, XMLSize_t childCount
, XMLSize_t* indexFailingChild)
{
//
// Look up the element id in our element decl pool. This will get us
// the element decl in our own way of looking at them.
//
if (!elemDecl)
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Val_InvalidElemId, getScanner()->getMemoryManager());
//
// Get the content spec type of this element. This will tell us what
// to do to validate it.
//
const DTDElementDecl::ModelTypes modelType = ((DTDElementDecl*) elemDecl)->getModelType();
if (modelType == DTDElementDecl::Empty)
{
//
// We can do this one here. It cannot have any children. If it does
// we return 0 as the index of the first bad child.
//
if (childCount)
{
*indexFailingChild=0;
return false;
}
}
else if (modelType == DTDElementDecl::Any)
{
// We pass no judgement on this one, anything goes
}
else if ((modelType == DTDElementDecl::Mixed_Simple)
|| (modelType == DTDElementDecl::Children))
{
// Get the element's content model or fault it in
const XMLContentModel* elemCM = elemDecl->getContentModel();
// Ask it to validate and return its return
return elemCM->validateContent(children, childCount, getScanner()->getEmptyNamespaceId(), indexFailingChild, getScanner()->getMemoryManager());
}
else
{
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMType, getScanner()->getMemoryManager());
}
// Went ok, so return success
return true;
}
void DTDValidator::faultInAttr(XMLAttr& toFill, const XMLAttDef& attDef) const
{
toFill.set(0, attDef.getFullName(), attDef.getValue(), attDef.getType());
}
void DTDValidator::reset()
{
}
bool DTDValidator::requiresNamespaces() const
{
// Namespaces are not supported for DTDs
return false;
}
void
DTDValidator::validateAttrValue(const XMLAttDef* attDef
, const XMLCh* const attrValue
, bool preValidation
, const XMLElementDecl*)
{
//
// Get quick refs to lost of of the stuff in the passed objects in
// order to simplify the code below, which will reference them very
// often.
//
const XMLAttDef::AttTypes type = attDef->getType();
const XMLAttDef::DefAttTypes defType = attDef->getDefaultType();
const XMLCh* const valueText = attDef->getValue();
const XMLCh* const fullName = attDef->getFullName();
const XMLCh* const enumList = attDef->getEnumeration();
//
// If the default type is fixed, then make sure the passed value maps
// to the fixed value.
// If during preContentValidation, the value we are validating is the fixed value itself
// so no need to compare.
// Only need to do this for regular attribute value validation
//
if (defType == XMLAttDef::Fixed && !preValidation)
{
if (!XMLString::equals(attrValue, valueText))
emitError(XMLValid::NotSameAsFixedValue, fullName, attrValue, valueText);
}
//
// If its a CDATA attribute, then we are done with any DTD level
// validation else do the rest.
//
if (type == XMLAttDef::CData)
return;
// An empty string cannot be valid for any of the other types
if (!attrValue[0])
{
emitError(XMLValid::InvalidEmptyAttValue, fullName);
return;
}
// See whether we are doing multiple values or not
const bool multipleValues =
(
(type == XMLAttDef::IDRefs)
|| (type == XMLAttDef::Entities)
|| (type == XMLAttDef::NmTokens)
|| (type == XMLAttDef::Notation)
|| (type == XMLAttDef::Enumeration)
);
// And whether we must check for a first name char
const bool firstNameChar =
(
(type == XMLAttDef::ID)
|| (type == XMLAttDef::IDRef)
|| (type == XMLAttDef::IDRefs)
|| (type == XMLAttDef::Entity)
|| (type == XMLAttDef::Entities)
|| (type == XMLAttDef::Notation)
);
// Whether it requires ref checking stuff
const bool isARefType
(
(type == XMLAttDef::ID)
|| (type == XMLAttDef::IDRef)
|| (type == XMLAttDef::IDRefs)
);
// Some trigger flags to avoid issuing redundant errors and whatnot
bool alreadyCapped = false;
//
// Make a copy of the text that we can mangle and get a pointer we can
// move through the value
//
// Use a stack-based buffer, when possible...
XMLCh tempBuffer[100];
XMLCh* pszTmpVal = 0;
ArrayJanitor<XMLCh> janTmpVal(0);
if (XMLString::stringLen(attrValue) < sizeof(tempBuffer) / sizeof(tempBuffer[0]))
{
XMLString::copyString(tempBuffer, attrValue);
pszTmpVal = tempBuffer;
}
else
{
janTmpVal.reset(XMLString::replicate(attrValue, getScanner()->getMemoryManager()), getScanner()->getMemoryManager());
pszTmpVal = janTmpVal.get();
}
XMLCh* valPtr = pszTmpVal;
bool doNamespace = getScanner()->getDoNamespaces();
while (true)
{
//
// Make sure the first character is a valid first name char, i.e.
// if its a Name value. For NmToken values we don't treat the first
// char any differently.
//
if (firstNameChar)
{
// If its not, emit and error but try to keep going
if (!getReaderMgr()->getCurrentReader()->isFirstNameChar(*valPtr))
emitError(XMLValid::AttrValNotName, valPtr, fullName);
valPtr++;
}
// Make sure all the remaining chars are valid name chars
while (*valPtr)
{
//
// If we hit a whitespace, its either a break between two
// or more values, or an error if we have a single value.
//
//
// XML1.0-3rd
//
// [6] Names ::= Name (#x20 Name)*
// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
//
// only and only ONE #x20 is allowed to be the delimiter
//
if (*valPtr==chSpace)
{
if (!multipleValues)
{
emitError(XMLValid::NoMultipleValues, fullName);
return;
}
break;
}
// Now this attribute can be of type
// ID, IDREF, IDREFS, ENTITY, ENTITIES, NOTATION, NMTOKEN, NMTOKENS, ENUMERATION
// All these must be valid XMLName
// If namespace is enabled, colon is not allowed in the first 6
if (doNamespace && *valPtr == chColon && firstNameChar)
emitError(XMLValid::ColonNotValidWithNS);
if (!getReaderMgr()->getCurrentReader()->isNameChar(*valPtr))
{
emitError(XMLValid::AttrValNotName, valPtr, fullName);
return;
}
valPtr++;
}
//
// Cap it off at the current non-name char. If already capped,
// then remember this.
//
if (!(*valPtr))
alreadyCapped = true;
*valPtr = 0;
//
// If this type of attribute requires that we track reference
// stuff, then handle that.
//
if (isARefType)
{
if ((type == XMLAttDef::ID)
|| (type == XMLAttDef::IDRef)
|| (type == XMLAttDef::IDRefs))
{
XMLRefInfo* find = getScanner()->getIDRefList()->get(pszTmpVal);
if (find)
{
if (find->getDeclared() && (type == XMLAttDef::ID))
emitError(XMLValid::ReusedIDValue, pszTmpVal);
}
else
{
find = new (getScanner()->getMemoryManager()) XMLRefInfo
(
pszTmpVal
, false
, false
, getScanner()->getMemoryManager()
);
getScanner()->getIDRefList()->put((void*)find->getRefName(), find);
}
//
// Mark it declared or used, which might be redundant in some cases
// but not worth checking
//
if (type == XMLAttDef::ID)
find->setDeclared(true);
else {
if (!preValidation) {
find->setUsed(true);
}
}
}
}
else if (!preValidation && ((type == XMLAttDef::Entity) || (type == XMLAttDef::Entities)))
{
//
// If its refering to a entity, then look up the name in the
// general entity pool. If not there, then its an error. If its
// not an external unparsed entity, then its an error.
//
// In case of pre-validation, the above errors should be ignored.
//
const XMLEntityDecl* decl = fDTDGrammar->getEntityDecl(pszTmpVal);
if (decl)
{
if (!decl->isUnparsed())
emitError(XMLValid::BadEntityRefAttr, pszTmpVal, fullName);
}
else
{
emitError
(
XMLValid::UnknownEntityRefAttr
, fullName
, pszTmpVal
);
}
}
else if ((type == XMLAttDef::Notation) || (type == XMLAttDef::Enumeration))
{
//
// Make sure that this value maps to one of the enumeration or
// notation values in the enumList parameter. We don't have to
// look it up in the notation pool (if a notation) because we
// will look up the enumerated values themselves. If they are in
// the notation pool (after the DTD is parsed), then obviously
// this value will be legal since it matches one of them.
//
if (!XMLString::isInList(pszTmpVal, enumList))
emitError(XMLValid::DoesNotMatchEnumList, pszTmpVal, fullName);
}
// If not doing multiple values, then we are done
if (!multipleValues)
break;
//
// If we are at the end, then break out now, else move up to the
// next char and update the base pointer.
//
if (alreadyCapped)
break;
valPtr++;
pszTmpVal = valPtr;
}
}
void DTDValidator::preContentValidation(bool
#if defined(XERCES_DEBUG)
reuseGrammar
#endif
,bool validateDefAttr)
{
//
// Lets enumerate all of the elements in the element decl pool
// and put out an error for any that did not get declared.
// We also check all of the attributes as well.
//
NameIdPoolEnumerator<DTDElementDecl> elemEnum = fDTDGrammar->getElemEnumerator();
fDTDGrammar->setValidated(true);
while (elemEnum.hasMoreElements())
{
const DTDElementDecl& curElem = elemEnum.nextElement();
const DTDElementDecl::CreateReasons reason = curElem.getCreateReason();
//
// See if this element decl was ever marked as declared. If
// not, then put out an error. In some cases its just
// a warning, such as being referenced in a content model.
//
if (reason != XMLElementDecl::Declared)
{
if (reason == XMLElementDecl::AttList)
{
getScanner()->emitError
(
XMLErrs::UndeclaredElemInAttList
, curElem.getFullName()
);
}
else if (reason == XMLElementDecl::AsRootElem)
{
// It's ok that the root element is not declared in the DTD
/*
emitError
(
XMLValid::UndeclaredElemInDocType
, curElem.getFullName()
);*/
}
else if (reason == XMLElementDecl::InContentModel)
{
getScanner()->emitError
(
XMLErrs::UndeclaredElemInCM
, curElem.getFullName()
);
}
else
{
#if defined(XERCES_DEBUG)
if(reuseGrammar && reason == XMLElementDecl::JustFaultIn){
}
else
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::DTD_UnknownCreateReason, getScanner()->getMemoryManager());
#endif
}
}
//
// Check all of the attributes of the current element.
// We check for:
//
// 1) Multiple ID attributes
// 2) That all of the default values of attributes are
// valid for their type.
// 3) That for any notation types, that their lists
// of possible values refer to declared notations.
//
// 4) XML1.0(3rd edition)
//
// Validity constraint: One Notation Per Element Type
// An element type MUST NOT have more than one NOTATION attribute specified.
//
// Validity constraint: No Notation on Empty Element
// For compatibility, an attribute of type NOTATION MUST NOT be declared on an element declared EMPTY.
//
// Validity constraint: No Duplicate Tokens
// The notation names in a single NotationType attribute declaration, as well as
// the NmTokens in a single Enumeration attribute declaration, MUST all be distinct.
//
XMLAttDefList& attDefList = curElem.getAttDefList();
bool seenId = false;
bool seenNOTATION = false;
bool elemEmpty = (curElem.getModelType() == DTDElementDecl::Empty);
for(XMLSize_t i=0; i<attDefList.getAttDefCount(); i++)
{
const XMLAttDef& curAttDef = attDefList.getAttDef(i);
if (curAttDef.getType() == XMLAttDef::ID)
{
if (seenId)
{
emitError
(
XMLValid::MultipleIdAttrs
, curElem.getFullName()
);
break;
}
seenId = true;
}
else if (curAttDef.getType() == XMLAttDef::Notation)
{
if (seenNOTATION)
{
emitError
(
XMLValid::ElemOneNotationAttr
, curElem.getFullName()
);
break;
}
seenNOTATION = true;
// no notation attribute on empty element
if (elemEmpty)
{
emitError
(
XMLValid::EmptyElemNotationAttr
, curElem.getFullName()
, curAttDef.getFullName()
);
break;
}
//go through enumeration list to check
// distinct
// notation declaration
if (curAttDef.getEnumeration())
{
checkTokenList(curAttDef, true);
}
}
else if (curAttDef.getType() == XMLAttDef::Enumeration )
{
//go through enumeration list to check
// distinct only
if (curAttDef.getEnumeration())
{
checkTokenList(curAttDef, false);
}
}
// If it has a default/fixed value, then validate it
if (validateDefAttr && curAttDef.getValue())
{
validateAttrValue
(
&curAttDef
, curAttDef.getValue()
, true
, &curElem
);
}
}
}
//
// And enumerate all of the general entities. If any of them
// reference a notation, then make sure the notation exists.
//
NameIdPoolEnumerator<DTDEntityDecl> entEnum = fDTDGrammar->getEntityEnumerator();
while (entEnum.hasMoreElements())
{
const DTDEntityDecl& curEntity = entEnum.nextElement();
if (!curEntity.getNotationName())
continue;
// It has a notation name, so look it up
if (!fDTDGrammar->getNotationDecl(curEntity.getNotationName()))
{
emitError
(
XMLValid::NotationNotDeclared
, curEntity.getNotationName()
);
}
}
}
void DTDValidator::postParseValidation()
{
//
// At this time, there is nothing to do here. The scanner itself handles
// ID/IDREF validation, since that is the same no matter what kind of
// validator.
//
}
//
// We need to verify that all of its possible values
// (in the enum list)
// is distinct and
// refer to valid notations if toValidateNotation is set on
//
void DTDValidator::checkTokenList(const XMLAttDef& curAttDef
, bool toValidateNotation)
{
XMLCh* list = XMLString::replicate(curAttDef.getEnumeration(), getScanner()->getMemoryManager());
ArrayJanitor<XMLCh> janList(list, getScanner()->getMemoryManager());
//
// Search forward for a space or a null. If a null,
// we are done. If a space, cap it and look it up.
//
bool breakFlag = false;
XMLCh* listPtr = list;
XMLCh* lastPtr = listPtr;
while (true)
{
while (*listPtr && (*listPtr != chSpace))
listPtr++;
//
// If at the end, indicate we need to break after
// this one. Else, cap it off here.
//
if (!*listPtr)
breakFlag = true;
else
*listPtr++ = chNull;
//distinction check
//there should be no same token found in the remaining list
if (XMLString::isInList(lastPtr, listPtr))
{
emitError
(
XMLValid::AttrDupToken
, curAttDef.getFullName()
, lastPtr
);
}
if (toValidateNotation && !fDTDGrammar->getNotationDecl(lastPtr))
{
emitError
(
XMLValid::UnknownNotRefAttr
, curAttDef.getFullName()
, lastPtr
);
}
// Break out if we hit the end last time
if (breakFlag)
break;
// Else move upwards and try again
lastPtr = listPtr;
}
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,158 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DTDValidator.hpp 676911 2008-07-15 13:27:32Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DTDVALIDATOR_HPP)
#define XERCESC_INCLUDE_GUARD_DTDVALIDATOR_HPP
#include <xercesc/util/NameIdPool.hpp>
#include <xercesc/framework/XMLValidator.hpp>
#include <xercesc/validators/DTD/DTDGrammar.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLMsgLoader;
//
// This is a derivative of the abstract validator interface. This class
// implements a validator that supports standard XML 1.0 DTD semantics.
// This class handles scanning the internal and external subsets of the
// DTD, and provides the standard validation services against the DTD info
// it found.
//
class VALIDATORS_EXPORT DTDValidator : public XMLValidator
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DTDValidator(XMLErrorReporter* const errReporter = 0);
virtual ~DTDValidator();
// -----------------------------------------------------------------------
// Implementation of the XMLValidator interface
// -----------------------------------------------------------------------
virtual bool checkContent
(
XMLElementDecl* const elemDecl
, QName** const children
, XMLSize_t childCount
, XMLSize_t* indexFailingChild
);
virtual void faultInAttr
(
XMLAttr& toFill
, const XMLAttDef& attDef
) const;
virtual void preContentValidation(bool reuseGrammar,
bool validateDefAttr = false);
virtual void postParseValidation();
virtual void reset();
virtual bool requiresNamespaces() const;
virtual void validateAttrValue
(
const XMLAttDef* attDef
, const XMLCh* const attrValue
, bool preValidation = false
, const XMLElementDecl* elemDecl = 0
);
virtual void validateElement
(
const XMLElementDecl* elemDef
);
virtual Grammar* getGrammar() const;
virtual void setGrammar(Grammar* aGrammar);
// -----------------------------------------------------------------------
// Virtual DTD handler interface.
// -----------------------------------------------------------------------
virtual bool handlesDTD() const;
// -----------------------------------------------------------------------
// Virtual Schema handler interface. handlesSchema() always return false.
// -----------------------------------------------------------------------
virtual bool handlesSchema() const;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DTDValidator(const DTDValidator &);
DTDValidator& operator = (const DTDValidator&);
// -----------------------------------------------------------------------
// Helper
// -----------------------------------------------------------------------
void checkTokenList(const XMLAttDef& attDef
, bool toValidateNotation);
// -----------------------------------------------------------------------
// Private data members
//
// fDTDGrammar
// The DTD information stored.
//
// -----------------------------------------------------------------------
DTDGrammar* fDTDGrammar;
};
// ---------------------------------------------------------------------------
// Virtual interface
// ---------------------------------------------------------------------------
inline Grammar* DTDValidator::getGrammar() const {
return fDTDGrammar;
}
inline void DTDValidator::setGrammar(Grammar* aGrammar) {
fDTDGrammar = (DTDGrammar*) aGrammar;
}
inline void DTDValidator::validateElement (const XMLElementDecl*) {
// no special DTD Element validation
}
// ---------------------------------------------------------------------------
// DTDValidator: DTD handler interface
// ---------------------------------------------------------------------------
inline bool DTDValidator::handlesDTD() const
{
// We definitely want to handle DTD scanning
return true;
}
// ---------------------------------------------------------------------------
// DTDValidator: Schema handler interface
// ---------------------------------------------------------------------------
inline bool DTDValidator::handlesSchema() const
{
// No Schema scanning
return false;
}
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,145 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: DocTypeHandler.hpp 557282 2007-07-18 14:54:15Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOCTYPEHANDLER_HPP)
#define XERCESC_INCLUDE_GUARD_DOCTYPEHANDLER_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/framework/XMLNotationDecl.hpp>
#include <xercesc/validators/DTD/DTDAttDef.hpp>
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
#include <xercesc/validators/DTD/DTDEntityDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This abstract class defines the document type handler API's which can be
// used to process the DTD events generated by the DTDScanner as it scans the
// internal and external subset.
class VALIDATORS_EXPORT DocTypeHandler
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
DocTypeHandler()
{
}
virtual ~DocTypeHandler()
{
}
// -----------------------------------------------------------------------
// The document type handler virtual handler interface
// -----------------------------------------------------------------------
virtual void attDef
(
const DTDElementDecl& elemDecl
, const DTDAttDef& attDef
, const bool ignoring
) = 0;
virtual void doctypeComment
(
const XMLCh* const comment
) = 0;
virtual void doctypeDecl
(
const DTDElementDecl& elemDecl
, const XMLCh* const publicId
, const XMLCh* const systemId
, const bool hasIntSubset
, const bool hasExtSubset = false
) = 0;
virtual void doctypePI
(
const XMLCh* const target
, const XMLCh* const data
) = 0;
virtual void doctypeWhitespace
(
const XMLCh* const chars
, const XMLSize_t length
) = 0;
virtual void elementDecl
(
const DTDElementDecl& decl
, const bool isIgnored
) = 0;
virtual void endAttList
(
const DTDElementDecl& elemDecl
) = 0;
virtual void endIntSubset() = 0;
virtual void endExtSubset() = 0;
virtual void entityDecl
(
const DTDEntityDecl& entityDecl
, const bool isPEDecl
, const bool isIgnored
) = 0;
virtual void resetDocType() = 0;
virtual void notationDecl
(
const XMLNotationDecl& notDecl
, const bool isIgnored
) = 0;
virtual void startAttList
(
const DTDElementDecl& elemDecl
) = 0;
virtual void startIntSubset() = 0;
virtual void startExtSubset() = 0;
virtual void TextDecl
(
const XMLCh* const versionStr
, const XMLCh* const encodingStr
) = 0;
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
DocTypeHandler(const DocTypeHandler&);
DocTypeHandler& operator=(const DocTypeHandler&);
};
XERCES_CPP_NAMESPACE_END
#endif
@@ -0,0 +1,133 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: XMLDTDDescriptionImpl.cpp 471747 2006-11-06 14:31:56Z amassari $
*/
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
#include <xercesc/validators/DTD/XMLDTDDescriptionImpl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
// ---------------------------------------------------------------------------
// XMLDTDDescriptionImpl: constructor and destructor
// ---------------------------------------------------------------------------
XMLDTDDescriptionImpl::XMLDTDDescriptionImpl(const XMLCh* const systemId
, MemoryManager* const memMgr )
:XMLDTDDescription(memMgr)
,fSystemId(0)
,fRootName(0)
{
if (systemId)
fSystemId = XMLString::replicate(systemId, memMgr);
}
XMLDTDDescriptionImpl::~XMLDTDDescriptionImpl()
{
if (fSystemId)
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fSystemId);
if (fRootName)
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fRootName);
}
const XMLCh* XMLDTDDescriptionImpl::getGrammarKey() const
{
return getSystemId();
}
const XMLCh* XMLDTDDescriptionImpl::getRootName() const
{
return fRootName;
}
const XMLCh* XMLDTDDescriptionImpl::getSystemId() const
{
return fSystemId;
}
void XMLDTDDescriptionImpl::setRootName(const XMLCh* const rootName)
{
if (fRootName)
{
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fRootName);
fRootName = 0;
}
if (rootName)
fRootName = XMLString::replicate(rootName, XMLGrammarDescription::getMemoryManager());
}
void XMLDTDDescriptionImpl::setSystemId(const XMLCh* const systemId)
{
if (fSystemId)
{
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fSystemId);
fSystemId = 0;
}
if (systemId)
fSystemId = XMLString::replicate(systemId, XMLGrammarDescription::getMemoryManager());
}
/***
* Support for Serialization/De-serialization
***/
IMPL_XSERIALIZABLE_TOCREATE(XMLDTDDescriptionImpl)
void XMLDTDDescriptionImpl::serialize(XSerializeEngine& serEng)
{
XMLDTDDescription::serialize(serEng);
if (serEng.isStoring())
{
serEng.writeString(fSystemId);
serEng.writeString(fRootName);
}
else
{
if (fSystemId)
{
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fSystemId);
}
serEng.readString((XMLCh*&)fSystemId);
//the original root name which came from the ctor needs deallocated
if (fRootName)
{
XMLGrammarDescription::getMemoryManager()->deallocate((void*)fRootName);
}
serEng.readString((XMLCh*&)fRootName);
}
}
XMLDTDDescriptionImpl::XMLDTDDescriptionImpl(MemoryManager* const memMgr)
:XMLDTDDescription(memMgr)
,fSystemId(0)
,fRootName(0)
{
}
XERCES_CPP_NAMESPACE_END
@@ -0,0 +1,108 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
/*
* $Id: XMLDTDDescriptionImpl.hpp 527149 2007-04-10 14:56:39Z amassari $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XMLDTDDESCRIPTIONIMPL_HPP)
#define XERCESC_INCLUDE_GUARD_XMLDTDDESCRIPTIONIMPL_HPP
#include <xercesc/framework/XMLDTDDescription.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLPARSER_EXPORT XMLDTDDescriptionImpl : public XMLDTDDescription
{
public :
// -----------------------------------------------------------------------
/** @name constructor and destructor */
// -----------------------------------------------------------------------
//@{
XMLDTDDescriptionImpl(
const XMLCh* const systemId
, MemoryManager* const memMgr
);
~XMLDTDDescriptionImpl();
//@}
// -----------------------------------------------------------------------
/** @name Implementation of GrammarDescription Interface */
// -----------------------------------------------------------------------
//@{
/**
* getGrammarKey
*
*/
virtual const XMLCh* getGrammarKey() const ;
//@}
// -----------------------------------------------------------------------
/** @name Implementation of DTDDescription Interface */
// -----------------------------------------------------------------------
//@{
/**
* Getter
*
*/
virtual const XMLCh* getRootName() const;
virtual const XMLCh* getSystemId() const;
/**
* Setter
*
*/
virtual void setRootName(const XMLCh* const);
virtual void setSystemId(const XMLCh* const);
//@}
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XMLDTDDescriptionImpl)
XMLDTDDescriptionImpl(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
private :
// -----------------------------------------------------------------------
/** name Unimplemented copy constructor and operator= */
// -----------------------------------------------------------------------
//@{
XMLDTDDescriptionImpl(const XMLDTDDescriptionImpl& );
XMLDTDDescriptionImpl& operator=(const XMLDTDDescriptionImpl& );
//@}
// -----------------------------------------------------------------------
//
// fSystemId:
// SYSTEM ID of the grammar
//
// fRootName:
// root name of the grammar
//
// -----------------------------------------------------------------------
const XMLCh* fSystemId;
const XMLCh* fRootName;
};
XERCES_CPP_NAMESPACE_END
#endif