Added Xerces-C++ 3.1.2
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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: BinOutputStream.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/BinOutputStream.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BinOutputStream: Virtual destructor!
|
||||
// ---------------------------------------------------------------------------
|
||||
BinOutputStream::~BinOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BinOutputStream: Hidden Constructors
|
||||
// ---------------------------------------------------------------------------
|
||||
BinOutputStream::BinOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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: BinOutputStream.hpp 553915 2007-07-06 14:57:08Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_BIN_OUTPUT_STREAM_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_BIN_OUTPUT_STREAM_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT BinOutputStream : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual destructor for derived classes
|
||||
// -----------------------------------------------------------------------
|
||||
virtual ~BinOutputStream();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual output stream interface
|
||||
// -----------------------------------------------------------------------
|
||||
virtual XMLFilePos curPos() const = 0;
|
||||
|
||||
virtual void writeBytes
|
||||
(
|
||||
const XMLByte* const toGo
|
||||
, const XMLSize_t maxToWrite
|
||||
) = 0;
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
BinOutputStream();
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
BinOutputStream(const BinOutputStream&);
|
||||
BinOutputStream& operator=(const BinOutputStream&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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: LocalFileFormatTarget.cpp 1662880 2015-02-28 01:55:31Z scantor $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/LocalFileFormatTarget.hpp>
|
||||
#include <xercesc/framework/MemoryManager.hpp>
|
||||
#include <xercesc/util/IOException.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
const XMLSize_t MAX_BUFFER_SIZE = 65536;
|
||||
|
||||
LocalFileFormatTarget::LocalFileFormatTarget( const XMLCh* const fileName
|
||||
, MemoryManager* const manager)
|
||||
: fSource(0)
|
||||
, fDataBuf(0)
|
||||
, fIndex(0)
|
||||
, fCapacity(1024)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fSource = XMLPlatformUtils::openFileToWrite(fileName, manager);
|
||||
|
||||
if (fSource == (FileHandle) XERCES_Invalid_File_Handle)
|
||||
ThrowXMLwithMemMgr1(IOException, XMLExcepts::File_CouldNotOpenFile, fileName, fMemoryManager);
|
||||
|
||||
fDataBuf = (XMLByte*) fMemoryManager->allocate (
|
||||
fCapacity * sizeof(XMLByte));
|
||||
}
|
||||
|
||||
LocalFileFormatTarget::LocalFileFormatTarget( const char* const fileName
|
||||
, MemoryManager* const manager)
|
||||
: fSource(0)
|
||||
, fDataBuf(0)
|
||||
, fIndex(0)
|
||||
, fCapacity(1024)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fSource = XMLPlatformUtils::openFileToWrite(fileName, manager);
|
||||
|
||||
if (fSource == (FileHandle) XERCES_Invalid_File_Handle)
|
||||
ThrowXMLwithMemMgr1(IOException, XMLExcepts::File_CouldNotOpenFile, fileName, fMemoryManager);
|
||||
|
||||
fDataBuf = (XMLByte*) fMemoryManager->allocate (
|
||||
fCapacity * sizeof(XMLByte));
|
||||
}
|
||||
|
||||
LocalFileFormatTarget::~LocalFileFormatTarget()
|
||||
{
|
||||
if (fSource && fSource != (FileHandle) XERCES_Invalid_File_Handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
// flush remaining buffer before destroy
|
||||
flush();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// There is nothing we can do about it here.
|
||||
}
|
||||
// XERCESC-2024: use separate try/catch so that we close the handle
|
||||
// even when flush() failed (e.g. because of a disk full)
|
||||
try
|
||||
{
|
||||
XMLPlatformUtils::closeFile(fSource, fMemoryManager);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// There is nothing we can do about it here.
|
||||
}
|
||||
}
|
||||
|
||||
fMemoryManager->deallocate(fDataBuf);//delete [] fDataBuf;
|
||||
}
|
||||
|
||||
void LocalFileFormatTarget::flush()
|
||||
{
|
||||
XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
|
||||
fIndex = 0;
|
||||
}
|
||||
|
||||
void LocalFileFormatTarget::writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter * const)
|
||||
{
|
||||
if (count == 0)
|
||||
return;
|
||||
if (count < MAX_BUFFER_SIZE)
|
||||
{
|
||||
// If we don't have enough space, see if we can grow the buffer.
|
||||
//
|
||||
if (fIndex + count > fCapacity && fCapacity < MAX_BUFFER_SIZE)
|
||||
ensureCapacity (count);
|
||||
|
||||
// If still not enough space, flush the buffer.
|
||||
//
|
||||
if (fIndex + count > fCapacity)
|
||||
flush();
|
||||
|
||||
memcpy(&fDataBuf[fIndex], toWrite, count * sizeof(XMLByte));
|
||||
fIndex += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
// block is too big to cache, flush the current cache...
|
||||
//
|
||||
if (fIndex)
|
||||
flush();
|
||||
|
||||
//... then write the data directly to disk
|
||||
//
|
||||
XMLPlatformUtils::writeBufferToFile(fSource, count, toWrite, fMemoryManager);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalFileFormatTarget::ensureCapacity(const XMLSize_t extraNeeded)
|
||||
{
|
||||
XMLSize_t newCap = fCapacity * 2;
|
||||
|
||||
while (fIndex + extraNeeded > newCap)
|
||||
newCap *= 2;
|
||||
|
||||
XMLByte* newBuf = (XMLByte*) fMemoryManager->allocate (
|
||||
newCap * sizeof(XMLByte));
|
||||
|
||||
// Copy over the old stuff
|
||||
memcpy(newBuf, fDataBuf, fIndex * sizeof(XMLByte));
|
||||
|
||||
// Clean up old buffer and store new stuff
|
||||
fMemoryManager->deallocate(fDataBuf);
|
||||
fDataBuf = newBuf;
|
||||
fCapacity = newCap;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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: LocalFileFormatTarget.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_LOCALFILEFORMATTARGET_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_LOCALFILEFORMATTARGET_HPP
|
||||
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLPARSER_EXPORT LocalFileFormatTarget : public XMLFormatTarget {
|
||||
public:
|
||||
|
||||
/** @name constructors and destructor */
|
||||
//@{
|
||||
LocalFileFormatTarget
|
||||
(
|
||||
const XMLCh* const
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
LocalFileFormatTarget
|
||||
(
|
||||
const char* const
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
~LocalFileFormatTarget();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the format target interface
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter);
|
||||
|
||||
virtual void flush();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented methods.
|
||||
// -----------------------------------------------------------------------
|
||||
LocalFileFormatTarget(const LocalFileFormatTarget&);
|
||||
LocalFileFormatTarget& operator=(const LocalFileFormatTarget&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private helpers
|
||||
// -----------------------------------------------------------------------
|
||||
void ensureCapacity(const XMLSize_t extraNeeded);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fSource
|
||||
// The source file that we represent. The FileHandle type is defined
|
||||
// per platform.
|
||||
//
|
||||
// fDataBuf
|
||||
// The pointer to the buffer data. Its always
|
||||
// one larger than fCapacity, to leave room for the null terminator.
|
||||
//
|
||||
// fIndex
|
||||
// The current index into the buffer, as characters are appended
|
||||
// to it. If its zero, then the buffer is empty.
|
||||
//
|
||||
// fCapacity
|
||||
// The current capacity of the buffer. Its actually always one
|
||||
// larger, to leave room for the null terminator.
|
||||
// -----------------------------------------------------------------------
|
||||
FileHandle fSource;
|
||||
XMLByte* fDataBuf;
|
||||
XMLSize_t fIndex;
|
||||
XMLSize_t fCapacity;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/LocalFileInputSource.hpp>
|
||||
#include <xercesc/util/BinFileInputStream.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/***
|
||||
*
|
||||
* Originated by Chris larsson
|
||||
*
|
||||
* Issue:
|
||||
*
|
||||
* There is an inconsistency in URI resolution in the case where the file itself is a
|
||||
* symbolic link to another path (or the path has path segment which is a symbolic
|
||||
* link to another path). So, is the base path the directory where the symbolic link resides
|
||||
* or the directory where the real file resides? I'm sure one could argue either way,
|
||||
* but I think that having the base path be the directory where the symbolic link resides
|
||||
* is more intuitive.
|
||||
*
|
||||
* Defining it this way would then make the behavior consistent with using an absolute
|
||||
* path as well as with the java behavior.
|
||||
*
|
||||
* Proposal:
|
||||
*
|
||||
* The URI is resolved within the parser code, and is somewhat independant of the OS.
|
||||
*
|
||||
* A relative path is resolved by querying the current directory and appending the
|
||||
* relative part onto the returned current directory string to obtain the base URI.
|
||||
* An absolute path is simply used as the base URI.
|
||||
* Then remove all "./" and "../" path segments using an algorithm like weavepath to obtain
|
||||
* the resolved base URI.
|
||||
*
|
||||
* When you need to access another file such as a dtd, use the resolved base URI and add on
|
||||
* the relative URI of the dtd file. Then resolve it using the same weavepath algorithm.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* Java parser behaves differently for a path containning symbolic path segment. When
|
||||
* it is given an absolute path, it can locate the primary instance document, while given
|
||||
* relative path, it might not.
|
||||
*
|
||||
* It is because Java parser uses URI solution where "/segment/../" is required to be removed
|
||||
* from the resultant path if a relative URI is merged to a baseURI. While this is NOT required
|
||||
* for an absolute URI.
|
||||
*
|
||||
* So if a path segment, which is symbolic link, happen to be followed by the '/../', it is
|
||||
* NOT removed from the path if it is given in absolute form, and the underlying file system
|
||||
* will locate the file, if in relative form, that symbolic link path segment together with
|
||||
* '../' is removed from the resultant path, and the file system may NOT be able to locate
|
||||
* the file, if there is a one, it is definitely not the one expected, in fact by accident.
|
||||
*
|
||||
* Therefore, to keep consistent with Java parser, for now, we do not apply removeDotDotSlash()
|
||||
* for absolute path.
|
||||
*
|
||||
***/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// LocalFileInputSource: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
LocalFileInputSource::LocalFileInputSource( const XMLCh* const basePath
|
||||
, const XMLCh* const relativePath
|
||||
, MemoryManager* const manager)
|
||||
: InputSource(manager)
|
||||
{
|
||||
//
|
||||
// If the relative part is really relative, then weave it together
|
||||
// with the base path. If not, just take the relative path as the
|
||||
// entire path.
|
||||
//
|
||||
if (XMLPlatformUtils::isRelative(relativePath, manager))
|
||||
{
|
||||
XMLCh* tmpBuf = XMLPlatformUtils::weavePaths(basePath, relativePath, manager);
|
||||
setSystemId(tmpBuf);
|
||||
manager->deallocate(tmpBuf); //delete [] tmpBuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLCh* tmpBuf = XMLString::replicate(relativePath, manager);
|
||||
XMLPlatformUtils::removeDotSlash(tmpBuf, manager);
|
||||
setSystemId(tmpBuf);
|
||||
manager->deallocate(tmpBuf);//delete [] tmpBuf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LocalFileInputSource::LocalFileInputSource(const XMLCh* const filePath,
|
||||
MemoryManager* const manager)
|
||||
: InputSource(manager)
|
||||
{
|
||||
|
||||
//
|
||||
// If the path is relative, then complete it acording to the current
|
||||
// working directory rules of the current platform. Else, just take
|
||||
// it as is.
|
||||
//
|
||||
if (XMLPlatformUtils::isRelative(filePath, manager))
|
||||
{
|
||||
XMLCh* curDir = XMLPlatformUtils::getCurrentDirectory(manager);
|
||||
|
||||
XMLSize_t curDirLen = XMLString::stringLen(curDir);
|
||||
XMLSize_t filePathLen = XMLString::stringLen(filePath);
|
||||
XMLCh* fullDir = (XMLCh*) manager->allocate
|
||||
(
|
||||
(curDirLen + filePathLen + 2) * sizeof(XMLCh)
|
||||
);//new XMLCh [ curDirLen + filePathLen + 2];
|
||||
|
||||
XMLString::copyString(fullDir, curDir);
|
||||
fullDir[curDirLen] = chForwardSlash;
|
||||
XMLString::copyString(&fullDir[curDirLen+1], filePath);
|
||||
|
||||
XMLPlatformUtils::removeDotSlash(fullDir, manager);
|
||||
XMLPlatformUtils::removeDotDotSlash(fullDir, manager);
|
||||
|
||||
setSystemId(fullDir);
|
||||
|
||||
manager->deallocate(curDir);//delete [] curDir;
|
||||
manager->deallocate(fullDir);//delete [] fullDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLCh* tmpBuf = XMLString::replicate(filePath, manager);
|
||||
XMLPlatformUtils::removeDotSlash(tmpBuf, manager);
|
||||
setSystemId(tmpBuf);
|
||||
manager->deallocate(tmpBuf);//delete [] tmpBuf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LocalFileInputSource::~LocalFileInputSource()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// LocalFileInputSource: InputSource interface implementation
|
||||
// ---------------------------------------------------------------------------
|
||||
BinInputStream* LocalFileInputSource::makeStream() const
|
||||
{
|
||||
BinFileInputStream* retStrm = new (getMemoryManager()) BinFileInputStream(getSystemId(), getMemoryManager());
|
||||
if (!retStrm->getIsOpen())
|
||||
{
|
||||
delete retStrm;
|
||||
return 0;
|
||||
}
|
||||
return retStrm;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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: LocalFileInputSource.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_LOCALFILEINPUTSOURCE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_LOCALFILEINPUTSOURCE_HPP
|
||||
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class BinInputStream;
|
||||
|
||||
/**
|
||||
* This class is a derivative of the standard InputSource class. It provides
|
||||
* for the parser access to data which is referenced via a local file path,
|
||||
* as apposed to remote file or URL. This is the most efficacious mechanism
|
||||
* by which local files can be parsed, since the parse knows that it refers
|
||||
* to a local file and will make no other attempts to interpret the passed
|
||||
* path.
|
||||
*
|
||||
* The path provided can either be a fully qualified path or a relative path.
|
||||
* If relative, it will be completed either relative to a passed base path
|
||||
* or relative to the current working directory of the process.
|
||||
*
|
||||
* As with all InputSource derivatives. The primary objective of an input
|
||||
* source is to create an input stream via which the parser can spool in
|
||||
* data from the referenced source.
|
||||
*/
|
||||
class XMLPARSER_EXPORT LocalFileInputSource : public InputSource
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* A local file input source requires a path to the file to load. This
|
||||
* can be provided either as a fully qualified path, a path relative to
|
||||
* the current working directly, or a path relative to a provided base
|
||||
* path.
|
||||
*
|
||||
* The completed path will become the system id of this input source.
|
||||
* The constructors don't take any public id for local files, but you
|
||||
* still set them via the parent class' setPublicId() method of course.
|
||||
*
|
||||
* This constructor takes an explicit base path and a possibly relative
|
||||
* path. If the relative path is seen to be fully qualified, it is used
|
||||
* as is. Otherwise, it is made relative to the passed base path.
|
||||
*
|
||||
* @param basePath The base path from which the passed relative path
|
||||
* will be based, if the relative part is indeed
|
||||
* relative.
|
||||
*
|
||||
* @param relativePath The relative part of the path. It can actually
|
||||
* be fully qualified, in which case it is taken
|
||||
* as is.
|
||||
*
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*
|
||||
* @exception XMLException If the path is relative and doesn't properly
|
||||
* resolve to a file.
|
||||
*/
|
||||
LocalFileInputSource
|
||||
(
|
||||
const XMLCh* const basePath
|
||||
, const XMLCh* const relativePath
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* This constructor takes a single parameter which is the fully qualified
|
||||
* or relative path. If it is fully qualified, it is taken as is. If it is
|
||||
* relative, then it is completed relative to the current working directory
|
||||
* (or the equivalent on the local host machine.)
|
||||
*
|
||||
* The completed path will become the system id of this input source.
|
||||
* The constructors don't take any public id for local files, but you
|
||||
* still set them via the parent class' setPublicId() method of course.
|
||||
*
|
||||
* @param filePath The relative or fully qualified path.
|
||||
*
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*
|
||||
* @exception XMLException If the path is relative and doesn't properly
|
||||
* resolve to a file.
|
||||
*/
|
||||
LocalFileInputSource
|
||||
(
|
||||
const XMLCh* const filePath
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~LocalFileInputSource();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual input source interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will return a binary input stream derivative that will
|
||||
* parse from the local file indicatedby the system id.
|
||||
*
|
||||
* @return A dynamically allocated binary input stream derivative that
|
||||
* can parse from the file indicated by the system id.
|
||||
*/
|
||||
virtual BinInputStream* makeStream() const;
|
||||
|
||||
//@}
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
LocalFileInputSource(const LocalFileInputSource&);
|
||||
LocalFileInputSource& operator=(const LocalFileInputSource&);
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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: MemBufFormatTarget.cpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/MemBufFormatTarget.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
MemBufFormatTarget::MemBufFormatTarget( XMLSize_t initCapacity
|
||||
, MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fDataBuf(0)
|
||||
, fIndex(0)
|
||||
, fCapacity(initCapacity)
|
||||
{
|
||||
// Buffer is one larger than capacity, to allow for zero term
|
||||
fDataBuf = (XMLByte*) fMemoryManager->allocate
|
||||
(
|
||||
(fCapacity + 4) * sizeof(XMLByte)
|
||||
);//new XMLByte[fCapacity+4];
|
||||
|
||||
// Keep it null terminated
|
||||
fDataBuf[0] = XMLByte(0);
|
||||
}
|
||||
|
||||
MemBufFormatTarget::~MemBufFormatTarget()
|
||||
{
|
||||
fMemoryManager->deallocate(fDataBuf);//delete [] fDataBuf;
|
||||
}
|
||||
|
||||
void MemBufFormatTarget::writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter * const)
|
||||
{
|
||||
|
||||
if (count)
|
||||
{
|
||||
if (fIndex + count >= fCapacity)
|
||||
ensureCapacity(count);
|
||||
|
||||
memcpy(&fDataBuf[fIndex], toWrite, count * sizeof(XMLByte));
|
||||
fIndex += count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const XMLByte* MemBufFormatTarget::getRawBuffer() const
|
||||
{
|
||||
fDataBuf[fIndex] = 0;
|
||||
fDataBuf[fIndex + 1] = 0;
|
||||
fDataBuf[fIndex + 2] = 0;
|
||||
fDataBuf[fIndex + 3] = 0;
|
||||
return fDataBuf;
|
||||
}
|
||||
|
||||
void MemBufFormatTarget::reset()
|
||||
{
|
||||
fIndex = 0;
|
||||
fDataBuf[0] = 0;
|
||||
fDataBuf[fIndex + 1] = 0;
|
||||
fDataBuf[fIndex + 2] = 0;
|
||||
fDataBuf[fIndex + 3] = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemBufFormatTarget: Private helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void MemBufFormatTarget::ensureCapacity(const XMLSize_t extraNeeded)
|
||||
{
|
||||
// Oops, not enough room. Calc new capacity and allocate new buffer
|
||||
const XMLSize_t newCap = ((fIndex + extraNeeded) * 2);
|
||||
XMLByte* newBuf = (XMLByte*) fMemoryManager->allocate
|
||||
(
|
||||
(newCap+4) * sizeof(XMLByte)
|
||||
);//new XMLByte[newCap+4];
|
||||
|
||||
// Copy over the old stuff
|
||||
memcpy(newBuf, fDataBuf, fIndex * sizeof(XMLByte));
|
||||
|
||||
// Clean up old buffer and store new stuff
|
||||
fMemoryManager->deallocate(fDataBuf); //delete [] fDataBuf;
|
||||
fDataBuf = newBuf;
|
||||
fCapacity = newCap;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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: MemBufFormatTarget.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_MEMBUFFORMATTARGET_HPP
|
||||
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/*
|
||||
* The MemBufFormatTarget is a derivative from XMLFormatTarget, which user code
|
||||
* may plug into DOMLSSerializer to retrieve the serialized XML stream (from DOM Tree)
|
||||
* in a memory buffer.
|
||||
*
|
||||
* The MemBufFormatTarget is initialized to have a memory buffer of 1023 upon
|
||||
* construction, which grows as needed. The buffer will be deleted when
|
||||
* MemBufFormatTarget is destructed; or will be reset when the reset() function
|
||||
* is called.
|
||||
*
|
||||
* The MemBufFormatTarget returns a NULL terminated XMLByte stream upon request,
|
||||
* through the method getRawBuffer(), and user should make its own copy of the
|
||||
* returned buffer if it intends to keep it independent on the state of the
|
||||
* MemBufFormatTarget.
|
||||
*/
|
||||
|
||||
class XMLPARSER_EXPORT MemBufFormatTarget : public XMLFormatTarget {
|
||||
public:
|
||||
|
||||
/** @name constructors and destructor */
|
||||
//@{
|
||||
MemBufFormatTarget
|
||||
(
|
||||
XMLSize_t initCapacity = 1023
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
) ;
|
||||
~MemBufFormatTarget();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the format target interface
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name getRawBuffer */
|
||||
//@{
|
||||
/**
|
||||
* Returned the internal raw buffer.
|
||||
*
|
||||
*/
|
||||
//@}
|
||||
const XMLByte* getRawBuffer() const;
|
||||
|
||||
/** @name getLen */
|
||||
//@{
|
||||
/**
|
||||
* Returned the length of the raw buffer.
|
||||
*
|
||||
*/
|
||||
//@}
|
||||
XMLSize_t getLen() const
|
||||
{
|
||||
return fIndex;
|
||||
}
|
||||
|
||||
/** @name reset */
|
||||
//@{
|
||||
/**
|
||||
* Reset the internal string buffer.
|
||||
*
|
||||
*/
|
||||
void reset();
|
||||
//@}
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented methods.
|
||||
// -----------------------------------------------------------------------
|
||||
MemBufFormatTarget(const MemBufFormatTarget&);
|
||||
MemBufFormatTarget& operator=(const MemBufFormatTarget&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private helpers
|
||||
// -----------------------------------------------------------------------
|
||||
void ensureCapacity(const XMLSize_t extraNeeded);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fDataBuf
|
||||
// The pointer to the buffer data. Its grown as needed. Its always
|
||||
// one larger than fCapacity, to leave room for the null terminator.
|
||||
//
|
||||
// fIndex
|
||||
// The current index into the buffer, as characters are appended
|
||||
// to it. If its zero, then the buffer is empty.
|
||||
//
|
||||
// fCapacity
|
||||
// The current capacity of the buffer. Its actually always one
|
||||
// larger, to leave room for the null terminator.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager* fMemoryManager;
|
||||
XMLByte* fDataBuf;
|
||||
XMLSize_t fIndex;
|
||||
XMLSize_t fCapacity;
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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: MemBufInputSource.cpp 553941 2007-07-06 16:14:22Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/BinMemInputStream.hpp>
|
||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemBufInputSource: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount
|
||||
, const XMLCh* const bufId
|
||||
, const bool adoptBuffer
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(bufId, manager)
|
||||
, fAdopted(adoptBuffer)
|
||||
, fByteCount(byteCount)
|
||||
, fCopyBufToStream(true)
|
||||
, fSrcBytes(srcDocBytes)
|
||||
{
|
||||
}
|
||||
|
||||
MemBufInputSource::MemBufInputSource( const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount
|
||||
, const char* const bufId
|
||||
, const bool adoptBuffer
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(bufId, manager)
|
||||
, fAdopted(adoptBuffer)
|
||||
, fByteCount(byteCount)
|
||||
, fCopyBufToStream(true)
|
||||
, fSrcBytes(srcDocBytes)
|
||||
{
|
||||
}
|
||||
|
||||
MemBufInputSource::~MemBufInputSource()
|
||||
{
|
||||
if (fAdopted)
|
||||
delete [] (XMLByte*)fSrcBytes;
|
||||
}
|
||||
|
||||
void MemBufInputSource::resetMemBufInputSource(const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount)
|
||||
{
|
||||
fByteCount = byteCount;
|
||||
fSrcBytes = srcDocBytes;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MemBufInputSource: InputSource interface implementation
|
||||
// ---------------------------------------------------------------------------
|
||||
BinInputStream* MemBufInputSource::makeStream() const
|
||||
{
|
||||
//
|
||||
// Create a memory input stream over our buffer. According to our
|
||||
// fCopyBufToStream flag, we either tell it to copy the buffer or to
|
||||
// just reference it.
|
||||
//
|
||||
return new (getMemoryManager()) BinMemInputStream
|
||||
(
|
||||
fSrcBytes
|
||||
, fByteCount
|
||||
, fCopyBufToStream ? BinMemInputStream::BufOpt_Copy
|
||||
: BinMemInputStream::BufOpt_Reference
|
||||
, getMemoryManager()
|
||||
);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* 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: MemBufInputSource.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_MEMBUFINPUTSOURCE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_MEMBUFINPUTSOURCE_HPP
|
||||
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class BinInputStream;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a derivative of the standard InputSource class. It provides
|
||||
* for the parser access to data stored in a memory buffer. The type of
|
||||
* buffer and its host specific attributes are of little concern here. The
|
||||
* only real requirement is that the memory be readable by the current
|
||||
* process.
|
||||
*
|
||||
* Note that the memory buffer size is expressed in <b>bytes</b>, not in
|
||||
* characters. If you pass it text data, you must account for the bytes
|
||||
* per character when indicating the buffer size.
|
||||
*
|
||||
* As with all InputSource derivatives. The primary objective of an input
|
||||
* source is to create an input stream via which the parser can spool in
|
||||
* data from the referenced source. In this case, there are two options
|
||||
* available.
|
||||
*
|
||||
* The passed buffer can be adopted or merely referenced. If it is adopted,
|
||||
* then it must be dynamically allocated and will be destroyed when the
|
||||
* input source is destroyed (no reference counting!.) If not adopted, the
|
||||
* caller must insure that it remains valid until the input source object
|
||||
* is destroyed.
|
||||
*
|
||||
* The other option indicates whether each stream created for this input
|
||||
* source should get its own copy of the data, or whether it should just
|
||||
* stream the data directly from this object's copy of the data. The same
|
||||
* rules apply here, in that the buffer must either be copied by the
|
||||
* stream or it must remain valid until the stream is destroyed.
|
||||
*/
|
||||
class XMLPARSER_EXPORT MemBufInputSource : public InputSource
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* A memory buffer input source is constructed from a buffer of byte
|
||||
* data, and the count of bytes in that buffer. The parser will parse
|
||||
* from this memory buffer until it has eaten the indicated number of
|
||||
* bytes.
|
||||
*
|
||||
* Note that the system id provided serves two purposes. Firstly it is
|
||||
* going to be displayed in error messages as the source of the error.
|
||||
* And secondly, any entities which are referred to from this entity
|
||||
* via relative paths/URLs will be relative to this fake system id.
|
||||
*
|
||||
* @param srcDocBytes The actual data buffer to be parsed from.
|
||||
* @param byteCount The count of bytes (not characters, bytes!)
|
||||
* in the buffer.
|
||||
* @param bufId A fake system id for the buffer.
|
||||
* @param adoptBuffer Indicates whether this object should adopt
|
||||
* the buffer (i.e. become responsible for
|
||||
* deletion) or just
|
||||
* use it in place.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
MemBufInputSource
|
||||
(
|
||||
const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount
|
||||
, const XMLCh* const bufId
|
||||
, const bool adoptBuffer = false
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* This constructor is identical to the previous one, except that it takes
|
||||
* the fake system id in local code page form and transcodes it internally.
|
||||
*/
|
||||
MemBufInputSource
|
||||
(
|
||||
const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount
|
||||
, const char* const bufId
|
||||
, const bool adoptBuffer = false
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
/**
|
||||
* If the buffer was adopted, the copy made during construction is deleted
|
||||
* at this point.
|
||||
*/
|
||||
~MemBufInputSource();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual input source interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will return a binary input stream derivative that will
|
||||
* parse from the memory buffer. If setCopyBufToStream() has been set,
|
||||
* then the stream will make its own copy. Otherwise, it will use the
|
||||
* buffer as is (in which case it must remain valid until the stream
|
||||
* is no longer in use, i.e. the parse completes.)
|
||||
*
|
||||
* @return A dynamically allocated binary input stream derivative that
|
||||
* can parse from the memory buffer.
|
||||
*/
|
||||
BinInputStream* makeStream() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* By default, for safety's sake, each newly created stream from this
|
||||
* input source will make its own copy of the buffer to stream from. This
|
||||
* avoids having to deal with aliasing of the buffer for simple work. But,
|
||||
* for higher performance applications or for large buffers, this is
|
||||
* obviously not optimal.
|
||||
*
|
||||
* In such cases, you can call this method to turn off that default
|
||||
* action. Once turned off, the streams will just get a pointer to the
|
||||
* buffer and parse directly from that. In this case, you must insure that
|
||||
* the buffer remains valid for as long as any parse events are still
|
||||
* using it.
|
||||
*
|
||||
* @param newState The new boolean flag state to set.
|
||||
*/
|
||||
void setCopyBufToStream(const bool newState);
|
||||
|
||||
/**
|
||||
* This methods allows the MemBufInputSource to be used for more than
|
||||
* one input source, instead of destructing/constructing another
|
||||
* MemBufInputSource.
|
||||
*
|
||||
* @param srcDocBytes The actual data buffer to be parsed from.
|
||||
* @param byteCount The count of bytes (not characters, bytes!)
|
||||
* in the buffer.
|
||||
*/
|
||||
void resetMemBufInputSource(const XMLByte* const srcDocBytes
|
||||
, const XMLSize_t byteCount);
|
||||
//@}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
MemBufInputSource(const MemBufInputSource&);
|
||||
MemBufInputSource& operator=(const MemBufInputSource&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fAdopted
|
||||
// Indicates whether the buffer is adopted or not. If so, then it
|
||||
// is destroyed when the input source is destroyed.
|
||||
//
|
||||
// fByteCount
|
||||
// The size of the source document.
|
||||
//
|
||||
// fCopyBufToStream
|
||||
// This defaults to true (the safe option), which causes it to
|
||||
// give a copy of the buffer to any streams it creates. If you set
|
||||
// it to false, it will allow the streams to just reference the
|
||||
// buffer (in which case this input source must stay alive as long
|
||||
// as the buffer is in use by the stream.)
|
||||
//
|
||||
// fSrcBytes
|
||||
// The source memory buffer that is being spooled from. Whether it
|
||||
// belongs to the this input source or not is controlled by the
|
||||
// fAdopted flag.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fAdopted;
|
||||
XMLSize_t fByteCount;
|
||||
bool fCopyBufToStream;
|
||||
const XMLByte* fSrcBytes;
|
||||
};
|
||||
|
||||
|
||||
inline void MemBufInputSource::setCopyBufToStream(const bool newState)
|
||||
{
|
||||
fCopyBufToStream = newState;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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: MemoryManager.hpp 673975 2008-07-04 09:23:56Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_MEMORYMANAGER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_MEMORYMANAGER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
/**
|
||||
* Configurable memory manager
|
||||
*
|
||||
* <p>This interface allows outside applications to plug in their own memory
|
||||
* manager to be used by Xerces for memory allocation/deallocation.</p>
|
||||
*/
|
||||
class XMLPARSER_EXPORT MemoryManager
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, only the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*/
|
||||
virtual ~MemoryManager()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called to obtain the memory manager that should be
|
||||
* used to allocate memory used in exceptions. If the same memory
|
||||
* manager can be used, simply return 'this' from this function.
|
||||
* Note, however, that if there is a possibility that an exception
|
||||
* thrown can outlive the memory manager (for example, because the
|
||||
* memory manager object is allocated on the stack or is managed by
|
||||
* a stack-bound object), it is recommended that you return
|
||||
* XMLPlatformUtils::fgMemoryManager.
|
||||
*
|
||||
* @return A pointer to the memory manager
|
||||
*/
|
||||
virtual MemoryManager* getExceptionMemoryManager() = 0;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual memory manager interface
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The pure virtual methods in this interface. */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method allocates requested memory.
|
||||
*
|
||||
* @param size The requested memory size
|
||||
*
|
||||
* @return A pointer to the allocated memory
|
||||
*/
|
||||
virtual void* allocate(XMLSize_t size) = 0;
|
||||
|
||||
/**
|
||||
* This method deallocates memory
|
||||
*
|
||||
* @param p The pointer to the allocated memory to be deleted
|
||||
*/
|
||||
virtual void deallocate(void* p) = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Protected default constructor
|
||||
*/
|
||||
MemoryManager()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager(const MemoryManager&);
|
||||
MemoryManager& operator=(const MemoryManager&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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: StdInInputSource.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/BinFileInputStream.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/StdInInputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StdInInputSource: Implementation of the input source interface
|
||||
// ---------------------------------------------------------------------------
|
||||
BinInputStream* StdInInputSource::makeStream() const
|
||||
{
|
||||
// Open a binary file stream for the standard input file handle
|
||||
BinFileInputStream* retStream = new (getMemoryManager()) BinFileInputStream
|
||||
(
|
||||
XMLPlatformUtils::openStdInHandle(getMemoryManager())
|
||||
);
|
||||
|
||||
if (!retStream->getIsOpen())
|
||||
{
|
||||
delete retStream;
|
||||
return 0;
|
||||
}
|
||||
return retStream;
|
||||
}
|
||||
|
||||
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: StdInInputSource.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_STDININPUTSOURCE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_STDININPUTSOURCE_HPP
|
||||
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class BinInputStream;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a derivative of the standard InputSource class. It provides
|
||||
* for the parser access to data via the standard input. This input source
|
||||
* is not commonly used, but can be useful when implementing such things
|
||||
* as pipe based tools which exchange XML data.
|
||||
*
|
||||
* As with all InputSource derivatives. The primary objective of an input
|
||||
* source is to create an input stream via which the parser can spool in
|
||||
* data from the referenced source.
|
||||
*/
|
||||
class XMLPARSER_EXPORT StdInInputSource : public InputSource
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Since the standard input is a canned source, the constructor is very
|
||||
* simple. It just uses local platform services to open up the standard
|
||||
* input source as file, a new handleof which it gives to each new stream
|
||||
* it creates.
|
||||
*/
|
||||
StdInInputSource(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~StdInInputSource();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual input source interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
|
||||
/** @name Virtual methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will return a binary input stream derivative that will
|
||||
* parse from the standard input of the local host.
|
||||
*
|
||||
* @return A dynamically allocated binary input stream derivative that
|
||||
* can parse from the standardinput.
|
||||
*/
|
||||
BinInputStream* makeStream() const;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
StdInInputSource(const StdInInputSource&);
|
||||
StdInInputSource& operator=(const StdInInputSource&);
|
||||
|
||||
};
|
||||
|
||||
inline StdInInputSource::StdInInputSource(MemoryManager* const manager) :
|
||||
|
||||
InputSource("stdin", manager)
|
||||
{
|
||||
}
|
||||
|
||||
inline StdInInputSource::~StdInInputSource()
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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: StdOutFormatTarget.cpp 881225 2009-11-17 10:19:57Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/StdOutFormatTarget.hpp>
|
||||
#include <stdio.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
StdOutFormatTarget::StdOutFormatTarget()
|
||||
{}
|
||||
|
||||
StdOutFormatTarget::~StdOutFormatTarget()
|
||||
{
|
||||
flush ();
|
||||
}
|
||||
|
||||
void StdOutFormatTarget::flush()
|
||||
{
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void StdOutFormatTarget::writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const)
|
||||
{
|
||||
XMLSize_t written=fwrite(toWrite, sizeof(XMLByte), count, stdout);
|
||||
if(written!=count)
|
||||
ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotWriteToFile);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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: StdOutFormatTarget.hpp 553937 2007-07-06 16:02:19Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_STDOUTFORMATTARGET_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_STDOUTFORMATTARGET_HPP
|
||||
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLPARSER_EXPORT StdOutFormatTarget : public XMLFormatTarget {
|
||||
public:
|
||||
|
||||
/** @name constructors and destructor */
|
||||
//@{
|
||||
StdOutFormatTarget() ;
|
||||
~StdOutFormatTarget();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementations of the format target interface
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void writeChars(const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter);
|
||||
|
||||
virtual void flush();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented methods.
|
||||
// -----------------------------------------------------------------------
|
||||
StdOutFormatTarget(const StdOutFormatTarget&);
|
||||
StdOutFormatTarget& operator=(const StdOutFormatTarget&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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: URLInputSource.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/BinFileInputStream.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#include <xercesc/util/XMLURL.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/framework/URLInputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// URLInputSource: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
URLInputSource::URLInputSource( const XMLURL& urlId
|
||||
, MemoryManager* const manager) :
|
||||
|
||||
InputSource(manager)
|
||||
, fURL(urlId)
|
||||
{
|
||||
setSystemId(fURL.getURLText());
|
||||
}
|
||||
|
||||
URLInputSource::URLInputSource( const XMLCh* const baseId
|
||||
, const XMLCh* const systemId
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(manager)
|
||||
, fURL(baseId, systemId)
|
||||
{
|
||||
// Create a URL that will build up the full URL and store as the system id
|
||||
setSystemId(fURL.getURLText());
|
||||
}
|
||||
|
||||
URLInputSource::URLInputSource( const XMLCh* const baseId
|
||||
, const XMLCh* const systemId
|
||||
, const XMLCh* const publicId
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(0, publicId, manager)
|
||||
, fURL(baseId, systemId)
|
||||
{
|
||||
setSystemId(fURL.getURLText());
|
||||
}
|
||||
|
||||
URLInputSource::URLInputSource( const XMLCh* const baseId
|
||||
, const char* const systemId
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(manager)
|
||||
, fURL(baseId, systemId)
|
||||
{
|
||||
setSystemId(fURL.getURLText());
|
||||
}
|
||||
|
||||
URLInputSource::URLInputSource( const XMLCh* const baseId
|
||||
, const char* const systemId
|
||||
, const char* const publicId
|
||||
, MemoryManager* const manager) :
|
||||
InputSource(0, publicId, manager)
|
||||
, fURL(baseId, systemId)
|
||||
{
|
||||
setSystemId(fURL.getURLText());
|
||||
}
|
||||
|
||||
URLInputSource::~URLInputSource()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// URLInputSource: Implementation of the input source interface
|
||||
// ---------------------------------------------------------------------------
|
||||
BinInputStream* URLInputSource::makeStream() const
|
||||
{
|
||||
// Ask the URL to create us an appropriate input stream
|
||||
return fURL.makeNewStream();
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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: URLInputSource.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_URLINPUTSOURCE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_URLINPUTSOURCE_HPP
|
||||
|
||||
#include <xercesc/util/XMLURL.hpp>
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class BinInputStream;
|
||||
|
||||
/**
|
||||
* This class is a derivative of the standard InputSource class. It provides
|
||||
* for the parser access to data which is referenced via a URL, as apposed to
|
||||
* a local file name. The URL can be provided via an XMLURL class, as a fully
|
||||
* qualified system id, or a base system id and a system id which may be
|
||||
* fully qualified or may be relative to the base.
|
||||
*
|
||||
* As with all InputSource derivatives. The primary objective of an input
|
||||
* source is to create an input stream via which the parser can spool in
|
||||
* data from the referenced source.
|
||||
*
|
||||
* Note that the parse system does not necessarily support URL based XML
|
||||
* entities out of the box. Support for socket based access is optional and
|
||||
* controlled by the per-platform support.
|
||||
*/
|
||||
class XMLPARSER_EXPORT URLInputSource : public InputSource
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This constructor accepts an already built URL. It is assumed that
|
||||
* it is correct and it will be used as is. In this case, no public id
|
||||
* accepted, but it can still be set via the parent class' setPublicId()
|
||||
* method.
|
||||
*
|
||||
* @param urlId The URL which holds the system id of the entity
|
||||
* to parse.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
URLInputSource
|
||||
(
|
||||
const XMLURL& urlId
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* This constructor takes a base system id URL and a possibly relative
|
||||
* system id. The relative part is parsed and, if it is indeed relative,
|
||||
* it will be made relative to the passed base id. Otherwise, it will be
|
||||
* taken as is.
|
||||
*
|
||||
* @param baseId The base system id URL which provides the base
|
||||
* for any relative id part.
|
||||
*
|
||||
* @param systemId The possibly relative system id URL. If its relative
|
||||
* its based on baseId, else its taken as is.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
URLInputSource
|
||||
(
|
||||
const XMLCh* const baseId
|
||||
, const XMLCh* const systemId
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* This constructor is identical to the previous one, except that it also
|
||||
* allows you to set a public id if you want to.
|
||||
*
|
||||
* @param baseId The base system id URL which provides the base
|
||||
* for any relative id part.
|
||||
*
|
||||
* @param systemId The possibly relative system id URL. If its relative
|
||||
* its based on baseId, else its taken as is.
|
||||
*
|
||||
* @param publicId The optional public id to set. This is just passed
|
||||
* on to the parent class for storage.
|
||||
*
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
URLInputSource
|
||||
(
|
||||
const XMLCh* const baseId
|
||||
, const XMLCh* const systemId
|
||||
, const XMLCh* const publicId
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* This constructor is identical to the second constructor above, except that
|
||||
* it accepts the relative system id part as a local code page string and
|
||||
* just transcodes it internally, as a convenience.
|
||||
*
|
||||
* @param baseId The base system id URL which provides the base
|
||||
* for any relative id part.
|
||||
*
|
||||
* @param systemId The possibly relative system id URL. If its relative
|
||||
* its based on baseId, else its taken as is.
|
||||
*
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
URLInputSource
|
||||
(
|
||||
const XMLCh* const baseId
|
||||
, const char* const systemId
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* This constructor is identical to the third constructor above, except that
|
||||
* it accepts the relative and public ids as local code page strings and just
|
||||
* transcodes them internally, as a convenience.
|
||||
*
|
||||
* @param baseId The base system id URL which provides the base
|
||||
* for any relative id part.
|
||||
*
|
||||
* @param systemId The possibly relative system id URL. If its relative
|
||||
* its based on baseId, else its taken as is.
|
||||
*
|
||||
* @param publicId The optional public id to set. This is just passed
|
||||
* on to the parent class for storage.
|
||||
* on to the parent class for storage.
|
||||
*
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
URLInputSource
|
||||
(
|
||||
const XMLCh* const baseId
|
||||
, const char* const systemId
|
||||
, const char* const publicId
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~URLInputSource();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual input source interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will return a binary input stream derivative that will
|
||||
* parse from the source referred to by the URL system id.
|
||||
*/
|
||||
BinInputStream* makeStream() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will return a const reference to the URL member which
|
||||
* contains the system id in pre-parsed URL form. If you just want the
|
||||
* string format, call getSystemId() on the parent class.
|
||||
*
|
||||
* @return A const reference to a URL object that contains the current
|
||||
* system id set for this input source.
|
||||
*/
|
||||
const XMLURL& urlSrc() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
URLInputSource(const URLInputSource&);
|
||||
URLInputSource& operator=(const URLInputSource&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fURL
|
||||
// This is the URL created from the passed ids.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLURL fURL;
|
||||
};
|
||||
|
||||
|
||||
inline const XMLURL& URLInputSource::urlSrc() const
|
||||
{
|
||||
return fURL;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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: ValidationContext.hpp 729944 2008-12-29 17:03:32Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_VALIDATION_CONTEXT_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_VALIDATION_CONTEXT_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/RefHashTableOf.hpp>
|
||||
#include <xercesc/util/NameIdPool.hpp>
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLRefInfo;
|
||||
class DTDEntityDecl;
|
||||
class DatatypeValidator;
|
||||
class ElemStack;
|
||||
class NamespaceScope;
|
||||
class XMLScanner;
|
||||
|
||||
class XMLPARSER_EXPORT ValidationContext : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual destructor for derived classes */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* virtual destructor
|
||||
*
|
||||
*/
|
||||
virtual ~ValidationContext(){};
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The ValidationContext Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* IDRefList
|
||||
*
|
||||
*/
|
||||
virtual RefHashTableOf<XMLRefInfo>* getIdRefList() const = 0;
|
||||
|
||||
virtual void setIdRefList(RefHashTableOf<XMLRefInfo>* const) = 0;
|
||||
|
||||
virtual void clearIdRefList() = 0;
|
||||
|
||||
virtual void addId(const XMLCh * const ) = 0;
|
||||
|
||||
virtual void addIdRef(const XMLCh * const ) = 0;
|
||||
|
||||
virtual void toCheckIdRefList(bool) = 0;
|
||||
|
||||
/**
|
||||
* EntityDeclPool
|
||||
*
|
||||
*/
|
||||
virtual const NameIdPool<DTDEntityDecl>* getEntityDeclPool() const = 0;
|
||||
|
||||
virtual const NameIdPool<DTDEntityDecl>* setEntityDeclPool(const NameIdPool<DTDEntityDecl>* const) = 0;
|
||||
|
||||
virtual void checkEntity(const XMLCh * const ) const = 0 ;
|
||||
|
||||
/**
|
||||
* Union datatype handling
|
||||
*
|
||||
*/
|
||||
|
||||
virtual DatatypeValidator * getValidatingMemberType() const = 0 ;
|
||||
virtual void setValidatingMemberType(DatatypeValidator * validatingMemberType) = 0 ;
|
||||
|
||||
/**
|
||||
* QName datatype handling
|
||||
* Create default implementations for source code compatibility
|
||||
*/
|
||||
virtual bool isPrefixUnknown(XMLCh* /* prefix */) { return true; };
|
||||
virtual void setElemStack(ElemStack* /* elemStack */) {};
|
||||
virtual const XMLCh* getURIForPrefix(XMLCh* /*prefix */) { return 0; };
|
||||
virtual void setScanner(XMLScanner* /* scanner */) { };
|
||||
virtual void setNamespaceScope(NamespaceScope* /* nsStack */) { };
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
/** Hidden Constructors */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
ValidationContext(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager)
|
||||
:fMemoryManager(memMgr)
|
||||
{
|
||||
};
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Data members
|
||||
//
|
||||
// fMemoryManager
|
||||
// Pluggable memory manager for dynamic allocation/deallocation.
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager* fMemoryManager;
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
ValidationContext(const ValidationContext& );
|
||||
ValidationContext& operator=(const ValidationContext& );
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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: Wrapper4DOMLSInput.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/Wrapper4DOMLSInput.hpp>
|
||||
#include <xercesc/dom/DOMLSInput.hpp>
|
||||
#include <xercesc/dom/DOMLSResourceResolver.hpp>
|
||||
#include <xercesc/util/NullPointerException.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||
#include <xercesc/framework/LocalFileInputSource.hpp>
|
||||
#include <xercesc/framework/URLInputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4DOMLSInput: Constructor and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
Wrapper4DOMLSInput::Wrapper4DOMLSInput(DOMLSInput* const inputSource,
|
||||
DOMLSResourceResolver* entityResolver,
|
||||
const bool adoptFlag,
|
||||
MemoryManager* const manager) :
|
||||
InputSource(manager)
|
||||
, fAdoptInputSource(adoptFlag)
|
||||
, fForceXMLChEncoding(false)
|
||||
, fInputSource(inputSource)
|
||||
, fEntityResolver(entityResolver)
|
||||
{
|
||||
if (!inputSource)
|
||||
ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, getMemoryManager());
|
||||
}
|
||||
|
||||
Wrapper4DOMLSInput::~Wrapper4DOMLSInput()
|
||||
{
|
||||
if (fAdoptInputSource)
|
||||
delete fInputSource;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4DOMLSInput: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool Wrapper4DOMLSInput::getIssueFatalErrorIfNotFound() const
|
||||
{
|
||||
return fInputSource->getIssueFatalErrorIfNotFound();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4DOMLSInput::getEncoding() const
|
||||
{
|
||||
if(fForceXMLChEncoding)
|
||||
return XMLUni::fgXMLChEncodingString;
|
||||
return fInputSource->getEncoding();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4DOMLSInput::getSystemId() const
|
||||
{
|
||||
return fInputSource->getSystemId();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4DOMLSInput::getPublicId() const
|
||||
{
|
||||
return fInputSource->getPublicId();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4DOMLSInput: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void Wrapper4DOMLSInput::setIssueFatalErrorIfNotFound(const bool flag)
|
||||
{
|
||||
fInputSource->setIssueFatalErrorIfNotFound(flag);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4DOMLSInput::setEncoding(const XMLCh* const encodingStr)
|
||||
{
|
||||
fInputSource->setEncoding(encodingStr);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4DOMLSInput::setPublicId(const XMLCh* const publicId)
|
||||
{
|
||||
fInputSource->setPublicId(publicId);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4DOMLSInput::setSystemId(const XMLCh* const systemId)
|
||||
{
|
||||
fInputSource->setSystemId(systemId);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4DOMLSInput: Stream methods
|
||||
// ---------------------------------------------------------------------------
|
||||
BinInputStream* Wrapper4DOMLSInput::makeStream() const
|
||||
{
|
||||
// The LSParser will use the LSInput object to determine how to read data. The LSParser will look at the different inputs specified in the
|
||||
// LSInput in the following order to know which one to read from, the first one that is not null and not an empty string will be used:
|
||||
// 1. LSInput.characterStream
|
||||
// 2. LSInput.byteStream
|
||||
// 3. LSInput.stringData
|
||||
// 4. LSInput.systemId
|
||||
// 5. LSInput.publicId
|
||||
InputSource* binStream=fInputSource->getByteStream();
|
||||
if(binStream)
|
||||
return binStream->makeStream();
|
||||
const XMLCh* xmlString=fInputSource->getStringData();
|
||||
if(xmlString)
|
||||
{
|
||||
MemBufInputSource is((const XMLByte*)xmlString, XMLString::stringLen(xmlString)*sizeof(XMLCh), "", false, getMemoryManager());
|
||||
is.setCopyBufToStream(false);
|
||||
return is.makeStream();
|
||||
}
|
||||
const XMLCh* szSystemId=fInputSource->getSystemId();
|
||||
if(szSystemId)
|
||||
{
|
||||
XMLURL urlTmp(getMemoryManager());
|
||||
if (urlTmp.setURL(szSystemId, fInputSource->getBaseURI(), urlTmp) && !urlTmp.isRelative())
|
||||
{
|
||||
URLInputSource src(urlTmp, getMemoryManager());
|
||||
return src.makeStream();
|
||||
}
|
||||
LocalFileInputSource src(szSystemId, getMemoryManager());
|
||||
return src.makeStream();
|
||||
}
|
||||
const XMLCh* szPublicId=fInputSource->getPublicId();
|
||||
if(szPublicId && fEntityResolver)
|
||||
{
|
||||
DOMLSInput* is = fEntityResolver->resolveResource(XMLUni::fgDOMDTDType, 0, szPublicId, 0, fInputSource->getBaseURI());
|
||||
if (is)
|
||||
return Wrapper4DOMLSInput(is, fEntityResolver, true, getMemoryManager()).makeStream();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* 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: Wrapper4DOMLSInput.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_WRAPPER4DOMLSINPUT_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_WRAPPER4DOMLSINPUT_HPP
|
||||
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class DOMLSInput;
|
||||
class DOMLSResourceResolver;
|
||||
|
||||
/**
|
||||
* Wrap a DOMLSInput object and make it behave like a SAX InputSource.
|
||||
*/
|
||||
class XMLPARSER_EXPORT Wrapper4DOMLSInput: public InputSource
|
||||
{
|
||||
public:
|
||||
/** @name Constructors and Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Wrap a DOMLSInput and make it behave like a SAX InputSource.
|
||||
* By default, the wrapper will adopt the DOMLSInput that is wrapped.
|
||||
*
|
||||
* @param inputSource The DOMLSInput to be wrapped
|
||||
* @param entityResolver The DOMLSResourceResolver to be used when resolving publicID entries
|
||||
* @param adoptFlag Indicates if the wrapper should adopt the wrapped
|
||||
* DOMLSInput. Default is true.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
Wrapper4DOMLSInput
|
||||
(
|
||||
DOMLSInput* const inputSource
|
||||
, DOMLSResourceResolver* entityResolver = 0
|
||||
, const bool adoptFlag = true
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
*/
|
||||
virtual ~Wrapper4DOMLSInput();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual input source interface */
|
||||
//@{
|
||||
/**
|
||||
*
|
||||
* Makes the byte stream for this input source.
|
||||
*
|
||||
* <p>The function will call the makeStream of the wrapped input source.
|
||||
* The returned stream becomes the parser's property.</p>
|
||||
*
|
||||
* @see BinInputStream
|
||||
*/
|
||||
BinInputStream* makeStream() const;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
/**
|
||||
*
|
||||
* An input source can be set to force the parser to assume a particular
|
||||
* encoding for the data that input source reprsents, via the setEncoding()
|
||||
* method. This method will delegate to the wrapped input source to return
|
||||
* name of the encoding that is to be forced. If the encoding has never
|
||||
* been forced, it returns a null pointer.
|
||||
*
|
||||
* @return The forced encoding, or null if none was supplied.
|
||||
* @see #setEncoding
|
||||
*/
|
||||
const XMLCh* getEncoding() const;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the public identifier for this input source. Delegated to the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* @return The public identifier, or null if none was supplied.
|
||||
* @see #setPublicId
|
||||
*/
|
||||
const XMLCh* getPublicId() const;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the system identifier for this input source. Delegated to the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>If the system ID is a URL, it will be fully resolved.</p>
|
||||
*
|
||||
* @return The system identifier.
|
||||
* @see #setSystemId
|
||||
*/
|
||||
const XMLCh* getSystemId() const;
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the flag that indicates if the parser should issue fatal error if
|
||||
* this input source is not found. Delegated to the wrapped input source
|
||||
* object.
|
||||
*
|
||||
* @return True if the parser should issue fatal error if this input source
|
||||
* is not found.
|
||||
* False if the parser issue warning message instead.
|
||||
* @see #setIssueFatalErrorIfNotFound
|
||||
*/
|
||||
bool getIssueFatalErrorIfNotFound() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
*
|
||||
* Set the encoding which will be required for use with the XML text read
|
||||
* via a stream opened by this input source. This will update the wrapped
|
||||
* input source object.
|
||||
*
|
||||
* <p>This is usually not set, allowing the encoding to be sensed in the
|
||||
* usual XML way. However, in some cases, the encoding in the file is known
|
||||
* to be incorrect because of intermediate transcoding, for instance
|
||||
* encapsulation within a MIME document.
|
||||
*
|
||||
* @param encodingStr The name of the encoding to force.
|
||||
*/
|
||||
void setEncoding(const XMLCh* const encodingStr);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Set the public identifier for this input source. This will update the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>The public identifier is always optional: if the application writer
|
||||
* includes one, it will be provided as part of the location information.</p>
|
||||
*
|
||||
* @param publicId The public identifier as a string.
|
||||
* @see Locator#getPublicId
|
||||
* @see SAXParseException#getPublicId
|
||||
* @see #getPublicId
|
||||
*/
|
||||
void setPublicId(const XMLCh* const publicId);
|
||||
|
||||
/**
|
||||
*
|
||||
* Set the system identifier for this input source. This will update the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>The system id is always required. The public id may be used to map
|
||||
* to another system id, but the system id must always be present as a fall
|
||||
* back.</p>
|
||||
*
|
||||
* <p>If the system ID is a URL, it must be fully resolved.</p>
|
||||
*
|
||||
* @param systemId The system identifier as a string.
|
||||
* @see #getSystemId
|
||||
* @see Locator#getSystemId
|
||||
* @see SAXParseException#getSystemId
|
||||
*/
|
||||
void setSystemId(const XMLCh* const systemId);
|
||||
|
||||
/**
|
||||
*
|
||||
* Indicates if the parser should issue fatal error if this input source
|
||||
* is not found. If set to false, the parser issue warning message instead.
|
||||
* This will update the wrapped input source object.
|
||||
*
|
||||
* @param flag True if the parser should issue fatal error if this input source is not found.
|
||||
* If set to false, the parser issue warning message instead. (Default: true)
|
||||
*
|
||||
* @see #getIssueFatalErrorIfNotFound
|
||||
*/
|
||||
void setIssueFatalErrorIfNotFound(const bool flag);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
Wrapper4DOMLSInput(const Wrapper4DOMLSInput&);
|
||||
Wrapper4DOMLSInput& operator=(const Wrapper4DOMLSInput&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
bool fAdoptInputSource,
|
||||
fForceXMLChEncoding;
|
||||
DOMLSInput* fInputSource;
|
||||
DOMLSResourceResolver* fEntityResolver;
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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: Wrapper4InputSource.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/Wrapper4InputSource.hpp>
|
||||
#include <xercesc/sax/InputSource.hpp>
|
||||
#include <xercesc/util/NullPointerException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Constructor and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
Wrapper4InputSource::Wrapper4InputSource(InputSource* const inputSource,
|
||||
const bool adoptFlag
|
||||
, MemoryManager* const manager) :
|
||||
fAdoptInputSource(adoptFlag)
|
||||
, fInputSource(inputSource)
|
||||
{
|
||||
if (!inputSource)
|
||||
ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, manager);
|
||||
}
|
||||
|
||||
Wrapper4InputSource::~Wrapper4InputSource()
|
||||
{
|
||||
if (fAdoptInputSource)
|
||||
delete fInputSource;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool Wrapper4InputSource::getIssueFatalErrorIfNotFound() const
|
||||
{
|
||||
return fInputSource->getIssueFatalErrorIfNotFound();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4InputSource::getEncoding() const
|
||||
{
|
||||
return fInputSource->getEncoding();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4InputSource::getSystemId() const
|
||||
{
|
||||
return fInputSource->getSystemId();
|
||||
}
|
||||
|
||||
const XMLCh* Wrapper4InputSource::getPublicId() const
|
||||
{
|
||||
return fInputSource->getPublicId();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void Wrapper4InputSource::setIssueFatalErrorIfNotFound(bool flag)
|
||||
{
|
||||
fInputSource->setIssueFatalErrorIfNotFound(flag);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4InputSource::setEncoding(const XMLCh* const encodingStr)
|
||||
{
|
||||
fInputSource->setEncoding(encodingStr);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4InputSource::setPublicId(const XMLCh* const publicId)
|
||||
{
|
||||
fInputSource->setPublicId(publicId);
|
||||
}
|
||||
|
||||
|
||||
void Wrapper4InputSource::setSystemId(const XMLCh* const systemId)
|
||||
{
|
||||
fInputSource->setSystemId(systemId);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Stream methods
|
||||
// ---------------------------------------------------------------------------
|
||||
InputSource* Wrapper4InputSource::getByteStream() const
|
||||
{
|
||||
return fInputSource;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Memory methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void Wrapper4InputSource::release()
|
||||
{
|
||||
Wrapper4InputSource* src = (Wrapper4InputSource*) this;
|
||||
delete src;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* 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: Wrapper4InputSource.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_WRAPPER4INPUTSOURCE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_WRAPPER4INPUTSOURCE_HPP
|
||||
|
||||
#include <xercesc/dom/DOMLSInput.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* Wrap a SAX InputSource object and make it behave like DOMLSInput.
|
||||
*/
|
||||
class XMLPARSER_EXPORT Wrapper4InputSource: public DOMLSInput
|
||||
{
|
||||
public:
|
||||
/** @name Constructors and Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Wrap a SAX InputSource and make it behave like a DOMLSInput.
|
||||
* By default, the wrapper will adopt the SAX InputSource that is wrapped.
|
||||
*
|
||||
* @param inputSource The SAX InputSource to be wrapped
|
||||
* @param adoptFlag Indicates if the wrapper should adopt the wrapped
|
||||
* SAX InputSource. Default is true.
|
||||
* @param manager The MemoryManager to use to allocate objects
|
||||
*/
|
||||
Wrapper4InputSource(InputSource* const inputSource
|
||||
, const bool adoptFlag = true
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
*/
|
||||
virtual ~Wrapper4InputSource();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual input source interface */
|
||||
//@{
|
||||
/**
|
||||
* This wrapper doesn't support string data
|
||||
*
|
||||
*/
|
||||
virtual const XMLCh* getStringData() const;
|
||||
|
||||
/**
|
||||
* Makes the byte stream for this input source.
|
||||
*
|
||||
* <p>The function will call the makeStream of the wrapped input source.
|
||||
* The returned stream becomes the parser's property.</p>
|
||||
*
|
||||
* @see InputSource
|
||||
*/
|
||||
virtual InputSource* getByteStream() const;
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
/**
|
||||
* An input source can be set to force the parser to assume a particular
|
||||
* encoding for the data that input source represents, via the setEncoding()
|
||||
* method. This method will delegate to the wrapped input source to return
|
||||
* name of the encoding that is to be forced. If the encoding has never
|
||||
* been forced, it returns a null pointer.
|
||||
*
|
||||
* @return The forced encoding, or null if none was supplied.
|
||||
* @see #setEncoding
|
||||
*/
|
||||
virtual const XMLCh* getEncoding() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the public identifier for this input source. Delegated to the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* @return The public identifier, or null if none was supplied.
|
||||
* @see #setPublicId
|
||||
*/
|
||||
const XMLCh* getPublicId() const;
|
||||
|
||||
|
||||
/**
|
||||
* Get the system identifier for this input source. Delegated to the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>If the system ID is a URL, it will be fully resolved.</p>
|
||||
*
|
||||
* @return The system identifier.
|
||||
* @see #setSystemId
|
||||
*/
|
||||
const XMLCh* getSystemId() const;
|
||||
|
||||
/**
|
||||
* Get the base URI to be used for resolving relative URIs to absolute
|
||||
* URIs. If the baseURI is itself a relative URI, the behavior is
|
||||
* implementation dependent. Delegated to the wrapped intput source
|
||||
* object.
|
||||
*
|
||||
* @return The base URI.
|
||||
* @see #setBaseURI
|
||||
* @since DOM Level 3
|
||||
*/
|
||||
const XMLCh* getBaseURI() const;
|
||||
|
||||
/**
|
||||
* Get the flag that indicates if the parser should issue fatal error if this input source
|
||||
* is not found. Delegated to the wrapped input source object.
|
||||
*
|
||||
* @return True if the parser should issue fatal error if this input source is not found.
|
||||
* False if the parser issue warning message instead.
|
||||
* @see #setIssueFatalErrorIfNotFound
|
||||
*/
|
||||
bool getIssueFatalErrorIfNotFound() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
/**
|
||||
* This wrapper only exposes the given InputSource, no setting allowed
|
||||
*
|
||||
*/
|
||||
virtual void setStringData(const XMLCh* data);
|
||||
|
||||
/**
|
||||
* This wrapper only exposes the given InputSource, no setting allowed
|
||||
*
|
||||
*/
|
||||
virtual void setByteStream(InputSource* stream);
|
||||
|
||||
/**
|
||||
* Set the encoding which will be required for use with the XML text read
|
||||
* via a stream opened by this input source. This will update the wrapped
|
||||
* input source object.
|
||||
*
|
||||
* <p>This is usually not set, allowing the encoding to be sensed in the
|
||||
* usual XML way. However, in some cases, the encoding in the file is known
|
||||
* to be incorrect because of intermediate transcoding, for instance
|
||||
* encapsulation within a MIME document.
|
||||
*
|
||||
* @param encodingStr The name of the encoding to force.
|
||||
*/
|
||||
void setEncoding(const XMLCh* const encodingStr);
|
||||
|
||||
|
||||
/**
|
||||
* Set the public identifier for this input source. This will update the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>The public identifier is always optional: if the application writer
|
||||
* includes one, it will be provided as part of the location information.</p>
|
||||
*
|
||||
* @param publicId The public identifier as a string.
|
||||
* @see Locator#getPublicId
|
||||
* @see SAXParseException#getPublicId
|
||||
* @see #getPublicId
|
||||
*/
|
||||
void setPublicId(const XMLCh* const publicId);
|
||||
|
||||
/**
|
||||
* Set the system identifier for this input source. This will update the
|
||||
* wrapped input source object.
|
||||
*
|
||||
* <p>The system id is always required. The public id may be used to map
|
||||
* to another system id, but the system id must always be present as a fall
|
||||
* back.</p>
|
||||
*
|
||||
* <p>If the system ID is a URL, it must be fully resolved.</p>
|
||||
*
|
||||
* @param systemId The system identifier as a string.
|
||||
* @see #getSystemId
|
||||
* @see Locator#getSystemId
|
||||
* @see SAXParseException#getSystemId
|
||||
*/
|
||||
void setSystemId(const XMLCh* const systemId);
|
||||
|
||||
/**
|
||||
* Set the base URI to be used for resolving relative URIs to absolute
|
||||
* URIs. If the baseURI is itself a relative URI, the behavior is
|
||||
* implementation dependent. This will update the wrapped input source
|
||||
* object.
|
||||
*
|
||||
* @param baseURI The base URI.
|
||||
* @see #getBaseURI
|
||||
* @since DOM Level 3
|
||||
*/
|
||||
void setBaseURI(const XMLCh* const baseURI);
|
||||
|
||||
/**
|
||||
* Indicates if the parser should issue fatal error if this input source
|
||||
* is not found. If set to false, the parser issue warning message
|
||||
* instead. This will update the wrapped input source object.
|
||||
*
|
||||
* @param flag True if the parser should issue fatal error if this input
|
||||
* source is not found.
|
||||
* If set to false, the parser issue warning message instead.
|
||||
* (Default: true)
|
||||
*
|
||||
* @see #getIssueFatalErrorIfNotFound
|
||||
*/
|
||||
void setIssueFatalErrorIfNotFound(bool flag);
|
||||
|
||||
/**
|
||||
* Called to indicate that this DOMInputSource is no longer in use
|
||||
* and that the implementation may relinquish any resources associated with it.
|
||||
*
|
||||
* Access to a released object will lead to unexpected result.
|
||||
*/
|
||||
void release();
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
Wrapper4InputSource(const Wrapper4InputSource&);
|
||||
Wrapper4InputSource& operator=(const Wrapper4InputSource&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
bool fAdoptInputSource;
|
||||
InputSource* fInputSource;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLCh* Wrapper4InputSource::getBaseURI() const
|
||||
{
|
||||
return 0; // REVISIT - should we return an empty string?
|
||||
}
|
||||
|
||||
inline const XMLCh* Wrapper4InputSource::getStringData() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wrapper4InputSource: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Wrapper4InputSource::setBaseURI(const XMLCh* const)
|
||||
{
|
||||
}
|
||||
|
||||
inline void Wrapper4InputSource::setStringData(const XMLCh*)
|
||||
{
|
||||
}
|
||||
|
||||
inline void Wrapper4InputSource::setByteStream(InputSource*)
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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: XMLAttDef.cpp 679359 2008-07-24 11:15:19Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLAttDef.hpp>
|
||||
#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local const data
|
||||
//
|
||||
// gAttTypeStrings
|
||||
// A list of strings which are used to map attribute type numbers to
|
||||
// attribute type names.
|
||||
//
|
||||
// gDefAttTypesStrings
|
||||
// A list of strings which are used to map default attribute type
|
||||
// numbers to default attribute type names.
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh* const gAttTypeStrings[XMLAttDef::AttTypes_Count] =
|
||||
{
|
||||
XMLUni::fgCDATAString
|
||||
, XMLUni::fgIDString
|
||||
, XMLUni::fgIDRefString
|
||||
, XMLUni::fgIDRefsString
|
||||
, XMLUni::fgEntityString
|
||||
, XMLUni::fgEntitiesString
|
||||
, XMLUni::fgNmTokenString
|
||||
, XMLUni::fgNmTokensString
|
||||
, XMLUni::fgNotationString
|
||||
, XMLUni::fgEnumerationString
|
||||
, XMLUni::fgCDATAString
|
||||
, XMLUni::fgCDATAString
|
||||
, XMLUni::fgCDATAString
|
||||
, XMLUni::fgCDATAString
|
||||
|
||||
};
|
||||
|
||||
const XMLCh* const gDefAttTypeStrings[XMLAttDef::DefAttTypes_Count] =
|
||||
{
|
||||
XMLUni::fgDefaultString
|
||||
, XMLUni::fgFixedString
|
||||
, XMLUni::fgRequiredString
|
||||
, XMLUni::fgImpliedString
|
||||
, XMLUni::fgImpliedString
|
||||
, XMLUni::fgImpliedString
|
||||
, XMLUni::fgImpliedString
|
||||
, XMLUni::fgImpliedString
|
||||
, XMLUni::fgImpliedString
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Public, static data members
|
||||
// ---------------------------------------------------------------------------
|
||||
const unsigned int XMLAttDef::fgInvalidAttrId = 0xFFFFFFFE;
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Public, static methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh* XMLAttDef::getAttTypeString(const XMLAttDef::AttTypes attrType
|
||||
, MemoryManager* const manager)
|
||||
{
|
||||
// Check for an invalid attribute type and return a null
|
||||
if ((attrType < AttTypes_Min) || (attrType > AttTypes_Max))
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttDef_BadAttType, manager);
|
||||
return gAttTypeStrings[attrType];
|
||||
}
|
||||
|
||||
const XMLCh* XMLAttDef::getDefAttTypeString(const XMLAttDef::DefAttTypes attrType
|
||||
, MemoryManager* const manager)
|
||||
{
|
||||
// Check for an invalid attribute type and return a null
|
||||
if ((attrType < DefAttTypes_Min) || (attrType > DefAttTypes_Max))
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttDef_BadDefAttType, manager);
|
||||
return gDefAttTypeStrings[attrType];
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLAttDef::~XMLAttDef()
|
||||
{
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Hidden constructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLAttDef::XMLAttDef( const XMLAttDef::AttTypes type
|
||||
, const XMLAttDef::DefAttTypes defType
|
||||
, MemoryManager* const manager) :
|
||||
|
||||
fDefaultType(defType)
|
||||
, fType(type)
|
||||
, fCreateReason(XMLAttDef::NoReason)
|
||||
, fExternalAttribute(false)
|
||||
, fId(XMLAttDef::fgInvalidAttrId)
|
||||
, fValue(0)
|
||||
, fEnumeration(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
typedef JanitorMemFunCall<XMLAttDef> CleanupType;
|
||||
|
||||
XMLAttDef::XMLAttDef( const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type
|
||||
, const XMLAttDef::DefAttTypes defType
|
||||
, const XMLCh* const enumValues
|
||||
, MemoryManager* const manager) :
|
||||
|
||||
fDefaultType(defType)
|
||||
, fType(type)
|
||||
, fCreateReason(XMLAttDef::NoReason)
|
||||
, fExternalAttribute(false)
|
||||
, fId(XMLAttDef::fgInvalidAttrId)
|
||||
, fValue(0)
|
||||
, fEnumeration(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLAttDef::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
fValue = XMLString::replicate(attrValue, fMemoryManager);
|
||||
fEnumeration = XMLString::replicate(enumValues, fMemoryManager);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Private helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLAttDef::cleanUp()
|
||||
{
|
||||
if (fEnumeration)
|
||||
fMemoryManager->deallocate(fEnumeration);
|
||||
|
||||
if (fValue)
|
||||
fMemoryManager->deallocate(fValue);
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLAttDef)
|
||||
|
||||
void XMLAttDef::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng<<(int)fDefaultType;
|
||||
serEng<<(int)fType;
|
||||
serEng<<(int)fCreateReason;
|
||||
serEng<<fExternalAttribute;
|
||||
serEng.writeSize (fId);
|
||||
|
||||
serEng.writeString(fValue);
|
||||
serEng.writeString(fEnumeration);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
serEng>>i;
|
||||
fDefaultType = (DefAttTypes) i;
|
||||
|
||||
serEng>>i;
|
||||
fType = (AttTypes)i;
|
||||
|
||||
serEng>>i;
|
||||
fCreateReason = (CreateReasons)i;
|
||||
|
||||
serEng>>fExternalAttribute;
|
||||
serEng.readSize (fId);
|
||||
|
||||
serEng.readString(fValue);
|
||||
serEng.readString(fEnumeration);
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,539 @@
|
||||
/*
|
||||
* 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: XMLAttDef.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLAttr;
|
||||
|
||||
/** Represents the core information of an attribute definition
|
||||
*
|
||||
* This class defines the basic characteristics of an attribute, no matter
|
||||
* what type of validator is used. If a particular schema associates more
|
||||
* information with an attribute it will create a derivative of this class.
|
||||
* So this class provides an abstract way to get basic information on
|
||||
* attributes from any type of validator.
|
||||
*
|
||||
* This class supports keyed collection semantics on the fully qualified
|
||||
* attribute name, by providing a getKey() method to extract the key string.
|
||||
* getKey(), in this case, just calls the virtual method getFullName() to
|
||||
* get the fully qualified name, as defined by the derived class.
|
||||
*
|
||||
* Note that the 'value' of an attribute type definition is the default or
|
||||
* of fixed value given to it in its definition. If the attribute is of the
|
||||
* enumerated or notation type, it will have an 'enumeration value' as well
|
||||
* which is a space separated list of its possible vlaues.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Class specific types
|
||||
//
|
||||
// AttTypes
|
||||
// The list of possible types that an attribute can have, according
|
||||
// to the XML 1.0 spec and schema.
|
||||
//
|
||||
// DefAttTypes
|
||||
// The modifiers that an attribute decl can have, which indicates
|
||||
// whether instances of that attributes are required, implied, etc..
|
||||
//
|
||||
// CreateReasons
|
||||
// This type is used to store how an attribute declaration got into
|
||||
// the elementdecl's attribute pool.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
enum AttTypes
|
||||
{
|
||||
CData = 0
|
||||
, ID = 1
|
||||
, IDRef = 2
|
||||
, IDRefs = 3
|
||||
, Entity = 4
|
||||
, Entities = 5
|
||||
, NmToken = 6
|
||||
, NmTokens = 7
|
||||
, Notation = 8
|
||||
, Enumeration = 9
|
||||
, Simple = 10
|
||||
, Any_Any = 11
|
||||
, Any_Other = 12
|
||||
, Any_List = 13
|
||||
|
||||
, AttTypes_Count
|
||||
, AttTypes_Min = 0
|
||||
, AttTypes_Max = 13
|
||||
, AttTypes_Unknown = -1
|
||||
};
|
||||
|
||||
enum DefAttTypes
|
||||
{
|
||||
Default = 0
|
||||
, Fixed = 1
|
||||
, Required = 2
|
||||
, Required_And_Fixed = 3
|
||||
, Implied = 4
|
||||
, ProcessContents_Skip = 5
|
||||
, ProcessContents_Lax = 6
|
||||
, ProcessContents_Strict = 7
|
||||
, Prohibited = 8
|
||||
|
||||
, DefAttTypes_Count
|
||||
, DefAttTypes_Min = 0
|
||||
, DefAttTypes_Max = 8
|
||||
, DefAttTypes_Unknown = -1
|
||||
};
|
||||
|
||||
enum CreateReasons
|
||||
{
|
||||
NoReason
|
||||
, JustFaultIn
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public static data members
|
||||
// -----------------------------------------------------------------------
|
||||
static const unsigned int fgInvalidAttrId;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public, static methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Public, static methods */
|
||||
//@{
|
||||
|
||||
/** Get a string representation of the passed attribute type enum
|
||||
*
|
||||
* This method allows you to get a textual representation of an attribute
|
||||
* type, mostly for debug or display.
|
||||
*
|
||||
* @param attrType The attribute type value to get the string for.
|
||||
* @param manager The MemoryManager to use to allocate objects
|
||||
* @return A const pointer to the static string that holds the text
|
||||
* description of the passed type.
|
||||
*/
|
||||
static const XMLCh* getAttTypeString(const AttTypes attrType
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/** Get a string representation of the passed def attribute type enum
|
||||
*
|
||||
* This method allows you to get a textual representation of an default
|
||||
* attributetype, mostly for debug or display.
|
||||
*
|
||||
* @param attrType The default attribute type value to get the string for.
|
||||
* @param manager The MemoryManager to use to allocate objects
|
||||
* @return A const pointer to the static string that holds the text
|
||||
* description of the passed default type.
|
||||
*/
|
||||
static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~XMLAttDef();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual attribute def interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual interface */
|
||||
//@{
|
||||
|
||||
/** Get the full name of this attribute type
|
||||
*
|
||||
* The derived class should return a const pointer to the full name of
|
||||
* this attribute. This will vary depending on the type of validator in
|
||||
* use.
|
||||
*
|
||||
* @return A const pointer to the full name of this attribute type.
|
||||
*/
|
||||
virtual const XMLCh* getFullName() const = 0;
|
||||
|
||||
/**
|
||||
* The derived class should implement any cleaning up required between
|
||||
* each use of an instance of this class for validation
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/** Get the default type of this attribute type
|
||||
*
|
||||
* This method returns the 'default type' of the attribute. Default
|
||||
* type in this case refers to the XML concept of a default type for
|
||||
* an attribute, i.e. \#FIXED, \#IMPLIED, etc...
|
||||
*
|
||||
* @return The default type enum for this attribute type.
|
||||
*/
|
||||
DefAttTypes getDefaultType() const;
|
||||
|
||||
/** Get the enumeration value (if any) of this attribute type
|
||||
*
|
||||
* If the attribute is of an enumeration or notation type, then this
|
||||
* method will return a const reference to a string that contains the
|
||||
* space separated values that can the attribute can have.
|
||||
*
|
||||
* @return A const pointer to a string that contains the space separated
|
||||
* legal values for this attribute.
|
||||
*/
|
||||
const XMLCh* getEnumeration() const;
|
||||
|
||||
/** Get the pool id of this attribute type
|
||||
*
|
||||
* This method will return the id of this attribute in the validator's
|
||||
* attribute pool. It was set by the validator when this attribute was
|
||||
* created.
|
||||
*
|
||||
* @return The pool id of this attribute type.
|
||||
*/
|
||||
XMLSize_t getId() const;
|
||||
|
||||
/** Get the type of this attribute
|
||||
*
|
||||
* Gets the type of this attribute. This type is represented by an enum
|
||||
* that converts the types of attributes allowed by XML, e.g. CDATA, NMTOKEN,
|
||||
* NOTATION, etc...
|
||||
*
|
||||
* @return The attribute type enumeration value for this type of
|
||||
* attribute.
|
||||
*/
|
||||
AttTypes getType() const;
|
||||
|
||||
/** Get the default/fixed value of this attribute (if any.)
|
||||
*
|
||||
* If the attribute defined a default/fixed value, then it is stored
|
||||
* and this method will retrieve it. If it has non, then a null pointer
|
||||
* is returned.
|
||||
*
|
||||
* @return A const pointer to the default/fixed value for this attribute
|
||||
* type.
|
||||
*/
|
||||
const XMLCh* getValue() const;
|
||||
|
||||
/** Get the create reason for this attribute
|
||||
*
|
||||
* This method returns an enumeration which indicates why this attribute
|
||||
* declaration exists.
|
||||
*
|
||||
* @return An enumerated value that indicates the reason why this attribute
|
||||
* was added to the attribute table.
|
||||
*/
|
||||
CreateReasons getCreateReason() const;
|
||||
|
||||
/** Indicate whether this attribute has been declared externally
|
||||
*
|
||||
* This method returns a boolean that indicates whether this attribute
|
||||
* has been declared externally.
|
||||
*
|
||||
* @return true if this attribute has been declared externally, else false.
|
||||
*/
|
||||
bool isExternal() const;
|
||||
|
||||
/** Get the plugged-in memory manager
|
||||
*
|
||||
* This method returns the plugged-in memory manager user for dynamic
|
||||
* memory allocation/deallocation.
|
||||
*
|
||||
* @return the plugged-in memory manager
|
||||
*/
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/** Set the default attribute type
|
||||
*
|
||||
* This method sets the default attribute type for this attribute.
|
||||
* This setting controls whether the attribute is required, fixed,
|
||||
* implied, etc...
|
||||
*
|
||||
* @param newValue The new default attribute to set
|
||||
*/
|
||||
void setDefaultType(const XMLAttDef::DefAttTypes newValue);
|
||||
|
||||
/** Set the pool id for this attribute type.
|
||||
*
|
||||
* This method sets the pool id of this attribute type. This is usually
|
||||
* called by the validator that creates the actual instance (which is of
|
||||
* a derived type known only by the validator.)
|
||||
*
|
||||
* @param newId The new pool id to set.
|
||||
*/
|
||||
void setId(const XMLSize_t newId);
|
||||
|
||||
/** Set the type of this attribute type.
|
||||
*
|
||||
* This method will set the type of the attribute. The type of an attribute
|
||||
* controls how it is normalized and what kinds of characters it can hold.
|
||||
*
|
||||
* @param newValue The new attribute type to set
|
||||
*/
|
||||
void setType(const XMLAttDef::AttTypes newValue);
|
||||
|
||||
/** Set the default/fixed value of this attribute type.
|
||||
*
|
||||
* This method set the fixed/default value for the attribute. This value
|
||||
* will be used when instances of this attribute type are faulted in. It
|
||||
* <b>must</b> be a valid value for the type set by setType(). If the
|
||||
* type is enumeration or notation, this must be one of the valid values
|
||||
* set in the setEnumeration() call.
|
||||
*
|
||||
* @param newValue The new fixed/default value to set.
|
||||
*/
|
||||
void setValue(const XMLCh* const newValue);
|
||||
|
||||
/** Set the enumerated value of this attribute type.
|
||||
*
|
||||
* This method sets the enumerated/notation value list for this attribute
|
||||
* type. It is a space separated set of possible values. These values must
|
||||
* meet the constrains of the XML spec for such values of this type of
|
||||
* attribute. This should only be set if the setType() method is used to
|
||||
* set the type to the enumeration or notation types.
|
||||
*
|
||||
* @param newValue The new enumerated/notation value list to set.
|
||||
*/
|
||||
void setEnumeration(const XMLCh* const newValue);
|
||||
|
||||
/** Update the create reason for this attribute type.
|
||||
*
|
||||
* This method will update the 'create reason' field for this attribute
|
||||
* decl object.
|
||||
*
|
||||
* @param newReason The new create reason.
|
||||
*/
|
||||
void setCreateReason(const CreateReasons newReason);
|
||||
|
||||
/**
|
||||
* Set the attribute decl to indicate external declaration
|
||||
*
|
||||
* @param aValue The new value to indicate external declaration.
|
||||
*/
|
||||
void setExternalAttDeclaration(const bool aValue);
|
||||
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLAttDef)
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden constructors
|
||||
// -----------------------------------------------------------------------
|
||||
XMLAttDef
|
||||
(
|
||||
const AttTypes type = CData
|
||||
, const DefAttTypes defType= Implied
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
XMLAttDef
|
||||
(
|
||||
const XMLCh* const attValue
|
||||
, const AttTypes type
|
||||
, const DefAttTypes defType
|
||||
, const XMLCh* const enumValues = 0
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLAttDef(const XMLAttDef&);
|
||||
XMLAttDef& operator=(const XMLAttDef&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void cleanUp();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fDefaultType
|
||||
// Indicates what, if any, default stuff this attribute has.
|
||||
//
|
||||
// fEnumeration
|
||||
// If its an enumeration, this is the list of values as space
|
||||
// separated values.
|
||||
//
|
||||
// fId
|
||||
// This is the unique id of this attribute, given to it when its put
|
||||
// into the validator's attribute decl pool. It defaults to the
|
||||
// special value XMLAttrDef::fgInvalidAttrId.
|
||||
//
|
||||
// fType
|
||||
// The type of attribute, which is one of the AttTypes values.
|
||||
//
|
||||
// fValue
|
||||
// This is the value of the attribute, which is the default value
|
||||
// given in the attribute declaration.
|
||||
//
|
||||
// fCreateReason
|
||||
// This flag tells us how this attribute got created. Sometimes even
|
||||
// the attribute was not declared for the element, we want to fault
|
||||
// fault it into the pool to avoid lots of redundant errors.
|
||||
//
|
||||
// fExternalAttribute
|
||||
// This flag indicates whether or not the attribute was declared externally.
|
||||
// -----------------------------------------------------------------------
|
||||
DefAttTypes fDefaultType;
|
||||
AttTypes fType;
|
||||
CreateReasons fCreateReason;
|
||||
bool fExternalAttribute;
|
||||
XMLSize_t fId;
|
||||
XMLCh* fValue;
|
||||
XMLCh* fEnumeration;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
|
||||
{
|
||||
return fDefaultType;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLAttDef::getEnumeration() const
|
||||
{
|
||||
return fEnumeration;
|
||||
}
|
||||
|
||||
inline XMLSize_t XMLAttDef::getId() const
|
||||
{
|
||||
return fId;
|
||||
}
|
||||
|
||||
inline XMLAttDef::AttTypes XMLAttDef::getType() const
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLAttDef::getValue() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
|
||||
inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
|
||||
{
|
||||
return fCreateReason;
|
||||
}
|
||||
|
||||
inline bool XMLAttDef::isExternal() const
|
||||
{
|
||||
return fExternalAttribute;
|
||||
}
|
||||
|
||||
inline MemoryManager* XMLAttDef::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDef: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
|
||||
{
|
||||
fDefaultType = newValue;
|
||||
}
|
||||
|
||||
inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
|
||||
{
|
||||
if (fEnumeration)
|
||||
fMemoryManager->deallocate(fEnumeration);
|
||||
|
||||
fEnumeration = XMLString::replicate(newValue, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLAttDef::setId(const XMLSize_t newId)
|
||||
{
|
||||
fId = newId;
|
||||
}
|
||||
|
||||
inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
|
||||
{
|
||||
fType = newValue;
|
||||
}
|
||||
|
||||
inline void XMLAttDef::setValue(const XMLCh* const newValue)
|
||||
{
|
||||
if (fValue)
|
||||
fMemoryManager->deallocate(fValue);
|
||||
|
||||
fValue = XMLString::replicate(newValue, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void
|
||||
XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
|
||||
{
|
||||
fCreateReason = newReason;
|
||||
}
|
||||
|
||||
inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
|
||||
{
|
||||
fExternalAttribute = aValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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: XMLAttDefList.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLAttDefList.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLAttDefList)
|
||||
|
||||
void XMLAttDefList::serialize(XSerializeEngine&)
|
||||
{
|
||||
//no data
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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: XMLAttDefList.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLATTDEFLIST_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLATTDEFLIST_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLAttDef;
|
||||
|
||||
/**
|
||||
* This class defines an abstract interface that all validators must support.
|
||||
* When the scanner scans the attributes in a start tag, it must have a list
|
||||
* of the defined attributes for that element. This is used to fault in
|
||||
* defaulted and fixed attributes, to know which ones are required, and to
|
||||
* know the their types in order to do the correct normalization.
|
||||
*
|
||||
* Since each validator will have its own derivatives of XMLAttDef and will
|
||||
* have its own specialized storage mechanisms for elements and the att
|
||||
* defs that they own, there must be an abstracted way for the scanner to
|
||||
* deal with this list.
|
||||
*
|
||||
* It does not derive from the generic Enumerator template class, because
|
||||
* there are portability issues with deriving from a template class in a
|
||||
* DLL. It does though provide a similar enumerator interface.
|
||||
*/
|
||||
|
||||
class XMLPARSER_EXPORT XMLAttDefList : public XSerializable, public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~XMLAttDefList();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
virtual bool isEmpty() const = 0;
|
||||
virtual XMLAttDef* findAttDef
|
||||
(
|
||||
const unsigned int uriID
|
||||
, const XMLCh* const attName
|
||||
) = 0;
|
||||
virtual const XMLAttDef* findAttDef
|
||||
(
|
||||
const unsigned int uriID
|
||||
, const XMLCh* const attName
|
||||
) const = 0;
|
||||
virtual XMLAttDef* findAttDef
|
||||
(
|
||||
const XMLCh* const attURI
|
||||
, const XMLCh* const attName
|
||||
) = 0;
|
||||
virtual const XMLAttDef* findAttDef
|
||||
(
|
||||
const XMLCh* const attURI
|
||||
, const XMLCh* const attName
|
||||
) const = 0;
|
||||
|
||||
/**
|
||||
* return total number of attributes in this list
|
||||
*/
|
||||
virtual XMLSize_t getAttDefCount() const = 0;
|
||||
|
||||
/**
|
||||
* return attribute at the index-th position in the list.
|
||||
*/
|
||||
virtual XMLAttDef &getAttDef(XMLSize_t index) = 0;
|
||||
|
||||
/**
|
||||
* return attribute at the index-th position in the list.
|
||||
*/
|
||||
virtual const XMLAttDef &getAttDef(XMLSize_t index) const = 0;
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLAttDefList)
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/** Get the memory manager
|
||||
*
|
||||
* This method returns the configurable memory manager used by the
|
||||
* element declaration for dynamic allocation/deallocation.
|
||||
*
|
||||
* @return the memory manager
|
||||
*/
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
//@}
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
private:
|
||||
// unimplemented
|
||||
XMLAttDefList(const XMLAttDefList&);
|
||||
XMLAttDefList& operator=(const XMLAttDefList&);
|
||||
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDefList: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
inline MemoryManager* XMLAttDefList::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDefList: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLAttDefList::~XMLAttDefList()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttDefList: Protected Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLAttDefList::XMLAttDefList(MemoryManager* const manager):
|
||||
fMemoryManager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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: XMLAttr.cpp 901107 2010-01-20 08:45:02Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLAttr.hpp>
|
||||
#include <xercesc/framework/MemoryManager.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLAttr::XMLAttr(MemoryManager* const manager) :
|
||||
|
||||
fSpecified(false)
|
||||
, fType(XMLAttDef::CData)
|
||||
, fValueBufSz(0)
|
||||
, fValue(0)
|
||||
, fAttName(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fAttName = new (fMemoryManager) QName(fMemoryManager);
|
||||
}
|
||||
|
||||
typedef JanitorMemFunCall<XMLAttr> CleanupType;
|
||||
|
||||
XMLAttr::XMLAttr( const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type
|
||||
, const bool specified
|
||||
, MemoryManager* const manager
|
||||
, DatatypeValidator*
|
||||
, const bool /*isSchema*/ ):
|
||||
|
||||
fSpecified(specified)
|
||||
, fType(type)
|
||||
, fValueBufSz(0)
|
||||
, fValue(0)
|
||||
, fAttName(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLAttr::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
//
|
||||
// Just call the local setters to set up everything. Too much
|
||||
// work is required to replicate that functionality here.
|
||||
//
|
||||
fAttName = new (fMemoryManager) QName(attrPrefix, attrName, uriId, fMemoryManager);
|
||||
setValue(attrValue);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
XMLAttr::XMLAttr( const unsigned int uriId
|
||||
, const XMLCh* const rawName
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type
|
||||
, const bool specified
|
||||
, MemoryManager* const manager
|
||||
, DatatypeValidator *
|
||||
, const bool /*isSchema*/ ):
|
||||
|
||||
fSpecified(specified)
|
||||
, fType(type)
|
||||
, fValueBufSz(0)
|
||||
, fValue(0)
|
||||
, fAttName(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLAttr::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
// Just call the local setters to set up everything. Too much
|
||||
// work is required to replicate that functionality here.
|
||||
fAttName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager);
|
||||
setValue(attrValue);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh* XMLAttr::getQName() const
|
||||
{
|
||||
return fAttName->getRawName();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLAttr::setName( const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix)
|
||||
{
|
||||
fAttName->setName(attrPrefix, attrName, uriId);
|
||||
}
|
||||
|
||||
|
||||
void XMLAttr::setURIId(const unsigned int uriId)
|
||||
{
|
||||
fAttName->setURI(uriId);
|
||||
}
|
||||
|
||||
|
||||
void XMLAttr::setValue(const XMLCh* const newValue)
|
||||
{
|
||||
const XMLSize_t newLen = XMLString::stringLen(newValue);
|
||||
if (!fValueBufSz || (newLen > fValueBufSz))
|
||||
{
|
||||
fMemoryManager->deallocate(fValue); //delete [] fValue;
|
||||
fValue = 0;
|
||||
fValueBufSz = newLen + 8;
|
||||
fValue = (XMLCh*) fMemoryManager->allocate((fValueBufSz+1) * sizeof(XMLCh)); //new XMLCh[fValueBufSz + 1];
|
||||
}
|
||||
XMLString::moveChars(fValue, newValue, newLen + 1);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Private, helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLAttr::cleanUp()
|
||||
{
|
||||
delete fAttName;
|
||||
fMemoryManager->deallocate(fValue); //delete [] fValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* 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: XMLAttr.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLATTR_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLATTR_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/QName.hpp>
|
||||
#include <xercesc/framework/XMLAttDef.hpp>
|
||||
#include <xercesc/validators/datatype/DatatypeValidator.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class defines the information about an attribute that will come out
|
||||
* of the scanner during parsing. This information does not depend upon the
|
||||
* type of validator because it is not tied to any scheme/DTD type info. Its
|
||||
* just the raw XML 1.0 information that will be reported about an attribute
|
||||
* in the startElement() callback method of the XMLDocumentHandler class.
|
||||
* Hence it is not intended to be extended or derived from. Its designed to
|
||||
* be used as is.
|
||||
*
|
||||
* The 'specified' field of this class indicates whether the attribute was
|
||||
* actually present or whether it was faulted in because it had a fixed or
|
||||
* default value.
|
||||
*
|
||||
* The code receiving this information can ask its validator for more info
|
||||
* about the attribute, i.e. get its declaration from the DTD/Schema info.
|
||||
*
|
||||
* Because of the heavy use (and reuse) of instances of this class, and the
|
||||
* number of string members it has, this class takes pains to not reallocate
|
||||
* string members unless it has to. It keeps up with how long each buffer
|
||||
* is and only reallocates if the new value won't fit.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLAttr : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor just setsup an empty attribute to be filled
|
||||
* in the later. Though the initial state is a reasonable one, it is
|
||||
* not documented because it should not be depended on.
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XMLAttr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/**
|
||||
* This is the primary constructor which takes all of the information
|
||||
* required to construct a complete attribute object.
|
||||
*
|
||||
* @param uriId The id into the validator's URI pool of the URI
|
||||
* that the prefix mapped to. Only used if namespaces
|
||||
* are enabled/supported.
|
||||
*
|
||||
* @param attrName The base name of the attribute, i.e. the part
|
||||
* after any prefix.
|
||||
*
|
||||
* @param attrPrefix The prefix, if any, of this attribute's name. If
|
||||
* this is empty, then uriID is meaningless as well.
|
||||
*
|
||||
* @param attrValue The value string of the attribute, which should
|
||||
* be fully normalized by XML rules!
|
||||
*
|
||||
* @param type The type of the attribute. This will indicate
|
||||
* the type of normalization done and constrains
|
||||
* the value content. Make sure that the value
|
||||
* set meets the constraints!
|
||||
*
|
||||
* @param specified Indicates whether the attribute was explicitly
|
||||
* specified or not. If not, then it was faulted
|
||||
* in from a FIXED or DEFAULT value.
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
* @param datatypeValidator type used to validate the attribute,
|
||||
* if it was validated by an XML Schema
|
||||
* @param isSchema true if and only if this attribute was validated
|
||||
* by an XML Schema
|
||||
*/
|
||||
XMLAttr
|
||||
(
|
||||
const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type = XMLAttDef::CData
|
||||
, const bool specified = true
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
, DatatypeValidator * datatypeValidator = 0
|
||||
, const bool isSchema = false
|
||||
);
|
||||
|
||||
/**
|
||||
* This is the primary constructor which takes all of the information
|
||||
* required to construct a complete attribute object.
|
||||
*
|
||||
* @param uriId The id into the validator's URI pool of the URI
|
||||
* that the prefix mapped to. Only used if namespaces
|
||||
* are enabled/supported.
|
||||
*
|
||||
* @param rawName The raw name of the attribute.
|
||||
*
|
||||
* @param attrValue The value string of the attribute, which should
|
||||
* be fully normalized by XML rules!
|
||||
*
|
||||
* @param type The type of the attribute. This will indicate
|
||||
* the type of normalization done and constrains
|
||||
* the value content. Make sure that the value
|
||||
* set meets the constraints!
|
||||
*
|
||||
* @param specified Indicates whether the attribute was explicitly
|
||||
* specified or not. If not, then it was faulted
|
||||
* in from a FIXED or DEFAULT value.
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
* @param datatypeValidator type used to validate the attribute,
|
||||
* if it was validated by an XML Schema
|
||||
* @param isSchema true if and only if this attribute was validated
|
||||
* by an XML Schema
|
||||
*/
|
||||
XMLAttr
|
||||
(
|
||||
const unsigned int uriId
|
||||
, const XMLCh* const rawName
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type = XMLAttDef::CData
|
||||
, const bool specified = true
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
, DatatypeValidator * datatypeValidator = 0
|
||||
, const bool isSchema = false
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLAttr();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method returns the attribute name in a QName format.
|
||||
*/
|
||||
QName* getAttName() const;
|
||||
|
||||
/**
|
||||
* This method gets a const pointer to the name of the attribute. The
|
||||
* form of this name is defined by the validator in use.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* This method will get a const pointer to the prefix string of this
|
||||
* attribute. Since prefixes are optional, it may be zero.
|
||||
*/
|
||||
const XMLCh* getPrefix() const;
|
||||
|
||||
/**
|
||||
* This method will get the QName of this attribute, which will be the
|
||||
* prefix if any, then a colon, then the base name. If there was no
|
||||
* prefix, its the same as the getName() method.
|
||||
*/
|
||||
const XMLCh* getQName() const;
|
||||
|
||||
/**
|
||||
* This method will get the specified flag, which indicates whether
|
||||
* the attribute was explicitly specified or just faulted in.
|
||||
*/
|
||||
bool getSpecified() const;
|
||||
|
||||
/**
|
||||
* This method will get the type of the attribute. The available types
|
||||
* are defined by the XML specification.
|
||||
*/
|
||||
XMLAttDef::AttTypes getType() const;
|
||||
|
||||
/**
|
||||
* This method will get the value of the attribute. The value can be
|
||||
* be an empty string, but never null if the object is correctly
|
||||
* set up.
|
||||
*/
|
||||
const XMLCh* getValue() const;
|
||||
|
||||
/**
|
||||
* This method will get the id of the URI that this attribute's prefix
|
||||
* mapped to. If namespaces are not on, then its value is meaningless.
|
||||
*/
|
||||
unsigned int getURIId() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method is called to set up a default constructed object after
|
||||
* the fact, or to reuse a previously used object.
|
||||
*
|
||||
* @param uriId The id into the validator's URI pool of the URI
|
||||
* that the prefix mapped to. Only used if namespaces
|
||||
* are enabled/supported.
|
||||
*
|
||||
* @param attrName The base name of the attribute, i.e. the part
|
||||
* after any prefix.
|
||||
*
|
||||
* @param attrPrefix The prefix, if any, of this attribute's name. If
|
||||
* this is empty, then uriID is meaningless as well.
|
||||
*
|
||||
* @param attrValue The value string of the attribute, which should
|
||||
* be fully normalized by XML rules according to the
|
||||
* attribute type.
|
||||
*
|
||||
* @param type The type of the attribute. This will indicate
|
||||
* the type of normalization done and constrains
|
||||
* the value content. Make sure that the value
|
||||
* set meets the constraints!
|
||||
* @param datatypeValidator type used to validate the attribute,
|
||||
* if it was validated by an XML Schema
|
||||
* @param isSchema true if and only if this attribute was validated
|
||||
* by an XML Schema
|
||||
*
|
||||
*/
|
||||
void set
|
||||
(
|
||||
const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type = XMLAttDef::CData
|
||||
, DatatypeValidator * datatypeValidator = 0
|
||||
, const bool isSchema = false
|
||||
);
|
||||
|
||||
/**
|
||||
* This method is called to set up a default constructed object after
|
||||
* the fact, or to reuse a previously used object.
|
||||
*
|
||||
* @param uriId The id into the validator's URI pool of the URI
|
||||
* that the prefix mapped to. Only used if namespaces
|
||||
* are enabled/supported.
|
||||
*
|
||||
* @param attrRawName The raw name of the attribute.
|
||||
*
|
||||
* @param attrValue The value string of the attribute, which should
|
||||
* be fully normalized by XML rules according to the
|
||||
* attribute type.
|
||||
*
|
||||
* @param type The type of the attribute. This will indicate
|
||||
* the type of normalization done and constrains
|
||||
* the value content. Make sure that the value
|
||||
* set meets the constraints!
|
||||
* @param datatypeValidator type used to validate the attribute,
|
||||
* if it was validated by an XML Schema
|
||||
* @param isSchema true if and only if this attribute was validated
|
||||
* by an XML Schema
|
||||
*/
|
||||
void set
|
||||
(
|
||||
const unsigned int uriId
|
||||
, const XMLCh* const attrRawName
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type = XMLAttDef::CData
|
||||
, DatatypeValidator * datatypeValidator = 0
|
||||
, const bool isSchema = false
|
||||
);
|
||||
|
||||
/**
|
||||
* This method will update just the name related fields of the
|
||||
* attribute object. The other fields are left as is.
|
||||
*
|
||||
* @param uriId The id into the validator's URI pool of the URI
|
||||
* that the prefix mapped to. Only used if namespaces
|
||||
* are enabled/supported.
|
||||
*
|
||||
* @param attrName The base name of the attribute, i.e. the part
|
||||
* after any prefix.
|
||||
*
|
||||
* @param attrPrefix The prefix, if any, of this attribute's name. If
|
||||
* this is empty, then uriID is meaningless as well.
|
||||
*/
|
||||
void setName
|
||||
(
|
||||
const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix
|
||||
);
|
||||
|
||||
/**
|
||||
* This method will update the specified state of the object.
|
||||
*
|
||||
* @param newValue Indicates whether the attribute was explicitly
|
||||
* specified or not. If not, then it was faulted
|
||||
* in from a FIXED or DEFAULT value.
|
||||
*/
|
||||
void setSpecified(const bool newValue);
|
||||
|
||||
/**
|
||||
* This method will update the attribute type of the object.
|
||||
*
|
||||
* @param newType The type of the attribute. This will indicate
|
||||
* the type of normalization done and constrains
|
||||
* the value content. Make sure that the value
|
||||
* set meets the constraints!
|
||||
*/
|
||||
void setType(const XMLAttDef::AttTypes newType);
|
||||
|
||||
/**
|
||||
* This method will update the value field of the attribute.
|
||||
*
|
||||
* @param newValue The value string of the attribute, which should
|
||||
* be fully normalized by XML rules according to the
|
||||
* attribute type.
|
||||
*/
|
||||
void setValue(const XMLCh* const newValue);
|
||||
|
||||
/**
|
||||
* This method will set the URI id field of this attribute. This is
|
||||
* generally only ever called internally by the parser itself during
|
||||
* the parsing process.
|
||||
*
|
||||
* @param uriId The uriId of the attribute.
|
||||
*/
|
||||
void setURIId(const unsigned int uriId);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLAttr(const XMLAttr&);
|
||||
XMLAttr& operator=(const XMLAttr&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private, helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void cleanUp();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private instance variables
|
||||
//
|
||||
// fAttName
|
||||
// The Attribute Name;
|
||||
//
|
||||
// fSpecified
|
||||
// True if this attribute appeared in the element; else, false if
|
||||
// it was defaulted from an AttDef.
|
||||
//
|
||||
// fType
|
||||
// The attribute type enum value for this attribute. Indicates what
|
||||
// type of attribute it was.
|
||||
//
|
||||
// fValue
|
||||
// fValueBufSz
|
||||
// The attribute value that was given in the attribute instance, and
|
||||
// its current buffer size (minus one, where the null is.)
|
||||
//
|
||||
// fMemoryManager
|
||||
// The memory manager used for dynamic memory allocation/deallocation
|
||||
// -----------------------------------------------------------------------
|
||||
bool fSpecified;
|
||||
XMLAttDef::AttTypes fType;
|
||||
XMLSize_t fValueBufSz;
|
||||
XMLCh* fValue;
|
||||
QName* fAttName;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLAttr::~XMLAttr()
|
||||
{
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline QName* XMLAttr::getAttName() const
|
||||
{
|
||||
return fAttName;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLAttr::getName() const
|
||||
{
|
||||
return fAttName->getLocalPart();
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLAttr::getPrefix() const
|
||||
{
|
||||
return fAttName->getPrefix();
|
||||
}
|
||||
|
||||
inline bool XMLAttr::getSpecified() const
|
||||
{
|
||||
return fSpecified;
|
||||
}
|
||||
|
||||
inline XMLAttDef::AttTypes XMLAttr::getType() const
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLAttr::getValue() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
|
||||
inline unsigned int XMLAttr::getURIId() const
|
||||
{
|
||||
return fAttName->getURI();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLAttr: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLAttr::set(const unsigned int uriId
|
||||
, const XMLCh* const attrName
|
||||
, const XMLCh* const attrPrefix
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type
|
||||
, DatatypeValidator * /*datatypeValidator */
|
||||
, const bool /*isSchema*/ )
|
||||
{
|
||||
// Set the name info and the value via their respective calls
|
||||
fAttName->setName(attrPrefix, attrName, uriId);
|
||||
setValue(attrValue);
|
||||
|
||||
// And store the type
|
||||
fType = type;
|
||||
}
|
||||
|
||||
inline void XMLAttr::set(const unsigned int uriId
|
||||
, const XMLCh* const attrRawName
|
||||
, const XMLCh* const attrValue
|
||||
, const XMLAttDef::AttTypes type
|
||||
, DatatypeValidator * /*datatypeValidator */
|
||||
, const bool /*isSchema*/ )
|
||||
{
|
||||
// Set the name info and the value via their respective calls
|
||||
fAttName->setName(attrRawName, uriId);
|
||||
setValue(attrValue);
|
||||
|
||||
// And store the type
|
||||
fType = type;
|
||||
}
|
||||
|
||||
inline void XMLAttr::setType(const XMLAttDef::AttTypes newValue)
|
||||
{
|
||||
fType = newValue;
|
||||
}
|
||||
|
||||
inline void XMLAttr::setSpecified(const bool newValue)
|
||||
{
|
||||
fSpecified = newValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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: XMLBuffer.cpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLBuffer.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLBuffer: Buffer management
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void XMLBuffer::ensureCapacity(const XMLSize_t extraNeeded)
|
||||
{
|
||||
// If we can't handle it, try doubling the buffer size.
|
||||
XMLSize_t newCap = (fIndex + extraNeeded) * 2;
|
||||
|
||||
// If a maximum size is set, and double the current buffer size exceeds that
|
||||
// maximum, first check if the maximum size will accomodate the extra needed.
|
||||
if (fFullHandler && (newCap > fFullSize))
|
||||
{
|
||||
// If the maximum buffer size accomodates the extra needed, resize to
|
||||
// the maximum
|
||||
if (fIndex + extraNeeded <= fFullSize)
|
||||
{
|
||||
newCap = fFullSize;
|
||||
}
|
||||
|
||||
// Otherwise, allow the registered full-handler to try to empty the buffer.
|
||||
// If it claims success, and we can accommodate the extra needed in the buffer
|
||||
// to be expanded, resize to the maximum
|
||||
// Note the order of evaluation: bufferFull() has the intentional side-effect
|
||||
// of modifying fIndex.
|
||||
else if (fFullHandler->bufferFull(*this) && (fIndex + extraNeeded <= fFullSize))
|
||||
{
|
||||
newCap = fFullSize;
|
||||
}
|
||||
|
||||
// Finally, if the full-handler failed, or the buffer (of maximum size)
|
||||
// still can't accomodate the extra needed, we must fail.
|
||||
else
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Array_BadNewSize, fMemoryManager);
|
||||
}
|
||||
|
||||
// Note the previous if block can modify newCap, so we may not need to allocate
|
||||
// at all.
|
||||
if (newCap > fCapacity)
|
||||
{
|
||||
// Allocate new buffer
|
||||
XMLCh* newBuf = (XMLCh*) fMemoryManager->allocate((newCap+1) * sizeof(XMLCh)); //new XMLCh[newCap+1];
|
||||
|
||||
// Copy over the old stuff
|
||||
memcpy(newBuf, fBuffer, fIndex * sizeof(XMLCh));
|
||||
|
||||
// Clean up old buffer and store new stuff
|
||||
fMemoryManager->deallocate(fBuffer); //delete [] fBuffer;
|
||||
fBuffer = newBuf;
|
||||
fCapacity = newCap;
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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: XMLBuffer.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLBUFFER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLBUFFER_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/MemoryManager.hpp>
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLBufferFullHandler;
|
||||
|
||||
/**
|
||||
* XMLBuffer is a lightweight, expandable Unicode text buffer. Since XML is
|
||||
* inherently theoretically unbounded in terms of the sizes of things, we
|
||||
* very often need to have expandable buffers. The primary concern here is
|
||||
* that appends of characters and other buffers or strings be very fast, so
|
||||
* it always maintains the current buffer size.
|
||||
*
|
||||
* The buffer is not null terminated until some asks to see the raw buffer
|
||||
* contents. This also avoids overhead during append operations.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLBuffer : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
XMLBuffer(const XMLSize_t capacity = 1023
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) :
|
||||
|
||||
fIndex(0)
|
||||
, fCapacity(capacity)
|
||||
, fFullSize(0)
|
||||
, fUsed(false)
|
||||
, fMemoryManager(manager)
|
||||
, fFullHandler(0)
|
||||
, fBuffer(0)
|
||||
{
|
||||
// Buffer is one larger than capacity, to allow for zero term
|
||||
fBuffer = (XMLCh*) manager->allocate((capacity+1) * sizeof(XMLCh)); //new XMLCh[fCapacity+1];
|
||||
|
||||
// Keep it null terminated
|
||||
fBuffer[0] = XMLCh(0);
|
||||
}
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLBuffer()
|
||||
{
|
||||
fMemoryManager->deallocate(fBuffer); //delete [] fBuffer;
|
||||
}
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Buffer Full Handler Management
|
||||
// -----------------------------------------------------------------------
|
||||
void setFullHandler(XMLBufferFullHandler* handler, const XMLSize_t fullSize)
|
||||
{
|
||||
if (handler && fullSize) {
|
||||
fFullHandler = handler;
|
||||
fFullSize = fullSize;
|
||||
|
||||
// Need to consider the case that the fullsize is less than the current capacity.
|
||||
// For example, say fullSize = 100 and fCapacity is 1023 (the default).
|
||||
// If the fIndex is less than the fullSize, then no problem. We can just carry
|
||||
// on by resetting fCapacity to fullsize and proceed business as usual.
|
||||
// If the fIndex is already bigger than the fullSize then we call ensureCapacity
|
||||
// to see if it can handle emptying the current buffer (it will throw an
|
||||
// exception if it can't).
|
||||
if (fullSize < fCapacity) {
|
||||
fCapacity = fullSize;
|
||||
if (fIndex >= fullSize) {
|
||||
ensureCapacity(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// reset fFullHandler to zero because setFullHandler had bad input
|
||||
fFullHandler = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Buffer Management
|
||||
// -----------------------------------------------------------------------
|
||||
void append(const XMLCh toAppend)
|
||||
{
|
||||
// Put in char and bump the index
|
||||
if (fIndex == fCapacity)
|
||||
ensureCapacity(1);
|
||||
fBuffer[fIndex++] = toAppend;
|
||||
}
|
||||
|
||||
void append (const XMLCh* const chars, const XMLSize_t count)
|
||||
{
|
||||
if (count) {
|
||||
if (fIndex + count >= fCapacity) {
|
||||
ensureCapacity(count);
|
||||
}
|
||||
memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
|
||||
fIndex += count;
|
||||
}
|
||||
else {
|
||||
append(chars);
|
||||
}
|
||||
}
|
||||
|
||||
void append (const XMLCh* const chars)
|
||||
{
|
||||
if (chars != 0 && *chars != 0) {
|
||||
// get length of chars
|
||||
XMLSize_t count = 0;
|
||||
for (; *(chars+count); count++ ) /*noop*/;
|
||||
|
||||
if (fIndex + count >= fCapacity) {
|
||||
ensureCapacity(count);
|
||||
}
|
||||
memcpy(&fBuffer[fIndex], chars, count * sizeof(XMLCh));
|
||||
fIndex += count;
|
||||
}
|
||||
}
|
||||
|
||||
void set (const XMLCh* const chars, const XMLSize_t count)
|
||||
{
|
||||
fIndex = 0;
|
||||
append(chars, count);
|
||||
}
|
||||
|
||||
void set (const XMLCh* const chars)
|
||||
{
|
||||
fIndex = 0;
|
||||
if (chars != 0 && *chars != 0)
|
||||
append(chars);
|
||||
}
|
||||
|
||||
const XMLCh* getRawBuffer() const
|
||||
{
|
||||
fBuffer[fIndex] = 0;
|
||||
return fBuffer;
|
||||
}
|
||||
|
||||
XMLCh* getRawBuffer()
|
||||
{
|
||||
fBuffer[fIndex] = 0;
|
||||
return fBuffer;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
fIndex = 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getters
|
||||
// -----------------------------------------------------------------------
|
||||
bool getInUse() const
|
||||
{
|
||||
return fUsed;
|
||||
}
|
||||
|
||||
XMLSize_t getLen() const
|
||||
{
|
||||
return fIndex;
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return (fIndex == 0);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setters
|
||||
// -----------------------------------------------------------------------
|
||||
void setInUse(const bool newValue)
|
||||
{
|
||||
fUsed = newValue;
|
||||
}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBuffer(const XMLBuffer&);
|
||||
XMLBuffer& operator=(const XMLBuffer&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Declare our friends
|
||||
// -----------------------------------------------------------------------
|
||||
friend class XMLBufBid;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private helpers
|
||||
// -----------------------------------------------------------------------
|
||||
void ensureCapacity(const XMLSize_t extraNeeded);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fBuffer
|
||||
// The pointer to the buffer data. Its grown as needed. Its always
|
||||
// one larger than fCapacity, to leave room for the null terminator.
|
||||
//
|
||||
// fIndex
|
||||
// The current index into the buffer, as characters are appended
|
||||
// to it. If its zero, then the buffer is empty.
|
||||
//
|
||||
// fCapacity
|
||||
// The current capacity of the buffer. Its actually always one
|
||||
// larger, to leave room for the null terminator.
|
||||
//
|
||||
// fUsed
|
||||
// Indicates whether this buffer is in use or not.
|
||||
//
|
||||
// fFullHandler, fFullSize
|
||||
// If fFullHandler is non-null, the buffer has a maximum size
|
||||
// indicated by fFullSize. If writing to the buffer would exceed the
|
||||
// buffer's maximum size, fFullHandler's bufferFull callback is
|
||||
// invoked, to empty the buffer.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fIndex;
|
||||
XMLSize_t fCapacity;
|
||||
XMLSize_t fFullSize;
|
||||
bool fUsed;
|
||||
MemoryManager* const fMemoryManager;
|
||||
XMLBufferFullHandler* fFullHandler;
|
||||
XMLCh* fBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* XMLBufferFullHandler is a callback interface for clients of
|
||||
* XMLBuffers that impose a size restriction (e.g. XMLScanner).
|
||||
* Note that this is intended solely as a mix-in for internal
|
||||
* use, and therefore does not derive from XMemory (to avoid
|
||||
* the ambiguous base class problem).
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLBufferFullHandler
|
||||
{
|
||||
public :
|
||||
|
||||
virtual ~XMLBufferFullHandler() {}
|
||||
|
||||
/**
|
||||
* Callback method, intended to allow clients of an XMLBuffer which has
|
||||
* become full to empty it appropriately.
|
||||
* @return true if the handler was able to empty the buffer (either
|
||||
* partially or completely), otherwise false to indicate an error.
|
||||
*/
|
||||
virtual bool bufferFull(XMLBuffer&) = 0;
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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: XMLBufferMgr.cpp 673679 2008-07-03 13:50:10Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
//#include <string.h>
|
||||
#include <xercesc/framework/XMLBufferMgr.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLBufferMgr::XMLBufferMgr(MemoryManager* const manager) :
|
||||
|
||||
fBufCount(32)
|
||||
, fMemoryManager(manager)
|
||||
, fBufList(0)
|
||||
{
|
||||
// Allocate the buffer list and zero it out
|
||||
fBufList = (XMLBuffer**) fMemoryManager->allocate(fBufCount * sizeof(XMLBuffer*)); // new XMLBuffer*[fBufCount];
|
||||
for (XMLSize_t index = 0; index < fBufCount; index++)
|
||||
fBufList[index] = 0;
|
||||
}
|
||||
|
||||
XMLBufferMgr::~XMLBufferMgr()
|
||||
{
|
||||
// Delete any buffers that got allocated
|
||||
for (XMLSize_t index = 0; index < fBufCount; index++)
|
||||
delete fBufList[index];
|
||||
|
||||
// And then the buffer list
|
||||
fMemoryManager->deallocate(fBufList); //delete [] fBufList;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Buffer management
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLBuffer& XMLBufferMgr::bidOnBuffer()
|
||||
{
|
||||
//
|
||||
// Look for a buffer that is not in use. If we hit a null entry, then
|
||||
// we have to add one.
|
||||
//
|
||||
for (XMLSize_t index = 0; index < fBufCount; index++)
|
||||
{
|
||||
// No more buffers available, so create one and take it
|
||||
if (!fBufList[index])
|
||||
{
|
||||
fBufList[index] = new (fMemoryManager) XMLBuffer(1023, fMemoryManager);
|
||||
fBufList[index]->setInUse(true);
|
||||
return *fBufList[index];
|
||||
}
|
||||
|
||||
//
|
||||
// There's one here, so see if its use. If not, mark it, reset it,
|
||||
// and take it
|
||||
//
|
||||
if (!fBufList[index]->getInUse())
|
||||
{
|
||||
fBufList[index]->reset();
|
||||
fBufList[index]->setInUse(true);
|
||||
return *(fBufList[index]);
|
||||
}
|
||||
}
|
||||
|
||||
// We did not find one, so freak out
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::BufMgr_NoMoreBuffers, fMemoryManager);
|
||||
|
||||
// NOTE: Dummy return to make some compilers happy. Never really gets called!
|
||||
return *fBufList[0];
|
||||
}
|
||||
|
||||
|
||||
void XMLBufferMgr::releaseBuffer(XMLBuffer& toRelease)
|
||||
{
|
||||
// Look for this buffer in the list
|
||||
for (XMLSize_t index = 0; index < fBufCount; index++)
|
||||
{
|
||||
if (fBufList[index] == &toRelease)
|
||||
{
|
||||
// Unmark it
|
||||
toRelease.setInUse(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// It was not a legal buffer
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::BufMgr_BufferNotInPool, fMemoryManager);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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: XMLBufferMgr.hpp 673679 2008-07-03 13:50:10Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLBUFFERMGR_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLBUFFERMGR_HPP
|
||||
|
||||
#include <xercesc/framework/XMLBuffer.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLBufBid;
|
||||
|
||||
/**
|
||||
* There are many places where XMLBuffer objects are needed. In order to
|
||||
* avoid either constantly creating and destroying them or maintaining a
|
||||
* fixed set and worrying about accidental reuse, a buffer manager can
|
||||
* provide a pool of buffers which can be temporarily used and then put
|
||||
* back into the pool. This provides a good compromise between performance
|
||||
* and easier maintenance.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLBufferMgr : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
XMLBufferMgr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLBufferMgr();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Buffer management
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBuffer& bidOnBuffer();
|
||||
void releaseBuffer(XMLBuffer& toRelease);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getBufferCount() const;
|
||||
XMLSize_t getAvailableBufferCount() const;
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBufferMgr(const XMLBufferMgr&);
|
||||
XMLBufferMgr& operator=(const XMLBufferMgr&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fBufCount
|
||||
// The count of buffers that have been allocated so far.
|
||||
//
|
||||
// fBufList;
|
||||
// The list of pointers to buffers that are loaned out. There will
|
||||
// never be a lot of them, so a flat list is good enough.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fBufCount;
|
||||
MemoryManager* fMemoryManager;
|
||||
XMLBuffer** fBufList;
|
||||
};
|
||||
|
||||
inline XMLSize_t XMLBufferMgr::getBufferCount() const
|
||||
{
|
||||
return fBufCount;
|
||||
}
|
||||
|
||||
inline XMLSize_t XMLBufferMgr::getAvailableBufferCount() const
|
||||
{
|
||||
XMLSize_t available = fBufCount;
|
||||
for (XMLSize_t index = 0; index < fBufCount && fBufList[index]; index++)
|
||||
{
|
||||
if (fBufList[index]->getInUse())
|
||||
--available;
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* XMLBufBid is a scoped based janitor that allows the scanner code to ask
|
||||
* for a buffer on a scoped basis and then insure that it gets freed back
|
||||
* into the pool no matter how the scope is exited (exception or normal exit.)
|
||||
*/
|
||||
class XMLBufBid : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBufBid(XMLBufferMgr* const srcMgr) :
|
||||
|
||||
fBuffer(srcMgr->bidOnBuffer())
|
||||
, fMgr(srcMgr)
|
||||
{
|
||||
}
|
||||
|
||||
~XMLBufBid()
|
||||
{
|
||||
fMgr->releaseBuffer(fBuffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Buffer access
|
||||
// -----------------------------------------------------------------------
|
||||
void append(const XMLCh toAppend)
|
||||
{
|
||||
fBuffer.append(toAppend);
|
||||
}
|
||||
|
||||
void append(const XMLCh* const toAppend, const XMLSize_t count = 0)
|
||||
{
|
||||
fBuffer.append(toAppend, count);
|
||||
}
|
||||
|
||||
const XMLBuffer& getBuffer() const
|
||||
{
|
||||
return fBuffer;
|
||||
}
|
||||
|
||||
XMLBuffer& getBuffer()
|
||||
{
|
||||
return fBuffer;
|
||||
}
|
||||
|
||||
const XMLCh* getRawBuffer() const
|
||||
{
|
||||
fBuffer.fBuffer[fBuffer.fIndex] = 0;
|
||||
return fBuffer.fBuffer;
|
||||
}
|
||||
|
||||
XMLCh* getRawBuffer()
|
||||
{
|
||||
fBuffer.fBuffer[fBuffer.fIndex] = 0;
|
||||
return fBuffer.fBuffer;
|
||||
}
|
||||
|
||||
XMLSize_t getLen() const
|
||||
{
|
||||
return fBuffer.fIndex;
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
return (fBuffer.fIndex == 0);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
fBuffer.reset();
|
||||
}
|
||||
|
||||
void set(const XMLCh* const chars, const XMLSize_t count = 0)
|
||||
{
|
||||
fBuffer.set(chars, count);
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBufBid(const XMLBufBid&);
|
||||
XMLBufBid& operator=(const XMLBufBid&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fBuffer
|
||||
// This is the buffer we got, and which we will release.
|
||||
//
|
||||
// fMgr
|
||||
// This is the buffer manager we got the buffer from. This is needed
|
||||
// to release the buffer later.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBuffer& fBuffer;
|
||||
XMLBufferMgr* const fMgr;
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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: XMLContentModel.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLContentModel.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// public static data
|
||||
// ---------------------------------------------------------------------------
|
||||
const unsigned int XMLContentModel::gInvalidTrans = 0xFFFFFFFF;
|
||||
const unsigned int XMLContentModel::gEOCFakeId = 0xFFFFFFF1;
|
||||
const unsigned int XMLContentModel::gEpsilonFakeId = 0xFFFFFFF2;
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -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: XMLContentModel.hpp 677705 2008-07-17 20:15:32Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLCONTENTMODEL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLCONTENTMODEL_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/QName.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class ContentLeafNameTypeVector;
|
||||
class GrammarResolver;
|
||||
class XMLStringPool;
|
||||
class XMLValidator;
|
||||
class SchemaGrammar;
|
||||
class SubstitutionGroupComparator;
|
||||
|
||||
/**
|
||||
* This class defines the abstract interface for all content models. All
|
||||
* elements have a content model against which (if validating) its content
|
||||
* is checked. Each type of validator (DTD, Schema, etc...) can have
|
||||
* different types of content models, and even with each type of validator
|
||||
* there can be specialized content models. So this simple class provides
|
||||
* the abstract API via which all the types of contents models are dealt
|
||||
* with generically. Its pretty simple.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLContentModel : public XMemory
|
||||
{
|
||||
public:
|
||||
// ---------------------------------------------------------------------------
|
||||
// Public static data
|
||||
//
|
||||
// gInvalidTrans
|
||||
// This value represents an invalid transition in each line of the
|
||||
// transition table.
|
||||
//
|
||||
// gEOCFakeId
|
||||
// gEpsilonFakeId
|
||||
// We have to put in a couple of special CMLeaf nodes to represent
|
||||
// special values, using fake element ids that we know won't conflict
|
||||
// with real element ids.
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
static const unsigned int gInvalidTrans;
|
||||
static const unsigned int gEOCFakeId;
|
||||
static const unsigned int gEpsilonFakeId;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, only the virtual Destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~XMLContentModel()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual content model interface provided by derived classes
|
||||
// -----------------------------------------------------------------------
|
||||
virtual bool validateContent
|
||||
(
|
||||
QName** const children
|
||||
, XMLSize_t childCount
|
||||
, unsigned int emptyNamespaceId
|
||||
, XMLSize_t* indexFailingChild
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
) const = 0;
|
||||
|
||||
virtual bool validateContentSpecial
|
||||
(
|
||||
QName** const children
|
||||
, XMLSize_t childCount
|
||||
, unsigned int emptyNamespaceId
|
||||
, GrammarResolver* const pGrammarResolver
|
||||
, XMLStringPool* const pStringPool
|
||||
, XMLSize_t* indexFailingChild
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
) const =0;
|
||||
|
||||
virtual void checkUniqueParticleAttribution
|
||||
(
|
||||
SchemaGrammar* const pGrammar
|
||||
, GrammarResolver* const pGrammarResolver
|
||||
, XMLStringPool* const pStringPool
|
||||
, XMLValidator* const pValidator
|
||||
, unsigned int* const pContentSpecOrgURI
|
||||
, const XMLCh* pComplexTypeName = 0
|
||||
) =0;
|
||||
|
||||
virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector()
|
||||
const = 0;
|
||||
|
||||
virtual unsigned int getNextState(unsigned int currentState,
|
||||
XMLSize_t elementIndex) const = 0;
|
||||
|
||||
virtual bool handleRepetitions( const QName* const curElem,
|
||||
unsigned int curState,
|
||||
unsigned int currentLoop,
|
||||
unsigned int& nextState,
|
||||
unsigned int& nextLoop,
|
||||
XMLSize_t elementIndex,
|
||||
SubstitutionGroupComparator * comparator) const = 0;
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
XMLContentModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLContentModel(const XMLContentModel&);
|
||||
XMLContentModel& operator=(const XMLContentModel&);
|
||||
};
|
||||
|
||||
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: XMLDTDDescription.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLDTDDescription.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
XMLDTDDescription::~XMLDTDDescription()
|
||||
{
|
||||
}
|
||||
|
||||
XMLDTDDescription::XMLDTDDescription(MemoryManager* const memMgr)
|
||||
:XMLGrammarDescription(memMgr)
|
||||
{
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLDTDDescription)
|
||||
|
||||
void XMLDTDDescription::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
|
||||
XMLGrammarDescription::serialize(serEng);
|
||||
|
||||
//no data
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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: XMLDTDDescription.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLDTDDESCRIPTION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLDTDDESCRIPTION_HPP
|
||||
|
||||
#include <xercesc/framework/XMLGrammarDescription.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLPARSER_EXPORT XMLDTDDescription : public XMLGrammarDescription
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual destructor for derived classes */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* virtual destructor
|
||||
*
|
||||
*/
|
||||
virtual ~XMLDTDDescription();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Implementation of Grammar Description Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* getGrammarType
|
||||
*
|
||||
*/
|
||||
virtual Grammar::GrammarType getGrammarType() const
|
||||
{
|
||||
return Grammar::DTDGrammarType;
|
||||
}
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The DTDDescription Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* Getter
|
||||
*
|
||||
*/
|
||||
virtual const XMLCh* getRootName() const = 0;
|
||||
virtual const XMLCh* getSystemId() const {return 0;};
|
||||
|
||||
/**
|
||||
* Setter
|
||||
*
|
||||
*/
|
||||
virtual void setRootName(const XMLCh* const) = 0;
|
||||
virtual void setSystemId(const XMLCh* const) {};
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLDTDDescription)
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
/** Hidden Constructors */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLDTDDescription(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLDTDDescription(const XMLDTDDescription& );
|
||||
XMLDTDDescription& operator=(const XMLDTDDescription& );
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* 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: XMLDocumentHandler.hpp 673679 2008-07-03 13:50:10Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLDOCUMENTHANDLER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLDOCUMENTHANDLER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/framework/XMLAttr.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLElementDecl;
|
||||
class XMLEntityDecl;
|
||||
|
||||
/**
|
||||
* This abstract class provides the interface for the scanner to return
|
||||
* XML document information up to the parser as it scans through the
|
||||
* document.
|
||||
*
|
||||
* The interface is very similar to org.sax.DocumentHandler, but
|
||||
* has some extra methods required to get all the data out.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLDocumentHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, just the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~XMLDocumentHandler()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
/** @name The document handler interface */
|
||||
//@{
|
||||
/** Receive notification of character data.
|
||||
*
|
||||
* <p>The scanner will call this method to report each chunk of
|
||||
* character data. The scanner may return all contiguous character
|
||||
* data in a single chunk, or they may split it into several
|
||||
* chunks; however, all of the characters in any single event
|
||||
* will come from the same external entity, so that the Locator
|
||||
* provides useful information.</p>
|
||||
*
|
||||
* <p>The parser must not attempt to read from the array
|
||||
* outside of the specified range.</p>
|
||||
*
|
||||
* @param chars The content (characters) between markup from the XML
|
||||
* document.
|
||||
* @param length The number of characters to read from the array.
|
||||
* @param cdataSection Indicates that this data is inside a CDATA
|
||||
* section.
|
||||
* @see #ignorableWhitespace
|
||||
* @see Locator
|
||||
*/
|
||||
virtual void docCharacters
|
||||
(
|
||||
const XMLCh* const chars
|
||||
, const XMLSize_t length
|
||||
, const bool cdataSection
|
||||
) = 0;
|
||||
|
||||
/** Receive notification of comments in the XML content being parsed.
|
||||
*
|
||||
* This scanner will call this method for any comments found in the
|
||||
* content of the document.
|
||||
*
|
||||
* @param comment The text of the comment.
|
||||
*/
|
||||
virtual void docComment
|
||||
(
|
||||
const XMLCh* const comment
|
||||
) = 0;
|
||||
|
||||
/** Receive notification of PI's parsed in the XML content.
|
||||
*
|
||||
* The scanner will call this method for any PIs it finds within the
|
||||
* content of the document.
|
||||
*
|
||||
* @param target The name of the PI.
|
||||
* @param data The body of the PI. This may be an empty string since
|
||||
* the body is optional.
|
||||
*/
|
||||
virtual void docPI
|
||||
(
|
||||
const XMLCh* const target
|
||||
, const XMLCh* const data
|
||||
) = 0;
|
||||
|
||||
/** Receive notification after the scanner has parsed the end of the
|
||||
* document.
|
||||
*
|
||||
* The scanner will call this method when the current document has been
|
||||
* fully parsed. The handler may use this opportunity to do something with
|
||||
* the data, clean up temporary data, etc...
|
||||
*/
|
||||
virtual void endDocument() = 0;
|
||||
|
||||
/** Receive notification of the end of an element.
|
||||
*
|
||||
* This method is called when scanner encounters the end of element tag.
|
||||
* There will be a corresponding startElement() event for every
|
||||
* endElement() event, but not necessarily the other way around. For
|
||||
* empty tags, there is only a startElement() call.
|
||||
*
|
||||
* @param elemDecl The name of the element whose end tag was just
|
||||
* parsed.
|
||||
* @param uriId The ID of the URI in the URI pool (only valid if
|
||||
* name spaces is enabled)
|
||||
* @param isRoot Indicates if this is the root element.
|
||||
* @param prefixName The string representing the prefix name
|
||||
*/
|
||||
virtual void endElement
|
||||
(
|
||||
const XMLElementDecl& elemDecl
|
||||
, const unsigned int uriId
|
||||
, const bool isRoot
|
||||
, const XMLCh* const prefixName = 0
|
||||
) = 0;
|
||||
|
||||
/** Receive notification when a referenced entity's content ends
|
||||
*
|
||||
* This method is called when scanner encounters the end of an entity
|
||||
* reference.
|
||||
*
|
||||
* @param entDecl The name of the entity reference just scanned.
|
||||
*/
|
||||
virtual void endEntityReference
|
||||
(
|
||||
const XMLEntityDecl& entDecl
|
||||
) = 0;
|
||||
|
||||
/** Receive notification of ignorable whitespace in element content.
|
||||
*
|
||||
* <p>Validating Parsers must use this method to report each chunk
|
||||
* of ignorable whitespace (see the W3C XML 1.0 recommendation,
|
||||
* section 2.10): non-validating parsers may also use this method
|
||||
* if they are capable of parsing and using content models.</p>
|
||||
*
|
||||
* <p>The scanner may return all contiguous whitespace in a single
|
||||
* chunk, or it may split it into several chunks; however, all of
|
||||
* the characters in any single event will come from the same
|
||||
* external entity, so that the Locator provides useful
|
||||
* information.</p>
|
||||
*
|
||||
* <p>The parser must not attempt to read from the array
|
||||
* outside of the specified range.</p>
|
||||
*
|
||||
* @param chars The whitespace characters from the XML document.
|
||||
* @param length The number of characters to read from the array.
|
||||
* @param cdataSection Indicates that this data is inside a CDATA
|
||||
* section.
|
||||
* @see #docCharacters
|
||||
*/
|
||||
virtual void ignorableWhitespace
|
||||
(
|
||||
const XMLCh* const chars
|
||||
, const XMLSize_t length
|
||||
, const bool cdataSection
|
||||
) = 0;
|
||||
|
||||
/** Reset the document handler's state, if required
|
||||
*
|
||||
* This method is used to give the registered document handler a
|
||||
* chance to reset itself. Its called by the scanner at the start of
|
||||
* every parse.
|
||||
*/
|
||||
virtual void resetDocument() = 0;
|
||||
|
||||
/** Receive notification of the start of a new document
|
||||
*
|
||||
* This method is the first callback called the scanner at the
|
||||
* start of every parse. This is before any content is parsed.
|
||||
*/
|
||||
virtual void startDocument() = 0;
|
||||
|
||||
/** Receive notification of a new start tag
|
||||
*
|
||||
* This method is called when scanner encounters the start of an element tag.
|
||||
* All elements must always have a startElement() tag. Empty tags will
|
||||
* only have the startElement() tag and no endElement() tag.
|
||||
*
|
||||
* @param elemDecl The name of the element whose start tag was just
|
||||
* parsed.
|
||||
* @param uriId The ID of the URI in the URI pool (only valid if
|
||||
* name spaces is enabled)
|
||||
* @param prefixName The string representing the prefix name
|
||||
* @param attrList List of attributes in the element
|
||||
* @param attrCount Count of the attributes in the element
|
||||
* @param isEmpty Indicates if the element is empty, in which case
|
||||
* you should not expect an endElement() event.
|
||||
* @param isRoot Indicates if this is the root element.
|
||||
*/
|
||||
virtual void startElement
|
||||
(
|
||||
const XMLElementDecl& elemDecl
|
||||
, const unsigned int uriId
|
||||
, const XMLCh* const prefixName
|
||||
, const RefVectorOf<XMLAttr>& attrList
|
||||
, const XMLSize_t attrCount
|
||||
, const bool isEmpty
|
||||
, const bool isRoot
|
||||
) = 0;
|
||||
|
||||
/** Receive notification when the scanner hits an entity reference.
|
||||
*
|
||||
* This is currently useful only to DOM parser configurations as SAX
|
||||
* does not provide any api to return this information.
|
||||
*
|
||||
* @param entDecl The name of the entity that was referenced.
|
||||
*/
|
||||
virtual void startEntityReference(const XMLEntityDecl& entDecl) = 0;
|
||||
|
||||
/** Receive notification of an XML declaration
|
||||
*
|
||||
* Currently neither DOM nor SAX provide API's to return back this
|
||||
* information.
|
||||
*
|
||||
* @param versionStr The value of the <code>version</code> pseudoattribute
|
||||
* of the XML decl.
|
||||
* @param encodingStr The value of the <code>encoding</code> pseudoattribute
|
||||
* of the XML decl.
|
||||
* @param standaloneStr The value of the <code>standalone</code>
|
||||
* pseudoattribute of the XML decl.
|
||||
* @param autoEncodingStr The encoding string auto-detected by the
|
||||
* scanner. In absence of any 'encoding' attribute in the
|
||||
* XML decl, the XML standard specifies how a parser can
|
||||
* auto-detect. If there is no <code>encodingStr</code>
|
||||
* this is what will be used to try to decode the file.
|
||||
*/
|
||||
virtual void XMLDecl
|
||||
(
|
||||
const XMLCh* const versionStr
|
||||
, const XMLCh* const encodingStr
|
||||
, const XMLCh* const standaloneStr
|
||||
, const XMLCh* const autoEncodingStr
|
||||
) = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
XMLDocumentHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLDocumentHandler(const XMLDocumentHandler&);
|
||||
XMLDocumentHandler& operator=(const XMLDocumentHandler&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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: XMLElementDecl.cpp 679359 2008-07-24 11:15:19Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLElementDecl.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/XMLUni.hpp>
|
||||
|
||||
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
|
||||
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLElementDecl: Public, static data
|
||||
// ---------------------------------------------------------------------------
|
||||
const unsigned int XMLElementDecl::fgInvalidElemId = 0xFFFFFFFE;
|
||||
const unsigned int XMLElementDecl::fgPCDataElemId = 0xFFFFFFFF;
|
||||
const XMLCh XMLElementDecl::fgPCDataElemName[] =
|
||||
{
|
||||
chPound, chLatin_P, chLatin_C, chLatin_D, chLatin_A
|
||||
, chLatin_T, chLatin_A, chNull
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLElementDecl: Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLElementDecl::~XMLElementDecl()
|
||||
{
|
||||
delete fElementName;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLElementDecl: Setter Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void
|
||||
XMLElementDecl::setElementName(const XMLCh* const prefix
|
||||
, const XMLCh* const localPart
|
||||
, const int uriId )
|
||||
{
|
||||
if (fElementName)
|
||||
fElementName->setName(prefix, localPart, uriId);
|
||||
else
|
||||
fElementName = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager);
|
||||
}
|
||||
|
||||
void
|
||||
XMLElementDecl::setElementName(const XMLCh* const rawName
|
||||
, const int uriId )
|
||||
{
|
||||
if (fElementName)
|
||||
fElementName->setName(rawName, uriId);
|
||||
else
|
||||
fElementName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager);
|
||||
}
|
||||
|
||||
void
|
||||
XMLElementDecl::setElementName(const QName* const elementName)
|
||||
{
|
||||
if (fElementName)
|
||||
fElementName->setValues(*elementName);
|
||||
else
|
||||
fElementName = new (fMemoryManager) QName(*elementName);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ElementDecl: Hidden constructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLElementDecl::XMLElementDecl(MemoryManager* const manager) :
|
||||
|
||||
fMemoryManager(manager)
|
||||
, fElementName(0)
|
||||
, fCreateReason(XMLElementDecl::NoReason)
|
||||
, fId(XMLElementDecl::fgInvalidElemId)
|
||||
, fExternalElement(false)
|
||||
{
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLElementDecl)
|
||||
|
||||
void XMLElementDecl::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng<<fElementName;
|
||||
serEng<<(int) fCreateReason;
|
||||
serEng.writeSize (fId);
|
||||
serEng<<fExternalElement;
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng>>fElementName;
|
||||
|
||||
int i;
|
||||
serEng>>i;
|
||||
fCreateReason=(CreateReasons)i;
|
||||
|
||||
serEng.readSize (fId);
|
||||
serEng>>fExternalElement;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
XMLElementDecl::storeElementDecl(XSerializeEngine& serEng
|
||||
, XMLElementDecl* const element)
|
||||
{
|
||||
if (element)
|
||||
{
|
||||
serEng<<(int) element->getObjectType();
|
||||
serEng<<element;
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng<<(int) UnKnown;
|
||||
}
|
||||
}
|
||||
|
||||
XMLElementDecl*
|
||||
XMLElementDecl::loadElementDecl(XSerializeEngine& serEng)
|
||||
{
|
||||
int type;
|
||||
serEng>>type;
|
||||
|
||||
switch((XMLElementDecl::objectType)type)
|
||||
{
|
||||
case Schema:
|
||||
SchemaElementDecl* schemaElementDecl;
|
||||
serEng>>schemaElementDecl;
|
||||
return schemaElementDecl;
|
||||
case DTD:
|
||||
DTDElementDecl* dtdElementDecl;
|
||||
serEng>>dtdElementDecl;
|
||||
return dtdElementDecl;
|
||||
case UnKnown:
|
||||
//fall through
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* 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: XMLElementDecl.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLELEMENTDECL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLELEMENTDECL_HPP
|
||||
|
||||
#include <xercesc/framework/XMLAttr.hpp>
|
||||
#include <xercesc/framework/XMLAttDefList.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class ContentSpecNode;
|
||||
class XMLContentModel;
|
||||
|
||||
/**
|
||||
* This class defines the core information of an element declaration. Each
|
||||
* validator (DTD, Schema, etc...) will have its own information that it
|
||||
* associations with the declaration of an element, but they must all share
|
||||
* at least this core information, i.e. they must all derive from this
|
||||
* class. The set of info enforced at this level is driven by the needs of
|
||||
* XML 1.0 spec validation and well formedness checks.
|
||||
*
|
||||
* This class defines some special element id values for invalid elements
|
||||
* and PCDATA elements, as well as a string for the special PCDATA element
|
||||
* name. All validators must honor these special values in order to allow
|
||||
* content models to work generically (i.e. to let code know when its dealing
|
||||
* with invalid or PCDATA element ids without having to know what type of
|
||||
* validator its messing with.)
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLElementDecl : public XSerializable, public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Class specific types
|
||||
//
|
||||
// CreateReasons
|
||||
// This type is used to store how an element declaration got into
|
||||
// the grammar's element pool. They are faulted in for various
|
||||
// reasons.
|
||||
//
|
||||
// LookupOpts
|
||||
// These are the values used by the attribute lookup methods.
|
||||
//
|
||||
// CharDataOpts
|
||||
// This is used to indicate how this type of element reacts to
|
||||
// character data as content.
|
||||
// -----------------------------------------------------------------------
|
||||
enum CreateReasons
|
||||
{
|
||||
NoReason
|
||||
, Declared
|
||||
, AttList
|
||||
, InContentModel
|
||||
, AsRootElem
|
||||
, JustFaultIn
|
||||
};
|
||||
|
||||
enum CharDataOpts
|
||||
{
|
||||
NoCharData
|
||||
, SpacesOk
|
||||
, AllCharData
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public static data
|
||||
//
|
||||
// fgInvalidElemId
|
||||
// A value to represent an invalid element node id.
|
||||
//
|
||||
// fgPCDataElemId
|
||||
// This is the value to use to represent a PCDATA node when an
|
||||
// element id is required.
|
||||
//
|
||||
// fgPCDataElemName
|
||||
// This is the value to use to represent a PCDATA node when an
|
||||
// element name is required.
|
||||
// -----------------------------------------------------------------------
|
||||
static const unsigned int fgInvalidElemId;
|
||||
static const unsigned int fgPCDataElemId;
|
||||
static const XMLCh fgPCDataElemName[];
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~XMLElementDecl();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual element decl interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virual ElementDecl interface */
|
||||
//@{
|
||||
|
||||
/** Get a list of attributes defined for this element.
|
||||
*
|
||||
* The derived class should return a reference to some member object which
|
||||
* implements the XMLAttDefList interface. This object gives the scanner the
|
||||
* ability to look through the attributes defined for this element.
|
||||
*
|
||||
* It is done this way for efficiency, though of course this is not thread
|
||||
* safe. The scanner guarantees that it won't ever call this method in any
|
||||
* nested way, but the outside world must be careful about when it calls
|
||||
* this method, and optimally never would.
|
||||
*/
|
||||
virtual XMLAttDefList& getAttDefList() const = 0;
|
||||
|
||||
/** The character data options for this element type
|
||||
*
|
||||
* The derived class should return an appropriate character data opts value
|
||||
* which correctly represents its tolerance towards whitespace or character
|
||||
* data inside of its instances. This allows the scanner to do all of the
|
||||
* validation of character data.
|
||||
*/
|
||||
virtual CharDataOpts getCharDataOpts() const = 0;
|
||||
|
||||
/** Indicate whether this element type defined any attributes
|
||||
*
|
||||
* The derived class should return a boolean that indicates whether this
|
||||
* element has any attributes defined for it or not. This is an optimization
|
||||
* that allows the scanner to skip some work if no attributes exist.
|
||||
*/
|
||||
virtual bool hasAttDefs() const = 0;
|
||||
|
||||
/** Get a pointer to the content spec node
|
||||
*
|
||||
* This method will return a const pointer to the content spec node object
|
||||
* of this element.
|
||||
*
|
||||
* @return A const pointer to the element's content spec node
|
||||
*/
|
||||
virtual const ContentSpecNode* getContentSpec() const = 0;
|
||||
|
||||
/** Get a pointer to the content spec node
|
||||
*
|
||||
* This method is identical to the previous one, except that it is non
|
||||
* const.
|
||||
*/
|
||||
virtual ContentSpecNode* getContentSpec() = 0;
|
||||
|
||||
/** Set the content spec node object for this element type
|
||||
*
|
||||
* This method will adopt the based content spec node object. This is called
|
||||
* by the actual validator which is parsing its DTD or Schema or whatever
|
||||
* and store it on the element decl object via this method.
|
||||
*
|
||||
* @param toAdopt This method will adopt the passed content node spec
|
||||
* object. Any previous object is destroyed.
|
||||
*/
|
||||
virtual void setContentSpec(ContentSpecNode* toAdopt) = 0;
|
||||
|
||||
/** Get a pointer to the abstract content model
|
||||
*
|
||||
* This method will return a const pointer to the content model object
|
||||
* of this element. This class is a simple abstraction that allows an
|
||||
* element to define and use multiple, specialized content model types
|
||||
* internally but still allow the outside world to do simple stuff with
|
||||
* them.
|
||||
*
|
||||
* @return A pointer to the element's content model, via the basic
|
||||
* abstract content model type.
|
||||
*/
|
||||
virtual XMLContentModel* getContentModel() = 0;
|
||||
|
||||
/** Set the content model object for this element type
|
||||
*
|
||||
* This method will adopt the based content model object. This is called
|
||||
* by the actual validator which is parsing its DTD or Schema or whatever
|
||||
* a creating an element decl. It will build what it feels is the correct
|
||||
* content model type object and store it on the element decl object via
|
||||
* this method.
|
||||
*
|
||||
* @param newModelToAdopt This method will adopt the passed content model
|
||||
* object. Any previous object is destroyed.
|
||||
*/
|
||||
virtual void setContentModel(XMLContentModel* const newModelToAdopt) = 0;
|
||||
|
||||
/** Geta formatted string of the content model
|
||||
*
|
||||
* This method is a convenience method which will create a formatted
|
||||
* representation of the content model of the element. It will not always
|
||||
* exactly recreate the original model, since some normalization or
|
||||
* or reformatting may occur. But, it will be a technically accurate
|
||||
* representation of the original content model.
|
||||
*
|
||||
* @return A pointer to an internal buffer which contains the formatted
|
||||
* content model. The caller does not own this buffer and should
|
||||
* copy it if it needs to be kept around.
|
||||
*/
|
||||
virtual const XMLCh* getFormattedContentModel () const = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/** Get the base name of this element type.
|
||||
*
|
||||
* Return the base name part of the element's name. This is the
|
||||
* same regardless of whether namespaces are enabled or not.
|
||||
*
|
||||
* @return A const pointer to the base name of the element decl.
|
||||
*/
|
||||
const XMLCh* getBaseName() const;
|
||||
XMLCh* getBaseName();
|
||||
|
||||
/** Get the URI id of this element type.
|
||||
*
|
||||
* Return the URI Id of this element.
|
||||
*
|
||||
* @return The URI Id of the element decl, or the emptyNamespaceId if not applicable.
|
||||
*/
|
||||
unsigned int getURI() const;
|
||||
|
||||
/** Get the QName of this element type.
|
||||
*
|
||||
* Return the QName part of the element's name. This is the
|
||||
* same regardless of whether namespaces are enabled or not.
|
||||
*
|
||||
* @return A const pointer to the QName of the element decl.
|
||||
*/
|
||||
const QName* getElementName() const;
|
||||
QName* getElementName();
|
||||
|
||||
/** Get the full name of this element type.
|
||||
*
|
||||
* Return the full name of the element. If namespaces
|
||||
* are not enabled, then this is the qName. Else it is the {uri}baseName
|
||||
* form. For those validators that always require namespace processing, it
|
||||
* will always be in the latter form because namespace processing will always
|
||||
* be on.
|
||||
*/
|
||||
const XMLCh* getFullName() const;
|
||||
|
||||
/** Get the create reason for this element type
|
||||
*
|
||||
* This method returns an enumeration which indicates why this element
|
||||
* declaration exists. Elements can be used before they are actually
|
||||
* declared, so they will often be faulted into the pool and marked as
|
||||
* to why they are there.
|
||||
*
|
||||
* @return An enumerated value that indicates the reason why this element
|
||||
* was added to the element decl pool.
|
||||
*/
|
||||
|
||||
CreateReasons getCreateReason() const;
|
||||
|
||||
/** Get the element decl pool id for this element type
|
||||
*
|
||||
* This method will return the element decl pool id of this element
|
||||
* declaration. This uniquely identifies this element type within the
|
||||
* parse event that it is declared within. This value is assigned by the
|
||||
* grammar whose decl pool this object belongs to.
|
||||
*
|
||||
* @return The element decl id of this element declaration.
|
||||
*/
|
||||
XMLSize_t getId() const;
|
||||
|
||||
/** Indicate whether this element type has been declared yet
|
||||
*
|
||||
* This method returns a boolean that indicates whether this element
|
||||
* has been declared yet. There are a number of reasons why an element
|
||||
* declaration can be faulted in, but eventually it must be declared or
|
||||
* its an error. See the CreateReasons enumeration.
|
||||
*
|
||||
* @return true if this element has been declared, else false.
|
||||
*/
|
||||
bool isDeclared() const;
|
||||
|
||||
/** Indicate whether this element type has been declared externally
|
||||
*
|
||||
* This method returns a boolean that indicates whether this element
|
||||
* has been declared externally.
|
||||
*
|
||||
* @return true if this element has been declared externally, else false.
|
||||
*/
|
||||
|
||||
bool isExternal() const;
|
||||
|
||||
/** Get the memory manager
|
||||
*
|
||||
* This method returns the configurable memory manager used by the
|
||||
* element declaration for dynamic allocation/deallocation.
|
||||
*
|
||||
* @return the memory manager
|
||||
*/
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/** Set the element name object for this element type
|
||||
*
|
||||
* This method will adopt the based content spec node object. This is called
|
||||
* by the actual validator which is parsing its DTD or Schema or whatever
|
||||
* and store it on the element decl object via this method.
|
||||
*
|
||||
* @param prefix Prefix of the element
|
||||
* @param localPart Base Name of the element
|
||||
* @param uriId The uriId of the element
|
||||
*/
|
||||
void setElementName(const XMLCh* const prefix
|
||||
, const XMLCh* const localPart
|
||||
, const int uriId );
|
||||
|
||||
/** Set the element name object for this element type
|
||||
*
|
||||
* This method will adopt the based content spec node object. This is called
|
||||
* by the actual validator which is parsing its DTD or Schema or whatever
|
||||
* and store it on the element decl object via this method.
|
||||
*
|
||||
* @param rawName Full Name of the element
|
||||
* @param uriId The uriId of the element
|
||||
*/
|
||||
void setElementName(const XMLCh* const rawName
|
||||
, const int uriId );
|
||||
|
||||
/** Set the element name object for this element type
|
||||
*
|
||||
* This method will adopt the based content spec node object. This is called
|
||||
* by the actual validator which is parsing its DTD or Schema or whatever
|
||||
* and store it on the element decl object via this method.
|
||||
*
|
||||
* @param elementName QName of the element
|
||||
*/
|
||||
void setElementName(const QName* const elementName);
|
||||
|
||||
/** Update the create reason for this element type.
|
||||
*
|
||||
* This method will update the 'create reason' field for this element
|
||||
* decl object. As the validator parses its DTD, Schema, etc... it will
|
||||
* encounter various references to an element declaration, which will
|
||||
* cause the element declaration to either be declared or to be faulted
|
||||
* into the pool in preparation for some future declaration. As it does
|
||||
* so,it will update this field to indicate the current status of the
|
||||
* decl object.
|
||||
*/
|
||||
void setCreateReason(const CreateReasons newReason);
|
||||
|
||||
/** Set the element decl pool id for this element type
|
||||
*
|
||||
* This method will set the pool id of this element decl. This is called
|
||||
* by the grammar which created this object, and will provide this
|
||||
* decl object with a unique id within the parse event that created it.
|
||||
*/
|
||||
void setId(const XMLSize_t newId);
|
||||
|
||||
|
||||
/** Set the element decl to indicate external declaration
|
||||
*
|
||||
*/
|
||||
void setExternalElemDeclaration(const bool aValue);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Miscellaneous methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Miscellaneous methods */
|
||||
//@{
|
||||
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLElementDecl)
|
||||
|
||||
enum objectType
|
||||
{
|
||||
Schema
|
||||
, DTD
|
||||
, UnKnown
|
||||
};
|
||||
|
||||
virtual XMLElementDecl::objectType getObjectType() const = 0;
|
||||
|
||||
static void storeElementDecl(XSerializeEngine& serEng
|
||||
, XMLElementDecl* const element);
|
||||
|
||||
static XMLElementDecl* loadElementDecl(XSerializeEngine& serEng);
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden constructors
|
||||
// -----------------------------------------------------------------------
|
||||
XMLElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLElementDecl(const XMLElementDecl&);
|
||||
XMLElementDecl& operator=(const XMLElementDecl&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Data members
|
||||
//
|
||||
// fElementName
|
||||
// This is the name of the element decl.
|
||||
//
|
||||
// fCreateReason
|
||||
// We sometimes have to put an element decl object into the elem
|
||||
// decl pool before the element's declaration is seen, such as when
|
||||
// its used in another element's content model or an att list is
|
||||
// seen for it. This flag tells us whether its been declared, and
|
||||
// if not why it had to be created.
|
||||
//
|
||||
// fId
|
||||
// The unique id of this element. This is created by the derived
|
||||
// class, or more accurately the grammar that owns the objects
|
||||
// of the derived types. But, since they all have to have them, we
|
||||
// let them all store the id here. It is defaulted to have the
|
||||
// value fgInvalidElem until explicitly set.
|
||||
//
|
||||
// fExternalElement
|
||||
// This flag indicates whether or the element was declared externally.
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager* fMemoryManager;
|
||||
QName* fElementName;
|
||||
CreateReasons fCreateReason;
|
||||
XMLSize_t fId;
|
||||
bool fExternalElement;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLElementDecl: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLCh* XMLElementDecl::getBaseName() const
|
||||
{
|
||||
return fElementName->getLocalPart();
|
||||
}
|
||||
|
||||
inline XMLCh* XMLElementDecl::getBaseName()
|
||||
{
|
||||
return fElementName->getLocalPart();
|
||||
}
|
||||
|
||||
inline unsigned int XMLElementDecl::getURI() const
|
||||
{
|
||||
return fElementName->getURI();
|
||||
}
|
||||
|
||||
inline const QName* XMLElementDecl::getElementName() const
|
||||
{
|
||||
return fElementName;
|
||||
}
|
||||
|
||||
inline QName* XMLElementDecl::getElementName()
|
||||
{
|
||||
return fElementName;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLElementDecl::getFullName() const
|
||||
{
|
||||
return fElementName->getRawName();
|
||||
}
|
||||
|
||||
inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const
|
||||
{
|
||||
return fCreateReason;
|
||||
}
|
||||
|
||||
inline XMLSize_t XMLElementDecl::getId() const
|
||||
{
|
||||
return fId;
|
||||
}
|
||||
|
||||
inline bool XMLElementDecl::isDeclared() const
|
||||
{
|
||||
return (fCreateReason == Declared);
|
||||
}
|
||||
|
||||
|
||||
inline bool XMLElementDecl::isExternal() const
|
||||
{
|
||||
return fExternalElement;
|
||||
}
|
||||
|
||||
inline MemoryManager* XMLElementDecl::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLElementDecl: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void
|
||||
XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)
|
||||
{
|
||||
fCreateReason = newReason;
|
||||
}
|
||||
|
||||
inline void XMLElementDecl::setId(const XMLSize_t newId)
|
||||
{
|
||||
fId = newId;
|
||||
}
|
||||
|
||||
|
||||
inline void XMLElementDecl::setExternalElemDeclaration(const bool aValue)
|
||||
{
|
||||
fExternalElement = aValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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: XMLEntityDecl.cpp 679359 2008-07-24 11:15:19Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLEntityDecl.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLEntityDecl::XMLEntityDecl(MemoryManager* const manager) :
|
||||
|
||||
fId(0)
|
||||
, fValueLen(0)
|
||||
, fValue(0)
|
||||
, fName(0)
|
||||
, fNotationName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fIsExternal(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
XMLEntityDecl::XMLEntityDecl(const XMLCh* const entName,
|
||||
MemoryManager* const manager) :
|
||||
|
||||
fId(0)
|
||||
, fValueLen(0)
|
||||
, fValue(0)
|
||||
, fName(0)
|
||||
, fNotationName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fIsExternal(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fName = XMLString::replicate(entName, fMemoryManager);
|
||||
}
|
||||
|
||||
typedef JanitorMemFunCall<XMLEntityDecl> CleanupType;
|
||||
|
||||
XMLEntityDecl::XMLEntityDecl(const XMLCh* const entName
|
||||
, const XMLCh* const value
|
||||
, MemoryManager* const manager) :
|
||||
fId(0)
|
||||
, fValueLen(XMLString::stringLen(value))
|
||||
, fValue(0)
|
||||
, fName(0)
|
||||
, fNotationName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fIsExternal(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
fValue = XMLString::replicate(value, fMemoryManager);
|
||||
fName = XMLString::replicate(entName, fMemoryManager);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
XMLEntityDecl::XMLEntityDecl(const XMLCh* const entName
|
||||
, const XMLCh value
|
||||
, MemoryManager* const manager) :
|
||||
fId(0)
|
||||
, fValueLen(1)
|
||||
, fValue(0)
|
||||
, fName(0)
|
||||
, fNotationName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fIsExternal(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
XMLCh dummy[2] = { chNull, chNull };
|
||||
dummy[0] = value;
|
||||
fValue = XMLString::replicate(dummy, fMemoryManager);
|
||||
fName = XMLString::replicate(entName, fMemoryManager);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
XMLEntityDecl::~XMLEntityDecl()
|
||||
{
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLEntityDecl::setName(const XMLCh* const entName)
|
||||
{
|
||||
// Clean up the current name stuff
|
||||
if (fName)
|
||||
fMemoryManager->deallocate(fName);
|
||||
|
||||
fName = XMLString::replicate(entName, fMemoryManager);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Private helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLEntityDecl::cleanUp()
|
||||
{
|
||||
fMemoryManager->deallocate(fName);
|
||||
fMemoryManager->deallocate(fNotationName);
|
||||
fMemoryManager->deallocate(fValue);
|
||||
fMemoryManager->deallocate(fPublicId);
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
fMemoryManager->deallocate(fBaseURI);
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLEntityDecl)
|
||||
|
||||
void XMLEntityDecl::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng.writeSize (fId);
|
||||
serEng.writeSize (fValueLen);
|
||||
serEng.writeString(fValue);
|
||||
serEng.writeString(fName);
|
||||
serEng.writeString(fNotationName);
|
||||
serEng.writeString(fPublicId);
|
||||
serEng.writeString(fSystemId);
|
||||
serEng.writeString(fBaseURI);
|
||||
serEng<<fIsExternal;
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng.readSize (fId);
|
||||
serEng.readSize (fValueLen);
|
||||
serEng.readString(fValue);
|
||||
serEng.readString(fName);
|
||||
serEng.readString(fNotationName);
|
||||
serEng.readString(fPublicId);
|
||||
serEng.readString(fSystemId);
|
||||
serEng.readString(fBaseURI);
|
||||
serEng>>fIsExternal;
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,512 @@
|
||||
/*
|
||||
* 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: XMLEntityDecl.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLENTITYDECL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLENTITYDECL_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class defines that core information that defines an XML entity, no
|
||||
* matter what validator is used. Each validator will create a derivative
|
||||
* of this class which adds any extra information it requires.
|
||||
*
|
||||
* This class supports keyed collection semantics via the getKey() method
|
||||
* which extracts the key field, the entity name in this case. The name will
|
||||
* have whatever form is deemed appropriate for the type of validator in
|
||||
* use.
|
||||
*
|
||||
* When setting the fields of this class, you must make sure that you do
|
||||
* not set conflicting values. For instance, an internal entity cannot have
|
||||
* a notation name. And an external entity cannot have a value string.
|
||||
* These rules are defined by the XML specification. In most cases, these
|
||||
* objects are created by validator objects as they parse a DTD or Schema
|
||||
* or whatever, at which time they confirm the correctness of the data before
|
||||
* creating the entity decl object.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLEntityDecl : public XSerializable, public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
XMLEntityDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/** Constructor with a const entity name
|
||||
*
|
||||
* @param entName The new name to give to this entity.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
XMLEntityDecl
|
||||
(
|
||||
const XMLCh* const entName
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor with a const entity name and value
|
||||
*
|
||||
* @param entName The new name to give to this entity.
|
||||
* @param value The new value to give to this entity name.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
XMLEntityDecl
|
||||
(
|
||||
const XMLCh* const entName
|
||||
, const XMLCh* const value
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor with a const entity name and single XMLCh value
|
||||
*
|
||||
* @param entName The new name to give to this entity.
|
||||
* @param value The new value to give to this entity name.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
XMLEntityDecl
|
||||
(
|
||||
const XMLCh* const entName
|
||||
, const XMLCh value
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*/
|
||||
virtual ~XMLEntityDecl();
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual entity decl interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name The pure virtual methods in this interface. */
|
||||
//@{
|
||||
|
||||
/** Get the 'declared in internal subset' flag
|
||||
*
|
||||
* Gets the state of the flag which indicates whether the entity was
|
||||
* declared in the internal or external subset. Some structural
|
||||
* description languages might not have an internal subset concept, in
|
||||
* which case this will always return false.
|
||||
*/
|
||||
virtual bool getDeclaredInIntSubset() const = 0;
|
||||
|
||||
/** Get the 'is parameter entity' flag
|
||||
*
|
||||
* Gets the state of the flag which indicates whether this entity is
|
||||
* a parameter entity. If not, then its a general entity.
|
||||
*/
|
||||
virtual bool getIsParameter() const = 0;
|
||||
|
||||
/** Get the 'is special char entity' flag
|
||||
*
|
||||
* Gets the state of the flag that indicates whether this entity is
|
||||
* one of the special, intrinsically supported character entities.
|
||||
*/
|
||||
virtual bool getIsSpecialChar() const = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Gets the pool id of this entity. Validators maintain all decls in
|
||||
* pools, from which they can be quickly extracted via id.
|
||||
*/
|
||||
XMLSize_t getId() const;
|
||||
|
||||
/**
|
||||
* Returns a const pointer to the name of this entity decl. This name
|
||||
* will be in whatever format is appropriate for the type of validator
|
||||
* in use.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* Gets the notation name, if any, declared for this entity. If this
|
||||
* entity is not a notation type entity, it will be a null pointer.
|
||||
*/
|
||||
const XMLCh* getNotationName() const;
|
||||
|
||||
/**
|
||||
* Gets the public id declared for this entity. Public ids are optional
|
||||
* so it can be a null pointer.
|
||||
*/
|
||||
const XMLCh* getPublicId() const;
|
||||
|
||||
/**
|
||||
* Gets the system id declared for this entity. The system id is required
|
||||
* so this method should never return a null pointers.
|
||||
*/
|
||||
const XMLCh* getSystemId() const;
|
||||
|
||||
/**
|
||||
* Gets the base URI for this entity.
|
||||
*/
|
||||
const XMLCh* getBaseURI() const;
|
||||
|
||||
/**
|
||||
* This method returns the value of an internal entity. If this is not
|
||||
* an internal entity (i.e. its external), then this will be a null
|
||||
* pointer.
|
||||
*/
|
||||
const XMLCh* getValue() const;
|
||||
|
||||
/**
|
||||
* This method returns the number of characters in the value returned
|
||||
* by getValue(). If this entity is external, this will be zero since
|
||||
* an external entity has no internal value.
|
||||
*/
|
||||
XMLSize_t getValueLen() const;
|
||||
|
||||
/**
|
||||
* Indicates that this entity is an external entity. If not, then it is
|
||||
* assumed to be an internal entity, surprise.
|
||||
*/
|
||||
bool isExternal() const;
|
||||
|
||||
/**
|
||||
* Indicates whether this entity is unparsed. This is meaningless for
|
||||
* internal entities. Some external entities are unparsed in that they
|
||||
* refer to something other than XML source.
|
||||
*/
|
||||
bool isUnparsed() const;
|
||||
|
||||
/** Get the plugged-in memory manager
|
||||
*
|
||||
* This method returns the plugged-in memory manager user for dynamic
|
||||
* memory allocation/deallocation.
|
||||
*
|
||||
* @return the plugged-in memory manager
|
||||
*/
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will set the entity name. The format of this name is
|
||||
* defined by the particular validator in use, since it will be the
|
||||
* one who creates entity definitions as it parses the DTD, Schema,
|
||||
* ect...
|
||||
*
|
||||
* @param entName The new name to give to this entity.
|
||||
*/
|
||||
void setName
|
||||
(
|
||||
const XMLCh* const entName
|
||||
);
|
||||
|
||||
/**
|
||||
* This method will mark whether the entity is external.
|
||||
*
|
||||
* @param value The new value for the 'is external' flag.
|
||||
*/
|
||||
void setIsExternal(bool value);
|
||||
|
||||
/**
|
||||
* This method will set the notation name for this entity. By setting
|
||||
* this, you are indicating that this is an unparsed external entity.
|
||||
*
|
||||
* @param newName The new notation name to give to this entity.
|
||||
*/
|
||||
void setNotationName(const XMLCh* const newName);
|
||||
|
||||
/**
|
||||
* This method will set a new public id on this entity. The public id
|
||||
* has no particular form and is purely for client consumption.
|
||||
*
|
||||
* @param newId The new public id to give to this entity.
|
||||
*/
|
||||
void setPublicId(const XMLCh* const newId);
|
||||
|
||||
/**
|
||||
* This method will set a new sysetm id on this entity. This will
|
||||
* then control where the source for this entity lives. If it is
|
||||
* an internal entity, then the system id is only for bookkeeping
|
||||
* purposes, and to allow any external entities referenced from
|
||||
* within the entity to be correctly resolved.
|
||||
*
|
||||
* @param newId The new system id to give to the entity.
|
||||
*/
|
||||
void setSystemId(const XMLCh* const newId);
|
||||
|
||||
/**
|
||||
* This method will set a new baseURI on this entity. This will
|
||||
* then control the URI used to resolve the relative system Id.
|
||||
*
|
||||
* @param newId The new base URI to give to the entity.
|
||||
*/
|
||||
void setBaseURI(const XMLCh* const newId);
|
||||
|
||||
/**
|
||||
* This method will set a new value for this entity. This is only
|
||||
* valid if the entity is to be an internal entity. By setting this
|
||||
* field, you are indicating that the entity is internal.
|
||||
*
|
||||
* @param newValue The new value to give to this entity.
|
||||
*/
|
||||
void setValue(const XMLCh* const newValue);
|
||||
|
||||
//@}
|
||||
|
||||
/* For internal use only */
|
||||
void setId(const XMLSize_t newId);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Support named pool syntax
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method allows objects of this class to be used within a standard
|
||||
* keyed collection used commonly within the parser system. The collection
|
||||
* calls this method to get the key (usually to hash it) by which the
|
||||
* object is to be stored.
|
||||
*/
|
||||
const XMLCh* getKey() const;
|
||||
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLEntityDecl)
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLEntityDecl(const XMLEntityDecl&);
|
||||
XMLEntityDecl& operator=(XMLEntityDecl&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// XMLEntityDecl: Private helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void cleanUp();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fId
|
||||
// This is the unique id given to this entity decl.
|
||||
//
|
||||
// fName
|
||||
// The name of the entity. Entity names are never namespace based.
|
||||
//
|
||||
// fNotationName
|
||||
// The optional notation of the entity. If there was none, then its
|
||||
// empty.
|
||||
//
|
||||
// fPublicId
|
||||
// The public id of the entity, which can be empty.
|
||||
//
|
||||
// fSystemId
|
||||
// The system id of the entity.
|
||||
//
|
||||
// fValue
|
||||
// fValueLen
|
||||
// The entity's value and length, which is only valid if its an
|
||||
// internal style entity.
|
||||
//
|
||||
// fBaseURI
|
||||
// The base URI of the entity. According to XML InfoSet, such value
|
||||
// is the URI where it is declared (NOT referenced).
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fId;
|
||||
XMLSize_t fValueLen;
|
||||
XMLCh* fValue;
|
||||
XMLCh* fName;
|
||||
XMLCh* fNotationName;
|
||||
XMLCh* fPublicId;
|
||||
XMLCh* fSystemId;
|
||||
XMLCh* fBaseURI;
|
||||
bool fIsExternal;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLSize_t XMLEntityDecl::getId() const
|
||||
{
|
||||
return fId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getNotationName() const
|
||||
{
|
||||
return fNotationName;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getPublicId() const
|
||||
{
|
||||
return fPublicId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getSystemId() const
|
||||
{
|
||||
return fSystemId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getBaseURI() const
|
||||
{
|
||||
return fBaseURI;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLEntityDecl::getValue() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
|
||||
inline XMLSize_t XMLEntityDecl::getValueLen() const
|
||||
{
|
||||
return fValueLen;
|
||||
}
|
||||
|
||||
inline bool XMLEntityDecl::isExternal() const
|
||||
{
|
||||
return fIsExternal;
|
||||
}
|
||||
|
||||
inline bool XMLEntityDecl::isUnparsed() const
|
||||
{
|
||||
// If it has a notation, its unparsed
|
||||
return (fNotationName != 0);
|
||||
}
|
||||
|
||||
inline MemoryManager* XMLEntityDecl::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLEntityDecl::setId(const XMLSize_t newId)
|
||||
{
|
||||
fId = newId;
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setIsExternal(bool value)
|
||||
{
|
||||
fIsExternal = value;
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setNotationName(const XMLCh* const newName)
|
||||
{
|
||||
if (fNotationName)
|
||||
fMemoryManager->deallocate(fNotationName);
|
||||
|
||||
fNotationName = XMLString::replicate(newName, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setPublicId(const XMLCh* const newId)
|
||||
{
|
||||
if (fPublicId)
|
||||
fMemoryManager->deallocate(fPublicId);
|
||||
|
||||
fPublicId = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setSystemId(const XMLCh* const newId)
|
||||
{
|
||||
if (fSystemId)
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
|
||||
fSystemId = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setBaseURI(const XMLCh* const newId)
|
||||
{
|
||||
if (fBaseURI)
|
||||
fMemoryManager->deallocate(fBaseURI);
|
||||
|
||||
fBaseURI = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLEntityDecl::setValue(const XMLCh* const newValue)
|
||||
{
|
||||
if (fValue)
|
||||
fMemoryManager->deallocate(fValue);
|
||||
|
||||
fValue = XMLString::replicate(newValue, fMemoryManager);
|
||||
fValueLen = XMLString::stringLen(newValue);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLEntityDecl: Support named pool syntax
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLCh* XMLEntityDecl::getKey() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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: XMLEntityHandler.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLENTITYHANDLER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLENTITYHANDLER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class InputSource;
|
||||
class XMLBuffer;
|
||||
class XMLResourceIdentifier;
|
||||
|
||||
/**
|
||||
* This abstract class is a callback mechanism for the scanner. By creating
|
||||
* a derivative of this class and plugging into the scanner, the scanner
|
||||
* will call back on the object's methods to entity events.
|
||||
*
|
||||
* This class is primarily for use by those writing their own parser classes.
|
||||
* If you use the standard parser classes, DOMParser and SAXParser, you won't
|
||||
* use this API. You will instead use a similar mechanism defined by the SAX
|
||||
* API, called EntityResolver.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLEntityHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, only the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*/
|
||||
virtual ~XMLEntityHandler()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual entity handler interface
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The pure virtual methods in this interface. */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method get called after the scanner has finished reading from
|
||||
* the given input source while processing external entity references.
|
||||
*
|
||||
* @param inputSource The input source for the entity
|
||||
*/
|
||||
virtual void endInputSource(const InputSource& inputSource) = 0;
|
||||
|
||||
/**
|
||||
* This method allows the passes the scanned systemId to the entity
|
||||
* handler, thereby giving it a chance to provide any customized
|
||||
* handling like resolving relative path names. The scanner first
|
||||
* calls this method before calling <code>resolveEntity</code>.
|
||||
*
|
||||
* @param systemId The system id extracted by the scanner from the
|
||||
* input source.
|
||||
* @param toFill The buffer in which the fully expanded system id needs
|
||||
* to be stored.
|
||||
*/
|
||||
virtual bool expandSystemId
|
||||
(
|
||||
const XMLCh* const systemId
|
||||
, XMLBuffer& toFill
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* This method allows the entity handler to reset itself, so that
|
||||
* it can be used again. It is called prior to a new document parse
|
||||
* operation.
|
||||
*/
|
||||
virtual void resetEntities() = 0;
|
||||
|
||||
/**
|
||||
* This method allows the entity handler to provide customized
|
||||
* application specific entity resolution.
|
||||
*
|
||||
* <i>Only one resolveEntity method will be used. If both setEntityResolver and
|
||||
* setXMLEntityResolver are called, then the last one is used.</i>
|
||||
*
|
||||
* @param resourceIdentifier An object containing the type of
|
||||
* resource to be resolved and the associated data members
|
||||
* corresponding to this type.
|
||||
* @return The value returned by the resolveEntity method or
|
||||
* NULL otherwise to indicate no processing was done.
|
||||
* The returned InputSource is owned by the parser which is
|
||||
* responsible to clean up the memory.
|
||||
*/
|
||||
virtual InputSource* resolveEntity
|
||||
(
|
||||
XMLResourceIdentifier* resourceIdentifier
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* This method will be called before the scanner starts reading
|
||||
* from an input source while processing external entity references.
|
||||
*
|
||||
* @param inputSource The external input source.
|
||||
*/
|
||||
virtual void startInputSource(const InputSource& inputSource) = 0;
|
||||
//@}
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Protected default constructor
|
||||
*/
|
||||
XMLEntityHandler()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and destructor
|
||||
// -----------------------------------------------------------------------
|
||||
XMLEntityHandler(const XMLEntityHandler&);
|
||||
XMLEntityHandler& operator=(const XMLEntityHandler&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,351 @@
|
||||
// This file is generated, don't edit it!!
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_ERRHEADER_XMLErrs)
|
||||
#define XERCESC_INCLUDE_GUARD_ERRHEADER_XMLErrs
|
||||
|
||||
#include <xercesc/framework/XMLErrorReporter.hpp>
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/dom/DOMError.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLErrs
|
||||
{
|
||||
public :
|
||||
enum Codes
|
||||
{
|
||||
NoError = 0
|
||||
, W_LowBounds = 1
|
||||
, NotationAlreadyExists = 2
|
||||
, AttListAlreadyExists = 3
|
||||
, ContradictoryEncoding = 4
|
||||
, UndeclaredElemInCM = 5
|
||||
, UndeclaredElemInAttList = 6
|
||||
, XMLException_Warning = 7
|
||||
, XIncludeResourceErrorWarning = 8
|
||||
, XIncludeCannotOpenFile = 9
|
||||
, XIncludeIncludeFailedResourceError = 10
|
||||
, W_HighBounds = 11
|
||||
, E_LowBounds = 12
|
||||
, FeatureUnsupported = 13
|
||||
, TopLevelNoNameComplexType = 14
|
||||
, TopLevelNoNameAttribute = 15
|
||||
, NoNameRefAttribute = 16
|
||||
, NoNameRefElement = 17
|
||||
, NoNameRefGroup = 18
|
||||
, NoNameRefAttGroup = 19
|
||||
, AnonComplexTypeWithName = 20
|
||||
, AnonSimpleTypeWithName = 21
|
||||
, InvalidElementContent = 22
|
||||
, SimpleTypeContentError = 23
|
||||
, ExpectedSimpleTypeInList = 24
|
||||
, ListUnionRestrictionError = 25
|
||||
, SimpleTypeDerivationByListError = 26
|
||||
, ExpectedSimpleTypeInRestriction = 27
|
||||
, DuplicateFacet = 28
|
||||
, ExpectedSimpleTypeInUnion = 29
|
||||
, EmptySimpleTypeContent = 30
|
||||
, InvalidSimpleContent = 31
|
||||
, UnspecifiedBase = 32
|
||||
, InvalidComplexContent = 33
|
||||
, SchemaElementContentError = 34
|
||||
, ContentError = 35
|
||||
, UnknownSimpleType = 36
|
||||
, UnknownComplexType = 37
|
||||
, UnresolvedPrefix = 38
|
||||
, RefElementNotFound = 39
|
||||
, TypeNotFound = 40
|
||||
, TopLevelAttributeNotFound = 41
|
||||
, InvalidChildInComplexType = 42
|
||||
, BaseTypeNotFound = 43
|
||||
, DatatypeValidatorCreationError = 44
|
||||
, InvalidChildFollowingSimpleContent = 45
|
||||
, InvalidChildFollowingConplexContent = 46
|
||||
, AttributeDefaultFixedValue = 47
|
||||
, NotOptionalDefaultAttValue = 48
|
||||
, DuplicateAttribute = 49
|
||||
, AttributeWithTypeAndSimpleType = 50
|
||||
, AttributeSimpleTypeNotFound = 51
|
||||
, ElementWithFixedAndDefault = 52
|
||||
, InvalidDeclarationName = 53
|
||||
, ElementWithTypeAndAnonType = 54
|
||||
, NotSimpleOrMixedElement = 55
|
||||
, DisallowedSimpleTypeExtension = 56
|
||||
, InvalidSimpleContentBase = 57
|
||||
, InvalidComplexTypeBase = 58
|
||||
, InvalidChildInSimpleContent = 59
|
||||
, InvalidChildInComplexContent = 60
|
||||
, AnnotationError = 61
|
||||
, DisallowedBaseDerivation = 62
|
||||
, InvalidBlockValue = 63
|
||||
, InvalidFinalValue = 64
|
||||
, InvalidSubstitutionGroupElement = 65
|
||||
, SubstitutionGroupTypeMismatch = 66
|
||||
, DuplicateElementDeclaration = 67
|
||||
, InvalidAttValue = 68
|
||||
, AttributeRefContentError = 69
|
||||
, DuplicateRefAttribute = 70
|
||||
, ForbiddenDerivationByRestriction = 71
|
||||
, ForbiddenDerivationByExtension = 72
|
||||
, BaseNotComplexType = 73
|
||||
, ImportNamespaceDifference = 74
|
||||
, DeclarationNoSchemaLocation = 75
|
||||
, IncludeNamespaceDifference = 76
|
||||
, OnlyAnnotationExpected = 77
|
||||
, InvalidAttributeContent = 78
|
||||
, AttributeRequiredGlobal = 79
|
||||
, AttributeRequiredLocal = 80
|
||||
, AttributeDisallowedGlobal = 81
|
||||
, AttributeDisallowedLocal = 82
|
||||
, InvalidMin2MaxOccurs = 83
|
||||
, AnyAttributeContentError = 84
|
||||
, NoNameGlobalElement = 85
|
||||
, NoCircularDefinition = 86
|
||||
, DuplicateGlobalType = 87
|
||||
, DuplicateGlobalDeclaration = 88
|
||||
, WS_CollapseExpected = 89
|
||||
, Import_1_1 = 90
|
||||
, Import_1_2 = 91
|
||||
, ElemIDValueConstraint = 92
|
||||
, NoNotationType = 93
|
||||
, EmptiableMixedContent = 94
|
||||
, EmptyComplexRestrictionDerivation = 95
|
||||
, MixedOrElementOnly = 96
|
||||
, InvalidContentRestriction = 97
|
||||
, ForbiddenDerivation = 98
|
||||
, AtomicItemType = 99
|
||||
, GroupContentError = 100
|
||||
, AttGroupContentError = 101
|
||||
, MinMaxOnGroupChild = 102
|
||||
, DeclarationNotFound = 103
|
||||
, AllContentLimited = 104
|
||||
, BadMinMaxAllCT = 105
|
||||
, BadMinMaxAllElem = 106
|
||||
, DuplicateAttInDerivation = 107
|
||||
, NotExpressibleWildCardIntersection = 108
|
||||
, BadAttDerivation_1 = 109
|
||||
, BadAttDerivation_2 = 110
|
||||
, BadAttDerivation_3 = 111
|
||||
, BadAttDerivation_4 = 112
|
||||
, BadAttDerivation_5 = 113
|
||||
, BadAttDerivation_6 = 114
|
||||
, BadAttDerivation_7 = 115
|
||||
, BadAttDerivation_8 = 116
|
||||
, BadAttDerivation_9 = 117
|
||||
, AllContentError = 118
|
||||
, RedefineNamespaceDifference = 119
|
||||
, Redefine_InvalidSimpleType = 120
|
||||
, Redefine_InvalidSimpleTypeBase = 121
|
||||
, Redefine_InvalidComplexType = 122
|
||||
, Redefine_InvalidComplexTypeBase = 123
|
||||
, Redefine_InvalidGroupMinMax = 124
|
||||
, Redefine_DeclarationNotFound = 125
|
||||
, Redefine_GroupRefCount = 126
|
||||
, Redefine_AttGroupRefCount = 127
|
||||
, Redefine_InvalidChild = 128
|
||||
, Notation_DeclNotFound = 129
|
||||
, IC_DuplicateDecl = 130
|
||||
, IC_BadContent = 131
|
||||
, IC_KeyRefReferNotFound = 132
|
||||
, IC_KeyRefCardinality = 133
|
||||
, IC_XPathExprMissing = 134
|
||||
, AttUseCorrect = 135
|
||||
, AttDeclPropCorrect3 = 136
|
||||
, AttDeclPropCorrect5 = 137
|
||||
, AttGrpPropCorrect3 = 138
|
||||
, InvalidTargetNSValue = 139
|
||||
, XMLException_Error = 140
|
||||
, InvalidRedefine = 141
|
||||
, InvalidNSReference = 142
|
||||
, NotAllContent = 143
|
||||
, InvalidAnnotationContent = 144
|
||||
, InvalidFacetName = 145
|
||||
, InvalidXMLSchemaRoot = 146
|
||||
, CircularSubsGroup = 147
|
||||
, ELTSchemaNS = 148
|
||||
, InvalidAttTNS = 149
|
||||
, NSDeclInvalid = 150
|
||||
, DOMLevel1Node = 151
|
||||
, DuplicateAnyAttribute = 152
|
||||
, AnyAttributeBeforeAttribute = 153
|
||||
, E_HighBounds = 154
|
||||
, F_LowBounds = 155
|
||||
, EntityExpansionLimitExceeded = 156
|
||||
, ExpectedCommentOrCDATA = 157
|
||||
, ExpectedAttrName = 158
|
||||
, ExpectedNotationName = 159
|
||||
, NoRepInMixed = 160
|
||||
, ExpectedDefAttrDecl = 161
|
||||
, ExpectedEqSign = 162
|
||||
, ExpectedElementName = 163
|
||||
, CommentsMustStartWith = 164
|
||||
, InvalidDocumentStructure = 165
|
||||
, ExpectedDeclString = 166
|
||||
, BadXMLVersion = 167
|
||||
, UnsupportedXMLVersion = 168
|
||||
, UnterminatedXMLDecl = 169
|
||||
, BadXMLEncoding = 170
|
||||
, BadStandalone = 171
|
||||
, UnterminatedComment = 172
|
||||
, PINameExpected = 173
|
||||
, UnterminatedPI = 174
|
||||
, InvalidCharacter = 175
|
||||
, UnterminatedStartTag = 176
|
||||
, ExpectedAttrValue = 177
|
||||
, UnterminatedEndTag = 178
|
||||
, ExpectedAttributeType = 179
|
||||
, ExpectedEndOfTagX = 180
|
||||
, ExpectedMarkup = 181
|
||||
, NotValidAfterContent = 182
|
||||
, ExpectedComment = 183
|
||||
, ExpectedCommentOrPI = 184
|
||||
, ExpectedWhitespace = 185
|
||||
, NoRootElemInDOCTYPE = 186
|
||||
, ExpectedQuotedString = 187
|
||||
, ExpectedPublicId = 188
|
||||
, InvalidPublicIdChar = 189
|
||||
, UnterminatedDOCTYPE = 190
|
||||
, InvalidCharacterInIntSubset = 191
|
||||
, UnexpectedWhitespace = 192
|
||||
, InvalidCharacterInAttrValue = 193
|
||||
, ExpectedMarkupDecl = 194
|
||||
, TextDeclNotLegalHere = 195
|
||||
, ConditionalSectInIntSubset = 196
|
||||
, ExpectedPEName = 197
|
||||
, UnterminatedEntityDecl = 198
|
||||
, InvalidCharacterRef = 199
|
||||
, UnterminatedCharRef = 200
|
||||
, ExpectedEntityRefName = 201
|
||||
, EntityNotFound = 202
|
||||
, NoUnparsedEntityRefs = 203
|
||||
, UnterminatedEntityRef = 204
|
||||
, RecursiveEntity = 205
|
||||
, PartialMarkupInEntity = 206
|
||||
, UnterminatedElementDecl = 207
|
||||
, ExpectedContentSpecExpr = 208
|
||||
, ExpectedAsterisk = 209
|
||||
, UnterminatedContentModel = 210
|
||||
, ExpectedSystemOrPublicId = 211
|
||||
, UnterminatedNotationDecl = 212
|
||||
, ExpectedSeqChoiceLeaf = 213
|
||||
, ExpectedChoiceOrCloseParen = 214
|
||||
, ExpectedSeqOrCloseParen = 215
|
||||
, ExpectedEnumValue = 216
|
||||
, ExpectedEnumSepOrParen = 217
|
||||
, UnterminatedEntityLiteral = 218
|
||||
, MoreEndThanStartTags = 219
|
||||
, ExpectedOpenParen = 220
|
||||
, AttrAlreadyUsedInSTag = 221
|
||||
, BracketInAttrValue = 222
|
||||
, Expected2ndSurrogateChar = 223
|
||||
, ExpectedEndOfConditional = 224
|
||||
, ExpectedIncOrIgn = 225
|
||||
, ExpectedINCLUDEBracket = 226
|
||||
, UnexpectedEOE = 227
|
||||
, PEPropogated = 228
|
||||
, ExtraCloseSquare = 229
|
||||
, PERefInMarkupInIntSubset = 230
|
||||
, EntityPropogated = 231
|
||||
, ExpectedNumericalCharRef = 232
|
||||
, ExpectedOpenSquareBracket = 233
|
||||
, BadSequenceInCharData = 234
|
||||
, IllegalSequenceInComment = 235
|
||||
, UnterminatedCDATASection = 236
|
||||
, ExpectedNDATA = 237
|
||||
, NDATANotValidForPE = 238
|
||||
, HexRadixMustBeLowerCase = 239
|
||||
, DeclStringRep = 240
|
||||
, DeclStringsInWrongOrder = 241
|
||||
, NoExtRefsInAttValue = 242
|
||||
, XMLDeclMustBeLowerCase = 243
|
||||
, ExpectedEntityValue = 244
|
||||
, BadDigitForRadix = 245
|
||||
, EndedWithTagsOnStack = 246
|
||||
, NestedCDATA = 247
|
||||
, UnknownPrefix = 248
|
||||
, PartialTagMarkupError = 249
|
||||
, EmptyMainEntity = 250
|
||||
, CDATAOutsideOfContent = 251
|
||||
, Unexpected2ndSurrogateChar = 252
|
||||
, NoPIStartsWithXML = 253
|
||||
, XMLDeclMustBeFirst = 254
|
||||
, XMLVersionRequired = 255
|
||||
, StandaloneNotLegal = 256
|
||||
, EncodingRequired = 257
|
||||
, ColonNotLegalWithNS = 258
|
||||
, XMLException_Fatal = 259
|
||||
, BadSchemaLocation = 260
|
||||
, SchemaScanFatalError = 261
|
||||
, IllegalRefInStandalone = 262
|
||||
, PEBetweenDecl = 263
|
||||
, NoEmptyStrNamespace = 264
|
||||
, NoUseOfxmlnsAsPrefix = 265
|
||||
, NoUseOfxmlnsURI = 266
|
||||
, PrefixXMLNotMatchXMLURI = 267
|
||||
, XMLURINotMatchXMLPrefix = 268
|
||||
, NoXMLNSAsElementPrefix = 269
|
||||
, CT_SimpleTypeChildRequired = 270
|
||||
, InvalidRootElemInDOCTYPE = 271
|
||||
, InvalidElementName = 272
|
||||
, InvalidAttrName = 273
|
||||
, InvalidEntityRefName = 274
|
||||
, DuplicateDocTypeDecl = 275
|
||||
, XIncludeOrphanFallback = 276
|
||||
, XIncludeNoHref = 277
|
||||
, XIncludeXPointerNotSupported = 278
|
||||
, XIncludeInvalidParseVal = 279
|
||||
, XIncludeMultipleFallbackElems = 280
|
||||
, XIncludeIncludeFailedNoFallback = 281
|
||||
, XIncludeCircularInclusionLoop = 282
|
||||
, XIncludeCircularInclusionDocIncludesSelf = 283
|
||||
, XIncludeDisallowedChild = 284
|
||||
, XIncludeConflictingNotation = 285
|
||||
, XIncludeConflictingEntity = 286
|
||||
, F_HighBounds = 287
|
||||
};
|
||||
|
||||
static bool isFatal(const XMLErrs::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));
|
||||
}
|
||||
|
||||
static bool isWarning(const XMLErrs::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));
|
||||
}
|
||||
|
||||
static bool isError(const XMLErrs::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));
|
||||
}
|
||||
|
||||
static XMLErrorReporter::ErrTypes errorType(const XMLErrs::Codes toCheck)
|
||||
{
|
||||
if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Warning;
|
||||
else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Fatal;
|
||||
else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Error;
|
||||
return XMLErrorReporter::ErrTypes_Unknown;
|
||||
}
|
||||
static DOMError::ErrorSeverity DOMErrorType(const XMLErrs::Codes toCheck)
|
||||
{
|
||||
if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))
|
||||
return DOMError::DOM_SEVERITY_WARNING;
|
||||
else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))
|
||||
return DOMError::DOM_SEVERITY_FATAL_ERROR;
|
||||
else return DOMError::DOM_SEVERITY_ERROR;
|
||||
}
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLErrs();
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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: XMLErrorReporter.hpp 672273 2008-06-27 13:57:00Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLERRORREPORTER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLERRORREPORTER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
/**
|
||||
* This abstract class defines a callback mechanism for the scanner. By
|
||||
* creating a class that implements this interface and plugging an instance
|
||||
* of that class into the scanner, the scanner will call back on the object's
|
||||
* virtual methods to report error events. This class is also used with the
|
||||
* validator, to allow it to report errors.
|
||||
*
|
||||
* This class is primarily for use by those writing their own parser classes.
|
||||
* If you use the standard parser classes, DOMParser and SAXParser, you won't
|
||||
* use this API. You will instead use a similar mechanism defined by the SAX
|
||||
* API, called ErrorHandler.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLErrorReporter
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// The types of errors we can issue
|
||||
// -----------------------------------------------------------------------
|
||||
enum ErrTypes
|
||||
{
|
||||
ErrType_Warning
|
||||
, ErrType_Error
|
||||
, ErrType_Fatal
|
||||
|
||||
, ErrTypes_Unknown
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, only the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*/
|
||||
virtual ~XMLErrorReporter()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The error handler interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Error Handler interface */
|
||||
//@{
|
||||
|
||||
/** Called to report errors from the scanner or validator
|
||||
*
|
||||
* This method is called back on by the scanner or validator (or any other
|
||||
* internal parser component which might need to report an error in the
|
||||
* future.) It contains all the information that the client code might
|
||||
* need to report or log the error.
|
||||
*
|
||||
* @param errCode The error code of the error being reported. What
|
||||
* this means is dependent on the domain it is from.
|
||||
*
|
||||
* @param errDomain The domain from which the error occured. The domain
|
||||
* is a means of providing a hierarchical layering to
|
||||
* the error system, so that a single set of error id
|
||||
* numbers don't have to be split up.
|
||||
*
|
||||
* @param type The error type, which is defined mostly by XML which
|
||||
* categorizes errors into warning, errors and validity
|
||||
* constraints.
|
||||
*
|
||||
* @param errorText The actual text of the error. This is translatable,
|
||||
* so can possibly be in the local language if a
|
||||
* translation has been provided.
|
||||
*
|
||||
* @param systemId The system id of the entity where the error occured,
|
||||
* fully qualified.
|
||||
*
|
||||
* @param publicId The optional public id of the entity were the error
|
||||
* occured. It can be an empty string if non was provided.
|
||||
*
|
||||
* @param lineNum The line number within the source XML of the error.
|
||||
*
|
||||
* @param colNum The column number within the source XML of the error.
|
||||
* Because of the parsing style, this is usually just
|
||||
* after the actual offending text.
|
||||
*/
|
||||
virtual void error
|
||||
(
|
||||
const unsigned int errCode
|
||||
, const XMLCh* const errDomain
|
||||
, const ErrTypes type
|
||||
, const XMLCh* const errorText
|
||||
, const XMLCh* const systemId
|
||||
, const XMLCh* const publicId
|
||||
, const XMLFileLoc lineNum
|
||||
, const XMLFileLoc colNum
|
||||
) = 0;
|
||||
|
||||
/** Called before a new parse event to allow the handler to reset
|
||||
*
|
||||
* This method is called by the scanner before a new parse event is
|
||||
* about to start. It gives the error handler a chance to reset its
|
||||
* internal state.
|
||||
*/
|
||||
virtual void resetErrors() = 0;
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
XMLErrorReporter()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and destructor
|
||||
// -----------------------------------------------------------------------
|
||||
XMLErrorReporter(const XMLErrorReporter&);
|
||||
XMLErrorReporter& operator=(const XMLErrorReporter&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,705 @@
|
||||
/*
|
||||
* 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: XMLFormatter.cpp 901107 2010-01-20 08:45:02Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/TransService.hpp>
|
||||
#include <xercesc/util/TranscodingException.hpp>
|
||||
#include <xercesc/util/XMLExceptMsgs.hpp>
|
||||
#include <xercesc/framework/XMLFormatter.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#include <xercesc/util/XMLChar.hpp>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// gXXXRef
|
||||
// These are hard coded versions of the char refs we put out for the
|
||||
// standard char refs.
|
||||
//
|
||||
// gEscapeChars
|
||||
// For each style of escape, we have a list of the chars that must
|
||||
// be escaped for that style. The first null hit in each list indicates
|
||||
// no more valid entries in that list. The first entry is a dummy for
|
||||
// the NoEscapes style.
|
||||
// ---------------------------------------------------------------------------
|
||||
static const XMLCh gAmpRef[] =
|
||||
{
|
||||
chAmpersand, chLatin_a, chLatin_m, chLatin_p, chSemiColon, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gAposRef[] =
|
||||
{
|
||||
chAmpersand, chLatin_a, chLatin_p, chLatin_o, chLatin_s, chSemiColon, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gGTRef[] =
|
||||
{
|
||||
chAmpersand, chLatin_g, chLatin_t, chSemiColon, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gLTRef[] =
|
||||
{
|
||||
chAmpersand, chLatin_l, chLatin_t, chSemiColon, chNull
|
||||
};
|
||||
|
||||
static const XMLCh gQuoteRef[] =
|
||||
{
|
||||
chAmpersand, chLatin_q, chLatin_u, chLatin_o, chLatin_t, chSemiColon, chNull
|
||||
};
|
||||
|
||||
static const unsigned int kEscapeCount = 7;
|
||||
static const XMLCh gEscapeChars[XMLFormatter::EscapeFlags_Count][kEscapeCount] =
|
||||
{
|
||||
{ chNull , chNull , chNull , chNull , chNull , chNull , chNull }
|
||||
, { chAmpersand , chCloseAngle , chDoubleQuote , chOpenAngle , chSingleQuote , chNull , chNull }
|
||||
, { chAmpersand , chOpenAngle , chDoubleQuote , chLF , chCR , chHTab , chNull }
|
||||
, { chAmpersand , chOpenAngle , chCloseAngle , chNull , chNull , chNull , chNull }
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool XMLFormatter::inEscapeList(const XMLFormatter::EscapeFlags escStyle
|
||||
, const XMLCh toCheck)
|
||||
{
|
||||
const XMLCh* escList = gEscapeChars[escStyle];
|
||||
while (*escList)
|
||||
{
|
||||
if (*escList++ == toCheck)
|
||||
return true;
|
||||
}
|
||||
|
||||
/***
|
||||
* XML1.1
|
||||
*
|
||||
* Finally, there is considerable demand to define a standard representation of
|
||||
* arbitrary Unicode characters in XML documents. Therefore, XML 1.1 allows the
|
||||
* use of character references to the control characters #x1 through #x1F,
|
||||
* most of which are forbidden in XML 1.0. For reasons of robustness, however,
|
||||
* these characters still cannot be used directly in documents.
|
||||
* In order to improve the robustness of character encoding detection, the
|
||||
* additional control characters #x7F through #x9F, which were freely allowed in
|
||||
* XML 1.0 documents, now must also appear only as character references.
|
||||
* (Whitespace characters are of course exempt.) The minor sacrifice of backward
|
||||
* compatibility is considered not significant.
|
||||
* Due to potential problems with APIs, #x0 is still forbidden both directly and
|
||||
* as a character reference.
|
||||
*
|
||||
***/
|
||||
if (fIsXML11)
|
||||
{
|
||||
// for XML11
|
||||
if ( XMLChar1_1::isControlChar(toCheck, 0) &&
|
||||
!XMLChar1_1::isWhitespace(toCheck, 0) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLFormatter::XMLFormatter( const char* const outEncoding
|
||||
, const char* const docVersion
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags
|
||||
, const UnRepFlags unrepFlags
|
||||
, MemoryManager* const manager)
|
||||
: fEscapeFlags(escapeFlags)
|
||||
, fOutEncoding(0)
|
||||
, fTarget(target)
|
||||
, fUnRepFlags(unrepFlags)
|
||||
, fXCoder(0)
|
||||
, fAposRef(0)
|
||||
, fAposLen(0)
|
||||
, fAmpRef(0)
|
||||
, fAmpLen(0)
|
||||
, fGTRef(0)
|
||||
, fGTLen(0)
|
||||
, fLTRef(0)
|
||||
, fLTLen(0)
|
||||
, fQuoteRef(0)
|
||||
, fQuoteLen(0)
|
||||
, fIsXML11(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
// Transcode the encoding string
|
||||
fOutEncoding = XMLString::transcode(outEncoding, fMemoryManager);
|
||||
|
||||
// Try to create a transcoder for this encoding
|
||||
XMLTransService::Codes resCode;
|
||||
fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor
|
||||
(
|
||||
fOutEncoding
|
||||
, resCode
|
||||
, kTmpBufSize
|
||||
, fMemoryManager
|
||||
);
|
||||
|
||||
if (!fXCoder)
|
||||
{
|
||||
fMemoryManager->deallocate(fOutEncoding); //delete [] fOutEncoding;
|
||||
ThrowXMLwithMemMgr1
|
||||
(
|
||||
TranscodingException
|
||||
, XMLExcepts::Trans_CantCreateCvtrFor
|
||||
, outEncoding
|
||||
, fMemoryManager
|
||||
);
|
||||
}
|
||||
|
||||
XMLCh* const tmpDocVer = XMLString::transcode(docVersion, fMemoryManager);
|
||||
ArrayJanitor<XMLCh> jname(tmpDocVer, fMemoryManager);
|
||||
fIsXML11 = XMLString::equals(tmpDocVer, XMLUni::fgVersion1_1);
|
||||
}
|
||||
|
||||
|
||||
XMLFormatter::XMLFormatter( const XMLCh* const outEncoding
|
||||
, const XMLCh* const docVersion
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags
|
||||
, const UnRepFlags unrepFlags
|
||||
, MemoryManager* const manager)
|
||||
: fEscapeFlags(escapeFlags)
|
||||
, fOutEncoding(0)
|
||||
, fTarget(target)
|
||||
, fUnRepFlags(unrepFlags)
|
||||
, fXCoder(0)
|
||||
, fAposRef(0)
|
||||
, fAposLen(0)
|
||||
, fAmpRef(0)
|
||||
, fAmpLen(0)
|
||||
, fGTRef(0)
|
||||
, fGTLen(0)
|
||||
, fLTRef(0)
|
||||
, fLTLen(0)
|
||||
, fQuoteRef(0)
|
||||
, fQuoteLen(0)
|
||||
, fIsXML11(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
// Try to create a transcoder for this encoding
|
||||
XMLTransService::Codes resCode;
|
||||
fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor
|
||||
(
|
||||
outEncoding
|
||||
, resCode
|
||||
, kTmpBufSize
|
||||
, fMemoryManager
|
||||
);
|
||||
|
||||
if (!fXCoder)
|
||||
{
|
||||
ThrowXMLwithMemMgr1
|
||||
(
|
||||
TranscodingException
|
||||
, XMLExcepts::Trans_CantCreateCvtrFor
|
||||
, outEncoding
|
||||
, fMemoryManager
|
||||
);
|
||||
}
|
||||
|
||||
// Copy the encoding string
|
||||
fOutEncoding = XMLString::replicate(outEncoding, fMemoryManager);
|
||||
|
||||
|
||||
fIsXML11 = XMLString::equals(docVersion, XMLUni::fgVersion1_1);
|
||||
}
|
||||
|
||||
XMLFormatter::XMLFormatter( const char* const outEncoding
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags
|
||||
, const UnRepFlags unrepFlags
|
||||
, MemoryManager* const manager)
|
||||
: fEscapeFlags(escapeFlags)
|
||||
, fOutEncoding(0)
|
||||
, fTarget(target)
|
||||
, fUnRepFlags(unrepFlags)
|
||||
, fXCoder(0)
|
||||
, fAposRef(0)
|
||||
, fAposLen(0)
|
||||
, fAmpRef(0)
|
||||
, fAmpLen(0)
|
||||
, fGTRef(0)
|
||||
, fGTLen(0)
|
||||
, fLTRef(0)
|
||||
, fLTLen(0)
|
||||
, fQuoteRef(0)
|
||||
, fQuoteLen(0)
|
||||
, fIsXML11(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
// this constructor uses "1.0" for the docVersion
|
||||
|
||||
// Transcode the encoding string
|
||||
fOutEncoding = XMLString::transcode(outEncoding, fMemoryManager);
|
||||
|
||||
// Try to create a transcoder for this encoding
|
||||
XMLTransService::Codes resCode;
|
||||
fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor
|
||||
(
|
||||
fOutEncoding
|
||||
, resCode
|
||||
, kTmpBufSize
|
||||
, fMemoryManager
|
||||
);
|
||||
|
||||
if (!fXCoder)
|
||||
{
|
||||
fMemoryManager->deallocate(fOutEncoding); //delete [] fOutEncoding;
|
||||
ThrowXMLwithMemMgr1
|
||||
(
|
||||
TranscodingException
|
||||
, XMLExcepts::Trans_CantCreateCvtrFor
|
||||
, outEncoding
|
||||
, fMemoryManager
|
||||
);
|
||||
}
|
||||
|
||||
//XMLCh* const tmpDocVer = XMLString::transcode("1.0", fMemoryManager);
|
||||
//ArrayJanitor<XMLCh> jname(tmpDocVer, fMemoryManager);
|
||||
//fIsXML11 = XMLString::equals(tmpDocVer, XMLUni::fgVersion1_1);
|
||||
fIsXML11 = false; // docVersion 1.0 is not 1.1!
|
||||
}
|
||||
|
||||
|
||||
XMLFormatter::XMLFormatter( const XMLCh* const outEncoding
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags
|
||||
, const UnRepFlags unrepFlags
|
||||
, MemoryManager* const manager)
|
||||
: fEscapeFlags(escapeFlags)
|
||||
, fOutEncoding(0)
|
||||
, fTarget(target)
|
||||
, fUnRepFlags(unrepFlags)
|
||||
, fXCoder(0)
|
||||
, fAposRef(0)
|
||||
, fAposLen(0)
|
||||
, fAmpRef(0)
|
||||
, fAmpLen(0)
|
||||
, fGTRef(0)
|
||||
, fGTLen(0)
|
||||
, fLTRef(0)
|
||||
, fLTLen(0)
|
||||
, fQuoteRef(0)
|
||||
, fQuoteLen(0)
|
||||
, fIsXML11(false)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
// this constructor uses XMLUni::fgVersion1_0 for the docVersion
|
||||
|
||||
// Try to create a transcoder for this encoding
|
||||
XMLTransService::Codes resCode;
|
||||
fXCoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor
|
||||
(
|
||||
outEncoding
|
||||
, resCode
|
||||
, kTmpBufSize
|
||||
, fMemoryManager
|
||||
);
|
||||
|
||||
if (!fXCoder)
|
||||
{
|
||||
ThrowXMLwithMemMgr1
|
||||
(
|
||||
TranscodingException
|
||||
, XMLExcepts::Trans_CantCreateCvtrFor
|
||||
, outEncoding
|
||||
, fMemoryManager
|
||||
);
|
||||
}
|
||||
|
||||
// Copy the encoding string
|
||||
fOutEncoding = XMLString::replicate(outEncoding, fMemoryManager);
|
||||
|
||||
//fIsXML11 = XMLString::equals(docVersion, XMLUni::fgVersion1_1);
|
||||
fIsXML11 = false; // docVersion 1.0 is not 1.1!
|
||||
}
|
||||
|
||||
XMLFormatter::~XMLFormatter()
|
||||
{
|
||||
fMemoryManager->deallocate(fAposRef); //delete [] fAposRef;
|
||||
fMemoryManager->deallocate(fAmpRef); //delete [] fAmpRef;
|
||||
fMemoryManager->deallocate(fGTRef); //delete [] fGTRef;
|
||||
fMemoryManager->deallocate(fLTRef); //delete [] fLTRef;
|
||||
fMemoryManager->deallocate(fQuoteRef); //delete [] fQuoteRef;
|
||||
fMemoryManager->deallocate(fOutEncoding); //delete [] fOutEncoding;
|
||||
delete fXCoder;
|
||||
|
||||
// We DO NOT own the target object!
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Formatting methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void
|
||||
XMLFormatter::formatBuf(const XMLCh* const toFormat
|
||||
, const XMLSize_t count
|
||||
, const EscapeFlags escapeFlags
|
||||
, const UnRepFlags unrepFlags)
|
||||
{
|
||||
//
|
||||
// Figure out the actual escape flag value. If the parameter is not
|
||||
// the default, then take it. Else take the current default.
|
||||
//
|
||||
const EscapeFlags actualEsc = (escapeFlags == DefaultEscape)
|
||||
? fEscapeFlags : escapeFlags;
|
||||
|
||||
// And do the same for the unrep flags
|
||||
const UnRepFlags actualUnRep = (unrepFlags == DefaultUnRep)
|
||||
? fUnRepFlags : unrepFlags;
|
||||
|
||||
//
|
||||
// If the actual unrep action is that they want to provide char refs
|
||||
// for unrepresentable chars, then this one is a much more difficult
|
||||
// one to do cleanly, and we handle it separately.
|
||||
//
|
||||
if (actualUnRep == UnRep_CharRef)
|
||||
{
|
||||
specialFormat(toFormat, count, actualEsc);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// If we don't have any escape flags set, then we can do the most
|
||||
// efficient loop, else we have to do it the hard way.
|
||||
//
|
||||
const XMLCh* srcPtr = toFormat;
|
||||
const XMLCh* endPtr = toFormat + count;
|
||||
if (actualEsc == NoEscapes)
|
||||
{
|
||||
//
|
||||
// Just do a whole buffer at a time into the temp buffer, cap
|
||||
// it off, and send it to the target.
|
||||
//
|
||||
if (srcPtr < endPtr)
|
||||
srcPtr += handleUnEscapedChars(srcPtr, endPtr - srcPtr, actualUnRep);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Escape chars that require it according tot he scale flags
|
||||
// we were given. For the others, try to accumulate them and
|
||||
// format them in as big as bulk as we can.
|
||||
//
|
||||
while (srcPtr < endPtr)
|
||||
{
|
||||
//
|
||||
// Run a temp pointer up until we hit a character that we have
|
||||
// to escape. Then we can convert all the chars between our
|
||||
// current source pointer and here all at once.
|
||||
//
|
||||
const XMLCh* tmpPtr = srcPtr;
|
||||
while ((tmpPtr < endPtr) && !inEscapeList(actualEsc, *tmpPtr))
|
||||
tmpPtr++;
|
||||
|
||||
//
|
||||
// If we got any chars, then lets convert them and write them
|
||||
// out.
|
||||
//
|
||||
if (tmpPtr > srcPtr)
|
||||
srcPtr += handleUnEscapedChars(srcPtr, tmpPtr - srcPtr,
|
||||
actualUnRep);
|
||||
|
||||
else if (tmpPtr < endPtr)
|
||||
{
|
||||
//
|
||||
// Ok, so we've hit a char that must be escaped. So do
|
||||
// this one specially.
|
||||
//
|
||||
const XMLByte * theChars;
|
||||
switch (*srcPtr) {
|
||||
case chAmpersand :
|
||||
theChars = getCharRef(fAmpLen, fAmpRef, gAmpRef);
|
||||
fTarget->writeChars(theChars, fAmpLen, this);
|
||||
break;
|
||||
|
||||
case chSingleQuote :
|
||||
theChars = getCharRef(fAposLen, fAposRef, gAposRef);
|
||||
fTarget->writeChars(theChars, fAposLen, this);
|
||||
break;
|
||||
|
||||
case chDoubleQuote :
|
||||
theChars = getCharRef(fQuoteLen, fQuoteRef, gQuoteRef);
|
||||
fTarget->writeChars(theChars, fQuoteLen, this);
|
||||
break;
|
||||
|
||||
case chCloseAngle :
|
||||
theChars = getCharRef(fGTLen, fGTRef, gGTRef);
|
||||
fTarget->writeChars(theChars, fGTLen, this);
|
||||
break;
|
||||
|
||||
case chOpenAngle :
|
||||
theChars = getCharRef(fLTLen, fLTRef, gLTRef);
|
||||
fTarget->writeChars(theChars, fLTLen, this);
|
||||
break;
|
||||
|
||||
default:
|
||||
// control characters
|
||||
writeCharRef(*srcPtr);
|
||||
break;
|
||||
}
|
||||
srcPtr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XMLSize_t
|
||||
XMLFormatter::handleUnEscapedChars(const XMLCh * srcPtr,
|
||||
const XMLSize_t oCount,
|
||||
const UnRepFlags actualUnRep)
|
||||
{
|
||||
//
|
||||
// Use that to figure out what I should pass to the transcoder. If we
|
||||
// are doing character references or failing for unrepresentable chars,
|
||||
// then we just throw, since we should never get a call for something
|
||||
// we cannot represent. Else, we tell it to just use the replacement
|
||||
// char.
|
||||
//
|
||||
const XMLTranscoder::UnRepOpts unRepOpts = (actualUnRep == UnRep_Replace)
|
||||
? XMLTranscoder::UnRep_RepChar
|
||||
: XMLTranscoder::UnRep_Throw;
|
||||
|
||||
XMLSize_t charsEaten;
|
||||
XMLSize_t count = oCount;
|
||||
|
||||
while (count) {
|
||||
const XMLSize_t srcChars = (count > XMLSize_t (kTmpBufSize))
|
||||
? XMLSize_t (kTmpBufSize) : count;
|
||||
|
||||
const XMLSize_t outBytes
|
||||
= fXCoder->transcodeTo(srcPtr, srcChars,
|
||||
fTmpBuf, kTmpBufSize,
|
||||
charsEaten, unRepOpts);
|
||||
|
||||
if (outBytes) {
|
||||
fTmpBuf[outBytes] = 0; fTmpBuf[outBytes + 1] = 0;
|
||||
fTmpBuf[outBytes + 2] = 0; fTmpBuf[outBytes + 3] = 0;
|
||||
fTarget->writeChars(fTmpBuf, outBytes, this);
|
||||
}
|
||||
|
||||
srcPtr += charsEaten;
|
||||
count -= charsEaten;
|
||||
}
|
||||
|
||||
return oCount; // This should be an assertion that count == 0.
|
||||
}
|
||||
|
||||
|
||||
XMLFormatter& XMLFormatter::operator<<(const XMLCh* const toFormat)
|
||||
{
|
||||
const XMLSize_t len = XMLString::stringLen(toFormat);
|
||||
formatBuf(toFormat, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
XMLFormatter& XMLFormatter::operator<<(const XMLCh toFormat)
|
||||
{
|
||||
// Make a temp string format that
|
||||
XMLCh szTmp[2];
|
||||
szTmp[0] = toFormat;
|
||||
szTmp[1] = 0;
|
||||
|
||||
formatBuf(szTmp, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* the parameter, count, is needed since stringLen()
|
||||
* does not work on a BOM like "0xFE0xFF0x000x00" or
|
||||
* "0x000x000xFF0xFE"
|
||||
**/
|
||||
void XMLFormatter::writeBOM(const XMLByte* const toFormat
|
||||
, const XMLSize_t count)
|
||||
{
|
||||
fTarget->writeChars(toFormat, count, this);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Private helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLFormatter::writeCharRef(const XMLCh &toWrite)
|
||||
{
|
||||
XMLCh tmpBuf[32];
|
||||
tmpBuf[0] = chAmpersand;
|
||||
tmpBuf[1] = chPound;
|
||||
tmpBuf[2] = chLatin_x;
|
||||
|
||||
// Build a char ref for the current char
|
||||
XMLString::binToText(toWrite, &tmpBuf[3], 8, 16, fMemoryManager);
|
||||
const XMLSize_t bufLen = XMLString::stringLen(tmpBuf);
|
||||
tmpBuf[bufLen] = chSemiColon;
|
||||
tmpBuf[bufLen+1] = chNull;
|
||||
|
||||
// write it out
|
||||
formatBuf(tmpBuf
|
||||
, bufLen + 1
|
||||
, XMLFormatter::NoEscapes
|
||||
, XMLFormatter::UnRep_Fail);
|
||||
|
||||
}
|
||||
|
||||
void XMLFormatter::writeCharRef(XMLSize_t toWrite)
|
||||
{
|
||||
XMLCh tmpBuf[64];
|
||||
tmpBuf[0] = chAmpersand;
|
||||
tmpBuf[1] = chPound;
|
||||
tmpBuf[2] = chLatin_x;
|
||||
|
||||
// Build a char ref for the current char
|
||||
XMLString::sizeToText(toWrite, &tmpBuf[3], 32, 16, fMemoryManager);
|
||||
const XMLSize_t bufLen = XMLString::stringLen(tmpBuf);
|
||||
tmpBuf[bufLen] = chSemiColon;
|
||||
tmpBuf[bufLen+1] = chNull;
|
||||
|
||||
// write it out
|
||||
formatBuf(tmpBuf
|
||||
, bufLen + 1
|
||||
, XMLFormatter::NoEscapes
|
||||
, XMLFormatter::UnRep_Fail);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const XMLByte* XMLFormatter::getCharRef(XMLSize_t &count,
|
||||
XMLByte* &ref,
|
||||
const XMLCh * stdRef)
|
||||
{
|
||||
if (!ref) {
|
||||
|
||||
XMLSize_t charsEaten;
|
||||
const XMLSize_t outBytes =
|
||||
fXCoder->transcodeTo(stdRef, XMLString::stringLen(stdRef),
|
||||
fTmpBuf, kTmpBufSize, charsEaten,
|
||||
XMLTranscoder::UnRep_Throw);
|
||||
|
||||
fTmpBuf[outBytes] = 0;
|
||||
fTmpBuf[outBytes + 1] = 0;
|
||||
fTmpBuf[outBytes + 2] = 0;
|
||||
fTmpBuf[outBytes + 3] = 0;
|
||||
|
||||
ref = (XMLByte*) fMemoryManager->allocate
|
||||
(
|
||||
(outBytes + 4) * sizeof(XMLByte)
|
||||
);//new XMLByte[outBytes + 4];
|
||||
memcpy(ref, fTmpBuf, outBytes + 4);
|
||||
count = outBytes;
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
void XMLFormatter::specialFormat(const XMLCh* const toFormat
|
||||
, const XMLSize_t count
|
||||
, const EscapeFlags escapeFlags)
|
||||
{
|
||||
//
|
||||
// We have to check each character and see if it could be represented.
|
||||
// As long as it can, we just keep up with where we started and how
|
||||
// many chars we've checked. When we hit an unrepresentable one, we
|
||||
// stop, transcode everything we've collected, then start handling
|
||||
// the unrepresentables via char refs. We repeat this until we get all
|
||||
// the chars done.
|
||||
//
|
||||
const XMLCh* srcPtr = toFormat;
|
||||
const XMLCh* endPtr = toFormat + count;
|
||||
|
||||
while (srcPtr < endPtr)
|
||||
{
|
||||
const XMLCh* tmpPtr = srcPtr;
|
||||
while (tmpPtr < endPtr)
|
||||
{
|
||||
if (fXCoder->canTranscodeTo(*tmpPtr))
|
||||
tmpPtr++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmpPtr > srcPtr)
|
||||
{
|
||||
// We got at least some chars that can be done normally
|
||||
formatBuf
|
||||
(
|
||||
srcPtr
|
||||
, tmpPtr - srcPtr
|
||||
, escapeFlags
|
||||
, XMLFormatter::UnRep_Fail
|
||||
);
|
||||
|
||||
// Update the source pointer to our new spot
|
||||
srcPtr = tmpPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// We hit something unrepresentable. So continue forward doing
|
||||
// char refs until we hit something representable again or the
|
||||
// end of input.
|
||||
//
|
||||
while (srcPtr < endPtr)
|
||||
{
|
||||
if ((*srcPtr & 0xFC00) == 0xD800) {
|
||||
// we have encountered a surrogate, need to recombine before printing out
|
||||
// use writeCharRef that takes XMLSize_t to get values larger than
|
||||
// hex 0xFFFF printed.
|
||||
tmpPtr = srcPtr;
|
||||
tmpPtr++; // point at low surrogate
|
||||
writeCharRef((XMLSize_t) (0x10000+((*srcPtr-0xD800)<<10)+*tmpPtr-0xDC00));
|
||||
srcPtr++; // advance to low surrogate (will advance again below)
|
||||
}
|
||||
else {
|
||||
writeCharRef(*srcPtr);
|
||||
}
|
||||
|
||||
// Move up the source pointer and break out if needed
|
||||
srcPtr++;
|
||||
if (fXCoder->canTranscodeTo(*srcPtr))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,538 @@
|
||||
/*
|
||||
* 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: XMLFormatter.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLFORMATTER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLFORMATTER_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLFormatTarget;
|
||||
class XMLTranscoder;
|
||||
|
||||
/**
|
||||
* This class provides the basic formatting capabilities that are required
|
||||
* to turn the Unicode based XML data from the parsers into a form that can
|
||||
* be used on non-Unicode based systems, that is, into local or generic text
|
||||
* encodings.
|
||||
*
|
||||
* A number of flags are provided to control whether various optional
|
||||
* formatting operations are performed.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLFormatter : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Class types
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Public Constants */
|
||||
//@{
|
||||
/**
|
||||
* EscapeFlags - Different styles of escape flags to control various formatting.
|
||||
*
|
||||
* <p><code>NoEscapes:</code>
|
||||
* No character needs to be escaped. Just write them out as is.</p>
|
||||
* <p><code>StdEscapes:</code>
|
||||
* The following characters need to be escaped:</p>
|
||||
* <table border='1'>
|
||||
* <tr>
|
||||
* <td>character</td>
|
||||
* <td>should be escaped and written as</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&amp;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>></td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&gt;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>"</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&quot;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'><</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&lt;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>'</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&apos;</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <p><code>AttrEscapes:</code>
|
||||
* The following characters need to be escaped:</p>
|
||||
* <table border='1'>
|
||||
* <tr>
|
||||
* <td>character</td>
|
||||
* <td>should be escaped and written as</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&amp;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>></td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&gt;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>"</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&quot;</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <p><code>CharEscapes:</code>
|
||||
* The following characters need to be escaped:</p>
|
||||
* <table border='1'>
|
||||
* <tr>
|
||||
* <td>character</td>
|
||||
* <td>should be escaped and written as</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&amp;</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>></td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>&gt;</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <p><code>EscapeFlags_Count:</code>
|
||||
* Special value, do not use directly.</p>
|
||||
* <p><code>DefaultEscape:</code>
|
||||
* Special value, do not use directly.</p>
|
||||
*
|
||||
*/
|
||||
enum EscapeFlags
|
||||
{
|
||||
NoEscapes
|
||||
, StdEscapes
|
||||
, AttrEscapes
|
||||
, CharEscapes
|
||||
|
||||
// Special values, don't use directly
|
||||
, EscapeFlags_Count
|
||||
, DefaultEscape = 999
|
||||
};
|
||||
|
||||
/**
|
||||
* UnRepFlags
|
||||
*
|
||||
* The unrepresentable flags that indicate how to react when a
|
||||
* character cannot be represented in the target encoding.
|
||||
*
|
||||
* <p><code>UnRep_Fail:</code>
|
||||
* Fail the operation.</p>
|
||||
* <p><code>UnRep_CharRef:</code>
|
||||
* Display the unrepresented character as reference.</p>
|
||||
* <p><code>UnRep_Replace:</code>
|
||||
* Replace the unrepresented character with the replacement character.</p>
|
||||
* <p><code>DefaultUnRep:</code>
|
||||
* Special value, do not use directly.</p>
|
||||
*
|
||||
*/
|
||||
enum UnRepFlags
|
||||
{
|
||||
UnRep_Fail
|
||||
, UnRep_CharRef
|
||||
, UnRep_Replace
|
||||
|
||||
, DefaultUnRep = 999
|
||||
};
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructor and Destructor */
|
||||
//@{
|
||||
/**
|
||||
* @param outEncoding the encoding for the formatted content.
|
||||
* @param docVersion the document version.
|
||||
* @param target the formatTarget where the formatted content is written to.
|
||||
* @param escapeFlags the escape style for certain character.
|
||||
* @param unrepFlags the reaction to unrepresentable character.
|
||||
* @param manager Pointer to the memory manager to be used to
|
||||
* allocate objects.
|
||||
*/
|
||||
XMLFormatter
|
||||
(
|
||||
const XMLCh* const outEncoding
|
||||
, const XMLCh* const docVersion
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags = NoEscapes
|
||||
, const UnRepFlags unrepFlags = UnRep_Fail
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
XMLFormatter
|
||||
(
|
||||
const char* const outEncoding
|
||||
, const char* const docVersion
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags = NoEscapes
|
||||
, const UnRepFlags unrepFlags = UnRep_Fail
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
XMLFormatter
|
||||
(
|
||||
const XMLCh* const outEncoding
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags = NoEscapes
|
||||
, const UnRepFlags unrepFlags = UnRep_Fail
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
XMLFormatter
|
||||
(
|
||||
const char* const outEncoding
|
||||
, XMLFormatTarget* const target
|
||||
, const EscapeFlags escapeFlags = NoEscapes
|
||||
, const UnRepFlags unrepFlags = UnRep_Fail
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
~XMLFormatter();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Formatting methods
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Formatting methods */
|
||||
//@{
|
||||
/**
|
||||
* @param toFormat the string to be formatted
|
||||
* @param count length of the string
|
||||
* @param escapeFlags the escape style for formatting toFormat
|
||||
* @param unrepFlags the reaction for any unrepresentable character in toFormat
|
||||
*
|
||||
*/
|
||||
void formatBuf
|
||||
(
|
||||
const XMLCh* const toFormat
|
||||
, const XMLSize_t count
|
||||
, const EscapeFlags escapeFlags = DefaultEscape
|
||||
, const UnRepFlags unrepFlags = DefaultUnRep
|
||||
);
|
||||
|
||||
/**
|
||||
* @see formatBuf
|
||||
*/
|
||||
XMLFormatter& operator<<
|
||||
(
|
||||
const XMLCh* const toFormat
|
||||
);
|
||||
|
||||
XMLFormatter& operator<<
|
||||
(
|
||||
const XMLCh toFormat
|
||||
);
|
||||
|
||||
void writeBOM(const XMLByte* const toFormat
|
||||
, const XMLSize_t count);
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Getter methods */
|
||||
//@{
|
||||
/**
|
||||
* @return return the encoding set for the formatted content
|
||||
*/
|
||||
|
||||
const XMLCh* getEncodingName() const;
|
||||
|
||||
/**
|
||||
* @return return constant transcoder used internally for transcoding the formatter conent
|
||||
*/
|
||||
inline const XMLTranscoder* getTranscoder() const;
|
||||
|
||||
/**
|
||||
* @return return the transcoder used internally for transcoding the formatter content
|
||||
*/
|
||||
inline XMLTranscoder* getTranscoder();
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
/**
|
||||
* @param newFlags set the escape style for the follow-on formatted content
|
||||
*/
|
||||
void setEscapeFlags
|
||||
(
|
||||
const EscapeFlags newFlags
|
||||
);
|
||||
|
||||
/**
|
||||
* @param newFlags set the reaction for unrepresentable character
|
||||
*/
|
||||
void setUnRepFlags
|
||||
(
|
||||
const UnRepFlags newFlags
|
||||
);
|
||||
|
||||
/**
|
||||
* @param newFlags set the escape style for the follow-on formatted content
|
||||
* @see setEscapeFlags
|
||||
*/
|
||||
XMLFormatter& operator<<
|
||||
(
|
||||
const EscapeFlags newFlags
|
||||
);
|
||||
|
||||
/**
|
||||
* @param newFlags set the reaction for unrepresentable character
|
||||
* @see setUnRepFlags
|
||||
*/
|
||||
XMLFormatter& operator<<
|
||||
(
|
||||
const UnRepFlags newFlags
|
||||
);
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
/**
|
||||
* @return return the escape style for the formatted content
|
||||
*/
|
||||
EscapeFlags getEscapeFlags() const;
|
||||
|
||||
/**
|
||||
* @return return the reaction for unrepresentable character
|
||||
*/
|
||||
UnRepFlags getUnRepFlags() const;
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLFormatter();
|
||||
XMLFormatter(const XMLFormatter&);
|
||||
XMLFormatter& operator=(const XMLFormatter&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private class constants
|
||||
// -----------------------------------------------------------------------
|
||||
enum Constants
|
||||
{
|
||||
kTmpBufSize = 16 * 1024
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
const XMLByte* getCharRef(XMLSize_t &count,
|
||||
XMLByte* &ref,
|
||||
const XMLCh * stdRef);
|
||||
|
||||
void writeCharRef(const XMLCh &toWrite);
|
||||
void writeCharRef(XMLSize_t toWrite);
|
||||
|
||||
bool inEscapeList(const XMLFormatter::EscapeFlags escStyle
|
||||
, const XMLCh toCheck);
|
||||
|
||||
|
||||
XMLSize_t handleUnEscapedChars(const XMLCh * srcPtr,
|
||||
const XMLSize_t count,
|
||||
const UnRepFlags unrepFlags);
|
||||
|
||||
void specialFormat
|
||||
(
|
||||
const XMLCh* const toFormat
|
||||
, const XMLSize_t count
|
||||
, const EscapeFlags escapeFlags
|
||||
);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private, non-virtual methods
|
||||
//
|
||||
// fEscapeFlags
|
||||
// The escape flags we were told to use in formatting. These are
|
||||
// defaults set in the ctor, which can be overridden on a particular
|
||||
// call.
|
||||
//
|
||||
// fOutEncoding
|
||||
// This the name of the output encoding. Saved mainly for meaningful
|
||||
// error messages.
|
||||
//
|
||||
// fTarget
|
||||
// This is the target object for the formatting operation.
|
||||
//
|
||||
// fUnRepFlags
|
||||
// The unrepresentable flags that indicate how to react when a
|
||||
// character cannot be represented in the target encoding.
|
||||
//
|
||||
// fXCoder
|
||||
// This the transcoder that we will use. It is created using the
|
||||
// encoding name we were told to use.
|
||||
//
|
||||
// fTmpBuf
|
||||
// An output buffer that we use to transcode chars into before we
|
||||
// send them off to be output.
|
||||
//
|
||||
// fAposRef
|
||||
// fAmpRef
|
||||
// fGTRef
|
||||
// fLTRef
|
||||
// fQuoteRef
|
||||
// These are character refs for the standard char refs, in the
|
||||
// output encoding. They are faulted in as required, by transcoding
|
||||
// them from fixed Unicode versions.
|
||||
//
|
||||
// fIsXML11
|
||||
// for performance reason, we do not store the actual version string
|
||||
// and do the string comparison again and again.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
EscapeFlags fEscapeFlags;
|
||||
XMLCh* fOutEncoding;
|
||||
XMLFormatTarget* fTarget;
|
||||
UnRepFlags fUnRepFlags;
|
||||
XMLTranscoder* fXCoder;
|
||||
XMLByte fTmpBuf[kTmpBufSize + 4];
|
||||
XMLByte* fAposRef;
|
||||
XMLSize_t fAposLen;
|
||||
XMLByte* fAmpRef;
|
||||
XMLSize_t fAmpLen;
|
||||
XMLByte* fGTRef;
|
||||
XMLSize_t fGTLen;
|
||||
XMLByte* fLTRef;
|
||||
XMLSize_t fLTLen;
|
||||
XMLByte* fQuoteRef;
|
||||
XMLSize_t fQuoteLen;
|
||||
bool fIsXML11;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
class XMLPARSER_EXPORT XMLFormatTarget : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
virtual ~XMLFormatTarget() {}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual interface
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void writeChars
|
||||
(
|
||||
const XMLByte* const toWrite
|
||||
, const XMLSize_t count
|
||||
, XMLFormatter* const formatter
|
||||
) = 0;
|
||||
|
||||
virtual void flush() {};
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLFormatTarget() {};
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLFormatTarget(const XMLFormatTarget&);
|
||||
XMLFormatTarget& operator=(const XMLFormatTarget&);
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLCh* XMLFormatter::getEncodingName() const
|
||||
{
|
||||
return fOutEncoding;
|
||||
}
|
||||
|
||||
inline const XMLTranscoder* XMLFormatter::getTranscoder() const
|
||||
{
|
||||
return fXCoder;
|
||||
}
|
||||
|
||||
inline XMLTranscoder* XMLFormatter::getTranscoder()
|
||||
{
|
||||
return fXCoder;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLFormatter::setEscapeFlags(const EscapeFlags newFlags)
|
||||
{
|
||||
fEscapeFlags = newFlags;
|
||||
}
|
||||
|
||||
inline void XMLFormatter::setUnRepFlags(const UnRepFlags newFlags)
|
||||
{
|
||||
fUnRepFlags = newFlags;
|
||||
}
|
||||
|
||||
|
||||
inline XMLFormatter& XMLFormatter::operator<<(const EscapeFlags newFlags)
|
||||
{
|
||||
fEscapeFlags = newFlags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline XMLFormatter& XMLFormatter::operator<<(const UnRepFlags newFlags)
|
||||
{
|
||||
fUnRepFlags = newFlags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLFormatter: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLFormatter::EscapeFlags XMLFormatter::getEscapeFlags() const
|
||||
{
|
||||
return fEscapeFlags;
|
||||
}
|
||||
|
||||
inline XMLFormatter::UnRepFlags XMLFormatter::getUnRepFlags() const
|
||||
{
|
||||
return fUnRepFlags;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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: XMLGrammarDescription.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLGrammarDescription.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
XMLGrammarDescription::~XMLGrammarDescription()
|
||||
{
|
||||
}
|
||||
|
||||
XMLGrammarDescription::XMLGrammarDescription(MemoryManager* const memMgr)
|
||||
:fMemMgr(memMgr)
|
||||
{
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLGrammarDescription)
|
||||
|
||||
void XMLGrammarDescription::serialize(XSerializeEngine&)
|
||||
{
|
||||
//no data
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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: XMLGrammarDescription.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLGRAMMARDESCRIPTION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLGRAMMARDESCRIPTION_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/validators/common/Grammar.hpp>
|
||||
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLPARSER_EXPORT XMLGrammarDescription : public XSerializable, public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual destructor for derived classes */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* virtual destructor
|
||||
*
|
||||
*/
|
||||
virtual ~XMLGrammarDescription();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The Grammar Description Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* getGrammarType
|
||||
*
|
||||
*/
|
||||
virtual Grammar::GrammarType getGrammarType() const = 0;
|
||||
|
||||
/**
|
||||
* getGrammarKey
|
||||
*
|
||||
*/
|
||||
virtual const XMLCh* getGrammarKey() const = 0;
|
||||
//@}
|
||||
|
||||
inline MemoryManager* getMemoryManager() const;
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLGrammarDescription)
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
/** Hidden Constructors */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLGrammarDescription(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLGrammarDescription(const XMLGrammarDescription& );
|
||||
XMLGrammarDescription& operator=(const XMLGrammarDescription& );
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// fMemMgr: plugged-in (or defaulted-in) memory manager,
|
||||
// not owned
|
||||
// no reset after initialization
|
||||
// allow derivatives to access directly
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager* const fMemMgr;
|
||||
};
|
||||
|
||||
inline MemoryManager* XMLGrammarDescription::getMemoryManager() const
|
||||
{
|
||||
return fMemMgr;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* 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: XMLGrammarPool.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLGRAMMARPOOL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLGRAMMARPOOL_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/RefHashTableOf.hpp>
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class Grammar;
|
||||
class XMLGrammarDescription;
|
||||
class DTDGrammar;
|
||||
class SchemaGrammar;
|
||||
class XMLDTDDescription;
|
||||
class XMLSchemaDescription;
|
||||
class XMLStringPool;
|
||||
class BinInputStream;
|
||||
class BinOutputStream;
|
||||
|
||||
class XMLPARSER_EXPORT XMLGrammarPool : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual destructor for derived classes */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* virtual destructor
|
||||
*
|
||||
*/
|
||||
virtual ~XMLGrammarPool(){};
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The Grammar Pool Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* cacheGrammar
|
||||
*
|
||||
* Provide the grammar pool with an opportunity
|
||||
* to cache the given grammar. If the pool does not choose to do so,
|
||||
* it should return false; otherwise, it should return true, so that
|
||||
* the caller knows whether the grammar has been adopted.
|
||||
*
|
||||
* @param gramToCache the Grammar to be cached in the grammar pool
|
||||
* @return true if the grammar pool has elected to cache the grammar (in which case
|
||||
* it is assumed to have adopted it); false if it does not cache it
|
||||
*
|
||||
*/
|
||||
virtual bool cacheGrammar(Grammar* const gramToCache) = 0;
|
||||
|
||||
/**
|
||||
* retrieveGrammar
|
||||
*
|
||||
* @param gramDesc the Grammar Description used to search for grammar
|
||||
* cached in the grammar pool
|
||||
*
|
||||
*/
|
||||
virtual Grammar* retrieveGrammar(XMLGrammarDescription* const gramDesc) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* orphanGrammar
|
||||
*
|
||||
* grammar removed from the grammar pool and owned by the caller
|
||||
*
|
||||
* @param nameSpaceKey Key used to search for grammar in the grammar pool
|
||||
* @return the grammar that was removed from the pool (0 if none)
|
||||
*/
|
||||
virtual Grammar* orphanGrammar(const XMLCh* const nameSpaceKey) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Get an enumeration of the cached Grammars in the Grammar pool
|
||||
*
|
||||
* @return enumeration of the cached Grammars in Grammar pool
|
||||
*/
|
||||
virtual RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const = 0;
|
||||
|
||||
/**
|
||||
* clear
|
||||
*
|
||||
* all grammars are removed from the grammar pool and deleted.
|
||||
* @return true if the grammar pool was cleared. false if it did not.
|
||||
*/
|
||||
virtual bool clear() = 0;
|
||||
|
||||
/**
|
||||
* lockPool
|
||||
*
|
||||
* When this method is called by the application, the
|
||||
* grammar pool should stop adding new grammars to the cache.
|
||||
* This should result in the grammar pool being sharable
|
||||
* among parsers operating in different threads.
|
||||
*
|
||||
*/
|
||||
virtual void lockPool() = 0;
|
||||
|
||||
/**
|
||||
* unlockPool
|
||||
*
|
||||
* After this method has been called, the grammar pool implementation
|
||||
* should return to its default behaviour when cacheGrammars(...) is called.
|
||||
* One effect, depending on the underlying implementation, is that the grammar pool
|
||||
* may no longer be thread-safe (even on read operations).
|
||||
*
|
||||
* For PSVI support any previous XSModel that was produced will be deleted.
|
||||
*/
|
||||
virtual void unlockPool() = 0;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Factory interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* createDTDGrammar
|
||||
*
|
||||
*/
|
||||
virtual DTDGrammar* createDTDGrammar() = 0;
|
||||
|
||||
/**
|
||||
* createSchemaGrammar
|
||||
*
|
||||
*/
|
||||
virtual SchemaGrammar* createSchemaGrammar() = 0;
|
||||
|
||||
/**
|
||||
* createDTDDescription
|
||||
*
|
||||
*/
|
||||
virtual XMLDTDDescription* createDTDDescription(const XMLCh* const systemId) = 0;
|
||||
/**
|
||||
* createSchemaDescription
|
||||
*
|
||||
*/
|
||||
virtual XMLSchemaDescription* createSchemaDescription(const XMLCh* const targetNamespace) = 0;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name schema component model support */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/***
|
||||
* Return an XSModel derived from the components of all SchemaGrammars
|
||||
* in the grammar pool. If the pool is locked, this should
|
||||
* be a thread-safe operation.
|
||||
*
|
||||
* NOTE: The function should NEVER return NULL. If there are no grammars in
|
||||
* the pool it should return an XSModel containing the Schema for Schema.
|
||||
*
|
||||
* Calling getXSModel() on an unlocked grammar pool may result in the
|
||||
* creation of a new XSModel with the old XSModel being deleted.
|
||||
* The bool parameter will indicate if the XSModel was changed.
|
||||
*
|
||||
*/
|
||||
virtual XSModel *getXSModel(bool& XSModelWasChanged) = 0;
|
||||
|
||||
// @}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Getter */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* getMemoryManager
|
||||
*
|
||||
*/
|
||||
inline MemoryManager* getMemoryManager()
|
||||
{
|
||||
return fMemMgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an XMLStringPool for use by validation routines.
|
||||
* Implementations should not create a string pool on each call to this
|
||||
* method, but should maintain one string pool for all grammars
|
||||
* for which this pool is responsible.
|
||||
*/
|
||||
virtual XMLStringPool *getURIStringPool() = 0;
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** serialization and deserialization support */
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/***
|
||||
*
|
||||
* 1. Context: Serialize/Deserialize All Grammars In One Session
|
||||
*
|
||||
* Since it is common that a declaration in one grammar may reference
|
||||
* to definitions in other grammars, it is required to serialize those
|
||||
* related (or interdependent) grammars in to one persistent data store
|
||||
* in one serialization session (storing), and deserialize them from the
|
||||
* persistent data store in one deserialization session (loading) back
|
||||
* to the grammar pool.
|
||||
*
|
||||
* 2. Multiple serializations
|
||||
*
|
||||
* It is acceptable that client application requests more than one
|
||||
* grammar serialization on a particular grammar pool, to track the
|
||||
* different grammars cached, or for whatever reasons that client
|
||||
* application is interested in.
|
||||
*
|
||||
* 3. Multiple deserializations
|
||||
*
|
||||
* Request for grammar deserialization either after the grammar pool has
|
||||
* its own cached grammars, or request for more than one grammar
|
||||
* deserialization, may cause undesired and unpredictable consequence
|
||||
* and therefore client application shall be aware that individual
|
||||
* implementationis may NOT support this.
|
||||
*
|
||||
* However it is strongly recommended that the client application requests
|
||||
* no more than one grammar deserialization even a particular implementation
|
||||
* may allow multiple deserializations.
|
||||
*
|
||||
* 4. Locking
|
||||
*
|
||||
* Both serialization and deserialization requires to lock the grammar pool
|
||||
* before operation and unlock after operation. In the case the grammar pool
|
||||
* is locked by a third party, the request for serialization/deserialization
|
||||
* will NOT be entertained.
|
||||
*
|
||||
* 5. Versioning
|
||||
*
|
||||
* The Persistent data store has a version tag to be verified during
|
||||
* deserialization, thus a grammar pool may decide if it supports
|
||||
* a binary data created by a different release of Xerces.
|
||||
*
|
||||
* 6. Clean up
|
||||
*
|
||||
* The client application shall be aware that in the event of an exception
|
||||
* thrown due to a corrupted data store during deserialization, implementation
|
||||
* may not be able to clean up all resources allocated, and therefore it is
|
||||
* client application's responsibility to clean up those unreleased resources.
|
||||
*
|
||||
*
|
||||
*/
|
||||
virtual void serializeGrammars(BinOutputStream* const) = 0;
|
||||
virtual void deserializeGrammars(BinInputStream* const) = 0;
|
||||
|
||||
/*
|
||||
* Set/get a flag to not create XSAnnotations when deserializing the grammar.
|
||||
* Defaults to false (create XSAnnotations when deserializing the grammar).
|
||||
*/
|
||||
inline void setIgnoreSerializedAnnotations(const bool flag)
|
||||
{
|
||||
fIgnoreSerializedAnnotations = flag;
|
||||
};
|
||||
inline bool getIgnoreSerializedAnnotations() const
|
||||
{
|
||||
return fIgnoreSerializedAnnotations;
|
||||
};
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
/** Hidden Constructors */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLGrammarPool(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager)
|
||||
:fMemMgr(memMgr)
|
||||
,fIgnoreSerializedAnnotations(false)
|
||||
{
|
||||
};
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLGrammarPool(const XMLGrammarPool& );
|
||||
XMLGrammarPool& operator=(const XMLGrammarPool& );
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// fMemMgr: plugged-in (or defaulted-in) memory manager
|
||||
// not owned
|
||||
// no reset after initialization
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
MemoryManager* const fMemMgr;
|
||||
bool fIgnoreSerializedAnnotations;
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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: XMLGrammarPoolImpl.cpp 676823 2008-07-15 07:57:44Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLGrammarPoolImpl.hpp>
|
||||
#include <xercesc/internal/XSerializeEngine.hpp>
|
||||
#include <xercesc/internal/XTemplateSerializer.hpp>
|
||||
#include <xercesc/validators/DTD/DTDGrammar.hpp>
|
||||
#include <xercesc/validators/DTD/XMLDTDDescriptionImpl.hpp>
|
||||
#include <xercesc/validators/schema/SchemaGrammar.hpp>
|
||||
#include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
#include <xercesc/util/SynchronizedStringPool.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// private function used to update fXSModel
|
||||
void XMLGrammarPoolImpl::createXSModel()
|
||||
{
|
||||
delete fXSModel;
|
||||
fXSModel = 0;
|
||||
fXSModel = new (getMemoryManager()) XSModel(this, getMemoryManager());
|
||||
fXSModelIsValid = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLGrammarPoolImpl: constructor and destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLGrammarPoolImpl::~XMLGrammarPoolImpl()
|
||||
{
|
||||
delete fGrammarRegistry;
|
||||
delete fStringPool;
|
||||
if(fSynchronizedStringPool)
|
||||
delete fSynchronizedStringPool;
|
||||
if(fXSModel)
|
||||
delete fXSModel;
|
||||
}
|
||||
|
||||
XMLGrammarPoolImpl::XMLGrammarPoolImpl(MemoryManager* const memMgr)
|
||||
:XMLGrammarPool(memMgr)
|
||||
,fGrammarRegistry(0)
|
||||
,fStringPool(0)
|
||||
,fSynchronizedStringPool(0)
|
||||
,fXSModel(0)
|
||||
,fLocked(false)
|
||||
,fXSModelIsValid(false)
|
||||
{
|
||||
fGrammarRegistry = new (memMgr) RefHashTableOf<Grammar>(29, true, memMgr);
|
||||
fStringPool = new (memMgr) XMLStringPool(109, memMgr);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of Grammar Pool Interface
|
||||
// -----------------------------------------------------------------------
|
||||
bool XMLGrammarPoolImpl::cacheGrammar(Grammar* const gramToCache )
|
||||
{
|
||||
if(fLocked || !gramToCache)
|
||||
return false;
|
||||
|
||||
const XMLCh* grammarKey = gramToCache->getGrammarDescription()->getGrammarKey();
|
||||
|
||||
if (fGrammarRegistry->containsKey(grammarKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fGrammarRegistry->put((void*) grammarKey, gramToCache);
|
||||
|
||||
if (fXSModelIsValid && gramToCache->getGrammarType() == Grammar::SchemaGrammarType)
|
||||
{
|
||||
fXSModelIsValid = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Grammar* XMLGrammarPoolImpl::retrieveGrammar(XMLGrammarDescription* const gramDesc)
|
||||
{
|
||||
if (!gramDesc)
|
||||
return 0;
|
||||
|
||||
/***
|
||||
* This implementation simply use GrammarKey
|
||||
*/
|
||||
return fGrammarRegistry->get(gramDesc->getGrammarKey());
|
||||
}
|
||||
|
||||
Grammar* XMLGrammarPoolImpl::orphanGrammar(const XMLCh* const nameSpaceKey)
|
||||
{
|
||||
if (!fLocked)
|
||||
{
|
||||
Grammar* grammar = fGrammarRegistry->orphanKey(nameSpaceKey);
|
||||
if (fXSModelIsValid && grammar && grammar->getGrammarType() == Grammar::SchemaGrammarType)
|
||||
{
|
||||
fXSModelIsValid = false;
|
||||
}
|
||||
return grammar;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RefHashTableOfEnumerator<Grammar>
|
||||
XMLGrammarPoolImpl::getGrammarEnumerator() const
|
||||
{
|
||||
return RefHashTableOfEnumerator<Grammar>(fGrammarRegistry, false, fGrammarRegistry->getMemoryManager());
|
||||
}
|
||||
|
||||
|
||||
bool XMLGrammarPoolImpl::clear()
|
||||
{
|
||||
if (!fLocked)
|
||||
{
|
||||
fGrammarRegistry->removeAll();
|
||||
|
||||
fXSModelIsValid = false;
|
||||
if (fXSModel)
|
||||
{
|
||||
delete fXSModel;
|
||||
fXSModel = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void XMLGrammarPoolImpl::lockPool()
|
||||
{
|
||||
if (!fLocked)
|
||||
{
|
||||
fLocked = true;
|
||||
MemoryManager *memMgr = getMemoryManager();
|
||||
if(!fSynchronizedStringPool)
|
||||
{
|
||||
fSynchronizedStringPool = new (memMgr) XMLSynchronizedStringPool(fStringPool, 109, memMgr);
|
||||
}
|
||||
if (!fXSModelIsValid)
|
||||
{
|
||||
createXSModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XMLGrammarPoolImpl::unlockPool()
|
||||
{
|
||||
if (fLocked)
|
||||
{
|
||||
fLocked = false;
|
||||
if(fSynchronizedStringPool)
|
||||
{
|
||||
fSynchronizedStringPool->flushAll();
|
||||
// if user calls Lock again, need to have null fSynchronizedStringPool
|
||||
delete fSynchronizedStringPool;
|
||||
fSynchronizedStringPool = 0;
|
||||
}
|
||||
fXSModelIsValid = false;
|
||||
if (fXSModel)
|
||||
{
|
||||
delete fXSModel;
|
||||
fXSModel = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Implementation of Factory Interface
|
||||
// -----------------------------------------------------------------------
|
||||
DTDGrammar* XMLGrammarPoolImpl::createDTDGrammar()
|
||||
{
|
||||
return new (getMemoryManager()) DTDGrammar(getMemoryManager());
|
||||
}
|
||||
|
||||
SchemaGrammar* XMLGrammarPoolImpl::createSchemaGrammar()
|
||||
{
|
||||
return new (getMemoryManager()) SchemaGrammar(getMemoryManager());
|
||||
}
|
||||
|
||||
XMLDTDDescription* XMLGrammarPoolImpl::createDTDDescription(const XMLCh* const systemId)
|
||||
{
|
||||
return new (getMemoryManager()) XMLDTDDescriptionImpl(systemId, getMemoryManager());
|
||||
}
|
||||
|
||||
XMLSchemaDescription* XMLGrammarPoolImpl::createSchemaDescription(const XMLCh* const targetNamespace)
|
||||
{
|
||||
return new (getMemoryManager()) XMLSchemaDescriptionImpl(targetNamespace, getMemoryManager());
|
||||
}
|
||||
|
||||
XSModel *XMLGrammarPoolImpl::getXSModel(bool& XSModelWasChanged)
|
||||
{
|
||||
XSModelWasChanged = false;
|
||||
if (fLocked || fXSModelIsValid)
|
||||
return fXSModel;
|
||||
|
||||
createXSModel();
|
||||
XSModelWasChanged = true;
|
||||
return fXSModel;
|
||||
}
|
||||
|
||||
XMLStringPool *XMLGrammarPoolImpl::getURIStringPool()
|
||||
{
|
||||
if(fLocked)
|
||||
return fSynchronizedStringPool;
|
||||
return fStringPool;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// serialization and deserialization support
|
||||
// -----------------------------------------------------------------------
|
||||
/***
|
||||
*
|
||||
* don't serialize
|
||||
*
|
||||
* XMLSynchronizedStringPool* fSynchronizedStringPool;
|
||||
*/
|
||||
|
||||
/***
|
||||
* .non-empty gramamrRegistry
|
||||
***/
|
||||
void XMLGrammarPoolImpl::serializeGrammars(BinOutputStream* const binOut)
|
||||
{
|
||||
RefHashTableOfEnumerator<Grammar> grammarEnum(fGrammarRegistry, false, getMemoryManager());
|
||||
if (!(grammarEnum.hasMoreElements()))
|
||||
{
|
||||
ThrowXMLwithMemMgr(XSerializationException, XMLExcepts::XSer_GrammarPool_Empty, getMemoryManager());
|
||||
}
|
||||
|
||||
XSerializeEngine serEng(binOut, this);
|
||||
|
||||
//version information
|
||||
serEng<<(unsigned int)XERCES_GRAMMAR_SERIALIZATION_LEVEL;
|
||||
|
||||
//lock status
|
||||
serEng<<fLocked;
|
||||
|
||||
//StringPool, don't use <<
|
||||
fStringPool->serialize(serEng);
|
||||
|
||||
/***
|
||||
* Serialize RefHashTableOf<Grammar>* fGrammarRegistry;
|
||||
***/
|
||||
XTemplateSerializer::storeObject(fGrammarRegistry, serEng);
|
||||
}
|
||||
|
||||
/***
|
||||
* .empty stringPool
|
||||
* .empty gramamrRegistry
|
||||
***/
|
||||
void XMLGrammarPoolImpl::deserializeGrammars(BinInputStream* const binIn)
|
||||
{
|
||||
MemoryManager *memMgr = getMemoryManager();
|
||||
unsigned int stringCount = fStringPool->getStringCount();
|
||||
if (stringCount)
|
||||
{
|
||||
/***
|
||||
* it contains only the four predefined one, that is ok
|
||||
* but we need to reset the string before deserialize it
|
||||
*
|
||||
***/
|
||||
if ( stringCount <= 4 )
|
||||
{
|
||||
fStringPool->flushAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowXMLwithMemMgr(XSerializationException, XMLExcepts::XSer_StringPool_NotEmpty, memMgr);
|
||||
}
|
||||
}
|
||||
|
||||
RefHashTableOfEnumerator<Grammar> grammarEnum(fGrammarRegistry, false, memMgr);
|
||||
if (grammarEnum.hasMoreElements())
|
||||
{
|
||||
ThrowXMLwithMemMgr(XSerializationException, XMLExcepts::XSer_GrammarPool_NotEmpty, memMgr);
|
||||
}
|
||||
|
||||
// This object will take care of cleaning up if an exception is
|
||||
// thrown during deserialization.
|
||||
JanitorMemFunCall<XMLGrammarPoolImpl> cleanup(this, &XMLGrammarPoolImpl::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
XSerializeEngine serEng(binIn, this);
|
||||
|
||||
//version information
|
||||
unsigned int StorerLevel;
|
||||
serEng>>StorerLevel;
|
||||
serEng.fStorerLevel = StorerLevel;
|
||||
|
||||
// The storer level must match the loader level.
|
||||
//
|
||||
if (StorerLevel != (unsigned int)XERCES_GRAMMAR_SERIALIZATION_LEVEL)
|
||||
{
|
||||
XMLCh StorerLevelChar[5];
|
||||
XMLCh LoaderLevelChar[5];
|
||||
XMLString::binToText(StorerLevel, StorerLevelChar, 4, 10, memMgr);
|
||||
XMLString::binToText(XERCES_GRAMMAR_SERIALIZATION_LEVEL, LoaderLevelChar, 4, 10, memMgr);
|
||||
|
||||
ThrowXMLwithMemMgr2(XSerializationException
|
||||
, XMLExcepts::XSer_Storer_Loader_Mismatch
|
||||
, StorerLevelChar
|
||||
, LoaderLevelChar
|
||||
, memMgr);
|
||||
}
|
||||
|
||||
//lock status
|
||||
serEng>>fLocked;
|
||||
|
||||
//StringPool, don't use >>
|
||||
fStringPool->serialize(serEng);
|
||||
|
||||
/***
|
||||
* Deserialize RefHashTableOf<Grammar>* fGrammarRegistry;
|
||||
***/
|
||||
XTemplateSerializer::loadObject(&fGrammarRegistry, 29, true, serEng);
|
||||
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
// This is a special case, because we don't want
|
||||
// to execute cleanup code on out-of-memory
|
||||
// conditions.
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
// Everything is OK, so we can release the cleanup object.
|
||||
cleanup.release();
|
||||
|
||||
if (fLocked)
|
||||
{
|
||||
createXSModel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XMLGrammarPoolImpl::cleanUp()
|
||||
{
|
||||
fLocked = false;
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* 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: XMLGrammarPoolImpl.hpp 671531 2008-06-25 12:38:28Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLGRAMMARPOOLIMPL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLGRAMMARPOOLIMPL_HPP
|
||||
|
||||
#include <xercesc/framework/XMLGrammarPool.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLSynchronizedStringPool;
|
||||
|
||||
class XMLUTIL_EXPORT XMLGrammarPoolImpl : public XMLGrammarPool
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name constructor and destructor */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
XMLGrammarPoolImpl(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
~XMLGrammarPoolImpl();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Implementation of Grammar Pool Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* cacheGrammar
|
||||
*
|
||||
* Provide the grammar pool with an opportunity
|
||||
* to cache the given grammar. If the pool does not choose to do so,
|
||||
* it should return false; otherwise, it should return true, so that
|
||||
* the caller knows whether the grammar has been adopted.
|
||||
*
|
||||
* @param gramToCache: the Grammar to be cached in the grammar pool
|
||||
* @return true if the grammar pool has elected to cache the grammar (in which case
|
||||
* it is assumed to have adopted it); false if it does not cache it
|
||||
*
|
||||
*/
|
||||
virtual bool cacheGrammar(Grammar* const gramToCache);
|
||||
|
||||
|
||||
/**
|
||||
* retrieveGrammar
|
||||
*
|
||||
* @param gramDesc: the Grammar Description used to search for grammar
|
||||
* cached in the grammar pool
|
||||
*
|
||||
*/
|
||||
virtual Grammar* retrieveGrammar(XMLGrammarDescription* const gramDesc);
|
||||
|
||||
|
||||
/**
|
||||
* orphanGrammar
|
||||
*
|
||||
* grammar removed from the grammar pool and owned by the caller
|
||||
*
|
||||
* @param nameSpaceKey: Key used to search for grammar in the grammar pool
|
||||
*
|
||||
*/
|
||||
virtual Grammar* orphanGrammar(const XMLCh* const nameSpaceKey);
|
||||
|
||||
|
||||
/**
|
||||
* Get an enumeration of the cached Grammars in the Grammar pool
|
||||
*
|
||||
* @return enumeration of the cached Grammars in Grammar pool
|
||||
*/
|
||||
virtual RefHashTableOfEnumerator<Grammar> getGrammarEnumerator() const;
|
||||
|
||||
/**
|
||||
* clear
|
||||
*
|
||||
* all grammars are removed from the grammar pool and deleted.
|
||||
* @return true if the grammar pool was cleared. false if it did not.
|
||||
*/
|
||||
virtual bool clear();
|
||||
|
||||
/**
|
||||
* lockPool
|
||||
*
|
||||
* When this method is called by the application, the
|
||||
* grammar pool should stop adding new grammars to the cache.
|
||||
*/
|
||||
virtual void lockPool();
|
||||
|
||||
/**
|
||||
* unlockPool
|
||||
*
|
||||
* After this method has been called, the grammar pool implementation
|
||||
* should return to its default behaviour when cacheGrammars(...) is called.
|
||||
*
|
||||
* For PSVI support any previous XSModel that was produced will be deleted.
|
||||
*/
|
||||
virtual void unlockPool();
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Implementation of Factory interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* createDTDGrammar
|
||||
*
|
||||
*/
|
||||
virtual DTDGrammar* createDTDGrammar();
|
||||
|
||||
/**
|
||||
* createSchemaGrammar
|
||||
*
|
||||
*/
|
||||
virtual SchemaGrammar* createSchemaGrammar();
|
||||
|
||||
/**
|
||||
* createDTDDescription
|
||||
*
|
||||
*/
|
||||
virtual XMLDTDDescription* createDTDDescription(const XMLCh* const systemId);
|
||||
/**
|
||||
* createSchemaDescription
|
||||
*
|
||||
*/
|
||||
virtual XMLSchemaDescription* createSchemaDescription(const XMLCh* const targetNamespace);
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name schema component model support */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/***
|
||||
* Return an XSModel derived from the components of all SchemaGrammars
|
||||
* in the grammar pool. If the pool is locked, this should
|
||||
* be a thread-safe operation.
|
||||
*
|
||||
* NOTE: The function should NEVER return NULL. If there are no grammars in
|
||||
* the pool it should return an XSModel containing the Schema for Schema.
|
||||
*
|
||||
* Calling getXSModel() on an unlocked grammar pool may result in the
|
||||
* creation of a new XSModel with the old XSModel being deleted.
|
||||
* The bool parameter will indicate if the XSModel was changed.
|
||||
*
|
||||
* In this implementation, when the pool is not locked a new XSModel will be
|
||||
* computed each this time the pool is called if the pool has changed (and the
|
||||
* previous one will be destroyed at that time). When the lockPool()
|
||||
* method is called, an XSModel will be generated and returned whenever this method is called
|
||||
* while the pool is in the locked state. This will be destroyed if the unlockPool()
|
||||
* operation is called. The XSModel will not be serialized,
|
||||
* but will be recreated if a deserialized pool is in the
|
||||
* locked state.
|
||||
*
|
||||
*/
|
||||
virtual XSModel *getXSModel(bool& XSModelWasChanged);
|
||||
|
||||
// @}
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Getter */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Return an XMLStringPool for use by validation routines.
|
||||
* Implementations should not create a string pool on each call to this
|
||||
* method, but should maintain one string pool for all grammars
|
||||
* for which this pool is responsible.
|
||||
*/
|
||||
virtual XMLStringPool *getURIStringPool();
|
||||
|
||||
// @}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// serialization and deserialization support
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/***
|
||||
*
|
||||
* Multiple serializations
|
||||
*
|
||||
* For multiple serializations, if the same file name is given, then the
|
||||
* last result will be in the file (overwriting mode), if different file
|
||||
* names are given, then there are multiple data stores for each serialization.
|
||||
*
|
||||
* Multiple deserializations
|
||||
*
|
||||
* Not supported
|
||||
*
|
||||
* Versioning
|
||||
*
|
||||
* Only binary data serialized with the current XercesC Version and
|
||||
* SerializationLevel is supported.
|
||||
*
|
||||
* Clean up
|
||||
*
|
||||
* In the event of an exception thrown due to a corrupted data store during
|
||||
* deserialization, this implementation may not be able to clean up all resources
|
||||
* allocated, and therefore it is the client application's responsibility to
|
||||
* clean up those unreleased resources.
|
||||
*
|
||||
* Coupling of Grammars and StringPool
|
||||
*
|
||||
* This implementation assumes that StringPool shall always be
|
||||
* serialized/deserialized together with the grammars. In the case that such a
|
||||
* coupling is not desired, client application can modify this behaviour by
|
||||
* either derivate from this imlementation and overwrite the serializeGrammars()
|
||||
* and/or deserializeGrammars() to decouple grammars and string pool, or
|
||||
* Once deserializeGrammars() is done, insert another StringPool through
|
||||
* setStringPool().
|
||||
*
|
||||
* Client application shall be aware of the unpredicatable/undefined consequence
|
||||
* of this decoupling.
|
||||
*/
|
||||
|
||||
virtual void serializeGrammars(BinOutputStream* const);
|
||||
virtual void deserializeGrammars(BinInputStream* const);
|
||||
|
||||
private:
|
||||
|
||||
virtual void createXSModel();
|
||||
|
||||
void
|
||||
cleanUp();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLGrammarPoolImpl(const XMLGrammarPoolImpl& );
|
||||
XMLGrammarPoolImpl& operator=(const XMLGrammarPoolImpl& );
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
//
|
||||
// fGrammarRegistry:
|
||||
//
|
||||
// container
|
||||
// fStringPool
|
||||
// grammars need a string pool for URI -> int mappings
|
||||
// fSynchronizedStringPool
|
||||
// When the grammar pool is locked, provide a string pool
|
||||
// that can be updated in a thread-safe manner.
|
||||
// fLocked
|
||||
// whether the pool has been locked
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
RefHashTableOf<Grammar>* fGrammarRegistry;
|
||||
XMLStringPool* fStringPool;
|
||||
XMLSynchronizedStringPool* fSynchronizedStringPool;
|
||||
XSModel* fXSModel;
|
||||
bool fLocked;
|
||||
bool fXSModelIsValid;
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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: XMLNotationDecl.cpp 679359 2008-07-24 11:15:19Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLNotationDecl.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLNotationDecl: Constructors and operators
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLNotationDecl::XMLNotationDecl(MemoryManager* const manager) :
|
||||
|
||||
fId(0)
|
||||
, fNameSpaceId(0)
|
||||
, fName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
typedef JanitorMemFunCall<XMLNotationDecl> CleanupType;
|
||||
|
||||
XMLNotationDecl::XMLNotationDecl( const XMLCh* const notName
|
||||
, const XMLCh* const pubId
|
||||
, const XMLCh* const sysId
|
||||
, const XMLCh* const baseURI
|
||||
, MemoryManager* const manager) :
|
||||
fId(0)
|
||||
, fNameSpaceId(0)
|
||||
, fName(0)
|
||||
, fPublicId(0)
|
||||
, fSystemId(0)
|
||||
, fBaseURI(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &XMLNotationDecl::cleanUp);
|
||||
|
||||
try
|
||||
{
|
||||
fName = XMLString::replicate(notName, fMemoryManager);
|
||||
fPublicId = XMLString::replicate(pubId, fMemoryManager);
|
||||
fSystemId = XMLString::replicate(sysId, fMemoryManager);
|
||||
fBaseURI = XMLString::replicate(baseURI, fMemoryManager);
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
XMLNotationDecl::~XMLNotationDecl()
|
||||
{
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void XMLNotationDecl::setName(const XMLCh* const notName)
|
||||
{
|
||||
// Clean up the current name stuff and replicate the passed name
|
||||
if (fName)
|
||||
fMemoryManager->deallocate(fName);
|
||||
|
||||
fName = XMLString::replicate(notName, fMemoryManager);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLNotationDecl: Private helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLNotationDecl::cleanUp()
|
||||
{
|
||||
fMemoryManager->deallocate(fName);
|
||||
fMemoryManager->deallocate(fPublicId);
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
fMemoryManager->deallocate(fBaseURI);
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_TOCREATE(XMLNotationDecl)
|
||||
|
||||
void XMLNotationDecl::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng.writeSize (fId);
|
||||
serEng<<fNameSpaceId;
|
||||
serEng.writeString(fName);
|
||||
serEng.writeString(fPublicId);
|
||||
serEng.writeString(fSystemId);
|
||||
serEng.writeString(fBaseURI);
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng.readSize (fId);
|
||||
serEng>>fNameSpaceId;
|
||||
serEng.readString(fName);
|
||||
serEng.readString(fPublicId);
|
||||
serEng.readString(fSystemId);
|
||||
serEng.readString(fBaseURI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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: XMLNotationDecl.hpp 676911 2008-07-15 13:27:32Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLNOTATIONDECL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLNOTATIONDECL_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class represents the core information about a notation declaration
|
||||
* that all validators must at least support. Each validator will create a
|
||||
* derivative of this class which adds any information it requires for its
|
||||
* own extra needs.
|
||||
*
|
||||
* At this common level, the information supported is the notation name
|
||||
* and the public and sysetm ids indicated in the notation declaration.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLNotationDecl : public XSerializable, public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
XMLNotationDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
XMLNotationDecl
|
||||
(
|
||||
const XMLCh* const notName
|
||||
, const XMLCh* const pubId
|
||||
, const XMLCh* const sysId
|
||||
, const XMLCh* const baseURI = 0
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLNotationDecl();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getId() const;
|
||||
const XMLCh* getName() const;
|
||||
const XMLCh* getPublicId() const;
|
||||
const XMLCh* getSystemId() const;
|
||||
const XMLCh* getBaseURI() const;
|
||||
unsigned int getNameSpaceId() const;
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setId(const XMLSize_t newId);
|
||||
void setName
|
||||
(
|
||||
const XMLCh* const notName
|
||||
);
|
||||
void setPublicId(const XMLCh* const newId);
|
||||
void setSystemId(const XMLCh* const newId);
|
||||
void setBaseURI(const XMLCh* const newId);
|
||||
void setNameSpaceId(const unsigned int newId);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Support named collection element semantics
|
||||
// -----------------------------------------------------------------------
|
||||
const XMLCh* getKey() const;
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLNotationDecl)
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLNotationDecl(const XMLNotationDecl&);
|
||||
XMLNotationDecl& operator=(const XMLNotationDecl&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// XMLNotationDecl: Private helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void cleanUp();
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fId
|
||||
// This is the unique id given to this notation decl.
|
||||
//
|
||||
// fName
|
||||
// The notation's name, which identifies the type of notation it
|
||||
// applies to.
|
||||
//
|
||||
// fPublicId
|
||||
// The text of the notation's public id, if any.
|
||||
//
|
||||
// fSystemId
|
||||
// The text of the notation's system id, if any.
|
||||
//
|
||||
// fBaseURI
|
||||
// The text of the notation's base URI
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t fId;
|
||||
unsigned int fNameSpaceId;
|
||||
XMLCh* fName;
|
||||
XMLCh* fPublicId;
|
||||
XMLCh* fSystemId;
|
||||
XMLCh* fBaseURI;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
inline XMLSize_t XMLNotationDecl::getId() const
|
||||
{
|
||||
return fId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLNotationDecl::getName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
inline unsigned int XMLNotationDecl::getNameSpaceId() const
|
||||
{
|
||||
return fNameSpaceId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLNotationDecl::getPublicId() const
|
||||
{
|
||||
return fPublicId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLNotationDecl::getSystemId() const
|
||||
{
|
||||
return fSystemId;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLNotationDecl::getBaseURI() const
|
||||
{
|
||||
return fBaseURI;
|
||||
}
|
||||
|
||||
inline MemoryManager* XMLNotationDecl::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
inline void XMLNotationDecl::setId(const XMLSize_t newId)
|
||||
{
|
||||
fId = newId;
|
||||
}
|
||||
|
||||
inline void XMLNotationDecl::setNameSpaceId(const unsigned int newId)
|
||||
{
|
||||
fNameSpaceId = newId;
|
||||
}
|
||||
|
||||
inline void XMLNotationDecl::setPublicId(const XMLCh* const newId)
|
||||
{
|
||||
if (fPublicId)
|
||||
fMemoryManager->deallocate(fPublicId);
|
||||
|
||||
fPublicId = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLNotationDecl::setSystemId(const XMLCh* const newId)
|
||||
{
|
||||
if (fSystemId)
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
|
||||
fSystemId = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void XMLNotationDecl::setBaseURI(const XMLCh* const newId)
|
||||
{
|
||||
if (fBaseURI)
|
||||
fMemoryManager->deallocate(fBaseURI);
|
||||
|
||||
fBaseURI = XMLString::replicate(newId, fMemoryManager);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLNotationDecl: Support named pool element semantics
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLCh* XMLNotationDecl::getKey() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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: XMLPScanToken.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLPSCANTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLPSCANTOKEN_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLScanner;
|
||||
|
||||
/**
|
||||
* This simple class is used as a sanity check when the scanner is used to
|
||||
* do progressive parsing. It insures that things are not done out of
|
||||
* sequence and that sequences of scan calls are made correctly to the
|
||||
* right scanner instances.
|
||||
*
|
||||
* To client code, it is just a magic cookie which is obtained when a
|
||||
* progressive parse is begun, and which is passed back in on each subsequent
|
||||
* call of the progressive parse.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLPScanToken : public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
XMLPScanToken();
|
||||
XMLPScanToken(const XMLPScanToken& toCopy);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLPScanToken();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLPScanToken& operator=(const XMLPScanToken& toCopy);
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// XMLScanner is our friend, can you say friend? Sure...
|
||||
// -----------------------------------------------------------------------
|
||||
friend class XMLScanner;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden methods for use by XMLScanner
|
||||
// -----------------------------------------------------------------------
|
||||
void set
|
||||
(
|
||||
const XMLUInt32 scannerId
|
||||
, const XMLUInt32 sequenceId
|
||||
);
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fScannerId
|
||||
// This field is set to the id of the scanner, to catch problems
|
||||
// where a token is gotten from one scanner and passed to another.
|
||||
// Each scanner is assigned an incrementing id.
|
||||
//
|
||||
// fSequenceId
|
||||
// In order to avoid problems such as calling scanNext() without
|
||||
// a call to scanFirst() and such, this value is set when scanFirst()
|
||||
// is called and matches this token to the current sequence id of
|
||||
// the scanner.
|
||||
// -----------------------------------------------------------------------
|
||||
XMLUInt32 fScannerId;
|
||||
XMLUInt32 fSequenceId;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLPScanToken: Constructors and Operators
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLPScanToken::XMLPScanToken() :
|
||||
|
||||
fScannerId(0)
|
||||
, fSequenceId(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline XMLPScanToken::XMLPScanToken(const XMLPScanToken& toCopy) :
|
||||
XMemory(toCopy)
|
||||
, fScannerId(toCopy.fScannerId)
|
||||
, fSequenceId(toCopy.fSequenceId)
|
||||
{
|
||||
}
|
||||
|
||||
inline XMLPScanToken::~XMLPScanToken()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLPScanToken: Public operators
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLPScanToken& XMLPScanToken::operator=(const XMLPScanToken& toCopy)
|
||||
{
|
||||
if (this == &toCopy)
|
||||
return *this;
|
||||
|
||||
fScannerId = toCopy.fScannerId;
|
||||
fSequenceId = toCopy.fSequenceId;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLPScanToken: Hidden methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLPScanToken::set( const XMLUInt32 scannerId
|
||||
, const XMLUInt32 sequenceId)
|
||||
{
|
||||
fScannerId = scannerId;
|
||||
fSequenceId = sequenceId;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* 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: XMLRecognizer.cpp 555320 2007-07-11 16:05:13Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLRecognizer.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
//
|
||||
// gEncodingNameMap
|
||||
// This array maps the Encodings enum values to their canonical names.
|
||||
// Be sure to keep this in sync with that enum!
|
||||
// ---------------------------------------------------------------------------
|
||||
static const XMLCh* gEncodingNameMap[XMLRecognizer::Encodings_Count] =
|
||||
{
|
||||
XMLUni::fgEBCDICEncodingString
|
||||
, XMLUni::fgUCS4BEncodingString
|
||||
, XMLUni::fgUCS4LEncodingString
|
||||
, XMLUni::fgUSASCIIEncodingString
|
||||
, XMLUni::fgUTF8EncodingString
|
||||
, XMLUni::fgUTF16BEncodingString
|
||||
, XMLUni::fgUTF16LEncodingString
|
||||
, XMLUni::fgXMLChEncodingString
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRecognizer: Public, const static data
|
||||
//
|
||||
// gXXXPre
|
||||
// gXXXPreLen
|
||||
// The byte sequence prefixes for all of the encodings that we can
|
||||
// auto sense. Also included is the length of each sequence.
|
||||
// ---------------------------------------------------------------------------
|
||||
const char XMLRecognizer::fgASCIIPre[] = { 0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20 };
|
||||
const XMLSize_t XMLRecognizer::fgASCIIPreLen = 6;
|
||||
const XMLByte XMLRecognizer::fgEBCDICPre[] = { 0x4C, 0x6F, 0xA7, 0x94, 0x93, 0x40 };
|
||||
const XMLSize_t XMLRecognizer::fgEBCDICPreLen = 6;
|
||||
const XMLByte XMLRecognizer::fgUTF16BPre[] = { 0x00, 0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x20 };
|
||||
const XMLByte XMLRecognizer::fgUTF16LPre[] = { 0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00, 0x20, 0x00 };
|
||||
const XMLSize_t XMLRecognizer::fgUTF16PreLen = 12;
|
||||
const XMLByte XMLRecognizer::fgUCS4BPre[] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x3F
|
||||
, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x6D
|
||||
, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x20
|
||||
};
|
||||
const XMLByte XMLRecognizer::fgUCS4LPre[] =
|
||||
{
|
||||
0x3C, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00
|
||||
, 0x78, 0x00, 0x00, 0x00, 0x6D, 0x00, 0x00, 0x00
|
||||
, 0x6C, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00
|
||||
};
|
||||
const XMLSize_t XMLRecognizer::fgUCS4PreLen = 24;
|
||||
|
||||
const char XMLRecognizer::fgUTF8BOM[] = {(char)0xEF, (char)0xBB, (char)0xBF};
|
||||
const XMLSize_t XMLRecognizer::fgUTF8BOMLen = 3;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRecognizer: Encoding recognition methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLRecognizer::Encodings
|
||||
XMLRecognizer::basicEncodingProbe( const XMLByte* const rawBuffer
|
||||
, const XMLSize_t rawByteCount)
|
||||
{
|
||||
//
|
||||
// As an optimization to check the 90% case, check first for the ASCII
|
||||
// sequence '<?xml', which means its either US-ASCII, UTF-8, or some
|
||||
// other encoding that we don't do manually but which happens to share
|
||||
// the US-ASCII code points for these characters. So just return UTF-8
|
||||
// to get us through the first line.
|
||||
//
|
||||
if (rawByteCount >= fgASCIIPreLen)
|
||||
{
|
||||
if (!memcmp(rawBuffer, fgASCIIPre, fgASCIIPreLen))
|
||||
return UTF_8;
|
||||
}
|
||||
|
||||
//
|
||||
// If the count of raw bytes is less than 2, it cannot be anything
|
||||
// we understand, so return UTF-8 as a fallback.
|
||||
//
|
||||
if (rawByteCount < 2)
|
||||
return UTF_8;
|
||||
|
||||
//
|
||||
// We have two to four bytes, so lets check for a UTF-16 BOM. That
|
||||
// is quick to check and enough to identify two major encodings.
|
||||
//
|
||||
|
||||
if (rawByteCount < 4)
|
||||
{
|
||||
if ((rawBuffer[0] == 0xFE) && (rawBuffer[1] == 0xFF))
|
||||
return UTF_16B;
|
||||
else if ((rawBuffer[0] == 0xFF) && (rawBuffer[1] == 0xFE))
|
||||
return UTF_16L;
|
||||
else
|
||||
return UTF_8;
|
||||
}
|
||||
|
||||
/***
|
||||
* F.1 Detection Without External Encoding Information
|
||||
*
|
||||
* Because each XML entity not accompanied by external encoding information and
|
||||
* not in UTF-8 or UTF-16 encoding must begin with an XML encoding declaration,
|
||||
* in which the first characters must be '<?xml', any conforming processor can detect,
|
||||
* after two to four octets of input, which of the following cases apply.
|
||||
*
|
||||
* In reading this list, it may help to know that in UCS-4, '<' is "#x0000003C" and
|
||||
* '?' is "#x0000003F", and the Byte Order Mark required of UTF-16 data streams is
|
||||
* "#xFEFF". The notation ## is used to denote any byte value except that two consecutive
|
||||
* ##s cannot be both 00.
|
||||
*
|
||||
* With a Byte Order Mark:
|
||||
*
|
||||
* 00 00 FE FF UCS-4, big-endian machine (1234 order)
|
||||
* FF FE 00 00 UCS-4, little-endian machine (4321 order)
|
||||
* 00 00 FF FE UCS-4, unusual octet order (2143)
|
||||
* FE FF 00 00 UCS-4, unusual octet order (3412)
|
||||
* FE FF ## ## UTF-16, big-endian
|
||||
* FF FE ## ## UTF-16, little-endian
|
||||
* EF BB BF UTF-8
|
||||
*
|
||||
***/
|
||||
|
||||
//
|
||||
// We have at least four bytes, so we can check all BOM
|
||||
// for UCS-4BE, UCS-4LE, UTF-16BE and UTF-16LE as well.
|
||||
//
|
||||
if ((rawBuffer[0] == 0x00) && (rawBuffer[1] == 0x00) && (rawBuffer[2] == 0xFE) && (rawBuffer[3] == 0xFF))
|
||||
return UCS_4B;
|
||||
else if ((rawBuffer[0] == 0xFF) && (rawBuffer[1] == 0xFE) && (rawBuffer[2] == 0x00) && (rawBuffer[3] == 0x00))
|
||||
return UCS_4L;
|
||||
else if ((rawBuffer[0] == 0xFE) && (rawBuffer[1] == 0xFF))
|
||||
return UTF_16B;
|
||||
else if ((rawBuffer[0] == 0xFF) && (rawBuffer[1] == 0xFE))
|
||||
return UTF_16L;
|
||||
|
||||
//
|
||||
// We have at least 4 bytes. So lets check the 4 byte sequences that
|
||||
// indicate other UTF-16 and UCS encodings.
|
||||
//
|
||||
if ((rawBuffer[0] == 0x00) || (rawBuffer[0] == 0x3C))
|
||||
{
|
||||
if (rawByteCount >= fgUCS4PreLen && !memcmp(rawBuffer, fgUCS4BPre, fgUCS4PreLen))
|
||||
return UCS_4B;
|
||||
else if (rawByteCount >= fgUCS4PreLen && !memcmp(rawBuffer, fgUCS4LPre, fgUCS4PreLen))
|
||||
return UCS_4L;
|
||||
else if (rawByteCount >= fgUTF16PreLen && !memcmp(rawBuffer, fgUTF16BPre, fgUTF16PreLen))
|
||||
return UTF_16B;
|
||||
else if (rawByteCount >= fgUTF16PreLen && !memcmp(rawBuffer, fgUTF16LPre, fgUTF16PreLen))
|
||||
return UTF_16L;
|
||||
}
|
||||
|
||||
//
|
||||
// See if we have enough bytes to possibly match the EBCDIC prefix.
|
||||
// If so, try it.
|
||||
//
|
||||
if (rawByteCount > fgEBCDICPreLen)
|
||||
{
|
||||
if (!memcmp(rawBuffer, fgEBCDICPre, fgEBCDICPreLen))
|
||||
return EBCDIC;
|
||||
}
|
||||
|
||||
//
|
||||
// Does not seem to be anything we know, so go with UTF-8 to get at
|
||||
// least through the first line and see what it really is.
|
||||
//
|
||||
return UTF_8;
|
||||
}
|
||||
|
||||
|
||||
XMLRecognizer::Encodings
|
||||
XMLRecognizer::encodingForName(const XMLCh* const encName)
|
||||
{
|
||||
//
|
||||
// Compare the passed string, assume input string is already uppercased,
|
||||
// to the variations that we recognize.
|
||||
//
|
||||
// !!NOTE: Note that we don't handle EBCDIC here because we don't handle
|
||||
// that one ourselves. It is allowed to fall into 'other'.
|
||||
//
|
||||
if (encName == XMLUni::fgXMLChEncodingString ||
|
||||
!XMLString::compareString(encName, XMLUni::fgXMLChEncodingString))
|
||||
{
|
||||
return XMLRecognizer::XERCES_XMLCH;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUTF8EncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUTF8EncodingString2))
|
||||
{
|
||||
return XMLRecognizer::UTF_8;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUSASCIIEncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUSASCIIEncodingString2)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUSASCIIEncodingString3)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUSASCIIEncodingString4))
|
||||
{
|
||||
return XMLRecognizer::US_ASCII;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUTF16LEncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUTF16LEncodingString2))
|
||||
{
|
||||
return XMLRecognizer::UTF_16L;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUTF16BEncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUTF16BEncodingString2))
|
||||
{
|
||||
return XMLRecognizer::UTF_16B;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUTF16EncodingString))
|
||||
{
|
||||
return XMLPlatformUtils::fgXMLChBigEndian?XMLRecognizer::UTF_16B:XMLRecognizer::UTF_16L;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUCS4LEncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUCS4LEncodingString2))
|
||||
{
|
||||
return XMLRecognizer::UCS_4L;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUCS4BEncodingString)
|
||||
|| !XMLString::compareString(encName, XMLUni::fgUCS4BEncodingString2))
|
||||
{
|
||||
return XMLRecognizer::UCS_4B;
|
||||
}
|
||||
else if (!XMLString::compareString(encName, XMLUni::fgUCS4EncodingString))
|
||||
{
|
||||
return XMLPlatformUtils::fgXMLChBigEndian?XMLRecognizer::UCS_4B:XMLRecognizer::UCS_4L;
|
||||
}
|
||||
|
||||
// Return 'other' since we don't recognizer it
|
||||
return XMLRecognizer::OtherEncoding;
|
||||
}
|
||||
|
||||
|
||||
const XMLCh*
|
||||
XMLRecognizer::nameForEncoding(const XMLRecognizer::Encodings theEncoding
|
||||
, MemoryManager* const manager)
|
||||
{
|
||||
if (theEncoding >= Encodings_Count)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::XMLRec_UnknownEncoding, manager);
|
||||
|
||||
return gEncodingNameMap[theEncoding];
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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: XMLRecognizer.hpp 555320 2007-07-11 16:05:13Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLRECOGNIZER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLRECOGNIZER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class provides some simple code to recognize the encodings of
|
||||
* XML files. This recognition only does very basic sensing of the encoding
|
||||
* in a broad sense. Basically its just enough to let us get started and
|
||||
* read the XMLDecl line. The scanner, once it reads the XMLDecl, will
|
||||
* tell the reader any actual encoding string it found and the reader can
|
||||
* update itself to be more specific at that point.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLRecognizer
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Class types
|
||||
//
|
||||
// This enum represents the various encoding families that we have to
|
||||
// deal with individually at the scanner level. This does not indicate
|
||||
// the exact encoding, just the rough family that would let us scan
|
||||
// the XML/TextDecl to find the encoding string.
|
||||
//
|
||||
// The 'L's and 'B's stand for little or big endian.
|
||||
//
|
||||
// OtherEncoding means that its some transcoder based encoding, i.e. not
|
||||
// one of the ones that we do internally. Its a special case and should
|
||||
// never be used directly outside of the reader.
|
||||
//
|
||||
// NOTE: Keep this in sync with the name map array in the Cpp file!!
|
||||
// -----------------------------------------------------------------------
|
||||
enum Encodings
|
||||
{
|
||||
EBCDIC = 0
|
||||
, UCS_4B = 1
|
||||
, UCS_4L = 2
|
||||
, US_ASCII = 3
|
||||
, UTF_8 = 4
|
||||
, UTF_16B = 5
|
||||
, UTF_16L = 6
|
||||
, XERCES_XMLCH = 7
|
||||
|
||||
, Encodings_Count
|
||||
, Encodings_Min = EBCDIC
|
||||
, Encodings_Max = XERCES_XMLCH
|
||||
|
||||
, OtherEncoding = 999
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public, const static data
|
||||
//
|
||||
// These are the byte sequences for each of the encodings that we can
|
||||
// auto sense, and their lengths.
|
||||
// -----------------------------------------------------------------------
|
||||
static const char fgASCIIPre[];
|
||||
static const XMLSize_t fgASCIIPreLen;
|
||||
static const XMLByte fgEBCDICPre[];
|
||||
static const XMLSize_t fgEBCDICPreLen;
|
||||
static const XMLByte fgUTF16BPre[];
|
||||
static const XMLByte fgUTF16LPre[];
|
||||
static const XMLSize_t fgUTF16PreLen;
|
||||
static const XMLByte fgUCS4BPre[];
|
||||
static const XMLByte fgUCS4LPre[];
|
||||
static const XMLSize_t fgUCS4PreLen;
|
||||
static const char fgUTF8BOM[];
|
||||
static const XMLSize_t fgUTF8BOMLen;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Encoding recognition methods
|
||||
// -----------------------------------------------------------------------
|
||||
static Encodings basicEncodingProbe
|
||||
(
|
||||
const XMLByte* const rawBuffer
|
||||
, const XMLSize_t rawByteCount
|
||||
);
|
||||
|
||||
static Encodings encodingForName
|
||||
(
|
||||
const XMLCh* const theEncName
|
||||
);
|
||||
|
||||
static const XMLCh* nameForEncoding(const Encodings theEncoding
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors, operators, and destructor
|
||||
//
|
||||
// This class is effectively being used as a namespace for some static
|
||||
// methods.
|
||||
//
|
||||
// (these functions are protected rather than private only to get rid of
|
||||
// some annoying compiler warnings.)
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
XMLRecognizer();
|
||||
~XMLRecognizer();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLRecognizer(const XMLRecognizer&);
|
||||
XMLRecognizer& operator=(const XMLRecognizer&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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: XMLRefInfo.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLRefInfo.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_TOCREATE(XMLRefInfo)
|
||||
|
||||
void XMLRefInfo::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng<<fDeclared;
|
||||
serEng<<fUsed;
|
||||
serEng.writeString(fRefName);
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng>>fDeclared;
|
||||
serEng>>fUsed;
|
||||
serEng.readString(fRefName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
XMLRefInfo::XMLRefInfo(MemoryManager* const manager)
|
||||
:fDeclared(false)
|
||||
,fUsed(false)
|
||||
,fRefName(0)
|
||||
,fMemoryManager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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: XMLRefInfo.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLREFINFO_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLREFINFO_HPP
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class provides a simple means to track ID Ref usage. Since id/idref
|
||||
* semantics are part of XML 1.0, any validator will likely to be able to
|
||||
* track them. Instances of this class represent a reference and two markers,
|
||||
* one for its being declared and another for its being used. When the
|
||||
* document is done, one can look at each instance and, if used but not
|
||||
* declared, its an error.
|
||||
*
|
||||
* The getKey() method allows it to support keyed collection semantics. It
|
||||
* returns the referenced name, so these objects will be stored via the hash
|
||||
* of the name. This name will either be a standard QName if namespaces are
|
||||
* not enabled/supported by the validator, or it will be in the form
|
||||
* {url}name if namespace processing is enabled.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLRefInfo : public XSerializable, public XMemory
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructor */
|
||||
//@{
|
||||
XMLRefInfo
|
||||
(
|
||||
const XMLCh* const refName
|
||||
, const bool fDeclared = false
|
||||
, const bool fUsed = false
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XMLRefInfo();
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool getDeclared() const;
|
||||
const XMLCh* getRefName() const;
|
||||
bool getUsed() const;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setDeclared(const bool newValue);
|
||||
void setUsed(const bool newValue);
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLRefInfo)
|
||||
|
||||
XMLRefInfo
|
||||
(
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLRefInfo(const XMLRefInfo&);
|
||||
XMLRefInfo& operator=(XMLRefInfo&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fDeclared
|
||||
// The name was declared somewhere as an ID attribute.
|
||||
//
|
||||
// fRefName
|
||||
// The name of the ref that this object represents. This is not a
|
||||
// name of the attribute, but of the value of an ID or IDREF attr
|
||||
// in content.
|
||||
//
|
||||
// fUsed
|
||||
// The name was used somewhere in an IDREF/IDREFS attribute. If this
|
||||
// is true, but fDeclared is false, then the ref does not refer to
|
||||
// a declared ID.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fDeclared;
|
||||
bool fUsed;
|
||||
XMLCh* fRefName;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRefInfo: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLRefInfo::XMLRefInfo( const XMLCh* const refName
|
||||
, const bool declared
|
||||
, const bool used
|
||||
, MemoryManager* const manager) :
|
||||
fDeclared(declared)
|
||||
, fUsed(used)
|
||||
, fRefName(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fRefName = XMLString::replicate(refName, fMemoryManager);
|
||||
}
|
||||
|
||||
inline XMLRefInfo::~XMLRefInfo()
|
||||
{
|
||||
fMemoryManager->deallocate(fRefName);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRefInfo: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline bool XMLRefInfo::getDeclared() const
|
||||
{
|
||||
return fDeclared;
|
||||
}
|
||||
|
||||
inline const XMLCh* XMLRefInfo::getRefName() const
|
||||
{
|
||||
return fRefName;
|
||||
}
|
||||
|
||||
inline bool XMLRefInfo::getUsed() const
|
||||
{
|
||||
return fUsed;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRefInfo: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void XMLRefInfo::setDeclared(const bool newValue)
|
||||
{
|
||||
fDeclared = newValue;
|
||||
}
|
||||
|
||||
inline void XMLRefInfo::setUsed(const bool newValue)
|
||||
{
|
||||
fUsed = newValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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: XMLSchemaDescription.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLSchemaDescription.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
XMLSchemaDescription::~XMLSchemaDescription()
|
||||
{
|
||||
}
|
||||
|
||||
XMLSchemaDescription::XMLSchemaDescription(MemoryManager* const memMgr)
|
||||
:XMLGrammarDescription(memMgr)
|
||||
{
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_NOCREATE(XMLSchemaDescription)
|
||||
|
||||
void XMLSchemaDescription::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
XMLGrammarDescription::serialize(serEng);
|
||||
|
||||
//no data
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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: XMLSchemaDescription.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLSCHEMADESCRIPTION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLSCHEMADESCRIPTION_HPP
|
||||
|
||||
#include <xercesc/framework/XMLGrammarDescription.hpp>
|
||||
#include <xercesc/util/RefArrayVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
typedef const XMLCh* const LocationHint;
|
||||
|
||||
class XMLPARSER_EXPORT XMLSchemaDescription : public XMLGrammarDescription
|
||||
{
|
||||
public :
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Virtual destructor for derived classes */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* virtual destructor
|
||||
*
|
||||
*/
|
||||
virtual ~XMLSchemaDescription();
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Implementation of Grammar Description Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
/**
|
||||
* getGrammarType
|
||||
*
|
||||
*/
|
||||
virtual Grammar::GrammarType getGrammarType() const
|
||||
{
|
||||
return Grammar::SchemaGrammarType;
|
||||
}
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name The SchemaDescription Interface */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
|
||||
enum ContextType
|
||||
{
|
||||
CONTEXT_INCLUDE,
|
||||
CONTEXT_REDEFINE,
|
||||
CONTEXT_IMPORT,
|
||||
CONTEXT_PREPARSE,
|
||||
CONTEXT_INSTANCE,
|
||||
CONTEXT_ELEMENT,
|
||||
CONTEXT_ATTRIBUTE,
|
||||
CONTEXT_XSITYPE,
|
||||
CONTEXT_UNKNOWN
|
||||
};
|
||||
|
||||
/**
|
||||
* getContextType
|
||||
*
|
||||
*/
|
||||
virtual ContextType getContextType() const = 0;
|
||||
|
||||
/**
|
||||
* getTargetNamespace
|
||||
*
|
||||
*/
|
||||
virtual const XMLCh* getTargetNamespace() const = 0;
|
||||
|
||||
/**
|
||||
* getLocationHints
|
||||
*
|
||||
*/
|
||||
virtual const RefArrayVectorOf<XMLCh>* getLocationHints() const = 0;
|
||||
|
||||
/**
|
||||
* getTriggeringComponent
|
||||
*
|
||||
*/
|
||||
virtual const QName* getTriggeringComponent() const = 0;
|
||||
|
||||
/**
|
||||
* getenclosingElementName
|
||||
*
|
||||
*/
|
||||
virtual const QName* getEnclosingElementName() const = 0;
|
||||
|
||||
/**
|
||||
* getAttributes
|
||||
*
|
||||
*/
|
||||
virtual const XMLAttDef* getAttributes() const = 0;
|
||||
|
||||
/**
|
||||
* setContextType
|
||||
*
|
||||
*/
|
||||
virtual void setContextType(ContextType) = 0;
|
||||
|
||||
/**
|
||||
* setTargetNamespace
|
||||
*
|
||||
*/
|
||||
virtual void setTargetNamespace(const XMLCh* const) = 0;
|
||||
|
||||
/**
|
||||
* setLocationHints
|
||||
*
|
||||
*/
|
||||
virtual void setLocationHints(const XMLCh* const) = 0;
|
||||
|
||||
/**
|
||||
* setTriggeringComponent
|
||||
*
|
||||
*/
|
||||
virtual void setTriggeringComponent(QName* const) = 0;
|
||||
|
||||
/**
|
||||
* getenclosingElementName
|
||||
*
|
||||
*/
|
||||
virtual void setEnclosingElementName(QName* const) = 0;
|
||||
|
||||
/**
|
||||
* setAttributes
|
||||
*
|
||||
*/
|
||||
virtual void setAttributes(XMLAttDef* const) = 0;
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XMLSchemaDescription)
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
/** Hidden Constructors */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLSchemaDescription(MemoryManager* const memMgr = XMLPlatformUtils::fgMemoryManager);
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
/** name Unimplemented copy constructor and operator= */
|
||||
// -----------------------------------------------------------------------
|
||||
//@{
|
||||
XMLSchemaDescription(const XMLSchemaDescription& );
|
||||
XMLSchemaDescription& operator=(const XMLSchemaDescription& );
|
||||
//@}
|
||||
|
||||
};
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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: XMLValidator.cpp 635560 2008-03-10 14:10:09Z borisk $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/framework/XMLValidator.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLInitializer.hpp>
|
||||
#include <xercesc/util/XMLMsgLoader.hpp>
|
||||
#include <xercesc/internal/XMLScanner.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
static XMLMsgLoader* sMsgLoader = 0;
|
||||
|
||||
void XMLInitializer::initializeXMLValidator()
|
||||
{
|
||||
sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain);
|
||||
|
||||
if (!sMsgLoader)
|
||||
XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain);
|
||||
}
|
||||
|
||||
void XMLInitializer::terminateXMLValidator()
|
||||
{
|
||||
delete sMsgLoader;
|
||||
sMsgLoader = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLValidator: Error emitting methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// These methods are called whenever the scanner wants to emit an error.
|
||||
// It handles getting the message loaded, doing token replacement, etc...
|
||||
// and then calling the error handler, if its installed.
|
||||
//
|
||||
void XMLValidator::emitError(const XMLValid::Codes toEmit)
|
||||
{
|
||||
// Bump the error count if it is not a warning
|
||||
if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
|
||||
fScanner->incrementErrorCount();
|
||||
|
||||
// Call error reporter if we have one
|
||||
if (fErrorReporter)
|
||||
{
|
||||
// Load the message into a local for display
|
||||
const XMLSize_t msgSize = 1023;
|
||||
XMLCh errText[msgSize + 1];
|
||||
|
||||
// load the text
|
||||
if (!sMsgLoader->loadMsg(toEmit, errText, msgSize))
|
||||
{
|
||||
// <TBD> Probably should load a default msg here
|
||||
}
|
||||
|
||||
//
|
||||
// Create a LastExtEntityInfo structure and get the reader manager
|
||||
// to fill it in for us. This will give us the information about
|
||||
// the last reader on the stack that was an external entity of some
|
||||
// sort (i.e. it will ignore internal entities.
|
||||
//
|
||||
ReaderMgr::LastExtEntityInfo lastInfo;
|
||||
fReaderMgr->getLastExtEntityInfo(lastInfo);
|
||||
|
||||
fErrorReporter->error
|
||||
(
|
||||
toEmit
|
||||
, XMLUni::fgValidityDomain
|
||||
, XMLValid::errorType(toEmit)
|
||||
, errText
|
||||
, lastInfo.systemId
|
||||
, lastInfo.publicId
|
||||
, lastInfo.lineNumber
|
||||
, lastInfo.colNumber
|
||||
);
|
||||
}
|
||||
|
||||
// Bail out if its fatal an we are to give up on the first fatal error
|
||||
if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
|
||||
|| XMLValid::isFatal(toEmit))
|
||||
&& fScanner->getExitOnFirstFatal()
|
||||
&& !fScanner->getInException())
|
||||
{
|
||||
throw toEmit;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLValidator::emitError(const XMLValid::Codes toEmit
|
||||
, const XMLCh* const text1
|
||||
, const XMLCh* const text2
|
||||
, const XMLCh* const text3
|
||||
, const XMLCh* const text4)
|
||||
{
|
||||
// Bump the error count if it is not a warning
|
||||
if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
|
||||
fScanner->incrementErrorCount();
|
||||
|
||||
// Call error reporter if we have one
|
||||
if (fErrorReporter)
|
||||
{
|
||||
//
|
||||
// Load the message into alocal and replace any tokens found in
|
||||
// the text.
|
||||
//
|
||||
const XMLSize_t maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
// load the text
|
||||
if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
|
||||
{
|
||||
// <TBD> Should probably load a default message here
|
||||
}
|
||||
|
||||
//
|
||||
// Create a LastExtEntityInfo structure and get the reader manager
|
||||
// to fill it in for us. This will give us the information about
|
||||
// the last reader on the stack that was an external entity of some
|
||||
// sort (i.e. it will ignore internal entities.
|
||||
//
|
||||
ReaderMgr::LastExtEntityInfo lastInfo;
|
||||
fReaderMgr->getLastExtEntityInfo(lastInfo);
|
||||
|
||||
fErrorReporter->error
|
||||
(
|
||||
toEmit
|
||||
, XMLUni::fgValidityDomain
|
||||
, XMLValid::errorType(toEmit)
|
||||
, errText
|
||||
, lastInfo.systemId
|
||||
, lastInfo.publicId
|
||||
, lastInfo.lineNumber
|
||||
, lastInfo.colNumber
|
||||
);
|
||||
}
|
||||
|
||||
// Bail out if its fatal an we are to give up on the first fatal error
|
||||
if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
|
||||
|| XMLValid::isFatal(toEmit))
|
||||
&& fScanner->getExitOnFirstFatal()
|
||||
&& !fScanner->getInException())
|
||||
{
|
||||
throw toEmit;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLValidator::emitError(const XMLValid::Codes toEmit
|
||||
, const char* const text1
|
||||
, const char* const text2
|
||||
, const char* const text3
|
||||
, const char* const text4)
|
||||
{
|
||||
// Bump the error count if it is not a warning
|
||||
if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
|
||||
fScanner->incrementErrorCount();
|
||||
|
||||
// Call error reporter if we have one
|
||||
if (fErrorReporter)
|
||||
{
|
||||
//
|
||||
// Load the message into alocal and replace any tokens found in
|
||||
// the text.
|
||||
//
|
||||
const XMLSize_t maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
// load the text
|
||||
if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
|
||||
{
|
||||
// <TBD> Should probably load a default message here
|
||||
}
|
||||
|
||||
//
|
||||
// Create a LastExtEntityInfo structure and get the reader manager
|
||||
// to fill it in for us. This will give us the information about
|
||||
// the last reader on the stack that was an external entity of some
|
||||
// sort (i.e. it will ignore internal entities.
|
||||
//
|
||||
ReaderMgr::LastExtEntityInfo lastInfo;
|
||||
fReaderMgr->getLastExtEntityInfo(lastInfo);
|
||||
|
||||
fErrorReporter->error
|
||||
(
|
||||
toEmit
|
||||
, XMLUni::fgValidityDomain
|
||||
, XMLValid::errorType(toEmit)
|
||||
, errText
|
||||
, lastInfo.systemId
|
||||
, lastInfo.publicId
|
||||
, lastInfo.lineNumber
|
||||
, lastInfo.colNumber
|
||||
);
|
||||
}
|
||||
|
||||
// Bail out if its fatal an we are to give up on the first fatal error
|
||||
if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
|
||||
|| XMLValid::isFatal(toEmit))
|
||||
&& fScanner->getExitOnFirstFatal()
|
||||
&& !fScanner->getInException())
|
||||
{
|
||||
throw toEmit;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLValidator::emitError(const XMLValid::Codes toEmit
|
||||
, const XMLExcepts::Codes originalExceptCode
|
||||
, const XMLCh* const text1
|
||||
, const XMLCh* const text2
|
||||
, const XMLCh* const text3
|
||||
, const XMLCh* const text4)
|
||||
{
|
||||
// Bump the error count if it is not a warning
|
||||
if (XMLValid::errorType(toEmit) != XMLErrorReporter::ErrType_Warning)
|
||||
fScanner->incrementErrorCount();
|
||||
|
||||
// Call error reporter if we have one
|
||||
if (fErrorReporter)
|
||||
{
|
||||
//
|
||||
// Load the message into alocal and replace any tokens found in
|
||||
// the text.
|
||||
//
|
||||
const XMLSize_t maxChars = 2047;
|
||||
XMLCh errText[maxChars + 1];
|
||||
|
||||
// load the text
|
||||
if (!sMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2, text3, text4, fScanner->getMemoryManager()))
|
||||
{
|
||||
// <TBD> Should probably load a default message here
|
||||
}
|
||||
|
||||
//
|
||||
// Create a LastExtEntityInfo structure and get the reader manager
|
||||
// to fill it in for us. This will give us the information about
|
||||
// the last reader on the stack that was an external entity of some
|
||||
// sort (i.e. it will ignore internal entities.
|
||||
//
|
||||
ReaderMgr::LastExtEntityInfo lastInfo;
|
||||
fReaderMgr->getLastExtEntityInfo(lastInfo);
|
||||
|
||||
fErrorReporter->error
|
||||
(
|
||||
originalExceptCode
|
||||
, XMLUni::fgExceptDomain //XMLUni::fgValidityDomain
|
||||
, XMLValid::errorType(toEmit)
|
||||
, errText
|
||||
, lastInfo.systemId
|
||||
, lastInfo.publicId
|
||||
, lastInfo.lineNumber
|
||||
, lastInfo.colNumber
|
||||
);
|
||||
}
|
||||
|
||||
// Bail out if its fatal an we are to give up on the first fatal error
|
||||
if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal())
|
||||
|| XMLValid::isFatal(toEmit))
|
||||
&& fScanner->getExitOnFirstFatal()
|
||||
&& !fScanner->getInException())
|
||||
{
|
||||
throw toEmit;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLValidator: Hidden Constructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLValidator::XMLValidator(XMLErrorReporter* const errReporter) :
|
||||
|
||||
fBufMgr(0)
|
||||
, fErrorReporter(errReporter)
|
||||
, fReaderMgr(0)
|
||||
, fScanner(0)
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
* 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: XMLValidator.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLVALIDATOR_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLVALIDATOR_HPP
|
||||
|
||||
#include <xercesc/framework/XMLAttr.hpp>
|
||||
#include <xercesc/framework/XMLValidityCodes.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class ReaderMgr;
|
||||
class XMLBufferMgr;
|
||||
class XMLElementDecl;
|
||||
class XMLScanner;
|
||||
class Grammar;
|
||||
|
||||
|
||||
/**
|
||||
* This abstract class provides the interface for all validators. This is
|
||||
* the simple amount of API that all validators must honor, in order for
|
||||
* the scanner to use them to do validation. All validators will actually
|
||||
* contain much more functionality than is accessible via this common API,
|
||||
* but that functionality requires that you know what type of validator you
|
||||
* are dealing with.
|
||||
*
|
||||
* Basically, at this level, the primary concern is to be able to query
|
||||
* core information about elements and attributes. Adding decls to the
|
||||
* validator requires that you go through the derived interface because they
|
||||
* all have their own decl types. At this level, we can return information
|
||||
* via the base decl classes, from which each validator derives its own
|
||||
* decl classes.
|
||||
*/
|
||||
class XMLPARSER_EXPORT XMLValidator : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, just the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The derived class should clean up its allocated data, then this class
|
||||
* will do the same for data allocated at this level.
|
||||
*/
|
||||
virtual ~XMLValidator()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The virtual validator interface
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual validator interface */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The derived class should look up its declaration of the passed element
|
||||
* from its element pool. It should then use the content model description
|
||||
* contained in that element declaration to validate that the passed list
|
||||
* of child elements are valid for that content model. The count can be
|
||||
* zero, indicating no child elements.
|
||||
*
|
||||
* Note that whitespace and text content are not validated here. Those are
|
||||
* handled by the scanner. So only element ids are provided here.
|
||||
*
|
||||
* @param elemDecl The element whose content is to be checked.
|
||||
*
|
||||
* @param children An array of element QName which represent the elements
|
||||
* found within the parent element, i.e. the content
|
||||
* to be validated.
|
||||
*
|
||||
* @param childCount The number of elements in the childIds array. It can
|
||||
* be zero if the element had none.
|
||||
*
|
||||
* @param indexFailingChild On return, it will contain the index of the
|
||||
* children failing validation, if the retun value
|
||||
* is false
|
||||
*
|
||||
*/
|
||||
virtual bool checkContent
|
||||
(
|
||||
XMLElementDecl* const elemDecl
|
||||
, QName** const children
|
||||
, XMLSize_t childCount
|
||||
, XMLSize_t* indexFailingChild
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* The derived class should fault in the passed XMLAttr value. It should
|
||||
* use the passeed attribute definition (which is passed via the base
|
||||
* type so it must often be downcast to the appropriate type for the
|
||||
* derived validator class), to fill in the passed attribute. This is done
|
||||
* as a performance enhancement since the derived class has more direct
|
||||
* access to the information.
|
||||
*/
|
||||
virtual void faultInAttr
|
||||
(
|
||||
XMLAttr& toFill
|
||||
, const XMLAttDef& attDef
|
||||
) const = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the scanner after a Grammar is scanned.
|
||||
*/
|
||||
virtual void preContentValidation(bool reuseGrammar,
|
||||
bool validateDefAttr = false) = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the scanner after the parse has completed. It
|
||||
* gives the validator a chance to check certain things that can only be
|
||||
* checked after the whole document has been parsed, such as referential
|
||||
* integrity of ID/IDREF pairs and so forth. The validator should just
|
||||
* issue errors for any problems it finds.
|
||||
*/
|
||||
virtual void postParseValidation() = 0;
|
||||
|
||||
/**
|
||||
* This method is called by the scanner before a new document is about
|
||||
* to start. It gives the validator a change to reset itself in preparation
|
||||
* for another validation pass.
|
||||
*/
|
||||
virtual void reset() = 0;
|
||||
|
||||
/**
|
||||
* The derived class should return a boolean that indicates whether it
|
||||
* requires namespace processing or not. Some do and some allow it to be
|
||||
* optional. This flag is used to control whether the client code's
|
||||
* requests to disable namespace processing can be honored or not.
|
||||
*/
|
||||
virtual bool requiresNamespaces() const = 0;
|
||||
|
||||
/**
|
||||
* The derived class should apply any rules to the passed attribute value
|
||||
* that are above and beyond those defined by XML 1.0. The scanner itself
|
||||
* will impose XML 1.0 rules, based on the type of the attribute. This
|
||||
* will generally be used to check things such as range checks and other
|
||||
* datatype related validation.
|
||||
*
|
||||
* If the value breaks any rules as defined by the derived class, it
|
||||
* should just issue errors as usual.
|
||||
*/
|
||||
virtual void validateAttrValue
|
||||
(
|
||||
const XMLAttDef* attDef
|
||||
, const XMLCh* const attrValue
|
||||
, bool preValidation = false
|
||||
, const XMLElementDecl* elemDecl = 0
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* The derived class should apply any rules to the passed element decl
|
||||
* that are above and beyond those defined by XML 1.0.
|
||||
*
|
||||
* If the value breaks any rules as defined by the derived class, it
|
||||
* should just issue errors as usual.
|
||||
*/
|
||||
virtual void validateElement
|
||||
(
|
||||
const XMLElementDecl* elemDef
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the Grammar used
|
||||
*/
|
||||
virtual Grammar* getGrammar() const =0;
|
||||
|
||||
/**
|
||||
* Set the Grammar
|
||||
*/
|
||||
virtual void setGrammar(Grammar* aGrammar) =0;
|
||||
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual DTD handler interface.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual DTD handler interface */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method allows the scanner to ask the validator if it handles
|
||||
* DTDs or not.
|
||||
*/
|
||||
virtual bool handlesDTD() const = 0;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Virtual Schema handler interface.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Virtual Schema handler interface */
|
||||
|
||||
/**
|
||||
* This method allows the scanner to ask the validator if it handles
|
||||
* Schema or not.
|
||||
*/
|
||||
virtual bool handlesSchema() const = 0;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
//
|
||||
// setScannerInfo() is called by the scanner to tell the validator
|
||||
// about the stuff it needs to have access to.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Setter methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* @param owningScanner This is a pointer to the scanner to which the
|
||||
* validator belongs. The validator will often
|
||||
* need to query state data from the scanner.
|
||||
*
|
||||
* @param readerMgr This is a pointer to the reader manager that is
|
||||
* being used by the scanner.
|
||||
*
|
||||
* @param bufMgr This is the buffer manager of the scanner. This
|
||||
* is provided as a convenience so that the validator
|
||||
* doesn't have to create its own buffer manager
|
||||
* during the parse process.
|
||||
*/
|
||||
void setScannerInfo
|
||||
(
|
||||
XMLScanner* const owningScanner
|
||||
, ReaderMgr* const readerMgr
|
||||
, XMLBufferMgr* const bufMgr
|
||||
);
|
||||
|
||||
/**
|
||||
* This method is called to set an error reporter on the validator via
|
||||
* which it will report any errors it sees during parsing or validation.
|
||||
* This is generally called by the owning scanner.
|
||||
*
|
||||
* @param errorReporter A pointer to the error reporter to use. This
|
||||
* is not adopted, just referenced so the caller
|
||||
* remains responsible for its cleanup, if any.
|
||||
*/
|
||||
void setErrorReporter
|
||||
(
|
||||
XMLErrorReporter* const errorReporter
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Error emitter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Error emittor methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This call is a convenience by which validators can emit errors. Most
|
||||
* of the grunt work of loading the text, getting the current source
|
||||
* location, ect... is handled here.
|
||||
*
|
||||
* If the loaded text has replacement parameters, then text strings can be
|
||||
* passed. These will be used to replace the tokens {0}, {1}, {2}, and {3}
|
||||
* in the order passed. So text1 will replace {0}, text2 will replace {1},
|
||||
* and so forth.
|
||||
*
|
||||
* textX Up to four replacement parameters. They can be provided
|
||||
* as either XMLCh strings, or local code page strings which
|
||||
* will be transcoded internally.
|
||||
*
|
||||
* @param toEmit The error code to emit. it must be one of the defined
|
||||
* validator error codes.
|
||||
*
|
||||
*/
|
||||
void emitError(const XMLValid::Codes toEmit);
|
||||
void emitError
|
||||
(
|
||||
const XMLValid::Codes toEmit
|
||||
, const XMLCh* const text1
|
||||
, const XMLCh* const text2 = 0
|
||||
, const XMLCh* const text3 = 0
|
||||
, const XMLCh* const text4 = 0
|
||||
);
|
||||
void emitError
|
||||
(
|
||||
const XMLValid::Codes toEmit
|
||||
, const char* const text1
|
||||
, const char* const text2 = 0
|
||||
, const char* const text3 = 0
|
||||
, const char* const text4 = 0
|
||||
);
|
||||
void emitError
|
||||
(
|
||||
const XMLValid::Codes toEmit
|
||||
, const XMLExcepts::Codes originalErrorCode
|
||||
, const XMLCh* const text1 = 0
|
||||
, const XMLCh* const text2 = 0
|
||||
, const XMLCh* const text3 = 0
|
||||
, const XMLCh* const text4 = 0
|
||||
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden constructors
|
||||
// -----------------------------------------------------------------------
|
||||
XMLValidator
|
||||
(
|
||||
XMLErrorReporter* const errReporter = 0
|
||||
);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected getters
|
||||
// -----------------------------------------------------------------------
|
||||
const XMLBufferMgr* getBufMgr() const;
|
||||
XMLBufferMgr* getBufMgr();
|
||||
const ReaderMgr* getReaderMgr() const;
|
||||
ReaderMgr* getReaderMgr();
|
||||
const XMLScanner* getScanner() const;
|
||||
XMLScanner* getScanner();
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented Constructors and Operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLValidator(const XMLValidator&);
|
||||
XMLValidator& operator=(const XMLValidator&);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fErrorReporter
|
||||
// The error reporter we are to use, if any.
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
XMLBufferMgr* fBufMgr;
|
||||
XMLErrorReporter* fErrorReporter;
|
||||
ReaderMgr* fReaderMgr;
|
||||
XMLScanner* fScanner;
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
inline void
|
||||
XMLValidator::setScannerInfo(XMLScanner* const owningScanner
|
||||
, ReaderMgr* const readerMgr
|
||||
, XMLBufferMgr* const bufMgr)
|
||||
{
|
||||
// We don't own any of these, we just reference them
|
||||
fScanner = owningScanner;
|
||||
fReaderMgr = readerMgr;
|
||||
fBufMgr = bufMgr;
|
||||
}
|
||||
|
||||
inline void
|
||||
XMLValidator::setErrorReporter(XMLErrorReporter* const errorReporter)
|
||||
{
|
||||
fErrorReporter = errorReporter;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLValidator: Protected getter
|
||||
// ---------------------------------------------------------------------------
|
||||
inline const XMLBufferMgr* XMLValidator::getBufMgr() const
|
||||
{
|
||||
return fBufMgr;
|
||||
}
|
||||
|
||||
inline XMLBufferMgr* XMLValidator::getBufMgr()
|
||||
{
|
||||
return fBufMgr;
|
||||
}
|
||||
|
||||
inline const ReaderMgr* XMLValidator::getReaderMgr() const
|
||||
{
|
||||
return fReaderMgr;
|
||||
}
|
||||
|
||||
inline ReaderMgr* XMLValidator::getReaderMgr()
|
||||
{
|
||||
return fReaderMgr;
|
||||
}
|
||||
|
||||
inline const XMLScanner* XMLValidator::getScanner() const
|
||||
{
|
||||
return fScanner;
|
||||
}
|
||||
|
||||
inline XMLScanner* XMLValidator::getScanner()
|
||||
{
|
||||
return fScanner;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,147 @@
|
||||
// This file is generated, don't edit it!!
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_ERRHEADER_XMLValid)
|
||||
#define XERCESC_INCLUDE_GUARD_ERRHEADER_XMLValid
|
||||
|
||||
#include <xercesc/framework/XMLErrorReporter.hpp>
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/dom/DOMError.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLValid
|
||||
{
|
||||
public :
|
||||
enum Codes
|
||||
{
|
||||
NoError = 0
|
||||
, E_LowBounds = 1
|
||||
, ElementNotDefined = 2
|
||||
, AttNotDefined = 3
|
||||
, NotationNotDeclared = 4
|
||||
, RootElemNotLikeDocType = 5
|
||||
, RequiredAttrNotProvided = 6
|
||||
, ElementNotValidForContent = 7
|
||||
, BadIDAttrDefType = 8
|
||||
, InvalidEmptyAttValue = 9
|
||||
, ElementAlreadyExists = 10
|
||||
, MultipleIdAttrs = 11
|
||||
, ReusedIDValue = 12
|
||||
, IDNotDeclared = 13
|
||||
, UnknownNotRefAttr = 14
|
||||
, UndeclaredElemInDocType = 15
|
||||
, EmptyNotValidForContent = 16
|
||||
, AttNotDefinedForElement = 17
|
||||
, BadEntityRefAttr = 18
|
||||
, UnknownEntityRefAttr = 19
|
||||
, ColonNotValidWithNS = 20
|
||||
, NotEnoughElemsForCM = 21
|
||||
, NoCharDataInCM = 22
|
||||
, DoesNotMatchEnumList = 23
|
||||
, AttrValNotName = 24
|
||||
, NoMultipleValues = 25
|
||||
, NotSameAsFixedValue = 26
|
||||
, RepElemInMixed = 27
|
||||
, FeatureUnsupported = 28
|
||||
, GroupContentRestricted = 29
|
||||
, UnknownBaseDatatype = 30
|
||||
, NoContentForRef = 31
|
||||
, DatatypeError = 32
|
||||
, ProhibitedAttributePresent = 33
|
||||
, IllegalXMLSpace = 34
|
||||
, WrongTargetNamespace = 35
|
||||
, SimpleTypeHasChild = 36
|
||||
, NoDatatypeValidatorForSimpleType = 37
|
||||
, GrammarNotFound = 38
|
||||
, DisplayErrorMessage = 39
|
||||
, NillNotAllowed = 40
|
||||
, NilAttrNotEmpty = 41
|
||||
, FixedDifferentFromActual = 42
|
||||
, NoDatatypeValidatorForAttribute = 43
|
||||
, GenericError = 44
|
||||
, ElementNotQualified = 45
|
||||
, ElementNotUnQualified = 46
|
||||
, VC_IllegalRefInStandalone = 47
|
||||
, NoDefAttForStandalone = 48
|
||||
, NoAttNormForStandalone = 49
|
||||
, NoWSForStandalone = 50
|
||||
, VC_EntityNotFound = 51
|
||||
, PartialMarkupInPE = 52
|
||||
, DatatypeValidationFailure = 53
|
||||
, UniqueParticleAttributionFail = 54
|
||||
, NoAbstractInXsiType = 55
|
||||
, NoDirectUseAbstractElement = 56
|
||||
, NoUseAbstractType = 57
|
||||
, BadXsiType = 58
|
||||
, NonDerivedXsiType = 59
|
||||
, ElemNoSubforBlock = 60
|
||||
, TypeNoSubforBlock = 61
|
||||
, AttributeNotQualified = 62
|
||||
, AttributeNotUnQualified = 63
|
||||
, IC_FieldMultipleMatch = 64
|
||||
, IC_UnknownField = 65
|
||||
, IC_AbsentKeyValue = 66
|
||||
, IC_KeyNotEnoughValues = 67
|
||||
, IC_KeyMatchesNillable = 68
|
||||
, IC_DuplicateUnique = 69
|
||||
, IC_DuplicateKey = 70
|
||||
, IC_KeyRefOutOfScope = 71
|
||||
, IC_KeyNotFound = 72
|
||||
, NonWSContent = 73
|
||||
, EmptyElemNotationAttr = 74
|
||||
, EmptyElemHasContent = 75
|
||||
, ElemOneNotationAttr = 76
|
||||
, AttrDupToken = 77
|
||||
, ElemChildrenHasInvalidWS = 78
|
||||
, E_HighBounds = 79
|
||||
, W_LowBounds = 80
|
||||
, W_HighBounds = 81
|
||||
, F_LowBounds = 82
|
||||
, F_HighBounds = 83
|
||||
};
|
||||
|
||||
static bool isFatal(const XMLValid::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));
|
||||
}
|
||||
|
||||
static bool isWarning(const XMLValid::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));
|
||||
}
|
||||
|
||||
static bool isError(const XMLValid::Codes toCheck)
|
||||
{
|
||||
return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));
|
||||
}
|
||||
|
||||
static XMLErrorReporter::ErrTypes errorType(const XMLValid::Codes toCheck)
|
||||
{
|
||||
if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Warning;
|
||||
else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Fatal;
|
||||
else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))
|
||||
return XMLErrorReporter::ErrType_Error;
|
||||
return XMLErrorReporter::ErrTypes_Unknown;
|
||||
}
|
||||
static DOMError::ErrorSeverity DOMErrorType(const XMLValid::Codes toCheck)
|
||||
{
|
||||
if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))
|
||||
return DOMError::DOM_SEVERITY_WARNING;
|
||||
else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))
|
||||
return DOMError::DOM_SEVERITY_FATAL_ERROR;
|
||||
else return DOMError::DOM_SEVERITY_ERROR;
|
||||
}
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLValid();
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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: PSVIAttribute.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIAttribute.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
PSVIAttribute::PSVIAttribute( MemoryManager* const manager ):
|
||||
PSVIItem(manager)
|
||||
, fAttributeDecl(0)
|
||||
, fDV(0)
|
||||
{
|
||||
}
|
||||
|
||||
void PSVIAttribute::reset(
|
||||
const XMLCh * const valContext
|
||||
, PSVIItem::VALIDITY_STATE state
|
||||
, PSVIItem::ASSESSMENT_TYPE assessmentType
|
||||
, XSSimpleTypeDefinition * validatingType
|
||||
, XSSimpleTypeDefinition * memberType
|
||||
, const XMLCh * const defaultValue
|
||||
, const bool isSpecified
|
||||
, XSAttributeDeclaration * attrDecl
|
||||
, DatatypeValidator *dv
|
||||
)
|
||||
{
|
||||
fValidationContext = valContext;
|
||||
fValidityState = state;
|
||||
fAssessmentType = assessmentType;
|
||||
fType = validatingType;
|
||||
fMemberType = memberType;
|
||||
fDefaultValue = defaultValue;
|
||||
fIsSpecified = isSpecified;
|
||||
fMemoryManager->deallocate((void *)fCanonicalValue);
|
||||
fCanonicalValue = 0;
|
||||
fNormalizedValue = 0;
|
||||
fAttributeDecl = attrDecl;
|
||||
fDV = dv;
|
||||
}
|
||||
|
||||
void PSVIAttribute::setValue(const XMLCh * const normalizedValue)
|
||||
{
|
||||
if(normalizedValue)
|
||||
{
|
||||
fNormalizedValue = normalizedValue;
|
||||
if(fDV && fValidityState == PSVIItem::VALIDITY_VALID)
|
||||
fCanonicalValue = (XMLCh *)fDV->getCanonicalRepresentation(normalizedValue, fMemoryManager);
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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: PSVIAttribute.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PSVIATTRIBUTE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PSVIATTRIBUTE_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIItem.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
#include <xercesc/validators/datatype/DatatypeValidator.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Represent the PSVI contributions for one attribute information item.
|
||||
* This is *always* owned by the scanner/parser object from which
|
||||
* it is obtained. The validator will specify
|
||||
* under what conditions it may be relied upon to have meaningful contents.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAttributeDeclaration;
|
||||
|
||||
class XMLPARSER_EXPORT PSVIAttribute : public PSVIItem
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
PSVIAttribute( MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~PSVIAttribute();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name PSVIAttribute methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* An item isomorphic to the attribute declaration used to validate
|
||||
* this attribute.
|
||||
*
|
||||
* @return an attribute declaration
|
||||
*/
|
||||
XSAttributeDeclaration *getAttributeDeclaration();
|
||||
|
||||
/**
|
||||
* An item isomorphic to the type definition used to validate this element.
|
||||
*
|
||||
* @return a type declaration
|
||||
*/
|
||||
XSTypeDefinition *getTypeDefinition();
|
||||
|
||||
/**
|
||||
* If and only if that type definition is a simple type definition
|
||||
* with {variety} union, or a complex type definition whose {content type}
|
||||
* is a simple thype definition with {variety} union, then an item isomorphic
|
||||
* to that member of the union's {member type definitions} which actually
|
||||
* validated the element item's normalized value.
|
||||
*
|
||||
* @return a simple type declaration
|
||||
*/
|
||||
XSSimpleTypeDefinition *getMemberTypeDefinition();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* reset this object. Intended to be called by
|
||||
* the implementation.
|
||||
*/
|
||||
void reset(
|
||||
const XMLCh * const valContext
|
||||
, PSVIItem::VALIDITY_STATE state
|
||||
, PSVIItem::ASSESSMENT_TYPE assessmentType
|
||||
, XSSimpleTypeDefinition * validatingType
|
||||
, XSSimpleTypeDefinition * memberType
|
||||
, const XMLCh * const defaultValue
|
||||
, const bool isSpecified
|
||||
, XSAttributeDeclaration * attrDecl
|
||||
, DatatypeValidator * dv
|
||||
);
|
||||
|
||||
/**
|
||||
* set the schema normalized value (and
|
||||
* implicitly the canonical value) of this object; intended to be used
|
||||
* by the implementation.
|
||||
*/
|
||||
void setValue(const XMLCh * const normalizedValue);
|
||||
|
||||
/**
|
||||
* set VALIDITY_STATE to specified value; intended to be
|
||||
* called by implementation.
|
||||
*/
|
||||
void updateValidity(VALIDITY_STATE newValue);
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIAttribute(const PSVIAttribute&);
|
||||
PSVIAttribute & operator=(const PSVIAttribute &);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
// fAttributeDecl
|
||||
// attribute declaration component that validated this attribute
|
||||
// fDV
|
||||
// implementation-specific datatype validator used to validate this attribute
|
||||
XSAttributeDeclaration * fAttributeDecl;
|
||||
DatatypeValidator * fDV;
|
||||
};
|
||||
inline PSVIAttribute::~PSVIAttribute()
|
||||
{
|
||||
fMemoryManager->deallocate((void *)fCanonicalValue);
|
||||
}
|
||||
|
||||
inline XSAttributeDeclaration *PSVIAttribute::getAttributeDeclaration()
|
||||
{
|
||||
return fAttributeDecl;
|
||||
}
|
||||
|
||||
inline XSTypeDefinition* PSVIAttribute::getTypeDefinition()
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
|
||||
inline XSSimpleTypeDefinition* PSVIAttribute::getMemberTypeDefinition()
|
||||
{
|
||||
return fMemberType;
|
||||
}
|
||||
|
||||
inline void PSVIAttribute::updateValidity(VALIDITY_STATE newValue)
|
||||
{
|
||||
fValidityState = newValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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: PSVIAttributeList.cpp 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIAttributeList.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
PSVIAttributeList::PSVIAttributeList( MemoryManager* const manager ):
|
||||
fMemoryManager(manager)
|
||||
, fAttrList(0)
|
||||
, fAttrPos(0)
|
||||
{
|
||||
fAttrList= new (fMemoryManager) RefVectorOf<PSVIAttributeStorage> (10, true, fMemoryManager);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the number of attributes whose PSVI contributions
|
||||
* are contained in this list.
|
||||
*/
|
||||
XMLSize_t PSVIAttributeList::getLength() const
|
||||
{
|
||||
return fAttrPos;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the PSVI contribution of attribute at position i
|
||||
* in this list. Indeces start from 0.
|
||||
* @param index index from which the attribute PSVI contribution
|
||||
* is to come.
|
||||
* @return PSVIAttribute containing the attributes PSVI contributions;
|
||||
* null is returned if the index is out of range.
|
||||
*/
|
||||
PSVIAttribute *PSVIAttributeList::getAttributePSVIAtIndex(const XMLSize_t index)
|
||||
{
|
||||
if(index >= fAttrPos)
|
||||
return 0;
|
||||
return fAttrList->elementAt(index)->fPSVIAttribute;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get local part of attribute name at position index in the list.
|
||||
* Indeces start from 0.
|
||||
* @param index index from which the attribute name
|
||||
* is to come.
|
||||
* @return local part of the attribute's name; null is returned if the index
|
||||
* is out of range.
|
||||
*/
|
||||
const XMLCh *PSVIAttributeList::getAttributeNameAtIndex(const XMLSize_t index)
|
||||
{
|
||||
|
||||
if(index >= fAttrPos)
|
||||
return 0;
|
||||
return fAttrList->elementAt(index)->fAttributeName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get namespace of attribute at position index in the list.
|
||||
* Indeces start from 0.
|
||||
* @param index index from which the attribute namespace
|
||||
* is to come.
|
||||
* @return namespace of the attribute;
|
||||
* null is returned if the index is out of range.
|
||||
*/
|
||||
const XMLCh *PSVIAttributeList::getAttributeNamespaceAtIndex(const XMLSize_t index)
|
||||
{
|
||||
if(index >= fAttrPos)
|
||||
return 0;
|
||||
return fAttrList->elementAt(index)->fAttributeNamespace;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the PSVI contribution of attribute with given
|
||||
* local name and namespace.
|
||||
* @param attrName local part of the attribute's name
|
||||
* @param attrNamespace namespace of the attribute
|
||||
* @return null if the attribute PSVI does not exist
|
||||
*/
|
||||
PSVIAttribute *PSVIAttributeList::getAttributePSVIByName(const XMLCh *attrName
|
||||
, const XMLCh * attrNamespace)
|
||||
{
|
||||
for (XMLSize_t index=0; index < fAttrPos; index++) {
|
||||
PSVIAttributeStorage* storage = fAttrList->elementAt(index);
|
||||
if (XMLString::equals(attrName,storage->fAttributeName) &&
|
||||
XMLString::equals(attrNamespace,storage->fAttributeNamespace))
|
||||
return storage->fPSVIAttribute;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* 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: PSVIAttributeList.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PSVIATTRIBUTE_LIST_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PSVIATTRIBUTE_LIST_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/psvi/PSVIAttribute.hpp>
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* A container for the PSVI contributions to attributes that occur
|
||||
* on a particular element.
|
||||
* This is always owned by the parser/validator from
|
||||
* which it is obtained. The parser/validator will specify
|
||||
* under what conditions it may be relied upon to have meaningful contents.
|
||||
*/
|
||||
|
||||
class XMLPARSER_EXPORT PSVIAttributeStorage : public XMemory
|
||||
{
|
||||
public:
|
||||
PSVIAttributeStorage() :
|
||||
fPSVIAttribute(0)
|
||||
, fAttributeName(0)
|
||||
, fAttributeNamespace(0)
|
||||
{
|
||||
}
|
||||
|
||||
~PSVIAttributeStorage()
|
||||
{
|
||||
delete fPSVIAttribute;
|
||||
}
|
||||
|
||||
PSVIAttribute* fPSVIAttribute;
|
||||
const XMLCh* fAttributeName;
|
||||
const XMLCh* fAttributeNamespace;
|
||||
};
|
||||
|
||||
class XMLPARSER_EXPORT PSVIAttributeList : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
PSVIAttributeList( MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~PSVIAttributeList();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name PSVIAttributeList methods */
|
||||
|
||||
//@{
|
||||
|
||||
/*
|
||||
* Get the number of attributes whose PSVI contributions
|
||||
* are contained in this list.
|
||||
*/
|
||||
XMLSize_t getLength() const;
|
||||
|
||||
/*
|
||||
* Get the PSVI contribution of attribute at position i
|
||||
* in this list. Indices start from 0.
|
||||
* @param index index from which the attribute PSVI contribution
|
||||
* is to come.
|
||||
* @return PSVIAttribute containing the attributes PSVI contributions;
|
||||
* null is returned if the index is out of range.
|
||||
*/
|
||||
PSVIAttribute *getAttributePSVIAtIndex(const XMLSize_t index);
|
||||
|
||||
/*
|
||||
* Get local part of attribute name at position index in the list.
|
||||
* Indices start from 0.
|
||||
* @param index index from which the attribute name
|
||||
* is to come.
|
||||
* @return local part of the attribute's name; null is returned if the index
|
||||
* is out of range.
|
||||
*/
|
||||
const XMLCh *getAttributeNameAtIndex(const XMLSize_t index);
|
||||
|
||||
/*
|
||||
* Get namespace of attribute at position index in the list.
|
||||
* Indices start from 0.
|
||||
* @param index index from which the attribute namespace
|
||||
* is to come.
|
||||
* @return namespace of the attribute;
|
||||
* null is returned if the index is out of range.
|
||||
*/
|
||||
const XMLCh *getAttributeNamespaceAtIndex(const XMLSize_t index);
|
||||
|
||||
/*
|
||||
* Get the PSVI contribution of attribute with given
|
||||
* local name and namespace.
|
||||
* @param attrName local part of the attribute's name
|
||||
* @param attrNamespace namespace of the attribute
|
||||
* @return null if the attribute PSVI does not exist
|
||||
*/
|
||||
PSVIAttribute *getAttributePSVIByName(const XMLCh *attrName
|
||||
, const XMLCh * attrNamespace);
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* returns a PSVI attribute of undetermined state and given name/namespace and
|
||||
* makes that object part of the internal list. Intended to be called
|
||||
* during validation of an element.
|
||||
* @param attrName name of this attribute
|
||||
* @param attrNS URI of the attribute
|
||||
* @return new, uninitialized, PSVIAttribute object
|
||||
*/
|
||||
PSVIAttribute *getPSVIAttributeToFill(
|
||||
const XMLCh * attrName
|
||||
, const XMLCh * attrNS);
|
||||
|
||||
/**
|
||||
* reset the list
|
||||
*/
|
||||
void reset();
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIAttributeList(const PSVIAttributeList&);
|
||||
PSVIAttributeList & operator=(const PSVIAttributeList &);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
// fMemoryManager
|
||||
// handler to provide dynamically-need memory
|
||||
// fAttrList
|
||||
// list of PSVIAttributes contained by this object
|
||||
// fAttrPos
|
||||
// current number of initialized PSVIAttributes in fAttrList
|
||||
MemoryManager* fMemoryManager;
|
||||
RefVectorOf<PSVIAttributeStorage>* fAttrList;
|
||||
XMLSize_t fAttrPos;
|
||||
};
|
||||
|
||||
inline PSVIAttributeList::~PSVIAttributeList()
|
||||
{
|
||||
delete fAttrList;
|
||||
}
|
||||
|
||||
inline PSVIAttribute *PSVIAttributeList::getPSVIAttributeToFill(
|
||||
const XMLCh *attrName
|
||||
, const XMLCh * attrNS)
|
||||
{
|
||||
PSVIAttributeStorage* storage = 0;
|
||||
if(fAttrPos == fAttrList->size())
|
||||
{
|
||||
storage = new (fMemoryManager) PSVIAttributeStorage();
|
||||
storage->fPSVIAttribute = new (fMemoryManager) PSVIAttribute(fMemoryManager);
|
||||
fAttrList->addElement(storage);
|
||||
}
|
||||
else
|
||||
{
|
||||
storage = fAttrList->elementAt(fAttrPos);
|
||||
}
|
||||
storage->fAttributeName = attrName;
|
||||
storage->fAttributeNamespace = attrNS;
|
||||
fAttrPos++;
|
||||
return storage->fPSVIAttribute;
|
||||
}
|
||||
|
||||
inline void PSVIAttributeList::reset()
|
||||
{
|
||||
fAttrPos = 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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: PSVIElement.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIElement.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
PSVIElement::PSVIElement(MemoryManager* const manager):
|
||||
PSVIItem(manager),
|
||||
fElementDecl(0),
|
||||
fNotationDecl(0),
|
||||
fSchemaInfo(0)
|
||||
{
|
||||
}
|
||||
|
||||
PSVIElement::~PSVIElement()
|
||||
{
|
||||
fMemoryManager->deallocate(fCanonicalValue);
|
||||
}
|
||||
|
||||
XSTypeDefinition* PSVIElement::getTypeDefinition()
|
||||
{
|
||||
return fType;
|
||||
}
|
||||
|
||||
/**
|
||||
* If and only if that type definition is a simple type definition
|
||||
* with {variety} union, or a complex type definition whose {content type}
|
||||
* is a simple type definition with {variety} union,
|
||||
|
||||
* then an item isomorphic
|
||||
* to that member of the union's {member type definitions} which actually
|
||||
* validated the element item's normalized value.
|
||||
*
|
||||
* @return a simple type declaration
|
||||
*/
|
||||
XSSimpleTypeDefinition* PSVIElement::getMemberTypeDefinition()
|
||||
{
|
||||
return fMemberType;
|
||||
}
|
||||
|
||||
void PSVIElement::reset( const VALIDITY_STATE validityState
|
||||
, const ASSESSMENT_TYPE assessmentType
|
||||
, const XMLCh* const validationContext
|
||||
, bool isSpecified
|
||||
, XSElementDeclaration* const elemDecl
|
||||
, XSTypeDefinition* const typeDef
|
||||
, XSSimpleTypeDefinition* const memberType
|
||||
, XSModel* const schemaInfo
|
||||
, const XMLCh* const defaultValue
|
||||
, const XMLCh* const normalizedValue
|
||||
, XMLCh* const canonicalValue
|
||||
, XSNotationDeclaration* const notationDecl)
|
||||
{
|
||||
fValidationContext = validationContext;
|
||||
fValidityState = validityState;
|
||||
fAssessmentType = assessmentType;
|
||||
fIsSpecified = isSpecified;
|
||||
fType = typeDef;
|
||||
fMemberType = memberType;
|
||||
fElementDecl = elemDecl;
|
||||
fNotationDecl = notationDecl;
|
||||
fSchemaInfo = schemaInfo;
|
||||
fDefaultValue = defaultValue;
|
||||
fNormalizedValue = normalizedValue;
|
||||
fMemoryManager->deallocate(fCanonicalValue);
|
||||
fCanonicalValue = canonicalValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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: PSVIElement.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PSVIELEMENT_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PSVIELEMENT_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIItem.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Represent the PSVI contributions for one element information item.
|
||||
* This is *always* owned by the scanner/parser object from which
|
||||
* it is obtained. The validator will specify
|
||||
* under what conditions it may be relied upon to have meaningful contents.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSElementDeclaration;
|
||||
class XSNotationDeclaration;
|
||||
class XSModel;
|
||||
|
||||
class XMLPARSER_EXPORT PSVIElement : public PSVIItem
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
PSVIElement( MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~PSVIElement();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name PSVIElement methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* An item isomorphic to the element declaration used to validate
|
||||
* this element.
|
||||
*
|
||||
* @return an element declaration
|
||||
*/
|
||||
XSElementDeclaration *getElementDeclaration();
|
||||
|
||||
/**
|
||||
* [notation]
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-notation">XML Schema Part 1: Structures [notation]</a>
|
||||
* @return The notation declaration.
|
||||
*/
|
||||
XSNotationDeclaration *getNotationDeclaration();
|
||||
|
||||
/**
|
||||
* [schema information]
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a>
|
||||
* @return The schema information property if it's the validation root,
|
||||
* null otherwise.
|
||||
*/
|
||||
XSModel *getSchemaInformation();
|
||||
|
||||
/**
|
||||
* An item isomorphic to the type definition used to validate this element.
|
||||
*
|
||||
* @return a type declaration
|
||||
*/
|
||||
XSTypeDefinition *getTypeDefinition();
|
||||
|
||||
/**
|
||||
* If and only if that type definition is a simple type definition
|
||||
* with {variety} union, or a complex type definition whose {content type}
|
||||
* is a simple type definition with {variety} union, then an item isomorphic
|
||||
* to that member of the union's {member type definitions} which actually
|
||||
* validated the element item's normalized value.
|
||||
*
|
||||
* @return a simple type declaration
|
||||
*/
|
||||
XSSimpleTypeDefinition *getMemberTypeDefinition();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
void reset
|
||||
(
|
||||
const VALIDITY_STATE validityState
|
||||
, const ASSESSMENT_TYPE assessmentType
|
||||
, const XMLCh* const validationContext
|
||||
, bool isSpecified
|
||||
, XSElementDeclaration* const elemDecl
|
||||
, XSTypeDefinition* const typeDef
|
||||
, XSSimpleTypeDefinition* const memberType
|
||||
, XSModel* const schemaInfo
|
||||
, const XMLCh* const defaultValue
|
||||
, const XMLCh* const normalizedValue = 0
|
||||
, XMLCh* const canonicalValue = 0
|
||||
, XSNotationDeclaration* const notationDecl = 0
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIElement(const PSVIElement&);
|
||||
PSVIElement & operator=(const PSVIElement &);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
// fElementDecl
|
||||
// element declaration component that validated this element
|
||||
// fNotationDecl
|
||||
// (optional) notation decl associated with this element
|
||||
// fSchemaInfo
|
||||
// Schema Information Item with which this validation episode is associated
|
||||
XSElementDeclaration *fElementDecl;
|
||||
XSNotationDeclaration *fNotationDecl;
|
||||
XSModel *fSchemaInfo;
|
||||
};
|
||||
|
||||
inline XSElementDeclaration *PSVIElement::getElementDeclaration()
|
||||
{
|
||||
return fElementDecl;
|
||||
}
|
||||
|
||||
inline XSNotationDeclaration* PSVIElement::getNotationDeclaration()
|
||||
{
|
||||
return fNotationDecl;
|
||||
}
|
||||
|
||||
inline XSModel* PSVIElement::getSchemaInformation()
|
||||
{
|
||||
return fSchemaInfo;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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: PSVIHandler.hpp 676796 2008-07-15 05:04:13Z dbertoni $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PSVIHANDLER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PSVIHANDLER_HPP
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
class PSVIElement;
|
||||
class PSVIAttributeList;
|
||||
|
||||
|
||||
/**
|
||||
* This abstract class provides the interface for the scanner to return
|
||||
* PSVI information to the application.
|
||||
*
|
||||
*/
|
||||
class XMLPARSER_EXPORT PSVIHandler
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors are hidden, just the virtual destructor is exposed
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~PSVIHandler()
|
||||
{
|
||||
}
|
||||
//@}
|
||||
|
||||
/** @name The PSVI handler interface */
|
||||
//@{
|
||||
/** Receive notification of the PSVI properties of an element.
|
||||
* The scanner will issue this call after the XMLDocumentHandler
|
||||
* endElement call. Since the scanner will issue the psviAttributes
|
||||
* call immediately after reading the start tag of an element, all element
|
||||
* content will be effectively bracketed by these two calls.
|
||||
* @param localName The name of the element whose end tag was just
|
||||
* parsed.
|
||||
* @param uri The namespace to which the element is bound
|
||||
* @param elementInfo Object containing the element's PSVI properties
|
||||
*/
|
||||
virtual void handleElementPSVI
|
||||
(
|
||||
const XMLCh* const localName
|
||||
, const XMLCh* const uri
|
||||
, PSVIElement * elementInfo
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Receive notification of partial PSVI properties of an element.
|
||||
* This callback is made right after the psviAttributes
|
||||
* call for non-empty element.
|
||||
*
|
||||
* The PSVIElement passed in has all fields properly set and it
|
||||
* can be safely accessed the same way as the one passed in handleElementPSVI.
|
||||
* However, fields listed below always have default values.
|
||||
*
|
||||
* getValidity() PSVIItem::VALIDITY_NOTKNOWN
|
||||
* getValidationAttemped() PSVIItem::VALIDATION_NONE
|
||||
* getMemberTypeDefinition() 0
|
||||
* getSchemaNormalizedValue() 0
|
||||
* getCanonicalRepresentation() 0
|
||||
* getNotationDeclaration() 0
|
||||
*
|
||||
*
|
||||
* @param localName The name of the element upon which start tag
|
||||
* these attributes were encountered.
|
||||
* @param uri The namespace to which the element is bound
|
||||
* @param elementInfo Object containing the element's partial PSVI properties
|
||||
*/
|
||||
virtual void handlePartialElementPSVI
|
||||
(
|
||||
const XMLCh* const localName
|
||||
, const XMLCh* const uri
|
||||
, PSVIElement * elementInfo
|
||||
);
|
||||
|
||||
/**
|
||||
* Enables PSVI information about attributes to be passed back to the
|
||||
* application. This callback will be made on *all*
|
||||
* elements; on elements with no attributes, the final parameter will
|
||||
* be null.
|
||||
* @param localName The name of the element upon which start tag
|
||||
* these attributes were encountered.
|
||||
* @param uri The namespace to which the element is bound
|
||||
* @param psviAttributes Object containing the attributes' PSVI properties
|
||||
* with information to identify them.
|
||||
*/
|
||||
virtual void handleAttributesPSVI
|
||||
(
|
||||
const XMLCh* const localName
|
||||
, const XMLCh* const uri
|
||||
, PSVIAttributeList * psviAttributes
|
||||
) = 0;
|
||||
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
|
||||
protected :
|
||||
// -----------------------------------------------------------------------
|
||||
// Hidden Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIHandler()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIHandler(const PSVIHandler&);
|
||||
PSVIHandler& operator=(const PSVIHandler&);
|
||||
};
|
||||
|
||||
inline void PSVIHandler::handlePartialElementPSVI(const XMLCh* const /*localName*/
|
||||
, const XMLCh* const /*uri*/
|
||||
, PSVIElement * /*elementInfo*/
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
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: PSVIItem.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/PSVIItem.hpp>
|
||||
#include <xercesc/framework/psvi/XSValue.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
PSVIItem::PSVIItem( MemoryManager* const manager ):
|
||||
fMemoryManager(manager),
|
||||
fValidationContext(0),
|
||||
fNormalizedValue(0),
|
||||
fDefaultValue(0),
|
||||
fCanonicalValue(0),
|
||||
fValidityState(VALIDITY_NOTKNOWN),
|
||||
fAssessmentType(VALIDATION_FULL),
|
||||
fIsSpecified(false),
|
||||
fType(0),
|
||||
fMemberType(0)
|
||||
{
|
||||
}
|
||||
|
||||
void PSVIItem::reset(
|
||||
const XMLCh* const validationContext
|
||||
, const XMLCh* const normalizedValue
|
||||
, const VALIDITY_STATE validityState
|
||||
, const ASSESSMENT_TYPE assessmentType
|
||||
)
|
||||
{
|
||||
// this is just a wrapper method; fValidationContext will
|
||||
// be valid as long as and no longer than the thing to which
|
||||
// validationContext points
|
||||
fValidationContext = validationContext;
|
||||
fNormalizedValue = normalizedValue;
|
||||
fValidityState = validityState;
|
||||
fAssessmentType = assessmentType;
|
||||
}
|
||||
|
||||
void PSVIItem::setValidationAttempted(PSVIItem::ASSESSMENT_TYPE attemptType)
|
||||
{
|
||||
fAssessmentType = attemptType;
|
||||
}
|
||||
|
||||
void PSVIItem::setValidity(PSVIItem::VALIDITY_STATE validity)
|
||||
{
|
||||
fValidityState = validity;
|
||||
}
|
||||
|
||||
XSValue* PSVIItem::getActualValue() const
|
||||
{
|
||||
/***
|
||||
* assessment
|
||||
* VALIDATION_PARTIAL
|
||||
* VALIDATION_FULL
|
||||
* validity
|
||||
* VALIDITY_VALID
|
||||
***/
|
||||
if ((fAssessmentType==VALIDATION_NONE) || (fValidityState!=VALIDITY_VALID))
|
||||
return 0;
|
||||
|
||||
/***
|
||||
* XSSimpleType or
|
||||
* XSComplexType's CONTENTTYPE_SIMPLE
|
||||
* allowed
|
||||
***/
|
||||
if ((!fType) ||
|
||||
((fType->getTypeCategory() == XSTypeDefinition::COMPLEX_TYPE) &&
|
||||
(((XSComplexTypeDefinition*)fType)->getContentType() != XSComplexTypeDefinition::CONTENTTYPE_SIMPLE)))
|
||||
return 0;
|
||||
|
||||
/***
|
||||
* Resolve dv
|
||||
*
|
||||
* 1. If fMemberType is not null, use the fMemberType->fDataTypeValidator
|
||||
* 2. If fType is XSSimpleType, use fType->fDataTypeValidator
|
||||
* 3. If fType is XSComplexType, use fType->fXSSimpleTypeDefinition-> fDataTypeValidator
|
||||
*
|
||||
***/
|
||||
|
||||
DatatypeValidator *dv = 0;
|
||||
|
||||
if (fMemberType)
|
||||
{
|
||||
/***
|
||||
* Now that fType is either XSSimpleTypeDefinition or
|
||||
* XSComlextTypeDefinition with CONTENTTYPE_SIMPLE, the
|
||||
* fMemberType must be XSSimpleTypeDefinition if present
|
||||
***/
|
||||
dv=((XSSimpleTypeDefinition*) fMemberType)->getDatatypeValidator();
|
||||
}
|
||||
else if (fType->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE)
|
||||
{
|
||||
dv=((XSSimpleTypeDefinition*) fType)->getDatatypeValidator();
|
||||
}
|
||||
else
|
||||
{
|
||||
XSSimpleTypeDefinition* simType = ((XSComplexTypeDefinition*)fType)->getSimpleType();
|
||||
if (simType)
|
||||
dv = simType->getDatatypeValidator();
|
||||
}
|
||||
|
||||
if (!dv) return 0;
|
||||
|
||||
/***
|
||||
* Get the ultimate base dv in the datatype registry
|
||||
***/
|
||||
DatatypeValidator *basedv = DatatypeValidatorFactory::getBuiltInBaseValidator(dv);
|
||||
|
||||
if (!basedv) return 0;
|
||||
|
||||
XSValue::Status status=XSValue::st_Init;
|
||||
|
||||
return XSValue::getActualValue(fNormalizedValue
|
||||
, XSValue::getDataType(basedv->getTypeLocalName())
|
||||
, status
|
||||
, XSValue::ver_10
|
||||
, false
|
||||
, fMemoryManager);
|
||||
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* 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: PSVIItem.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PSVIITEM_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PSVIITEM_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Represent the PSVI contributions for one element or one attribute information item.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained. It is designed to be subclassed; subclasses will
|
||||
* specify under what conditions it may be relied upon to have meaningful contents.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSTypeDefinition;
|
||||
class XSSimpleTypeDefinition;
|
||||
class XSValue;
|
||||
|
||||
class XMLPARSER_EXPORT PSVIItem : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
enum VALIDITY_STATE {
|
||||
/** Validity value indicating that validation has either not
|
||||
been performed or that a strict assessment of validity could
|
||||
not be performed
|
||||
*/
|
||||
VALIDITY_NOTKNOWN = 0,
|
||||
|
||||
/** Validity value indicating that validation has been strictly
|
||||
assessed and the element in question is invalid according to the
|
||||
rules of schema validation.
|
||||
*/
|
||||
VALIDITY_INVALID = 1,
|
||||
|
||||
/** Validity value indicating that validation has been strictly
|
||||
assessed and the element in question is valid according to the rules
|
||||
of schema validation.
|
||||
*/
|
||||
VALIDITY_VALID = 2
|
||||
};
|
||||
|
||||
enum ASSESSMENT_TYPE {
|
||||
/** Validation status indicating that schema validation has been
|
||||
performed and the element in question has specifically been skipped.
|
||||
*/
|
||||
VALIDATION_NONE = 0,
|
||||
|
||||
/** Validation status indicating that schema validation has been
|
||||
performed on the element in question under the rules of lax validation.
|
||||
*/
|
||||
VALIDATION_PARTIAL = 1,
|
||||
|
||||
/** Validation status indicating that full schema validation has been
|
||||
performed on the element. */
|
||||
VALIDATION_FULL = 2
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
PSVIItem(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
virtual ~PSVIItem();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name PSVIItem methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [validation context]
|
||||
*
|
||||
* @return A string identifying the nearest ancestor element
|
||||
* information item with a [schema information] property
|
||||
* (or this element item itself if it has such a property)
|
||||
* (form to be determined)
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-validation_context">XML Schema Part 1: Structures [validation context]</a>
|
||||
*/
|
||||
const XMLCh *getValidationContext();
|
||||
|
||||
/**
|
||||
* Determine the validity of the node with respect
|
||||
* to the validation being attempted
|
||||
*
|
||||
* @return return the [validity] property. Possible values are:
|
||||
* VALIDITY_UNKNOWN, VALIDITY_INVALID, VALIDITY_VALID
|
||||
*/
|
||||
VALIDITY_STATE getValidity() const;
|
||||
|
||||
/**
|
||||
* Determines the extent to which the item has been validated
|
||||
*
|
||||
* @return return the [validation attempted] property. The possible values are
|
||||
* VALIDATION_NONE, VALIDATION_ORDERED_PARTIAL and VALIDATION_FULL
|
||||
*/
|
||||
ASSESSMENT_TYPE getValidationAttempted() const;
|
||||
|
||||
/**
|
||||
* A list of error codes generated from validation attempts.
|
||||
* Need to find all the possible sub-clause reports that need reporting
|
||||
*
|
||||
* @return list of error codes
|
||||
*/
|
||||
/***
|
||||
const XMLCh ** getErrorCodes();
|
||||
****/
|
||||
|
||||
/**
|
||||
* [schema normalized value]
|
||||
*
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value">XML Schema Part 1: Structures [schema normalized value]</a>
|
||||
* @return the normalized value of this item after validation
|
||||
*/
|
||||
const XMLCh *getSchemaNormalizedValue();
|
||||
|
||||
/**
|
||||
* An item isomorphic to the type definition used to validate this element.
|
||||
*
|
||||
* @return a type declaration
|
||||
*/
|
||||
virtual XSTypeDefinition *getTypeDefinition() = 0;
|
||||
|
||||
/**
|
||||
* If and only if that type definition is a simple type definition
|
||||
* with {variety} union, or a complex type definition whose {content type}
|
||||
* is a simple thype definition with {variety} union, then an item isomorphic
|
||||
* to that member of the union's {member type definitions} which actually
|
||||
* validated the element item's normalized value.
|
||||
*
|
||||
* @return a simple type declaration
|
||||
*/
|
||||
virtual XSSimpleTypeDefinition *getMemberTypeDefinition() = 0;
|
||||
|
||||
/**
|
||||
* [schema default]
|
||||
*
|
||||
* @return The canonical lexical representation of the declaration's {value constraint} value.
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default">XML Schema Part 1: Structures [schema default]</a>
|
||||
*/
|
||||
const XMLCh *getSchemaDefault();
|
||||
|
||||
/**
|
||||
* [schema specified]
|
||||
* @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
|
||||
* @return true - value was specified in schema, false - value comes from the infoset
|
||||
*/
|
||||
bool getIsSchemaSpecified() const;
|
||||
|
||||
/**
|
||||
* Return the canonical representation of this value.
|
||||
* Note that, formally, this is not a PSVI property.
|
||||
* @return string representing the canonical representation, if this item
|
||||
* was validated by a simple type definition for which canonical
|
||||
* representations of values are defined.
|
||||
*/
|
||||
const XMLCh *getCanonicalRepresentation() const;
|
||||
|
||||
//@}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get actual value in the form of XSValue,
|
||||
* caller needs to delete the object returned.
|
||||
*
|
||||
* @return an XSValue
|
||||
*/
|
||||
virtual XSValue *getActualValue() const;
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
void setValidationAttempted(PSVIItem::ASSESSMENT_TYPE attemptType);
|
||||
void setValidity(PSVIItem::VALIDITY_STATE validity);
|
||||
|
||||
/** reset the object
|
||||
* @param validationContext corresponds to schema validation context property
|
||||
* @param normalizedValue corresponds to schema normalized value property
|
||||
* @param validityState state of item's validity
|
||||
* @param assessmentType type of assessment carried out on item
|
||||
*/
|
||||
void reset(
|
||||
const XMLCh* const validationContext
|
||||
, const XMLCh* const normalizedValue
|
||||
, const VALIDITY_STATE validityState
|
||||
, const ASSESSMENT_TYPE assessmentType
|
||||
);
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
PSVIItem(const PSVIItem&);
|
||||
PSVIItem & operator=(const PSVIItem &);
|
||||
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
// fMemoryManager:
|
||||
// used for any memory allocations
|
||||
// fValidationContext
|
||||
// corresponds to the schema [validation context] property
|
||||
// fNormalizedValue
|
||||
// The schema normalized value (when present)
|
||||
// fDefaultValue
|
||||
// default value specified in the schema, if any
|
||||
// fCanonicalValue
|
||||
// canonicalized version of normalizedValue
|
||||
// fValidityState
|
||||
// Whether this item is valid or not
|
||||
// fAssessmentType
|
||||
// The kind of assessment that produced the given validity outcome
|
||||
// fIsSpecified
|
||||
// Whether this item exists because a default was specified in the schema
|
||||
// fType
|
||||
// type responsible for validating this item
|
||||
// fMemberType
|
||||
// If fType is a union type, the member type that validated this item
|
||||
MemoryManager* const fMemoryManager;
|
||||
const XMLCh* fValidationContext;
|
||||
const XMLCh* fNormalizedValue;
|
||||
const XMLCh* fDefaultValue;
|
||||
XMLCh* fCanonicalValue;
|
||||
VALIDITY_STATE fValidityState;
|
||||
ASSESSMENT_TYPE fAssessmentType;
|
||||
bool fIsSpecified;
|
||||
XSTypeDefinition * fType;
|
||||
XSSimpleTypeDefinition* fMemberType;
|
||||
};
|
||||
|
||||
inline PSVIItem::~PSVIItem() {}
|
||||
|
||||
inline const XMLCh *PSVIItem::getValidationContext()
|
||||
{
|
||||
return fValidationContext;
|
||||
}
|
||||
|
||||
inline const XMLCh* PSVIItem::getSchemaNormalizedValue()
|
||||
{
|
||||
return fNormalizedValue;
|
||||
}
|
||||
|
||||
inline const XMLCh* PSVIItem::getSchemaDefault()
|
||||
{
|
||||
return fDefaultValue;
|
||||
}
|
||||
|
||||
inline const XMLCh* PSVIItem::getCanonicalRepresentation() const
|
||||
{
|
||||
return fCanonicalValue;
|
||||
}
|
||||
|
||||
inline PSVIItem::VALIDITY_STATE PSVIItem::getValidity() const
|
||||
{
|
||||
return fValidityState;
|
||||
}
|
||||
|
||||
inline bool PSVIItem::getIsSchemaSpecified() const
|
||||
{
|
||||
return fIsSpecified;
|
||||
}
|
||||
|
||||
inline PSVIItem::ASSESSMENT_TYPE PSVIItem::getValidationAttempted() const
|
||||
{
|
||||
return fAssessmentType;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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: XSAnnotation.cpp 679296 2008-07-24 08:13:42Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||
|
||||
#include <xercesc/sax2/SAX2XMLReader.hpp>
|
||||
#include <xercesc/sax2/XMLReaderFactory.hpp>
|
||||
#include <xercesc/parsers/XercesDOMParser.hpp>
|
||||
#include <xercesc/dom/DOMElement.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
XSAnnotation::XSAnnotation(const XMLCh* const content,
|
||||
MemoryManager * const manager)
|
||||
:XSObject(XSConstants::ANNOTATION, 0, manager)
|
||||
,fContents(XMLString::replicate(content, manager))
|
||||
,fNext(0)
|
||||
,fSystemId(0)
|
||||
,fLine(0)
|
||||
,fCol(0)
|
||||
{
|
||||
}
|
||||
|
||||
XSAnnotation::XSAnnotation(MemoryManager * const manager)
|
||||
:XSObject(XSConstants::ANNOTATION, 0, manager)
|
||||
,fContents(0)
|
||||
,fNext(0)
|
||||
,fSystemId(0)
|
||||
,fLine(0)
|
||||
,fCol(0)
|
||||
{
|
||||
}
|
||||
|
||||
XSAnnotation::~XSAnnotation()
|
||||
{
|
||||
fMemoryManager->deallocate(fContents);
|
||||
|
||||
if (fNext)
|
||||
delete fNext;
|
||||
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
}
|
||||
|
||||
// XSAnnotation methods
|
||||
void XSAnnotation::writeAnnotation(DOMNode* node, ANNOTATION_TARGET targetType)
|
||||
{
|
||||
XercesDOMParser *parser = new (fMemoryManager) XercesDOMParser(0, fMemoryManager);
|
||||
parser->setDoNamespaces(true);
|
||||
parser->setValidationScheme(XercesDOMParser::Val_Never);
|
||||
|
||||
DOMDocument* futureOwner = (targetType == W3C_DOM_ELEMENT) ?
|
||||
((DOMElement*)node)->getOwnerDocument() :
|
||||
(DOMDocument*)node;
|
||||
|
||||
MemBufInputSource* memBufIS = new (fMemoryManager) MemBufInputSource
|
||||
(
|
||||
(const XMLByte*)fContents
|
||||
, XMLString::stringLen(fContents)*sizeof(XMLCh)
|
||||
, ""
|
||||
, false
|
||||
, fMemoryManager
|
||||
);
|
||||
memBufIS->setEncoding(XMLUni::fgXMLChEncodingString);
|
||||
memBufIS->setCopyBufToStream(false);
|
||||
|
||||
try
|
||||
{
|
||||
parser->parse(*memBufIS);
|
||||
}
|
||||
catch (const XMLException&)
|
||||
{
|
||||
// REVISIT: should we really eat this?
|
||||
}
|
||||
|
||||
DOMNode* newElem = futureOwner->importNode((parser->getDocument())->getDocumentElement(), true);
|
||||
node->insertBefore(newElem, node->getFirstChild());
|
||||
|
||||
delete parser;
|
||||
delete memBufIS;
|
||||
}
|
||||
|
||||
|
||||
void XSAnnotation::writeAnnotation(ContentHandler* handler)
|
||||
{
|
||||
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(fMemoryManager);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
|
||||
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
|
||||
parser->setContentHandler(handler);
|
||||
|
||||
MemBufInputSource* memBufIS = new (fMemoryManager) MemBufInputSource
|
||||
(
|
||||
(const XMLByte*)fContents
|
||||
, XMLString::stringLen(fContents)*sizeof(XMLCh)
|
||||
, ""
|
||||
, false
|
||||
, fMemoryManager
|
||||
);
|
||||
memBufIS->setEncoding(XMLUni::fgXMLChEncodingString);
|
||||
memBufIS->setCopyBufToStream(false);
|
||||
|
||||
try
|
||||
{
|
||||
parser->parse(*memBufIS);
|
||||
}
|
||||
catch (const XMLException&)
|
||||
{
|
||||
}
|
||||
|
||||
delete parser;
|
||||
delete memBufIS;
|
||||
}
|
||||
|
||||
|
||||
void XSAnnotation::setNext(XSAnnotation* const nextAnnotation)
|
||||
{
|
||||
if (fNext)
|
||||
fNext->setNext(nextAnnotation);
|
||||
else
|
||||
fNext = nextAnnotation;
|
||||
}
|
||||
|
||||
XSAnnotation* XSAnnotation::getNext()
|
||||
{
|
||||
return fNext;
|
||||
}
|
||||
|
||||
void XSAnnotation::setSystemId(const XMLCh* const systemId)
|
||||
{
|
||||
if (fSystemId)
|
||||
{
|
||||
fMemoryManager->deallocate(fSystemId);
|
||||
fSystemId = 0;
|
||||
}
|
||||
|
||||
if (systemId)
|
||||
fSystemId = XMLString::replicate(systemId, fMemoryManager);
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
|
||||
IMPL_XSERIALIZABLE_TOCREATE(XSAnnotation)
|
||||
|
||||
void XSAnnotation::serialize(XSerializeEngine& serEng)
|
||||
{
|
||||
|
||||
if (serEng.isStoring())
|
||||
{
|
||||
serEng.writeString(fContents);
|
||||
serEng<<fNext;
|
||||
serEng.writeString(fSystemId);
|
||||
|
||||
serEng.writeUInt64 (fLine);
|
||||
serEng.writeUInt64 (fCol);
|
||||
}
|
||||
else
|
||||
{
|
||||
serEng.readString(fContents);
|
||||
serEng>>fNext;
|
||||
serEng.readString(fSystemId);
|
||||
|
||||
serEng.readUInt64 (fLine);
|
||||
serEng.readUInt64 (fCol);
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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: XSAnnotation.hpp 672273 2008-06-27 13:57:00Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSANNOTATION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSANNOTATION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
#include <xercesc/internal/XSerializable.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Annotation
|
||||
* component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class DOMNode;
|
||||
class ContentHandler;
|
||||
|
||||
class XMLPARSER_EXPORT XSAnnotation : public XSerializable, public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// TargetType
|
||||
enum ANNOTATION_TARGET {
|
||||
/**
|
||||
* The object type is <code>org.w3c.dom.Element</code>.
|
||||
*/
|
||||
W3C_DOM_ELEMENT = 1,
|
||||
/**
|
||||
* The object type is <code>org.w3c.dom.Document</code>.
|
||||
*/
|
||||
W3C_DOM_DOCUMENT = 2
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param contents The string that is to be the content of this XSAnnotation
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSAnnotation
|
||||
(
|
||||
const XMLCh* const contents
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSAnnotation();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSAnnotation methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Write contents of the annotation to the specified DOM object. In-scope
|
||||
* namespace declarations for <code>annotation</code> element are added as
|
||||
* attribute nodes of the serialized <code>annotation</code>.
|
||||
* @param node A target pointer to the annotation target object, i.e.
|
||||
* either <code>DOMDocument</code> or <code>DOMElement</code> cast as
|
||||
* <code>DOMNode</code>.
|
||||
* @param targetType A target type.
|
||||
*/
|
||||
|
||||
void writeAnnotation(DOMNode* node, ANNOTATION_TARGET targetType);
|
||||
|
||||
/**
|
||||
* Write contents of the annotation to the specified object.
|
||||
* The corresponding events for all in-scope namespace declarations are
|
||||
* sent via the specified document handler.
|
||||
* @param handler A target pointer to the annotation target object, i.e.
|
||||
* <code>ContentHandler</code>.
|
||||
*/
|
||||
void writeAnnotation(ContentHandler* handler);
|
||||
|
||||
/**
|
||||
* A text representation of annotation.
|
||||
*/
|
||||
const XMLCh *getAnnotationString() const;
|
||||
XMLCh *getAnnotationString();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
//@{
|
||||
void setNext(XSAnnotation* const nextAnnotation);
|
||||
XSAnnotation* getNext();
|
||||
//@}
|
||||
|
||||
//-----------------------------
|
||||
/** Getter */
|
||||
//@{
|
||||
inline void getLineCol(XMLFileLoc& line, XMLFileLoc& col) const;
|
||||
inline const XMLCh* getSystemId() const;
|
||||
//@}
|
||||
|
||||
//-----------------------------
|
||||
/** Setter */
|
||||
//@{
|
||||
inline void setLineCol(XMLFileLoc line, XMLFileLoc col);
|
||||
void setSystemId(const XMLCh* const systemId);
|
||||
//@}
|
||||
|
||||
/***
|
||||
* Support for Serialization/De-serialization
|
||||
***/
|
||||
DECL_XSERIALIZABLE(XSAnnotation)
|
||||
XSAnnotation(MemoryManager* const manager);
|
||||
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSAnnotation(const XSAnnotation&);
|
||||
XSAnnotation & operator=(const XSAnnotation &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
XMLCh* fContents;
|
||||
XSAnnotation* fNext;
|
||||
|
||||
private:
|
||||
|
||||
XMLCh* fSystemId;
|
||||
XMLFileLoc fLine;
|
||||
XMLFileLoc fCol;
|
||||
|
||||
};
|
||||
|
||||
inline const XMLCh *XSAnnotation::getAnnotationString() const
|
||||
{
|
||||
return fContents;
|
||||
}
|
||||
|
||||
inline XMLCh *XSAnnotation::getAnnotationString()
|
||||
{
|
||||
return fContents;
|
||||
}
|
||||
|
||||
inline void XSAnnotation::getLineCol(XMLFileLoc& line, XMLFileLoc& col) const
|
||||
{
|
||||
line = fLine;
|
||||
col = fCol;
|
||||
}
|
||||
|
||||
inline const XMLCh* XSAnnotation::getSystemId() const
|
||||
{
|
||||
return fSystemId;
|
||||
}
|
||||
|
||||
inline void XSAnnotation::setLineCol(XMLFileLoc line, XMLFileLoc col)
|
||||
{
|
||||
fLine = line;
|
||||
fCol = col;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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: XSAttributeDeclaration.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamespaceItem.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/util/StringPool.hpp>
|
||||
#include <xercesc/validators/schema/SchemaGrammar.hpp>
|
||||
#include <xercesc/validators/schema/SchemaAttDef.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeDeclaration: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSAttributeDeclaration::XSAttributeDeclaration(SchemaAttDef* const attDef,
|
||||
XSSimpleTypeDefinition* const typeDef,
|
||||
XSAnnotation* const annot,
|
||||
XSModel* const xsModel,
|
||||
XSConstants::SCOPE scope,
|
||||
XSComplexTypeDefinition* enclosingCTDefinition,
|
||||
MemoryManager * const manager)
|
||||
: XSObject(XSConstants::ATTRIBUTE_DECLARATION, xsModel, manager)
|
||||
, fAttDef(attDef)
|
||||
, fTypeDefinition(typeDef)
|
||||
, fAnnotation(annot)
|
||||
, fScope(scope)
|
||||
, fEnclosingCTDefinition(enclosingCTDefinition)
|
||||
{
|
||||
}
|
||||
|
||||
XSAttributeDeclaration::~XSAttributeDeclaration()
|
||||
{
|
||||
// don't delete fTypeDefinition - deleted by XSModel
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeDeclaration: XSObject virtual methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh *XSAttributeDeclaration::getName() const
|
||||
{
|
||||
return fAttDef->getAttName()->getLocalPart();
|
||||
}
|
||||
|
||||
const XMLCh *XSAttributeDeclaration::getNamespace()
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fAttDef->getAttName()->getURI());
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSAttributeDeclaration::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeDeclaration: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
XSConstants::VALUE_CONSTRAINT XSAttributeDeclaration::getConstraintType() const
|
||||
{
|
||||
if (fScope != XSConstants::SCOPE_GLOBAL)
|
||||
return XSConstants::VALUE_CONSTRAINT_NONE;
|
||||
|
||||
if (fAttDef->getDefaultType() == XMLAttDef::Default)
|
||||
return XSConstants::VALUE_CONSTRAINT_DEFAULT;
|
||||
|
||||
if ((fAttDef->getDefaultType() == XMLAttDef::Fixed) ||
|
||||
(fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed))
|
||||
return XSConstants::VALUE_CONSTRAINT_FIXED;
|
||||
|
||||
return XSConstants::VALUE_CONSTRAINT_NONE;
|
||||
}
|
||||
|
||||
const XMLCh *XSAttributeDeclaration::getConstraintValue()
|
||||
{
|
||||
if (fScope == XSConstants::SCOPE_GLOBAL)
|
||||
return fAttDef->getValue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool XSAttributeDeclaration::getRequired() const
|
||||
{
|
||||
if (fAttDef->getDefaultType() == XMLAttDef::Required ||
|
||||
fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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: XSAttributeDeclaration.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSATTRIBUTEDECLARATION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSATTRIBUTEDECLARATION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Attribute
|
||||
* Declaration component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSComplexTypeDefinition;
|
||||
class XSSimpleTypeDefinition;
|
||||
class SchemaAttDef;
|
||||
|
||||
class XMLPARSER_EXPORT XSAttributeDeclaration : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param attDef
|
||||
* @param typeDef
|
||||
* @param annot
|
||||
* @param xsModel
|
||||
* @param scope
|
||||
* @param enclosingCTDefinition
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSAttributeDeclaration
|
||||
(
|
||||
SchemaAttDef* const attDef
|
||||
, XSSimpleTypeDefinition* const typeDef
|
||||
, XSAnnotation* const annot
|
||||
, XSModel* const xsModel
|
||||
, XSConstants::SCOPE scope
|
||||
, XSComplexTypeDefinition* enclosingCTDefinition
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSAttributeDeclaration();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name overridden XSObject methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem* getNamespaceItem();
|
||||
|
||||
//@}
|
||||
|
||||
/** @name XSAttributeDeclaration methods **/
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [type definition]: A simple type definition
|
||||
*/
|
||||
XSSimpleTypeDefinition *getTypeDefinition() const;
|
||||
|
||||
/**
|
||||
* Optional. One of <code>SCOPE_GLOBAL</code>, <code>SCOPE_LOCAL</code>,
|
||||
* or <code>SCOPE_ABSENT</code>. If the scope is local, then the
|
||||
* <code>enclosingCTDefinition</code> is present.
|
||||
*/
|
||||
XSConstants::SCOPE getScope() const;
|
||||
|
||||
/**
|
||||
* The complex type definition for locally scoped declarations (see
|
||||
* <code>scope</code>).
|
||||
*/
|
||||
XSComplexTypeDefinition *getEnclosingCTDefinition();
|
||||
|
||||
/**
|
||||
* Value constraint: one of <code>VC_NONE, VC_DEFAULT, VC_FIXED</code>.
|
||||
*/
|
||||
XSConstants::VALUE_CONSTRAINT getConstraintType() const;
|
||||
|
||||
/**
|
||||
* Value constraint: The actual value with respect to the [type definition
|
||||
* ].
|
||||
*/
|
||||
const XMLCh *getConstraintValue();
|
||||
|
||||
/**
|
||||
* Optional. Annotation.
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
bool getRequired() const;
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
void setEnclosingCTDefinition(XSComplexTypeDefinition* const toSet);
|
||||
friend class XSObjectFactory;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSAttributeDeclaration(const XSAttributeDeclaration&);
|
||||
XSAttributeDeclaration & operator=(const XSAttributeDeclaration &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
SchemaAttDef* fAttDef;
|
||||
XSSimpleTypeDefinition* fTypeDefinition;
|
||||
XSAnnotation* fAnnotation;
|
||||
XSConstants::SCOPE fScope;
|
||||
XSComplexTypeDefinition* fEnclosingCTDefinition;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeDeclaration: inline methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XSSimpleTypeDefinition* XSAttributeDeclaration::getTypeDefinition() const
|
||||
{
|
||||
return fTypeDefinition;
|
||||
}
|
||||
|
||||
inline XSAnnotation *XSAttributeDeclaration::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
inline XSConstants::SCOPE XSAttributeDeclaration::getScope() const
|
||||
{
|
||||
return fScope;
|
||||
}
|
||||
|
||||
inline XSComplexTypeDefinition *XSAttributeDeclaration::getEnclosingCTDefinition()
|
||||
{
|
||||
return fEnclosingCTDefinition;
|
||||
}
|
||||
|
||||
inline void XSAttributeDeclaration::setEnclosingCTDefinition
|
||||
(
|
||||
XSComplexTypeDefinition* const toSet
|
||||
)
|
||||
{
|
||||
fEnclosingCTDefinition = toSet;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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: XSAttributeGroupDefinition.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeUse.hpp>
|
||||
#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeGroupDefinition: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSAttributeGroupDefinition::XSAttributeGroupDefinition
|
||||
(
|
||||
XercesAttGroupInfo* const xercesAttGroupInfo
|
||||
, XSAttributeUseList* const xsAttList
|
||||
, XSWildcard* const xsWildcard
|
||||
, XSAnnotation* const xsAnnot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager * const manager
|
||||
)
|
||||
: XSObject(XSConstants::ATTRIBUTE_GROUP_DEFINITION, xsModel, manager)
|
||||
, fXercesAttGroupInfo(xercesAttGroupInfo)
|
||||
, fXSAttributeUseList(xsAttList)
|
||||
, fXSWildcard(xsWildcard)
|
||||
, fAnnotation(xsAnnot)
|
||||
{
|
||||
}
|
||||
|
||||
XSAttributeGroupDefinition::~XSAttributeGroupDefinition()
|
||||
{
|
||||
if (fXSAttributeUseList)
|
||||
delete fXSAttributeUseList;
|
||||
|
||||
// don't delete fXSWildcard - deleted by XSModel
|
||||
}
|
||||
|
||||
// XSObject methods
|
||||
const XMLCh *XSAttributeGroupDefinition::getName() const
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fXercesAttGroupInfo->getNameId());
|
||||
}
|
||||
|
||||
const XMLCh *XSAttributeGroupDefinition::getNamespace()
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fXercesAttGroupInfo->getNamespaceId());
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSAttributeGroupDefinition::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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: XSAttributeGroupDefinition.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSATTRIBUTEGROUPDEFINITION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSATTRIBUTEGROUPDEFINITION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Attribute
|
||||
* Group Definition component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSAttributeUse;
|
||||
class XSWildcard;
|
||||
class XercesAttGroupInfo;
|
||||
|
||||
class XMLPARSER_EXPORT XSAttributeGroupDefinition : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param xercesAttGroupInfo
|
||||
* @param xsAttList
|
||||
* @param xsWildcard
|
||||
* @param xsAnnot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSAttributeGroupDefinition
|
||||
(
|
||||
XercesAttGroupInfo* const xercesAttGroupInfo
|
||||
, XSAttributeUseList* const xsAttList
|
||||
, XSWildcard* const xsWildcard
|
||||
, XSAnnotation* const xsAnnot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSAttributeGroupDefinition();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name overridden XSObject methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem* getNamespaceItem();
|
||||
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSAttributeGroupDefinition methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* A set of [attribute uses].
|
||||
*/
|
||||
XSAttributeUseList *getAttributeUses();
|
||||
|
||||
/**
|
||||
* Optional. A [wildcard].
|
||||
*/
|
||||
XSWildcard *getAttributeWildcard() const;
|
||||
|
||||
/**
|
||||
* Optional. An [annotation].
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSAttributeGroupDefinition(const XSAttributeGroupDefinition&);
|
||||
XSAttributeGroupDefinition & operator=(const XSAttributeGroupDefinition &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
XercesAttGroupInfo* fXercesAttGroupInfo;
|
||||
XSAttributeUseList* fXSAttributeUseList;
|
||||
XSWildcard* fXSWildcard;
|
||||
XSAnnotation* fAnnotation;
|
||||
};
|
||||
|
||||
inline XSAttributeUseList* XSAttributeGroupDefinition::getAttributeUses()
|
||||
{
|
||||
return fXSAttributeUseList;
|
||||
}
|
||||
|
||||
inline XSWildcard* XSAttributeGroupDefinition::getAttributeWildcard() const
|
||||
{
|
||||
return fXSWildcard;
|
||||
}
|
||||
|
||||
inline XSAnnotation* XSAttributeGroupDefinition::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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: XSAttributeUse.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSAttributeUse.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeUse: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSAttributeUse::XSAttributeUse(XSAttributeDeclaration* const xsAttDecl,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager)
|
||||
: XSObject(XSConstants::ATTRIBUTE_USE, xsModel, manager)
|
||||
, fRequired(false)
|
||||
, fConstraintType(XSConstants::VALUE_CONSTRAINT_NONE)
|
||||
, fConstraintValue(0)
|
||||
, fXSAttributeDeclaration(xsAttDecl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
XSAttributeUse::~XSAttributeUse()
|
||||
{
|
||||
// don't delete fXSAttributeDeclaration - deleted by XSModel
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSAttributeUse: helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XSAttributeUse::set(const bool isRequired,
|
||||
XSConstants::VALUE_CONSTRAINT constraintType,
|
||||
const XMLCh* const constraintValue)
|
||||
{
|
||||
fRequired = isRequired;
|
||||
fConstraintType = constraintType;
|
||||
fConstraintValue = constraintValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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: XSAttributeUse.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSATTRIBUTEUSE_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSATTRIBUTEUSE_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Attribute
|
||||
* Use component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAttributeDeclaration;
|
||||
|
||||
class XMLPARSER_EXPORT XSAttributeUse : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
* @param xsAttDecl
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSAttributeUse
|
||||
(
|
||||
XSAttributeDeclaration* const xsAttDecl,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSAttributeUse();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSAttributeUse methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [required]: determines whether this use of an attribute declaration
|
||||
* requires an appropriate attribute information item to be present, or
|
||||
* merely allows it.
|
||||
*/
|
||||
bool getRequired() const;
|
||||
|
||||
/**
|
||||
* [attribute declaration]: provides the attribute declaration itself,
|
||||
* which will in turn determine the simple type definition used.
|
||||
*/
|
||||
XSAttributeDeclaration *getAttrDeclaration() const;
|
||||
|
||||
/**
|
||||
* Value Constraint: one of default, fixed.
|
||||
*/
|
||||
XSConstants::VALUE_CONSTRAINT getConstraintType() const;
|
||||
|
||||
/**
|
||||
* Value Constraint: The actual value.
|
||||
*/
|
||||
const XMLCh *getConstraintValue();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
// set data
|
||||
void set
|
||||
(
|
||||
const bool isRequired
|
||||
, XSConstants::VALUE_CONSTRAINT constraintType
|
||||
, const XMLCh* const constraintValue
|
||||
);
|
||||
|
||||
friend class XSObjectFactory;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSAttributeUse(const XSAttributeUse&);
|
||||
XSAttributeUse & operator=(const XSAttributeUse &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
bool fRequired;
|
||||
XSConstants::VALUE_CONSTRAINT fConstraintType;
|
||||
const XMLCh* fConstraintValue;
|
||||
XSAttributeDeclaration* fXSAttributeDeclaration;
|
||||
};
|
||||
|
||||
inline XSAttributeDeclaration *XSAttributeUse::getAttrDeclaration() const
|
||||
{
|
||||
return fXSAttributeDeclaration;
|
||||
}
|
||||
|
||||
inline bool XSAttributeUse::getRequired() const
|
||||
{
|
||||
return fRequired;
|
||||
}
|
||||
|
||||
inline XSConstants::VALUE_CONSTRAINT XSAttributeUse::getConstraintType() const
|
||||
{
|
||||
return fConstraintType;
|
||||
}
|
||||
|
||||
inline const XMLCh *XSAttributeUse::getConstraintValue()
|
||||
{
|
||||
return fConstraintValue;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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: XSComplexTypeDefinition.cpp 594002 2007-11-12 01:05:09Z cargilld $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSWildcard.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeUse.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/validators/schema/ComplexTypeInfo.hpp>
|
||||
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
|
||||
#include <xercesc/validators/schema/SchemaAttDefList.hpp>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSComplexTypeDefinition: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSComplexTypeDefinition::XSComplexTypeDefinition
|
||||
(
|
||||
ComplexTypeInfo* const complexTypeInfo
|
||||
, XSWildcard* const xsWildcard
|
||||
, XSSimpleTypeDefinition* const xsSimpleType
|
||||
, XSAttributeUseList* const xsAttList
|
||||
, XSTypeDefinition* const xsBaseType
|
||||
, XSParticle* const xsParticle
|
||||
, XSAnnotation* const headAnnot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager
|
||||
)
|
||||
: XSTypeDefinition(COMPLEX_TYPE, xsBaseType, xsModel, manager)
|
||||
, fComplexTypeInfo(complexTypeInfo)
|
||||
, fXSWildcard(xsWildcard)
|
||||
, fXSAttributeUseList(xsAttList)
|
||||
, fXSSimpleTypeDefinition(xsSimpleType)
|
||||
, fXSAnnotationList(0)
|
||||
, fParticle(xsParticle)
|
||||
, fProhibitedSubstitution(0)
|
||||
{
|
||||
int blockset = fComplexTypeInfo->getBlockSet();
|
||||
if (blockset)
|
||||
{
|
||||
if (blockset & SchemaSymbols::XSD_EXTENSION)
|
||||
fProhibitedSubstitution |= XSConstants::DERIVATION_EXTENSION;
|
||||
|
||||
if (blockset & SchemaSymbols::XSD_RESTRICTION)
|
||||
fProhibitedSubstitution |= XSConstants::DERIVATION_RESTRICTION;
|
||||
}
|
||||
|
||||
int finalSet = fComplexTypeInfo->getFinalSet();
|
||||
if (finalSet)
|
||||
{
|
||||
if (finalSet & SchemaSymbols::XSD_EXTENSION)
|
||||
fFinal |= XSConstants::DERIVATION_EXTENSION;
|
||||
|
||||
if (finalSet & SchemaSymbols::XSD_RESTRICTION)
|
||||
fFinal |= XSConstants::DERIVATION_RESTRICTION;
|
||||
}
|
||||
|
||||
if (headAnnot)
|
||||
{
|
||||
fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(1, false, manager);
|
||||
XSAnnotation* annot = headAnnot;
|
||||
|
||||
do
|
||||
{
|
||||
fXSAnnotationList->addElement(annot);
|
||||
annot = annot->getNext();
|
||||
} while (annot);
|
||||
}
|
||||
}
|
||||
|
||||
XSComplexTypeDefinition::~XSComplexTypeDefinition()
|
||||
{
|
||||
// don't delete fXSWildcard - deleted by XSModel
|
||||
// don't delete fXSSimpleTypeDefinition - deleted by XSModel
|
||||
if (fXSAttributeUseList)
|
||||
delete fXSAttributeUseList;
|
||||
|
||||
if (fXSAnnotationList)
|
||||
delete fXSAnnotationList;
|
||||
|
||||
if (fParticle)
|
||||
delete fParticle;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSComplexTypeDefinition: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XSConstants::DERIVATION_TYPE XSComplexTypeDefinition::getDerivationMethod() const
|
||||
{
|
||||
if(fComplexTypeInfo->getDerivedBy() == SchemaSymbols::XSD_EXTENSION)
|
||||
return XSConstants::DERIVATION_EXTENSION;
|
||||
return XSConstants::DERIVATION_RESTRICTION;
|
||||
}
|
||||
|
||||
bool XSComplexTypeDefinition::getAbstract() const
|
||||
{
|
||||
return fComplexTypeInfo->getAbstract();
|
||||
}
|
||||
|
||||
|
||||
XSComplexTypeDefinition::CONTENT_TYPE XSComplexTypeDefinition::getContentType() const
|
||||
{
|
||||
switch(fComplexTypeInfo->getContentType()) {
|
||||
case SchemaElementDecl::Simple:
|
||||
return CONTENTTYPE_SIMPLE;
|
||||
case SchemaElementDecl::Empty:
|
||||
case SchemaElementDecl::ElementOnlyEmpty:
|
||||
return CONTENTTYPE_EMPTY;
|
||||
case SchemaElementDecl::Children:
|
||||
return CONTENTTYPE_ELEMENT;
|
||||
default:
|
||||
//case SchemaElementDecl::Mixed_Complex:
|
||||
//case SchemaElementDecl::Mixed_Simple:
|
||||
//case SchemaElementDecl::Any:
|
||||
return CONTENTTYPE_MIXED;
|
||||
}
|
||||
}
|
||||
|
||||
bool XSComplexTypeDefinition::isProhibitedSubstitution(XSConstants::DERIVATION_TYPE toTest)
|
||||
{
|
||||
if (fProhibitedSubstitution & toTest)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
XSAnnotationList *XSComplexTypeDefinition::getAnnotations()
|
||||
{
|
||||
return fXSAnnotationList;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSComplexTypeDefinition: virtual methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh *XSComplexTypeDefinition::getName() const
|
||||
{
|
||||
return fComplexTypeInfo->getTypeLocalName();
|
||||
}
|
||||
|
||||
const XMLCh *XSComplexTypeDefinition::getNamespace()
|
||||
{
|
||||
return fComplexTypeInfo->getTypeUri();
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSComplexTypeDefinition::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
bool XSComplexTypeDefinition::getAnonymous() const
|
||||
{
|
||||
return fComplexTypeInfo->getAnonymous();
|
||||
}
|
||||
|
||||
XSTypeDefinition *XSComplexTypeDefinition::getBaseType()
|
||||
{
|
||||
return fBaseType;
|
||||
}
|
||||
|
||||
bool XSComplexTypeDefinition::derivedFromType(const XSTypeDefinition * const ancestorType)
|
||||
{
|
||||
if (!ancestorType)
|
||||
return false;
|
||||
|
||||
XSTypeDefinition* type = (XSTypeDefinition*) ancestorType;
|
||||
|
||||
if (ancestorType == type->getBaseType())
|
||||
{
|
||||
// ancestor is anytype
|
||||
return true;
|
||||
}
|
||||
|
||||
type = this;
|
||||
XSTypeDefinition* lastType = 0; // anytype has a basetype of anytype so will have infinite loop...
|
||||
|
||||
while (type && (type != ancestorType) && (type != lastType))
|
||||
{
|
||||
lastType = type;
|
||||
type = type->getBaseType();
|
||||
}
|
||||
|
||||
return (type == ancestorType);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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: XSComplexTypeDefinition.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSCOMPLEXTYPEDEFINITION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSCOMPLEXTYPEDEFINITION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class represents a complexType definition
|
||||
* schema component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSAttributeUse;
|
||||
class XSSimpleTypeDefinition;
|
||||
class XSParticle;
|
||||
class XSWildcard;
|
||||
class ComplexTypeInfo;
|
||||
|
||||
class XMLPARSER_EXPORT XSComplexTypeDefinition : public XSTypeDefinition
|
||||
{
|
||||
public:
|
||||
|
||||
// Content Model Types
|
||||
enum CONTENT_TYPE {
|
||||
/**
|
||||
* Represents an empty content type. A content type with the distinguished
|
||||
* value empty validates elements with no character or element
|
||||
* information item children.
|
||||
*/
|
||||
CONTENTTYPE_EMPTY = 0,
|
||||
/**
|
||||
* Represents a simple content type. A content type which is a simple
|
||||
* validates elements with character-only children.
|
||||
*/
|
||||
CONTENTTYPE_SIMPLE = 1,
|
||||
/**
|
||||
* Represents an element-only content type. An element-only content type
|
||||
* validates elements with children that conform to the supplied content
|
||||
* model.
|
||||
*/
|
||||
CONTENTTYPE_ELEMENT = 2,
|
||||
/**
|
||||
* Represents a mixed content type.
|
||||
*/
|
||||
CONTENTTYPE_MIXED = 3
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param complexTypeInfo
|
||||
* @param xsWildcard
|
||||
* @param xsSimpleType
|
||||
* @param xsAttList
|
||||
* @param xsBaseType
|
||||
* @param xsParticle
|
||||
* @param headAnnot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSComplexTypeDefinition
|
||||
(
|
||||
ComplexTypeInfo* const complexTypeInfo
|
||||
, XSWildcard* const xsWildcard
|
||||
, XSSimpleTypeDefinition* const xsSimpleType
|
||||
, XSAttributeUseList* const xsAttList
|
||||
, XSTypeDefinition* const xsBaseType
|
||||
, XSParticle* const xsParticle
|
||||
, XSAnnotation* const headAnnot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSComplexTypeDefinition();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSComplexTypeDefinition methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [derivation method]: either <code>DERIVATION_EXTENSION</code>,
|
||||
* <code>DERIVATION_RESTRICTION</code>, or <code>DERIVATION_NONE</code>
|
||||
* (see <code>XSObject</code>).
|
||||
*/
|
||||
XSConstants::DERIVATION_TYPE getDerivationMethod() const;
|
||||
|
||||
/**
|
||||
* [abstract]: a boolean. Complex types for which <code>abstract</code> is
|
||||
* true must not be used as the type definition for the validation of
|
||||
* element information items.
|
||||
*/
|
||||
bool getAbstract() const;
|
||||
|
||||
/**
|
||||
* A set of attribute uses.
|
||||
*/
|
||||
XSAttributeUseList *getAttributeUses();
|
||||
|
||||
/**
|
||||
* Optional.An attribute wildcard.
|
||||
*/
|
||||
XSWildcard *getAttributeWildcard() const;
|
||||
|
||||
/**
|
||||
* [content type]: one of empty (<code>CONTENTTYPE_EMPTY</code>), a simple
|
||||
* type definition (<code>CONTENTTYPE_SIMPLE</code>), mixed (
|
||||
* <code>CONTENTTYPE_MIXED</code>), or element-only (
|
||||
* <code>CONTENTTYPE_ELEMENT</code>).
|
||||
*/
|
||||
CONTENT_TYPE getContentType() const;
|
||||
|
||||
/**
|
||||
* A simple type definition corresponding to simple content model,
|
||||
* otherwise <code>null</code>
|
||||
*/
|
||||
XSSimpleTypeDefinition *getSimpleType() const;
|
||||
|
||||
/**
|
||||
* A particle for mixed or element-only content model, otherwise
|
||||
* <code>null</code>
|
||||
*/
|
||||
XSParticle *getParticle() const;
|
||||
|
||||
/**
|
||||
* [prohibited substitutions]: a subset of {extension, restriction}
|
||||
* @param toTest Extension or restriction constants (see
|
||||
* <code>XSObject</code>).
|
||||
* @return True if toTest is a prohibited substitution, otherwise
|
||||
* false.
|
||||
*/
|
||||
bool isProhibitedSubstitution(XSConstants::DERIVATION_TYPE toTest);
|
||||
|
||||
/**
|
||||
* [prohibited substitutions]: A subset of {extension, restriction} or
|
||||
* <code>DERIVATION_NONE</code> represented as a bit flag (see
|
||||
* <code>XSObject</code>).
|
||||
*/
|
||||
short getProhibitedSubstitutions() const;
|
||||
|
||||
/**
|
||||
* A set of [annotations].
|
||||
*/
|
||||
XSAnnotationList *getAnnotations();
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem *getNamespaceItem();
|
||||
|
||||
/**
|
||||
* A boolean that specifies if the type definition is
|
||||
* anonymous. Convenience attribute.
|
||||
*/
|
||||
bool getAnonymous() const;
|
||||
|
||||
/**
|
||||
* {base type definition}: either a simple type definition or a complex
|
||||
* type definition.
|
||||
*/
|
||||
XSTypeDefinition *getBaseType();
|
||||
|
||||
/**
|
||||
* Convenience method: check if this type is derived from the given
|
||||
* <code>ancestorType</code>.
|
||||
* @param ancestorType An ancestor type definition.
|
||||
* @return Return true if this type is derived from
|
||||
* <code>ancestorType</code>.
|
||||
*/
|
||||
bool derivedFromType(const XSTypeDefinition* const ancestorType);
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Set the base type
|
||||
*/
|
||||
void setBaseType(XSTypeDefinition* const xsBaseType);
|
||||
friend class XSObjectFactory;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSComplexTypeDefinition(const XSComplexTypeDefinition&);
|
||||
XSComplexTypeDefinition & operator=(const XSComplexTypeDefinition &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
ComplexTypeInfo* fComplexTypeInfo;
|
||||
XSWildcard* fXSWildcard;
|
||||
XSAttributeUseList* fXSAttributeUseList;
|
||||
XSSimpleTypeDefinition* fXSSimpleTypeDefinition;
|
||||
XSAnnotationList* fXSAnnotationList;
|
||||
XSParticle* fParticle;
|
||||
short fProhibitedSubstitution;
|
||||
};
|
||||
|
||||
|
||||
inline XSAttributeUseList* XSComplexTypeDefinition::getAttributeUses()
|
||||
{
|
||||
return fXSAttributeUseList;
|
||||
}
|
||||
|
||||
inline XSWildcard* XSComplexTypeDefinition::getAttributeWildcard() const
|
||||
{
|
||||
return fXSWildcard;
|
||||
}
|
||||
|
||||
inline XSSimpleTypeDefinition* XSComplexTypeDefinition::getSimpleType() const
|
||||
{
|
||||
return fXSSimpleTypeDefinition;
|
||||
}
|
||||
|
||||
inline short XSComplexTypeDefinition::getProhibitedSubstitutions() const
|
||||
{
|
||||
return fProhibitedSubstitution;
|
||||
}
|
||||
|
||||
inline XSParticle *XSComplexTypeDefinition::getParticle() const
|
||||
{
|
||||
return fParticle;
|
||||
}
|
||||
|
||||
inline void
|
||||
XSComplexTypeDefinition::setBaseType(XSTypeDefinition* const xsBaseType)
|
||||
{
|
||||
fBaseType = xsBaseType;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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: XSConstants.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSCONSTANTS_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSCONSTANTS_HPP
|
||||
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/util/RefArrayVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This contains constants needed in the schema component model.
|
||||
*/
|
||||
|
||||
// forward definitions for typedefs
|
||||
class XSAnnotation;
|
||||
class XSAttributeUse;
|
||||
class XSFacet;
|
||||
class XSMultiValueFacet;
|
||||
class XSNamespaceItem;
|
||||
class XSParticle;
|
||||
class XSSimpleTypeDefinition;
|
||||
|
||||
// these typedefs are intended to help hide dependence on utility
|
||||
// classes, as well as to define more intuitive names for commonly
|
||||
// used concepts.
|
||||
|
||||
typedef RefVectorOf <XSAnnotation> XSAnnotationList;
|
||||
typedef RefVectorOf <XSAttributeUse> XSAttributeUseList;
|
||||
typedef RefVectorOf <XSFacet> XSFacetList;
|
||||
typedef RefVectorOf <XSMultiValueFacet> XSMultiValueFacetList;
|
||||
typedef RefVectorOf <XSNamespaceItem> XSNamespaceItemList;
|
||||
typedef RefVectorOf <XSParticle> XSParticleList;
|
||||
typedef RefVectorOf <XSSimpleTypeDefinition> XSSimpleTypeDefinitionList;
|
||||
typedef RefArrayVectorOf <XMLCh> StringList;
|
||||
|
||||
class XMLPARSER_EXPORT XSConstants
|
||||
{
|
||||
public:
|
||||
|
||||
// XML Schema Components
|
||||
enum COMPONENT_TYPE {
|
||||
/**
|
||||
* The object describes an attribute declaration.
|
||||
*/
|
||||
ATTRIBUTE_DECLARATION = 1,
|
||||
/**
|
||||
* The object describes an element declaration.
|
||||
*/
|
||||
ELEMENT_DECLARATION = 2,
|
||||
/**
|
||||
* The object describes a complex type or simple type definition.
|
||||
*/
|
||||
TYPE_DEFINITION = 3,
|
||||
/**
|
||||
* The object describes an attribute use definition.
|
||||
*/
|
||||
ATTRIBUTE_USE = 4,
|
||||
/**
|
||||
* The object describes an attribute group definition.
|
||||
*/
|
||||
ATTRIBUTE_GROUP_DEFINITION= 5,
|
||||
/**
|
||||
* The object describes a model group definition.
|
||||
*/
|
||||
MODEL_GROUP_DEFINITION = 6,
|
||||
/**
|
||||
* A model group.
|
||||
*/
|
||||
MODEL_GROUP = 7,
|
||||
/**
|
||||
* The object describes a particle.
|
||||
*/
|
||||
PARTICLE = 8,
|
||||
/**
|
||||
* The object describes a wildcard.
|
||||
*/
|
||||
WILDCARD = 9,
|
||||
/**
|
||||
* The object describes an identity constraint definition.
|
||||
*/
|
||||
IDENTITY_CONSTRAINT = 10,
|
||||
/**
|
||||
* The object describes a notation declaration.
|
||||
*/
|
||||
NOTATION_DECLARATION = 11,
|
||||
/**
|
||||
* The object describes an annotation.
|
||||
*/
|
||||
ANNOTATION = 12,
|
||||
/**
|
||||
* The object describes a constraining facet.
|
||||
*/
|
||||
FACET = 13,
|
||||
|
||||
/**
|
||||
* The object describes enumeration/pattern facets.
|
||||
*/
|
||||
MULTIVALUE_FACET = 14
|
||||
};
|
||||
|
||||
// Derivation constants
|
||||
enum DERIVATION_TYPE {
|
||||
/**
|
||||
* No constraint is available.
|
||||
*/
|
||||
DERIVATION_NONE = 0,
|
||||
/**
|
||||
* <code>XSTypeDefinition</code> final set or
|
||||
* <code>XSElementDeclaration</code> disallowed substitution group.
|
||||
*/
|
||||
DERIVATION_EXTENSION = 1,
|
||||
/**
|
||||
* <code>XSTypeDefinition</code> final set or
|
||||
* <code>XSElementDeclaration</code> disallowed substitution group.
|
||||
*/
|
||||
DERIVATION_RESTRICTION = 2,
|
||||
/**
|
||||
* <code>XSTypeDefinition</code> final set.
|
||||
*/
|
||||
DERIVATION_SUBSTITUTION = 4,
|
||||
/**
|
||||
* <code>XSTypeDefinition</code> final set.
|
||||
*/
|
||||
DERIVATION_UNION = 8,
|
||||
/**
|
||||
* <code>XSTypeDefinition</code> final set.
|
||||
*/
|
||||
DERIVATION_LIST = 16
|
||||
};
|
||||
|
||||
// Scope
|
||||
enum SCOPE {
|
||||
/**
|
||||
* The scope of a declaration within named model groups or attribute
|
||||
* groups is <code>absent</code>. The scope of such declaration is
|
||||
* determined when it is used in the construction of complex type
|
||||
* definitions.
|
||||
*/
|
||||
SCOPE_ABSENT = 0,
|
||||
/**
|
||||
* A scope of <code>global</code> identifies top-level declarations.
|
||||
*/
|
||||
SCOPE_GLOBAL = 1,
|
||||
/**
|
||||
* <code>Locally scoped</code> declarations are available for use only
|
||||
* within the complex type.
|
||||
*/
|
||||
SCOPE_LOCAL = 2
|
||||
};
|
||||
|
||||
// Value Constraint
|
||||
enum VALUE_CONSTRAINT {
|
||||
/**
|
||||
* Indicates that the component does not have any value constraint.
|
||||
*/
|
||||
VALUE_CONSTRAINT_NONE = 0,
|
||||
/**
|
||||
* Indicates that there is a default value constraint.
|
||||
*/
|
||||
VALUE_CONSTRAINT_DEFAULT = 1,
|
||||
/**
|
||||
* Indicates that there is a fixed value constraint for this attribute.
|
||||
*/
|
||||
VALUE_CONSTRAINT_FIXED = 2
|
||||
};
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSConstants();
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* 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: XSElementDeclaration.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSIDCDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
|
||||
#include <xercesc/util/StringPool.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSElementDeclaration: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSElementDeclaration::XSElementDeclaration
|
||||
(
|
||||
SchemaElementDecl* const schemaElementDecl
|
||||
, XSTypeDefinition* const typeDefinition
|
||||
, XSElementDeclaration* const substitutionGroupAffiliation
|
||||
, XSAnnotation* const annot
|
||||
, XSNamedMap<XSIDCDefinition>* const identityConstraints
|
||||
, XSModel* const xsModel
|
||||
, XSConstants::SCOPE elemScope
|
||||
, XSComplexTypeDefinition* const enclosingTypeDefinition
|
||||
, MemoryManager* const manager
|
||||
)
|
||||
: XSObject(XSConstants::ELEMENT_DECLARATION, xsModel, manager)
|
||||
, fDisallowedSubstitutions(0)
|
||||
, fSubstitutionGroupExclusions(0)
|
||||
, fScope(elemScope)
|
||||
, fSchemaElementDecl(schemaElementDecl)
|
||||
, fTypeDefinition(typeDefinition)
|
||||
, fEnclosingTypeDefinition(enclosingTypeDefinition)
|
||||
, fSubstitutionGroupAffiliation(substitutionGroupAffiliation)
|
||||
, fAnnotation(annot)
|
||||
, fIdentityConstraints(identityConstraints)
|
||||
{
|
||||
// set block and final information
|
||||
// NOTE: rest of setup will be taken care of in construct()
|
||||
int blockFinalSet = fSchemaElementDecl->getBlockSet();
|
||||
if (blockFinalSet)
|
||||
{
|
||||
if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
|
||||
fDisallowedSubstitutions |= XSConstants::DERIVATION_EXTENSION;
|
||||
|
||||
if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
|
||||
fDisallowedSubstitutions |= XSConstants::DERIVATION_RESTRICTION;
|
||||
|
||||
if (blockFinalSet & SchemaSymbols::XSD_SUBSTITUTION)
|
||||
fDisallowedSubstitutions |= XSConstants::DERIVATION_SUBSTITUTION;
|
||||
}
|
||||
|
||||
if (0 != (blockFinalSet = fSchemaElementDecl->getFinalSet()))
|
||||
{
|
||||
if (blockFinalSet & SchemaSymbols::XSD_EXTENSION)
|
||||
fSubstitutionGroupExclusions |= XSConstants::DERIVATION_EXTENSION;
|
||||
|
||||
if (blockFinalSet & SchemaSymbols::XSD_RESTRICTION)
|
||||
fSubstitutionGroupExclusions |= XSConstants::DERIVATION_RESTRICTION;
|
||||
}
|
||||
}
|
||||
|
||||
XSElementDeclaration::~XSElementDeclaration()
|
||||
{
|
||||
// don't delete fTypeDefinition - deleted by XSModel
|
||||
// don't delete fSubstitutionGroupAffiliation - deleted by XSModel
|
||||
if (fIdentityConstraints)
|
||||
delete fIdentityConstraints;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSElementDeclaration: XSObject virtual methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh *XSElementDeclaration::getName() const
|
||||
{
|
||||
return fSchemaElementDecl->getElementName()->getLocalPart();
|
||||
}
|
||||
|
||||
const XMLCh *XSElementDeclaration::getNamespace()
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fSchemaElementDecl->getURI());
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSElementDeclaration::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSElementDeclaration: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XSConstants::VALUE_CONSTRAINT XSElementDeclaration::getConstraintType() const
|
||||
{
|
||||
if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_FIXED)
|
||||
return XSConstants::VALUE_CONSTRAINT_FIXED;
|
||||
|
||||
if (fSchemaElementDecl->getDefaultValue())
|
||||
return XSConstants::VALUE_CONSTRAINT_DEFAULT;
|
||||
|
||||
return XSConstants::VALUE_CONSTRAINT_NONE;
|
||||
}
|
||||
|
||||
const XMLCh *XSElementDeclaration::getConstraintValue()
|
||||
{
|
||||
return fSchemaElementDecl->getDefaultValue();
|
||||
}
|
||||
|
||||
bool XSElementDeclaration::getNillable() const
|
||||
{
|
||||
if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_NILLABLE)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool XSElementDeclaration::isSubstitutionGroupExclusion(XSConstants::DERIVATION_TYPE exclusion)
|
||||
{
|
||||
if (fSubstitutionGroupExclusions & exclusion)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool XSElementDeclaration::isDisallowedSubstitution(XSConstants::DERIVATION_TYPE disallowed)
|
||||
{
|
||||
if (fDisallowedSubstitutions & disallowed)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool XSElementDeclaration::getAbstract() const
|
||||
{
|
||||
if (fSchemaElementDecl->getMiscFlags() & SchemaSymbols::XSD_ABSTRACT)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* 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: XSElementDeclaration.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSELEMENTDECLARATION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSELEMENTDECLARATION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamedMap.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Element Declaration
|
||||
* component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSComplexTypeDefinition;
|
||||
class XSIDCDefinition;
|
||||
class XSTypeDefinition;
|
||||
class SchemaElementDecl;
|
||||
|
||||
class XMLPARSER_EXPORT XSElementDeclaration : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param schemaElementDecl
|
||||
* @param typeDefinition
|
||||
* @param substitutionGroupAffiliation
|
||||
* @param annot
|
||||
* @param identityConstraints
|
||||
* @param xsModel
|
||||
* @param elemScope
|
||||
* @param enclosingTypeDefinition
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSElementDeclaration
|
||||
(
|
||||
SchemaElementDecl* const schemaElementDecl
|
||||
, XSTypeDefinition* const typeDefinition
|
||||
, XSElementDeclaration* const substitutionGroupAffiliation
|
||||
, XSAnnotation* const annot
|
||||
, XSNamedMap<XSIDCDefinition>* const identityConstraints
|
||||
, XSModel* const xsModel
|
||||
, XSConstants::SCOPE elemScope = XSConstants::SCOPE_ABSENT
|
||||
, XSComplexTypeDefinition* const enclosingTypeDefinition = 0
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSElementDeclaration();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name overridden XSXSObject methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem *getNamespaceItem();
|
||||
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSElementDeclaration methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [type definition]: either a simple type definition or a complex type
|
||||
* definition.
|
||||
*/
|
||||
XSTypeDefinition *getTypeDefinition() const;
|
||||
|
||||
/**
|
||||
* Optional. One of <code>SCOPE_GLOBAL</code>, <code>SCOPE_LOCAL</code>,
|
||||
* or <code>SCOPE_ABSENT</code>. If the scope is local, then the
|
||||
* <code>enclosingCTDefinition</code> is present.
|
||||
*/
|
||||
XSConstants::SCOPE getScope() const;
|
||||
|
||||
/**
|
||||
* The complex type definition for locally scoped declarations (see
|
||||
* <code>scope</code>).
|
||||
*/
|
||||
XSComplexTypeDefinition *getEnclosingCTDefinition() const;
|
||||
|
||||
/**
|
||||
* [Value constraint]: one of <code>VC_NONE, VC_DEFAULT, VC_FIXED</code>.
|
||||
*/
|
||||
XSConstants::VALUE_CONSTRAINT getConstraintType() const;
|
||||
|
||||
/**
|
||||
* [Value constraint]: the actual value with respect to the [type
|
||||
* definition].
|
||||
*/
|
||||
const XMLCh *getConstraintValue();
|
||||
|
||||
/**
|
||||
* If nillable is true, then an element may also be valid if it carries
|
||||
* the namespace qualified attribute with local name <code>nil</code>
|
||||
* from namespace <code>http://www.w3.org/2001/XMLSchema-instance</code>
|
||||
* and value <code>true</code> (xsi:nil) even if it has no text or
|
||||
* element content despite a <code>content type</code> which would
|
||||
* otherwise require content.
|
||||
*/
|
||||
bool getNillable() const;
|
||||
|
||||
/**
|
||||
* identity-constraint definitions: a set of constraint definitions.
|
||||
*/
|
||||
XSNamedMap <XSIDCDefinition> *getIdentityConstraints();
|
||||
|
||||
/**
|
||||
* [substitution group affiliation]: optional. A top-level element
|
||||
* definition.
|
||||
*/
|
||||
XSElementDeclaration *getSubstitutionGroupAffiliation() const;
|
||||
|
||||
/**
|
||||
* Convenience method. Check if <code>exclusion</code> is a substitution
|
||||
* group exclusion for this element declaration.
|
||||
* @param exclusion
|
||||
* <code>DERIVATION_EXTENSION, DERIVATION_RESTRICTION</code> or
|
||||
* <code>DERIVATION_NONE</code>. Represents final set for the element.
|
||||
* @return True if <code>exclusion</code> is a part of the substitution
|
||||
* group exclusion subset.
|
||||
*/
|
||||
bool isSubstitutionGroupExclusion(XSConstants::DERIVATION_TYPE exclusion);
|
||||
|
||||
/**
|
||||
* [substitution group exclusions]: the returned value is a bit
|
||||
* combination of the subset of {
|
||||
* <code>DERIVATION_EXTENSION, DERIVATION_RESTRICTION</code>} or
|
||||
* <code>DERIVATION_NONE</code>.
|
||||
*/
|
||||
short getSubstitutionGroupExclusions() const;
|
||||
|
||||
/**
|
||||
* Convenience method. Check if <code>disallowed</code> is a disallowed
|
||||
* substitution for this element declaration.
|
||||
* @param disallowed {
|
||||
* <code>DERIVATION_SUBSTITUTION, DERIVATION_EXTENSION, DERIVATION_RESTRICTION</code>
|
||||
* } or <code>DERIVATION_NONE</code>. Represents a block set for the
|
||||
* element.
|
||||
* @return True if <code>disallowed</code> is a part of the substitution
|
||||
* group exclusion subset.
|
||||
*/
|
||||
bool isDisallowedSubstitution(XSConstants::DERIVATION_TYPE disallowed);
|
||||
|
||||
/**
|
||||
* [disallowed substitutions]: the returned value is a bit combination of
|
||||
* the subset of {
|
||||
* <code>DERIVATION_SUBSTITUTION, DERIVATION_EXTENSION, DERIVATION_RESTRICTION</code>
|
||||
* } corresponding to substitutions disallowed by this
|
||||
* <code>XSElementDeclaration</code> or <code>DERIVATION_NONE</code>.
|
||||
*/
|
||||
short getDisallowedSubstitutions() const;
|
||||
|
||||
/**
|
||||
* {abstract} A boolean.
|
||||
*/
|
||||
bool getAbstract() const;
|
||||
|
||||
/**
|
||||
* Optional. Annotation.
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
void setTypeDefinition(XSTypeDefinition* typeDefinition);
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
void setEnclosingCTDefinition(XSComplexTypeDefinition* const toSet);
|
||||
friend class XSObjectFactory;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSElementDeclaration(const XSElementDeclaration&);
|
||||
XSElementDeclaration & operator=(const XSElementDeclaration &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
short fDisallowedSubstitutions;
|
||||
short fSubstitutionGroupExclusions;
|
||||
XSConstants::SCOPE fScope;
|
||||
SchemaElementDecl* fSchemaElementDecl;
|
||||
XSTypeDefinition* fTypeDefinition;
|
||||
XSComplexTypeDefinition* fEnclosingTypeDefinition;
|
||||
XSElementDeclaration* fSubstitutionGroupAffiliation;
|
||||
XSAnnotation* fAnnotation;
|
||||
XSNamedMap<XSIDCDefinition>* fIdentityConstraints;
|
||||
};
|
||||
|
||||
inline XSTypeDefinition* XSElementDeclaration::getTypeDefinition() const
|
||||
{
|
||||
return fTypeDefinition;
|
||||
}
|
||||
|
||||
inline XSNamedMap<XSIDCDefinition>* XSElementDeclaration::getIdentityConstraints()
|
||||
{
|
||||
return fIdentityConstraints;
|
||||
}
|
||||
|
||||
inline XSElementDeclaration* XSElementDeclaration::getSubstitutionGroupAffiliation() const
|
||||
{
|
||||
return fSubstitutionGroupAffiliation;
|
||||
}
|
||||
|
||||
inline short XSElementDeclaration::getSubstitutionGroupExclusions() const
|
||||
{
|
||||
return fSubstitutionGroupExclusions;
|
||||
}
|
||||
|
||||
inline short XSElementDeclaration::getDisallowedSubstitutions() const
|
||||
{
|
||||
return fDisallowedSubstitutions;
|
||||
}
|
||||
|
||||
inline XSAnnotation *XSElementDeclaration::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
inline XSConstants::SCOPE XSElementDeclaration::getScope() const
|
||||
{
|
||||
return fScope;
|
||||
}
|
||||
|
||||
inline XSComplexTypeDefinition *XSElementDeclaration::getEnclosingCTDefinition() const
|
||||
{
|
||||
return fEnclosingTypeDefinition;
|
||||
}
|
||||
|
||||
inline void XSElementDeclaration::setTypeDefinition(XSTypeDefinition* typeDefinition)
|
||||
{
|
||||
fTypeDefinition = typeDefinition;
|
||||
}
|
||||
|
||||
inline void XSElementDeclaration::setEnclosingCTDefinition(XSComplexTypeDefinition* const toSet)
|
||||
{
|
||||
fEnclosingTypeDefinition = toSet;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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: XSFacet.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSFacet.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSFacet: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSFacet::XSFacet(XSSimpleTypeDefinition::FACET facetKind,
|
||||
const XMLCh* const lexicalValue,
|
||||
bool isFixed,
|
||||
XSAnnotation* const annot,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager)
|
||||
: XSObject(XSConstants::FACET, xsModel, manager)
|
||||
, fFacetKind(facetKind)
|
||||
, fIsFixed(isFixed)
|
||||
, fLexicalValue(lexicalValue)
|
||||
, fAnnotation(annot)
|
||||
{
|
||||
}
|
||||
|
||||
XSFacet::~XSFacet()
|
||||
{
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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: XSFacet.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSFACET_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSFACET_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This represents all Schema Facet components with the exception
|
||||
* of Enumeration and Pattern Facets, which are represented by the
|
||||
* XSMultiValueFacet interface.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
|
||||
class XMLPARSER_EXPORT XSFacet : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param facetKind
|
||||
* @param lexicalValue
|
||||
* @param isFixed
|
||||
* @param annot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSFacet
|
||||
(
|
||||
XSSimpleTypeDefinition::FACET facetKind
|
||||
, const XMLCh* const lexicalValue
|
||||
, bool isFixed
|
||||
, XSAnnotation* const annot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSFacet();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSFacet methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* @return An indication as to the facet's type; see <code>XSSimpleTypeDefinition::FACET</code>
|
||||
*/
|
||||
XSSimpleTypeDefinition::FACET getFacetKind() const;
|
||||
|
||||
/**
|
||||
* @return Returns a value of a constraining facet.
|
||||
*/
|
||||
const XMLCh *getLexicalFacetValue() const;
|
||||
|
||||
/**
|
||||
* Check whether a facet value is fixed.
|
||||
*/
|
||||
bool isFixed() const;
|
||||
|
||||
/**
|
||||
* @return an annotation
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSFacet(const XSFacet&);
|
||||
XSFacet & operator=(const XSFacet &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
XSSimpleTypeDefinition::FACET fFacetKind;
|
||||
bool fIsFixed;
|
||||
const XMLCh* fLexicalValue;
|
||||
XSAnnotation* fAnnotation;
|
||||
};
|
||||
|
||||
inline XSSimpleTypeDefinition::FACET XSFacet::getFacetKind() const
|
||||
{
|
||||
return fFacetKind;
|
||||
}
|
||||
|
||||
inline const XMLCh* XSFacet::getLexicalFacetValue() const
|
||||
{
|
||||
return fLexicalValue;
|
||||
}
|
||||
|
||||
inline bool XSFacet::isFixed() const
|
||||
{
|
||||
return fIsFixed;
|
||||
}
|
||||
|
||||
inline XSAnnotation* XSFacet::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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: XSIDCDefinition.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSIDCDefinition.hpp>
|
||||
#include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
|
||||
#include <xercesc/validators/schema/identity/IC_Selector.hpp>
|
||||
#include <xercesc/validators/schema/identity/XercesXPath.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/util/StringPool.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSIDCDefinition: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSIDCDefinition::XSIDCDefinition(IdentityConstraint* const identityConstraint,
|
||||
XSIDCDefinition* const keyIC,
|
||||
XSAnnotation* const headAnnot,
|
||||
StringList* const stringList,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager)
|
||||
: XSObject(XSConstants::IDENTITY_CONSTRAINT, xsModel, manager)
|
||||
, fIdentityConstraint(identityConstraint)
|
||||
, fKey(keyIC)
|
||||
, fStringList(stringList)
|
||||
, fXSAnnotationList(0)
|
||||
{
|
||||
if (headAnnot)
|
||||
{
|
||||
fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(1, false, manager);
|
||||
|
||||
XSAnnotation* annot = headAnnot;
|
||||
do
|
||||
{
|
||||
fXSAnnotationList->addElement(annot);
|
||||
annot = annot->getNext();
|
||||
} while (annot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
XSIDCDefinition::~XSIDCDefinition()
|
||||
{
|
||||
if (fStringList)
|
||||
delete fStringList;
|
||||
|
||||
// don't delete fKey - deleted by XSModel
|
||||
if (fXSAnnotationList)
|
||||
delete fXSAnnotationList;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSIDCDefinition: XSObject virtual methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh *XSIDCDefinition::getName() const
|
||||
{
|
||||
return fIdentityConstraint->getIdentityConstraintName();
|
||||
}
|
||||
|
||||
const XMLCh *XSIDCDefinition::getNamespace()
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fIdentityConstraint->getNamespaceURI());
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSIDCDefinition::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSIDCDefinition: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XSIDCDefinition::IC_CATEGORY XSIDCDefinition::getCategory() const
|
||||
{
|
||||
switch(fIdentityConstraint->getType()) {
|
||||
case IdentityConstraint::ICType_UNIQUE:
|
||||
return IC_UNIQUE;
|
||||
case IdentityConstraint::ICType_KEY:
|
||||
return IC_KEY;
|
||||
case IdentityConstraint::ICType_KEYREF:
|
||||
return IC_KEYREF;
|
||||
default:
|
||||
// REVISIT:
|
||||
// should never really get here... IdentityConstraint::Unknown is the other
|
||||
// choice so need a default case for completeness; should issues error?
|
||||
return IC_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
const XMLCh *XSIDCDefinition::getSelectorStr()
|
||||
{
|
||||
return fIdentityConstraint->getSelector()->getXPath()->getExpression();
|
||||
}
|
||||
|
||||
|
||||
XSAnnotationList *XSIDCDefinition::getAnnotations()
|
||||
{
|
||||
return fXSAnnotationList;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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: XSIDCDefinition.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSIDCDEFINITION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSIDCDEFINITION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Identity Constraint
|
||||
* Definition component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class IdentityConstraint;
|
||||
|
||||
class XMLPARSER_EXPORT XSIDCDefinition : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Identity Constraints
|
||||
enum IC_CATEGORY {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
IC_KEY = 1,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
IC_KEYREF = 2,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
IC_UNIQUE = 3
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param identityConstraint
|
||||
* @param keyIC
|
||||
* @param headAnnot
|
||||
* @param stringList
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSIDCDefinition
|
||||
(
|
||||
IdentityConstraint* const identityConstraint
|
||||
, XSIDCDefinition* const keyIC
|
||||
, XSAnnotation* const headAnnot
|
||||
, StringList* const stringList
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSIDCDefinition();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name overridden XSXSObject methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem *getNamespaceItem();
|
||||
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSIDCDefinition methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [identity-constraint category]: one of IC_KEY, IC_KEYREF or IC_UNIQUE.
|
||||
*/
|
||||
IC_CATEGORY getCategory() const;
|
||||
|
||||
/**
|
||||
* [selector]: a restricted XPath expression.
|
||||
*/
|
||||
const XMLCh *getSelectorStr();
|
||||
|
||||
/**
|
||||
* [fields]: a non-empty list of restricted XPath ([XPath]) expressions.
|
||||
*/
|
||||
StringList *getFieldStrs();
|
||||
|
||||
/**
|
||||
* [referenced key]: required if [identity-constraint category] is IC_KEYREF,
|
||||
* forbidden otherwise (when an identity-constraint definition with [
|
||||
* identity-constraint category] equal to IC_KEY or IC_UNIQUE).
|
||||
*/
|
||||
XSIDCDefinition *getRefKey() const;
|
||||
|
||||
/**
|
||||
* A set of [annotations].
|
||||
*/
|
||||
XSAnnotationList *getAnnotations();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSIDCDefinition(const XSIDCDefinition&);
|
||||
XSIDCDefinition & operator=(const XSIDCDefinition &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
IdentityConstraint* fIdentityConstraint;
|
||||
XSIDCDefinition* fKey;
|
||||
StringList* fStringList;
|
||||
XSAnnotationList* fXSAnnotationList;
|
||||
};
|
||||
|
||||
|
||||
inline StringList* XSIDCDefinition::getFieldStrs()
|
||||
{
|
||||
return fStringList;
|
||||
}
|
||||
|
||||
inline XSIDCDefinition* XSIDCDefinition::getRefKey() const
|
||||
{
|
||||
return fKey;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,799 @@
|
||||
/*
|
||||
* 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: XSModel.cpp 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamespaceItem.hpp>
|
||||
#include <xercesc/validators/schema/SchemaGrammar.hpp>
|
||||
#include <xercesc/validators/common/GrammarResolver.hpp>
|
||||
#include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
|
||||
#include <xercesc/validators/schema/XercesGroupInfo.hpp>
|
||||
#include <xercesc/internal/XSObjectFactory.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSNotationDeclaration.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModel: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSModel::XSModel( XMLGrammarPool *grammarPool
|
||||
, MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fNamespaceStringList(0)
|
||||
, fXSNamespaceItemList(0)
|
||||
, fURIStringPool(0)
|
||||
, fXSAnnotationList(0)
|
||||
, fHashNamespace(0)
|
||||
, fObjFactory(0)
|
||||
, fDeleteNamespace(0)
|
||||
, fParent(0)
|
||||
, fDeleteParent(false)
|
||||
, fAddedS4SGrammar(false)
|
||||
{
|
||||
fURIStringPool = grammarPool->getURIStringPool();
|
||||
fObjFactory = new (fMemoryManager) XSObjectFactory(manager);
|
||||
|
||||
// Populate XSNamedMaps by going through the components
|
||||
for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
|
||||
(
|
||||
20, // size
|
||||
29, // modulus
|
||||
fURIStringPool,
|
||||
false, // adoptElems
|
||||
fMemoryManager
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// ATTRIBUTE_USE
|
||||
// MODEL_GROUP
|
||||
// PARTICLE
|
||||
// IDENTITY_CONSTRAINT
|
||||
// WILDCARD
|
||||
// ANNOTATION
|
||||
// FACET
|
||||
// MULTIVALUE
|
||||
fComponentMap[i] = 0;
|
||||
break;
|
||||
}
|
||||
fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);
|
||||
}
|
||||
|
||||
fNamespaceStringList = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);
|
||||
fXSNamespaceItemList = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);
|
||||
fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);
|
||||
fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);
|
||||
|
||||
// Loop through all grammars in the grammar pool to create the XSNamespaceItem's
|
||||
// which will have access to Annotation Information which can be used later when
|
||||
// we create all the XS components.
|
||||
XSNamespaceItem* namespaceItem = 0;
|
||||
RefHashTableOfEnumerator<Grammar> grammarEnum = grammarPool->getGrammarEnumerator();
|
||||
while (grammarEnum.hasMoreElements())
|
||||
{
|
||||
SchemaGrammar& sGrammar = (SchemaGrammar&) grammarEnum.nextElement();
|
||||
if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType ||
|
||||
XMLString::equals(sGrammar.getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))
|
||||
continue;
|
||||
|
||||
// NOTE: In the grammarpool, preprocessed grammars without targetnamespace
|
||||
// will use an empty string...
|
||||
XMLCh* NameSpace = XMLString::replicate(sGrammar.getTargetNamespace(), manager);
|
||||
fNamespaceStringList->addElement(NameSpace);
|
||||
namespaceItem = new (manager) XSNamespaceItem(this, &sGrammar, manager);
|
||||
fXSNamespaceItemList->addElement(namespaceItem);
|
||||
fHashNamespace->put(NameSpace, namespaceItem);
|
||||
}
|
||||
|
||||
// Now loop through all of the NamespaceItem's
|
||||
// First, we add S4S namespace (irrespective of whether we have any grammars)
|
||||
namespaceItem = new (manager) XSNamespaceItem
|
||||
(
|
||||
this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager
|
||||
);
|
||||
|
||||
fNamespaceStringList->addElement
|
||||
(
|
||||
XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager)
|
||||
);
|
||||
fXSNamespaceItemList->addElement(namespaceItem);
|
||||
fHashNamespace->put
|
||||
(
|
||||
(void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA
|
||||
, namespaceItem
|
||||
);
|
||||
|
||||
DatatypeValidatorFactory dvFactory(manager);
|
||||
addS4SToXSModel
|
||||
(
|
||||
namespaceItem
|
||||
, dvFactory.getBuiltInRegistry()
|
||||
);
|
||||
// don't include S4S (thus the -1)
|
||||
XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size() -1;
|
||||
for (XMLSize_t j = 0; j < numberOfNamespaces; j++)
|
||||
addGrammarToXSModel(fXSNamespaceItemList->elementAt(j));
|
||||
}
|
||||
|
||||
XSModel::XSModel( XSModel *baseModel
|
||||
, GrammarResolver *grammarResolver
|
||||
, MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fNamespaceStringList(0)
|
||||
, fXSNamespaceItemList(0)
|
||||
, fURIStringPool(0)
|
||||
, fXSAnnotationList(0)
|
||||
, fHashNamespace(0)
|
||||
, fObjFactory(0)
|
||||
, fDeleteNamespace(0)
|
||||
, fParent(baseModel)
|
||||
, fDeleteParent(true)
|
||||
, fAddedS4SGrammar(false)
|
||||
{
|
||||
fURIStringPool = grammarResolver->getStringPool();
|
||||
fObjFactory = new (manager) XSObjectFactory(manager);
|
||||
|
||||
XMLSize_t i;
|
||||
// Populate XSNamedMaps by going through the components
|
||||
for (i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
|
||||
(
|
||||
20, // size
|
||||
29, // modulus
|
||||
fURIStringPool,
|
||||
false, // adoptElems
|
||||
fMemoryManager
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// ATTRIBUTE_USE
|
||||
// MODEL_GROUP
|
||||
// PARTICLE
|
||||
// IDENTITY_CONSTRAINT
|
||||
// WILDCARD
|
||||
// ANNOTATION
|
||||
// FACET
|
||||
// MULTIVALUE
|
||||
fComponentMap[i] = 0;
|
||||
break;
|
||||
}
|
||||
fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager);
|
||||
}
|
||||
|
||||
fNamespaceStringList = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager);
|
||||
fXSNamespaceItemList = new (manager) RefVectorOf <XSNamespaceItem>(10, false, manager);
|
||||
fDeleteNamespace = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager);
|
||||
fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager);
|
||||
fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager);
|
||||
|
||||
if (fParent)
|
||||
{
|
||||
if (fParent->fAddedS4SGrammar)
|
||||
fAddedS4SGrammar = true;
|
||||
|
||||
// Need to copy information from parent so it can be returned in this object...
|
||||
for (i=0; i<fParent->fXSNamespaceItemList->size(); i++)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem = fParent->fXSNamespaceItemList->elementAt(i);
|
||||
fXSNamespaceItemList->addElement(namespaceItem);
|
||||
fNamespaceStringList->addElement
|
||||
(
|
||||
XMLString::replicate
|
||||
(
|
||||
namespaceItem->getSchemaNamespace(), manager
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
for (i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
for (XMLSize_t j=0; j<fParent->fComponentMap[i]->getLength(); j++)
|
||||
{
|
||||
XSObject* copyObj = fParent->fComponentMap[i]->item(j);
|
||||
fComponentMap[i]->addElement(copyObj,
|
||||
copyObj->getName(),
|
||||
copyObj->getNamespace());
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (XMLSize_t j=0; j<fParent->fIdVector[i]->size(); j++)
|
||||
{
|
||||
fIdVector[i]->addElement(fParent->fIdVector[i]->elementAt(j));
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<fParent->fXSAnnotationList->size(); i++)
|
||||
{
|
||||
fXSAnnotationList->addElement(fParent->fXSAnnotationList->elementAt(i));
|
||||
}
|
||||
|
||||
} // end of copying parent info
|
||||
|
||||
// Now add information from the new grammars but first create the
|
||||
// XSNamespaceItem's so we can have access to the XSAnnotations...
|
||||
ValueVectorOf<SchemaGrammar*>* grammarsToAdd = grammarResolver->getGrammarsToAddToXSModel();
|
||||
XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size();
|
||||
XMLSize_t numberOfNamespacesToAdd = 0;
|
||||
for (i=0; i < grammarsToAdd->size(); i++)
|
||||
{
|
||||
SchemaGrammar* lGrammar = grammarsToAdd->elementAt(i);
|
||||
if (lGrammar->getGrammarType() != Grammar::SchemaGrammarType ||
|
||||
XMLString::equals(lGrammar->getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA))
|
||||
continue;
|
||||
|
||||
XMLCh* NameSpace = XMLString::replicate(lGrammar->getTargetNamespace(), manager);
|
||||
fNamespaceStringList->addElement(NameSpace);
|
||||
|
||||
XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem(this, lGrammar, manager);
|
||||
fXSNamespaceItemList->addElement(namespaceItem);
|
||||
fHashNamespace->put(NameSpace, namespaceItem);
|
||||
fDeleteNamespace->addElement(namespaceItem);
|
||||
++numberOfNamespacesToAdd;
|
||||
}
|
||||
|
||||
// Add S4S namespace if needed
|
||||
if (!fAddedS4SGrammar)
|
||||
{
|
||||
DatatypeValidatorFactory dvFactory(manager);
|
||||
|
||||
XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem
|
||||
(
|
||||
this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager
|
||||
);
|
||||
|
||||
fNamespaceStringList->addElement
|
||||
(
|
||||
XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager)
|
||||
);
|
||||
fXSNamespaceItemList->addElement(namespaceItem);
|
||||
fHashNamespace->put
|
||||
(
|
||||
(void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA , namespaceItem
|
||||
);
|
||||
fDeleteNamespace->addElement(namespaceItem);
|
||||
addS4SToXSModel
|
||||
(
|
||||
namespaceItem
|
||||
, dvFactory.getBuiltInRegistry()
|
||||
);
|
||||
}
|
||||
|
||||
// Now loop through all of the newly created NamespaceItem's
|
||||
for (i=numberOfNamespaces; i<(numberOfNamespaces+numberOfNamespacesToAdd); i++)
|
||||
{
|
||||
addGrammarToXSModel(fXSNamespaceItemList->elementAt(i));
|
||||
} // end of namespaceItem loop
|
||||
}
|
||||
|
||||
XSModel::~XSModel()
|
||||
{
|
||||
for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
delete fComponentMap[i];
|
||||
break;
|
||||
}
|
||||
delete fIdVector[i];
|
||||
}
|
||||
|
||||
delete fNamespaceStringList;
|
||||
delete fXSNamespaceItemList;
|
||||
delete fXSAnnotationList;
|
||||
delete fHashNamespace;
|
||||
delete fObjFactory;
|
||||
|
||||
if (fDeleteNamespace)
|
||||
delete fDeleteNamespace;
|
||||
|
||||
if (fDeleteParent && fParent && fParent->fDeleteParent)
|
||||
delete fParent;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModel: Helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XSModel::addComponentToIdVector(XSObject* const component,
|
||||
XMLSize_t componentIndex)
|
||||
{
|
||||
component->setId(fIdVector[componentIndex]->size());
|
||||
fIdVector[componentIndex]->addElement(component);
|
||||
}
|
||||
|
||||
|
||||
void XSModel::addComponentToNamespace(XSNamespaceItem* const namespaceItem,
|
||||
XSObject* const component,
|
||||
XMLSize_t componentIndex,
|
||||
bool addToXSModel)
|
||||
{
|
||||
namespaceItem->fComponentMap[componentIndex]->addElement
|
||||
(
|
||||
component, component->getName(), namespaceItem->getSchemaNamespace()
|
||||
);
|
||||
namespaceItem->fHashMap[componentIndex]->put
|
||||
(
|
||||
(void *) component->getName(), component
|
||||
);
|
||||
|
||||
if (addToXSModel)
|
||||
{
|
||||
fComponentMap[componentIndex]->addElement
|
||||
(
|
||||
component, component->getName(), namespaceItem->getSchemaNamespace()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
XSModel::addS4SToXSModel(XSNamespaceItem* const namespaceItem,
|
||||
RefHashTableOf<DatatypeValidator>* const builtInDV)
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind
|
||||
(
|
||||
ComplexTypeInfo::getAnyType
|
||||
(
|
||||
fURIStringPool->getId(XMLUni::fgZeroLenString)
|
||||
)
|
||||
, this
|
||||
)
|
||||
, XSConstants::TYPE_DEFINITION - 1
|
||||
);
|
||||
|
||||
// Loop through built-in simple types
|
||||
// First add 'anySimpleType' which is the base for the other built-ins
|
||||
DatatypeValidator* dv = builtInDV->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind(dv, this, true)
|
||||
, XSConstants::TYPE_DEFINITION - 1
|
||||
);
|
||||
|
||||
// add remaining built-in
|
||||
RefHashTableOfEnumerator<DatatypeValidator> simpleEnum =
|
||||
RefHashTableOfEnumerator<DatatypeValidator> (builtInDV, false, fMemoryManager);
|
||||
while (simpleEnum.hasMoreElements())
|
||||
{
|
||||
DatatypeValidator& curSimple = simpleEnum.nextElement();
|
||||
if (&curSimple == dv)
|
||||
continue;
|
||||
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind(&curSimple, this)
|
||||
, XSConstants::TYPE_DEFINITION - 1
|
||||
);
|
||||
}
|
||||
|
||||
// Set flag to indicate that we have added S4S grammar info
|
||||
fAddedS4SGrammar = true;
|
||||
}
|
||||
|
||||
|
||||
void XSModel::addGrammarToXSModel(XSNamespaceItem* namespaceItem)
|
||||
{
|
||||
// Loop through top-level attribute declarations in the grammar...
|
||||
RefHashTableOf<XMLAttDef>* attDeclRegistry = namespaceItem->fGrammar->getAttributeDeclRegistry();
|
||||
if(attDeclRegistry) {
|
||||
RefHashTableOfEnumerator<XMLAttDef> attrEnum = RefHashTableOfEnumerator<XMLAttDef> (attDeclRegistry, false, fMemoryManager);
|
||||
while (attrEnum.hasMoreElements())
|
||||
{
|
||||
XSAttributeDeclaration* xsAttrDecl = fObjFactory->addOrFind
|
||||
(
|
||||
(SchemaAttDef*) &(attrEnum.nextElement()), this
|
||||
);
|
||||
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem, xsAttrDecl, XSConstants::ATTRIBUTE_DECLARATION - 1
|
||||
);
|
||||
} // end of attribute loop
|
||||
}
|
||||
|
||||
// Loop through top-level elements in the grammar...
|
||||
RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = namespaceItem->fGrammar->getElemEnumerator();
|
||||
while (elemEnum.hasMoreElements())
|
||||
{
|
||||
SchemaElementDecl& curElem = elemEnum.nextElement();
|
||||
if (curElem.getEnclosingScope() == Grammar::TOP_LEVEL_SCOPE)
|
||||
{
|
||||
XSElementDeclaration* xsElemDecl = fObjFactory->addOrFind
|
||||
(
|
||||
&curElem, this
|
||||
);
|
||||
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem, xsElemDecl, XSConstants::ELEMENT_DECLARATION -1
|
||||
);
|
||||
}
|
||||
} // end of element loop
|
||||
|
||||
// Now loop through top-level User Defined simple type definitions in the grammar...
|
||||
DVHashTable* dvHT = namespaceItem->fGrammar->getDatatypeRegistry()->getUserDefinedRegistry();
|
||||
if (dvHT)
|
||||
{
|
||||
RefHashTableOfEnumerator<DatatypeValidator> simpleUserEnum = RefHashTableOfEnumerator<DatatypeValidator> (dvHT, false, fMemoryManager);
|
||||
while (simpleUserEnum.hasMoreElements())
|
||||
{
|
||||
DatatypeValidator& curSimple = simpleUserEnum.nextElement();
|
||||
if (!curSimple.getAnonymous())
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind(&curSimple, this)
|
||||
, XSConstants::TYPE_DEFINITION - 1
|
||||
);
|
||||
}
|
||||
} // end of simple User loop
|
||||
}
|
||||
|
||||
// Loop through top-level COMPLEX type definitions in the grammar...
|
||||
RefHashTableOf<ComplexTypeInfo>* complexTypeRegistry = namespaceItem->fGrammar->getComplexTypeRegistry();
|
||||
if(complexTypeRegistry) {
|
||||
RefHashTableOfEnumerator<ComplexTypeInfo> complexEnum = RefHashTableOfEnumerator<ComplexTypeInfo> (complexTypeRegistry, false, fMemoryManager);
|
||||
while (complexEnum.hasMoreElements())
|
||||
{
|
||||
ComplexTypeInfo& curComplex = complexEnum.nextElement();
|
||||
if (!curComplex.getAnonymous())
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind(&curComplex, this)
|
||||
, XSConstants::TYPE_DEFINITION - 1
|
||||
);
|
||||
}
|
||||
} // end of type definition loop
|
||||
}
|
||||
|
||||
// Loop through top-level attribute group definitions in the grammar...
|
||||
RefHashTableOf<XercesAttGroupInfo>* attGroupInfoRegistry = namespaceItem->fGrammar->getAttGroupInfoRegistry();
|
||||
if(attGroupInfoRegistry) {
|
||||
RefHashTableOfEnumerator<XercesAttGroupInfo> attrGroupEnum = RefHashTableOfEnumerator<XercesAttGroupInfo> (attGroupInfoRegistry, false, fMemoryManager);
|
||||
while (attrGroupEnum.hasMoreElements())
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->createXSAttGroupDefinition
|
||||
(
|
||||
&(attrGroupEnum.nextElement()), this
|
||||
)
|
||||
, XSConstants::ATTRIBUTE_GROUP_DEFINITION - 1
|
||||
);
|
||||
} // end of attribute group loop
|
||||
}
|
||||
|
||||
// Loop through top-level model group definitions in the grammar...
|
||||
RefHashTableOf<XercesGroupInfo>* groupInfoRegistry = namespaceItem->fGrammar->getGroupInfoRegistry();
|
||||
if(groupInfoRegistry) {
|
||||
RefHashTableOfEnumerator<XercesGroupInfo> modelGroupEnum = RefHashTableOfEnumerator<XercesGroupInfo> (groupInfoRegistry, false, fMemoryManager);
|
||||
while (modelGroupEnum.hasMoreElements())
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->createXSModelGroupDefinition
|
||||
(
|
||||
&(modelGroupEnum.nextElement()), this
|
||||
)
|
||||
, XSConstants::MODEL_GROUP_DEFINITION - 1
|
||||
);
|
||||
} // end of model group loop
|
||||
}
|
||||
|
||||
// Loop through notations in the grammar...
|
||||
NameIdPoolEnumerator<XMLNotationDecl> notationEnum = namespaceItem->fGrammar->getNotationEnumerator();
|
||||
while (notationEnum.hasMoreElements())
|
||||
{
|
||||
addComponentToNamespace
|
||||
(
|
||||
namespaceItem
|
||||
, fObjFactory->addOrFind(&(notationEnum.nextElement()), this)
|
||||
, XSConstants::NOTATION_DECLARATION - 1
|
||||
);
|
||||
} // end of notation loop
|
||||
|
||||
// Loop through annotations in the grammar...
|
||||
// As annotations are already created as XSAnnotations no need to create them
|
||||
// or store them in the XercesToXSMap.
|
||||
XSAnnotation* annot = namespaceItem->fGrammar->getAnnotation();
|
||||
while (annot)
|
||||
{
|
||||
fXSAnnotationList->addElement(annot);
|
||||
namespaceItem->fXSAnnotationList->addElement(annot);
|
||||
addComponentToIdVector(annot, XSConstants::ANNOTATION -1);
|
||||
annot = annot->getNext();
|
||||
} // end of annotation loop
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModel: Access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* [schema components]: a list of top-level components, i.e. element
|
||||
* declarations, attribute declarations, etc.
|
||||
* @param objectType The type of the declaration, i.e.
|
||||
* <code>ELEMENT_DECLARATION</code>,
|
||||
* <code>TYPE_DEFINITION</code> and any other component type that
|
||||
* may be a property of a schema component.
|
||||
* @return A list of top-level definition of the specified type in
|
||||
* <code>objectType</code> or <code>null</code>.
|
||||
*/
|
||||
XSNamedMap <XSObject> *XSModel::getComponents(XSConstants::COMPONENT_TYPE objectType)
|
||||
{
|
||||
return fComponentMap[objectType -1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a list of top-level component declarations
|
||||
* that are defined within the specified namespace, i.e. element
|
||||
* declarations, attribute declarations, etc.
|
||||
* @param objectType The type of the declaration, i.e.
|
||||
* <code>ELEMENT_DECLARATION</code>.
|
||||
* @param compNamespace The namespace to which declaration belong or
|
||||
* <code>null</code> (for components with no target namespace).
|
||||
* @return A list of top-level definitions of the specified type in
|
||||
* <code>objectType</code> and defined in the specified
|
||||
* <code>namespace</code> or <code>null</code>.
|
||||
*/
|
||||
XSNamedMap <XSObject> *XSModel::getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType,
|
||||
const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getComponents(objectType);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* [annotations]: a set of annotations.
|
||||
*/
|
||||
XSAnnotationList *XSModel::getAnnotations()
|
||||
{
|
||||
return fXSAnnotationList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level element declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level element declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSElementDeclaration *XSModel::getElementDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getElementDeclaration(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level attribute declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level attribute declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSAttributeDeclaration *XSModel::getAttributeDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getAttributeDeclaration(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level simple or complex type
|
||||
* definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return An <code>XSTypeDefinition</code> or <code>null</code> if such
|
||||
* definition does not exist.
|
||||
*/
|
||||
XSTypeDefinition *XSModel::getTypeDefinition(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getTypeDefinition(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level attribute group definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level attribute group definition or <code>null</code> if
|
||||
* such definition does not exist.
|
||||
*/
|
||||
XSAttributeGroupDefinition *XSModel::getAttributeGroup(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getAttributeGroup(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level model group definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level model group definition definition or
|
||||
* <code>null</code> if such definition does not exist.
|
||||
*/
|
||||
XSModelGroupDefinition *XSModel::getModelGroupDefinition(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getModelGroupDefinition(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level notation declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level notation declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSNotationDeclaration *XSModel::getNotationDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace)
|
||||
{
|
||||
XSNamespaceItem* namespaceItem;
|
||||
if (compNamespace)
|
||||
namespaceItem = getNamespaceItem(compNamespace);
|
||||
else
|
||||
namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString);
|
||||
|
||||
if (namespaceItem)
|
||||
return namespaceItem->getNotationDeclaration(name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Return a component given a component type and a unique Id.
|
||||
* May not be supported for all component types.
|
||||
* @param compId unique Id of the component within its type
|
||||
* @param compType type of the component
|
||||
* @return the component of the given type with the given Id, or 0
|
||||
* if no such component exists or this is unsupported for
|
||||
* this type of component.
|
||||
*/
|
||||
XSObject *XSModel::getXSObjectById(XMLSize_t compId
|
||||
, XSConstants::COMPONENT_TYPE compType)
|
||||
{
|
||||
if (compId < fIdVector[compType -1]->size())
|
||||
return fIdVector[compType -1]->elementAt(compId);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSNamespaceItem* XSModel::getNamespaceItem(const XMLCh* const key)
|
||||
{
|
||||
XSNamespaceItem* xsName = fHashNamespace->get(key);
|
||||
if (xsName)
|
||||
return xsName;
|
||||
if (fParent)
|
||||
return fParent->getNamespaceItem(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSObject* XSModel::getXSObject(void* key)
|
||||
{
|
||||
XSObject* xsObj = fObjFactory->getObjectFromMap(key);
|
||||
|
||||
if (!xsObj && fParent)
|
||||
xsObj = fParent->getXSObject(key);
|
||||
|
||||
return xsObj;
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* 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: XSModel.hpp 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSMODEL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSMODEL_HPP
|
||||
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
#include <xercesc/framework/psvi/XSNamedMap.hpp>
|
||||
|
||||
#include <xercesc/util/ValueVectorOf.hpp>
|
||||
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class contains all properties of the Schema infoitem as determined
|
||||
* after an entire validation episode. That is, it contains all the properties
|
||||
* of all the Schema Namespace Information objects that went into
|
||||
* the validation episode.
|
||||
* Since it is not like other components, it does not
|
||||
* inherit from the XSObject interface.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained. It is designed to be subclassed; subclasses will
|
||||
* specify under what conditions it may be relied upon to have meaningful contents.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class Grammar;
|
||||
class XMLGrammarPool;
|
||||
class XSAnnotation;
|
||||
class XSAttributeDeclaration;
|
||||
class XSAttributeGroupDefinition;
|
||||
class XSElementDeclaration;
|
||||
class XSModelGroupDefinition;
|
||||
class XSNamespaceItem;
|
||||
class XSNotationDeclaration;
|
||||
class XSTypeDefinition;
|
||||
class XSObjectFactory;
|
||||
|
||||
class XMLPARSER_EXPORT XSModel : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The constructor to be used when a grammar pool contains all needed info
|
||||
* @param grammarPool the grammar pool containing the underlying data structures
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSModel( XMLGrammarPool *grammarPool
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/**
|
||||
* The constructor to be used when the XSModel must represent all
|
||||
* components in the union of an existing XSModel and a newly-created
|
||||
* Grammar(s) from the GrammarResolver
|
||||
*
|
||||
* @param baseModel the XSModel upon which this one is based
|
||||
* @param grammarResolver the grammar(s) whose components are to be merged
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSModel( XSModel *baseModel
|
||||
, GrammarResolver *grammarResolver
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSModel();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSModel methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a list of all namespaces that belong to
|
||||
* this schema. The value <code>null</code> is not a valid namespace
|
||||
* name, but if there are components that don't have a target namespace,
|
||||
* <code>null</code> is included in this list.
|
||||
*/
|
||||
StringList *getNamespaces();
|
||||
|
||||
/**
|
||||
* A set of namespace schema information information items ( of type
|
||||
* <code>XSNamespaceItem</code>), one for each namespace name which
|
||||
* appears as the target namespace of any schema component in the schema
|
||||
* used for that assessment, and one for absent if any schema component
|
||||
* in the schema had no target namespace. For more information see
|
||||
* schema information.
|
||||
*/
|
||||
XSNamespaceItemList *getNamespaceItems();
|
||||
|
||||
/**
|
||||
* [schema components]: a list of top-level components, i.e. element
|
||||
* declarations, attribute declarations, etc.
|
||||
* @param objectType The type of the declaration, i.e.
|
||||
* <code>ELEMENT_DECLARATION</code>,
|
||||
* <code>TYPE_DEFINITION</code> and any other component type that
|
||||
* may be a property of a schema component.
|
||||
* @return A list of top-level definition of the specified type in
|
||||
* <code>objectType</code> or <code>null</code>.
|
||||
*/
|
||||
XSNamedMap<XSObject> *getComponents(XSConstants::COMPONENT_TYPE objectType);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a list of top-level component declarations
|
||||
* that are defined within the specified namespace, i.e. element
|
||||
* declarations, attribute declarations, etc.
|
||||
* @param objectType The type of the declaration, i.e.
|
||||
* <code>ELEMENT_DECLARATION</code>.
|
||||
* @param compNamespace The namespace to which declaration belongs or
|
||||
* <code>null</code> (for components with no target namespace).
|
||||
* @return A list of top-level definitions of the specified type in
|
||||
* <code>objectType</code> and defined in the specified
|
||||
* <code>namespace</code> or <code>null</code>.
|
||||
*/
|
||||
XSNamedMap<XSObject> *getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType,
|
||||
const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* [annotations]: a set of annotations.
|
||||
*/
|
||||
XSAnnotationList *getAnnotations();
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level element declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level element declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSElementDeclaration *getElementDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level attribute declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level attribute declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSAttributeDeclaration *getAttributeDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level simple or complex type
|
||||
* definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return An <code>XSTypeDefinition</code> or <code>null</code> if such
|
||||
* definition does not exist.
|
||||
*/
|
||||
XSTypeDefinition *getTypeDefinition(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level attribute group definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level attribute group definition or <code>null</code> if
|
||||
* such definition does not exist.
|
||||
*/
|
||||
XSAttributeGroupDefinition *getAttributeGroup(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level model group definition.
|
||||
* @param name The name of the definition.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level model group definition definition or
|
||||
* <code>null</code> if such definition does not exist.
|
||||
*/
|
||||
XSModelGroupDefinition *getModelGroupDefinition(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Convenience method. Returns a top-level notation declaration.
|
||||
* @param name The name of the declaration.
|
||||
* @param compNamespace The namespace of the declaration, null if absent.
|
||||
* @return A top-level notation declaration or <code>null</code> if such
|
||||
* declaration does not exist.
|
||||
*/
|
||||
XSNotationDeclaration *getNotationDeclaration(const XMLCh *name
|
||||
, const XMLCh *compNamespace);
|
||||
|
||||
/**
|
||||
* Optional. Return a component given a component type and a unique Id.
|
||||
* May not be supported for all component types.
|
||||
* @param compId unique Id of the component within its type
|
||||
* @param compType type of the component
|
||||
* @return the component of the given type with the given Id, or 0
|
||||
* if no such component exists or this is unsupported for
|
||||
* this type of component.
|
||||
*/
|
||||
XSObject *getXSObjectById(XMLSize_t compId,
|
||||
XSConstants::COMPONENT_TYPE compType);
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
XMLStringPool* getURIStringPool();
|
||||
|
||||
XSNamespaceItem* getNamespaceItem(const XMLCh* const key);
|
||||
|
||||
/**
|
||||
* Get the XSObject (i.e. XSElementDeclaration) that corresponds to
|
||||
* to a schema grammar component (i.e. SchemaElementDecl)
|
||||
* @param key schema component object
|
||||
*
|
||||
* @return the corresponding XSObject
|
||||
*/
|
||||
XSObject* getXSObject(void* key);
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void addGrammarToXSModel
|
||||
(
|
||||
XSNamespaceItem* namespaceItem
|
||||
);
|
||||
void addS4SToXSModel
|
||||
(
|
||||
XSNamespaceItem* const namespaceItem
|
||||
, RefHashTableOf<DatatypeValidator>* const builtInDV
|
||||
);
|
||||
void addComponentToNamespace
|
||||
(
|
||||
XSNamespaceItem* const namespaceItem
|
||||
, XSObject* const component
|
||||
, XMLSize_t componentIndex
|
||||
, bool addToXSModel = true
|
||||
);
|
||||
|
||||
void addComponentToIdVector
|
||||
(
|
||||
XSObject* const component
|
||||
, XMLSize_t componentIndex
|
||||
);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSModel(const XSModel&);
|
||||
XSModel & operator=(const XSModel &);
|
||||
|
||||
protected:
|
||||
friend class XSObjectFactory;
|
||||
friend class XSObject;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
// fMemoryManager:
|
||||
// used for any memory allocations
|
||||
MemoryManager* const fMemoryManager;
|
||||
|
||||
StringList* fNamespaceStringList;
|
||||
XSNamespaceItemList* fXSNamespaceItemList;
|
||||
|
||||
RefVectorOf<XSObject>* fIdVector[XSConstants::MULTIVALUE_FACET];
|
||||
|
||||
/* Need a XSNamedMap for each component top-level?
|
||||
ATTRIBUTE_DECLARATION = 1,
|
||||
ELEMENT_DECLARATION = 2,
|
||||
TYPE_DEFINITION = 3,
|
||||
ATTRIBUTE_USE = 4, no
|
||||
ATTRIBUTE_GROUP_DEFINITION= 5,
|
||||
MODEL_GROUP_DEFINITION = 6,
|
||||
MODEL_GROUP = 7, no
|
||||
PARTICLE = 8, no
|
||||
WILDCARD = 9, no
|
||||
IDENTITY_CONSTRAINT = 10, no
|
||||
NOTATION_DECLARATION = 11,
|
||||
ANNOTATION = 12, no
|
||||
FACET = 13, no
|
||||
MULTIVALUE_FACET = 14 no
|
||||
*/
|
||||
XSNamedMap<XSObject>* fComponentMap[XSConstants::MULTIVALUE_FACET];
|
||||
XMLStringPool* fURIStringPool;
|
||||
XSAnnotationList* fXSAnnotationList;
|
||||
RefHashTableOf<XSNamespaceItem>* fHashNamespace;
|
||||
XSObjectFactory* fObjFactory;
|
||||
RefVectorOf<XSNamespaceItem>* fDeleteNamespace;
|
||||
XSModel* fParent;
|
||||
bool fDeleteParent;
|
||||
bool fAddedS4SGrammar;
|
||||
};
|
||||
|
||||
inline XMLStringPool* XSModel::getURIStringPool()
|
||||
{
|
||||
return fURIStringPool;
|
||||
}
|
||||
|
||||
inline StringList *XSModel::getNamespaces()
|
||||
{
|
||||
return fNamespaceStringList;
|
||||
}
|
||||
|
||||
inline XSNamespaceItemList *XSModel::getNamespaceItems()
|
||||
{
|
||||
return fXSNamespaceItemList;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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: XSModelGroup.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSModelGroup.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModelGroup: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XSModelGroup::XSModelGroup(COMPOSITOR_TYPE compositorType,
|
||||
XSParticleList* const particleList,
|
||||
XSAnnotation* const annot,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager * const manager)
|
||||
: XSObject(XSConstants::MODEL_GROUP, xsModel, manager)
|
||||
, fCompositorType(compositorType)
|
||||
, fParticleList(particleList)
|
||||
, fAnnotation(annot)
|
||||
{
|
||||
}
|
||||
|
||||
XSModelGroup::~XSModelGroup()
|
||||
{
|
||||
if (fParticleList)
|
||||
delete fParticleList;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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: XSModelGroup.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSMODELGROUP_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSMODELGROUP_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Model Group
|
||||
* component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSParticle;
|
||||
|
||||
class XMLPARSER_EXPORT XSModelGroup : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Content model compositors
|
||||
enum COMPOSITOR_TYPE {
|
||||
/**
|
||||
* This constant value signifies a sequence operator.
|
||||
*/
|
||||
COMPOSITOR_SEQUENCE = 1,
|
||||
/**
|
||||
* This constant value signifies a choice operator.
|
||||
*/
|
||||
COMPOSITOR_CHOICE = 2,
|
||||
/**
|
||||
* This content model represents a simplified version of the SGML
|
||||
* &-Connector and is limited to the top-level of any content model.
|
||||
* No element in the all content model may appear more than once.
|
||||
*/
|
||||
COMPOSITOR_ALL = 3
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param compositorType
|
||||
* @param particleList
|
||||
* @param annot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSModelGroup
|
||||
(
|
||||
COMPOSITOR_TYPE compositorType
|
||||
, XSParticleList* const particleList
|
||||
, XSAnnotation* const annot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSModelGroup();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSModelGroup methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* [compositor]: one of all, choice or sequence. The valid constants
|
||||
* values are:
|
||||
* <code>COMPOSITOR_SEQUENCE, COMPOSITOR_CHOICE, COMPOSITOR_ALL</code>.
|
||||
*/
|
||||
COMPOSITOR_TYPE getCompositor() const;
|
||||
|
||||
/**
|
||||
* A list of [particles].
|
||||
*/
|
||||
XSParticleList *getParticles() const;
|
||||
|
||||
/**
|
||||
* Optional. An [annotation].
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSModelGroup(const XSModelGroup&);
|
||||
XSModelGroup & operator=(const XSModelGroup &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
COMPOSITOR_TYPE fCompositorType;
|
||||
XSParticleList* fParticleList;
|
||||
XSAnnotation* fAnnotation;
|
||||
};
|
||||
|
||||
inline XSModelGroup::COMPOSITOR_TYPE XSModelGroup::getCompositor() const
|
||||
{
|
||||
return fCompositorType;
|
||||
}
|
||||
|
||||
inline XSParticleList* XSModelGroup::getParticles() const
|
||||
{
|
||||
return fParticleList;
|
||||
}
|
||||
|
||||
inline XSAnnotation* XSModelGroup::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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: XSModelGroupDefinition.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
|
||||
#include <xercesc/framework/psvi/XSParticle.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/validators/schema/XercesGroupInfo.hpp>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModelGroupDefinition: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XSModelGroupDefinition::XSModelGroupDefinition(XercesGroupInfo* const groupInfo,
|
||||
XSParticle* const groupParticle,
|
||||
XSAnnotation* const annot,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager)
|
||||
: XSObject(XSConstants::MODEL_GROUP_DEFINITION, xsModel, manager)
|
||||
, fGroupInfo(groupInfo)
|
||||
, fModelGroupParticle(groupParticle)
|
||||
, fAnnotation(annot)
|
||||
{
|
||||
}
|
||||
|
||||
XSModelGroupDefinition::~XSModelGroupDefinition()
|
||||
{
|
||||
if (fModelGroupParticle) // Not owned by XSModel
|
||||
delete fModelGroupParticle;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModelGroupDefinition: XSModel virtual methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh *XSModelGroupDefinition::getName() const
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fGroupInfo->getNameId());
|
||||
}
|
||||
|
||||
const XMLCh *XSModelGroupDefinition::getNamespace()
|
||||
{
|
||||
return fXSModel->getURIStringPool()->getValueForId(fGroupInfo->getNamespaceId());
|
||||
}
|
||||
|
||||
XSNamespaceItem *XSModelGroupDefinition::getNamespaceItem()
|
||||
{
|
||||
return fXSModel->getNamespaceItem(getNamespace());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSModelGroupDefinition: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XSModelGroup* XSModelGroupDefinition::getModelGroup()
|
||||
{
|
||||
if (fModelGroupParticle)
|
||||
return fModelGroupParticle->getModelGroupTerm();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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: XSModelGroupDefinition.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSMODELGROUPDEFINITION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSMODELGROUPDEFINITION_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class describes all properties of a Schema Model Group
|
||||
* Definition component.
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
class XSModelGroup;
|
||||
class XSParticle;
|
||||
class XercesGroupInfo;
|
||||
|
||||
class XMLPARSER_EXPORT XSModelGroupDefinition : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param groupInfo
|
||||
* @param groupParticle
|
||||
* @param annot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSModelGroupDefinition
|
||||
(
|
||||
XercesGroupInfo* const groupInfo
|
||||
, XSParticle* const groupParticle
|
||||
, XSAnnotation* const annot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSModelGroupDefinition();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name overridden XSXSObject methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The name of type <code>NCName</code> of this declaration as defined in
|
||||
* XML Namespaces.
|
||||
*/
|
||||
const XMLCh* getName() const;
|
||||
|
||||
/**
|
||||
* The [target namespace] of this object, or <code>null</code> if it is
|
||||
* unspecified.
|
||||
*/
|
||||
const XMLCh* getNamespace();
|
||||
|
||||
/**
|
||||
* A namespace schema information item corresponding to the target
|
||||
* namespace of the component, if it's globally declared; or null
|
||||
* otherwise.
|
||||
*/
|
||||
XSNamespaceItem *getNamespaceItem();
|
||||
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSModelGroupDefinition methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* A model group.
|
||||
*/
|
||||
XSModelGroup *getModelGroup();
|
||||
|
||||
/**
|
||||
* Optional. An [annotation].
|
||||
*/
|
||||
XSAnnotation *getAnnotation() const;
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSModelGroupDefinition(const XSModelGroupDefinition&);
|
||||
XSModelGroupDefinition & operator=(const XSModelGroupDefinition &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
XercesGroupInfo* fGroupInfo;
|
||||
XSParticle* fModelGroupParticle;
|
||||
XSAnnotation* fAnnotation;
|
||||
};
|
||||
|
||||
inline XSAnnotation* XSModelGroupDefinition::getAnnotation() const
|
||||
{
|
||||
return fAnnotation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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: XSMultiValueFacet.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSMultiValueFacet.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSMultiValueFacet: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XSMultiValueFacet::XSMultiValueFacet(XSSimpleTypeDefinition::FACET facetKind,
|
||||
StringList* lexicalValues,
|
||||
bool isFixed,
|
||||
XSAnnotation* const headAnnot,
|
||||
XSModel* const xsModel,
|
||||
MemoryManager* const manager)
|
||||
: XSObject(XSConstants::MULTIVALUE_FACET, xsModel, manager)
|
||||
, fFacetKind(facetKind)
|
||||
, fIsFixed(isFixed)
|
||||
, fLexicalValues(lexicalValues)
|
||||
, fXSAnnotationList(0)
|
||||
{
|
||||
if (headAnnot)
|
||||
{
|
||||
fXSAnnotationList = new (manager) RefVectorOf<XSAnnotation>(1, false, manager);
|
||||
|
||||
XSAnnotation* annot = headAnnot;
|
||||
do
|
||||
{
|
||||
fXSAnnotationList->addElement(annot);
|
||||
annot = annot->getNext();
|
||||
} while (annot);
|
||||
}
|
||||
}
|
||||
|
||||
XSMultiValueFacet::~XSMultiValueFacet()
|
||||
{
|
||||
if (fXSAnnotationList)
|
||||
delete fXSAnnotationList;
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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: XSMultiValueFacet.hpp 527149 2007-04-10 14:56:39Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSMULTIVALUEFACET_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSMULTIVALUEFACET_HPP
|
||||
|
||||
#include <xercesc/framework/psvi/XSObject.hpp>
|
||||
#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* This class represents all Schema Facets which may possess multiple
|
||||
* lexical values/annotations (i.e., Pattern and Enumeration facets).
|
||||
* This is *always* owned by the validator /parser object from which
|
||||
* it is obtained.
|
||||
*/
|
||||
|
||||
// forward declarations
|
||||
class XSAnnotation;
|
||||
|
||||
class XMLPARSER_EXPORT XSMultiValueFacet : public XSObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The default constructor
|
||||
*
|
||||
* @param facetKind
|
||||
* @param lexicalValues
|
||||
* @param isFixed
|
||||
* @param headAnnot
|
||||
* @param xsModel
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
XSMultiValueFacet
|
||||
(
|
||||
XSSimpleTypeDefinition::FACET facetKind
|
||||
, StringList* lexicalValues
|
||||
, bool isFixed
|
||||
, XSAnnotation* const headAnnot
|
||||
, XSModel* const xsModel
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@};
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSMultiValueFacet();
|
||||
//@}
|
||||
|
||||
//---------------------
|
||||
/** @name XSMultiValueFacet methods */
|
||||
|
||||
//@{
|
||||
|
||||
/**
|
||||
* @return An indication as to the facet's type; see <code>XSSimpleTypeDefinition::FACET</code>
|
||||
*/
|
||||
XSSimpleTypeDefinition::FACET getFacetKind() const;
|
||||
|
||||
/**
|
||||
* @return Returns the values of a constraining facet.
|
||||
*/
|
||||
StringList *getLexicalFacetValues();
|
||||
|
||||
/**
|
||||
* Check whether a facet value is fixed.
|
||||
*/
|
||||
bool isFixed() const;
|
||||
|
||||
/**
|
||||
* @return the annotations belonging to this facet's values
|
||||
*/
|
||||
XSAnnotationList *getAnnotations();
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
|
||||
//@}
|
||||
private:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSMultiValueFacet(const XSMultiValueFacet&);
|
||||
XSMultiValueFacet & operator=(const XSMultiValueFacet &);
|
||||
|
||||
protected:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// data members
|
||||
// -----------------------------------------------------------------------
|
||||
XSSimpleTypeDefinition::FACET fFacetKind;
|
||||
bool fIsFixed;
|
||||
StringList* fLexicalValues; // not owned by this class
|
||||
XSAnnotationList* fXSAnnotationList;
|
||||
};
|
||||
|
||||
|
||||
inline XSSimpleTypeDefinition::FACET XSMultiValueFacet::getFacetKind() const
|
||||
{
|
||||
return fFacetKind;
|
||||
}
|
||||
|
||||
inline bool XSMultiValueFacet::isFixed() const
|
||||
{
|
||||
return fIsFixed;
|
||||
}
|
||||
|
||||
inline StringList *XSMultiValueFacet::getLexicalFacetValues()
|
||||
{
|
||||
return fLexicalValues;
|
||||
}
|
||||
|
||||
inline XSAnnotationList *XSMultiValueFacet::getAnnotations()
|
||||
{
|
||||
return fXSAnnotationList;
|
||||
}
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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: XSNamedMap.c 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Include
|
||||
// ---------------------------------------------------------------------------
|
||||
#if defined(XERCES_TMPLSINC)
|
||||
#include <xercesc/framework/psvi/XSNamedMap.hpp>
|
||||
#endif
|
||||
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/util/StringPool.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSNamedMap: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
template <class TVal>
|
||||
XSNamedMap<TVal>::XSNamedMap(const XMLSize_t maxElems,
|
||||
const XMLSize_t modulus,
|
||||
XMLStringPool* uriStringPool,
|
||||
const bool adoptElems,
|
||||
MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fURIStringPool(uriStringPool)
|
||||
{
|
||||
// allow one of the Vector or Hash to own the data... but not both...
|
||||
fVector = new (manager) RefVectorOf<TVal> (maxElems, false, manager);
|
||||
fHash = new (manager) RefHash2KeysTableOf<TVal> (modulus, adoptElems, manager);
|
||||
}
|
||||
template <class TVal> XSNamedMap<TVal>::~XSNamedMap()
|
||||
{
|
||||
delete fVector;
|
||||
delete fHash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The number of <code>XSObjects</code> in the <code>XSObjectList</code>.
|
||||
* The range of valid child object indices is 0 to
|
||||
* <code>mapLength-1</code> inclusive.
|
||||
*/
|
||||
template <class TVal>
|
||||
XMLSize_t XSNamedMap<TVal>::getLength() const
|
||||
{
|
||||
return fVector->size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>index</code>th item in the collection. The index
|
||||
* starts at 0. If <code>index</code> is greater than or equal to the
|
||||
* number of objects in the list, this returns <code>null</code>.
|
||||
* @param index index into the collection.
|
||||
* @return The <code>XSObject</code> at the <code>index</code>th
|
||||
* position in the <code>XSObjectList</code>, or <code>null</code> if
|
||||
* that is not a valid index.
|
||||
*/
|
||||
template <class TVal>
|
||||
TVal* XSNamedMap<TVal>::item(XMLSize_t index)
|
||||
{
|
||||
if (index >= fVector->size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return fVector->elementAt(index);
|
||||
}
|
||||
|
||||
template <class TVal>
|
||||
const TVal* XSNamedMap<TVal>::item(XMLSize_t index) const
|
||||
{
|
||||
if (index >= fVector->size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return fVector->elementAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a component specified by local name and namespace URI.
|
||||
* <br>applications must use the value null as the
|
||||
* <code>compNamespace</code> parameter for components whose targetNamespace property
|
||||
* is absent.
|
||||
* @param compNamespace The namespace URI of the component to retrieve.
|
||||
* @param localName The local name of the component to retrieve.
|
||||
* @return A component (of any type) with the specified local
|
||||
* name and namespace URI, or <code>null</code> if they do not
|
||||
* identify any node in this map.
|
||||
*/
|
||||
template <class TVal>
|
||||
TVal *XSNamedMap<TVal>::itemByName(const XMLCh *compNamespace,
|
||||
const XMLCh *localName)
|
||||
{
|
||||
return fHash->get((void*)localName, fURIStringPool->getId(compNamespace));
|
||||
}
|
||||
|
||||
|
||||
template <class TVal>
|
||||
void XSNamedMap<TVal>::addElement(TVal* const toAdd, const XMLCh* key1, const XMLCh* key2)
|
||||
{
|
||||
fVector->addElement(toAdd);
|
||||
fHash->put((void*)key1, fURIStringPool->getId(key2), toAdd);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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: XSNamedMap.hpp 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XSNAMEDMAP_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XSNAMEDMAP_HPP
|
||||
|
||||
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/RefHash2KeysTableOf.hpp>
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLStringPool;
|
||||
|
||||
/*
|
||||
* This template provides convenient mappings between name,namespace
|
||||
* pairs and individual components, as well as means to iterate through all the
|
||||
* named components on some object.
|
||||
*/
|
||||
|
||||
template <class TVal> class XSNamedMap: public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
XSNamedMap(const XMLSize_t maxElems,
|
||||
const XMLSize_t modulus,
|
||||
XMLStringPool* uriStringPool,
|
||||
const bool adoptElems,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
//@}
|
||||
|
||||
/** @name Destructor */
|
||||
//@{
|
||||
~XSNamedMap();
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// XSNamedMap methods
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name XSNamedMap methods */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* The number of <code>XSObjects</code> in the <code>XSObjectList</code>.
|
||||
* The range of valid child object indices is 0 to
|
||||
* <code>mapLength-1</code> inclusive.
|
||||
*/
|
||||
XMLSize_t getLength() const;
|
||||
|
||||
/**
|
||||
* Returns the <code>index</code>th item in the collection. The index
|
||||
* starts at 0. If <code>index</code> is greater than or equal to the
|
||||
* number of objects in the list, this returns <code>null</code>.
|
||||
* @param index index into the collection.
|
||||
* @return The <code>XSObject</code> at the <code>index</code>th
|
||||
* position in the <code>XSObjectList</code>, or <code>null</code> if
|
||||
* that is not a valid index.
|
||||
*/
|
||||
TVal *item(XMLSize_t index);
|
||||
const TVal *item(XMLSize_t index) const;
|
||||
|
||||
/**
|
||||
* Retrieves a component specified by local name and namespace URI.
|
||||
* <br>applications must use the value null as the
|
||||
* <code>compNamespace</code> parameter for components whose targetNamespace property
|
||||
* is absent.
|
||||
* @param compNamespace The namespace URI of the component to retrieve.
|
||||
* @param localName The local name of the component to retrieve.
|
||||
* @return A component (of any type) with the specified local
|
||||
* name and namespace URI, or <code>null</code> if they do not
|
||||
* identify any node in this map.
|
||||
*/
|
||||
TVal *itemByName(const XMLCh *compNamespace,
|
||||
const XMLCh *localName);
|
||||
|
||||
//@}
|
||||
|
||||
//----------------------------------
|
||||
/** methods needed by implementation */
|
||||
|
||||
//@{
|
||||
void addElement(TVal* const toAdd, const XMLCh* key1, const XMLCh* key2);
|
||||
//@}
|
||||
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XSNamedMap(const XSNamedMap<TVal>&);
|
||||
XSNamedMap<TVal>& operator=(const XSNamedMap<TVal>&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Data members
|
||||
//
|
||||
// fMemoryManager
|
||||
// manager used to allocate memory needed by this object
|
||||
MemoryManager *const fMemoryManager;
|
||||
XMLStringPool* fURIStringPool;
|
||||
RefVectorOf<TVal>* fVector;
|
||||
RefHash2KeysTableOf<TVal>* fHash;
|
||||
};
|
||||
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#if !defined(XERCES_TMPLSINC)
|
||||
#include <xercesc/framework/psvi/XSNamedMap.c>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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: XSNamespaceItem.cpp 674012 2008-07-04 11:18:21Z borisk $
|
||||
*/
|
||||
|
||||
#include <xercesc/framework/psvi/XSNamespaceItem.hpp>
|
||||
#include <xercesc/validators/schema/SchemaGrammar.hpp>
|
||||
#include <xercesc/framework/psvi/XSModel.hpp>
|
||||
#include <xercesc/framework/psvi/XSAnnotation.hpp>
|
||||
#include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSNamespaceItem: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
XSNamespaceItem::XSNamespaceItem(XSModel* const xsModel,
|
||||
SchemaGrammar* const grammar,
|
||||
MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fGrammar(grammar)
|
||||
, fXSModel(xsModel)
|
||||
, fXSAnnotationList(0)
|
||||
, fSchemaNamespace(grammar->getTargetNamespace())
|
||||
{
|
||||
// Populate XSNamedMaps by going through the components
|
||||
for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
|
||||
(
|
||||
20, // size
|
||||
29, // modulus
|
||||
fXSModel->getURIStringPool(),
|
||||
false, // adoptElems
|
||||
fMemoryManager
|
||||
);
|
||||
fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
|
||||
(
|
||||
29,
|
||||
false,
|
||||
fMemoryManager
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// ATTRIBUTE_USE
|
||||
// MODEL_GROUP
|
||||
// PARTICLE
|
||||
// IDENTITY_CONSTRAINT
|
||||
// WILDCARD
|
||||
// ANNOTATION
|
||||
// FACET
|
||||
// MULTIVALUE
|
||||
fComponentMap[i] = 0;
|
||||
fHashMap[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
|
||||
}
|
||||
|
||||
XSNamespaceItem::XSNamespaceItem(XSModel* const xsModel,
|
||||
const XMLCh* const schemaNamespace,
|
||||
MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fGrammar(0)
|
||||
, fXSModel(xsModel)
|
||||
, fXSAnnotationList(0)
|
||||
, fSchemaNamespace(schemaNamespace)
|
||||
{
|
||||
// Populate XSNamedMaps by going through the components
|
||||
for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject>
|
||||
(
|
||||
20, // size
|
||||
29, // modulus
|
||||
fXSModel->getURIStringPool(),
|
||||
false, // adoptElems
|
||||
fMemoryManager
|
||||
);
|
||||
fHashMap[i] = new (fMemoryManager) RefHashTableOf<XSObject>
|
||||
(
|
||||
29,
|
||||
false,
|
||||
fMemoryManager
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// ATTRIBUTE_USE
|
||||
// MODEL_GROUP
|
||||
// PARTICLE
|
||||
// IDENTITY_CONSTRAINT
|
||||
// WILDCARD
|
||||
// ANNOTATION
|
||||
// FACET
|
||||
// MULTIVALUE
|
||||
fComponentMap[i] = 0;
|
||||
fHashMap[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (5, false, manager);
|
||||
}
|
||||
|
||||
XSNamespaceItem::~XSNamespaceItem()
|
||||
{
|
||||
for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++)
|
||||
{
|
||||
switch (i+1)
|
||||
{
|
||||
case XSConstants::ATTRIBUTE_DECLARATION:
|
||||
case XSConstants::ELEMENT_DECLARATION:
|
||||
case XSConstants::TYPE_DEFINITION:
|
||||
case XSConstants::ATTRIBUTE_GROUP_DEFINITION:
|
||||
case XSConstants::MODEL_GROUP_DEFINITION:
|
||||
case XSConstants::NOTATION_DECLARATION:
|
||||
delete fComponentMap[i];
|
||||
delete fHashMap[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete fXSAnnotationList;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XSNamespaceItem: access methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XSNamedMap<XSObject> *XSNamespaceItem::getComponents(XSConstants::COMPONENT_TYPE objectType)
|
||||
{
|
||||
return fComponentMap[objectType -1];
|
||||
}
|
||||
|
||||
XSElementDeclaration *XSNamespaceItem::getElementDeclaration(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSElementDeclaration*) fHashMap[XSConstants::ELEMENT_DECLARATION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSAttributeDeclaration *XSNamespaceItem::getAttributeDeclaration(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSAttributeDeclaration*) fHashMap[XSConstants::ATTRIBUTE_DECLARATION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSTypeDefinition *XSNamespaceItem::getTypeDefinition(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSTypeDefinition*) fHashMap[XSConstants::TYPE_DEFINITION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSAttributeGroupDefinition *XSNamespaceItem::getAttributeGroup(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSAttributeGroupDefinition*) fHashMap[XSConstants::ATTRIBUTE_GROUP_DEFINITION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSModelGroupDefinition *XSNamespaceItem::getModelGroupDefinition(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSModelGroupDefinition*) fHashMap[XSConstants::MODEL_GROUP_DEFINITION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
XSNotationDeclaration *XSNamespaceItem::getNotationDeclaration(const XMLCh *name)
|
||||
{
|
||||
if (name)
|
||||
return (XSNotationDeclaration*) fHashMap[XSConstants::NOTATION_DECLARATION -1]->get(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const StringList *XSNamespaceItem::getDocumentLocations()
|
||||
{
|
||||
if (fGrammar)
|
||||
return ((XMLSchemaDescriptionImpl*) fGrammar->getGrammarDescription())->getLocationHints();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user