You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ro...@locus.apache.org on 2000/01/12 01:15:05 UTC
cvs commit: xml-xerces/c/src/internal ReaderMgr.cpp ReaderMgr.hpp XMLScanner.cpp XMLScanner.hpp XMLScanner2.cpp
roddey 00/01/11 16:15:05
Modified: c/src/internal ReaderMgr.cpp ReaderMgr.hpp XMLScanner.cpp
XMLScanner.hpp XMLScanner2.cpp
Log:
Changes to deal with multiply nested, relative pathed, entities and to deal
with the new URL class changes.
Revision Changes Path
1.3 +35 -48 xml-xerces/c/src/internal/ReaderMgr.cpp
Index: ReaderMgr.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/ReaderMgr.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReaderMgr.cpp 1999/12/18 00:20:00 1.2
+++ ReaderMgr.cpp 2000/01/12 00:15:03 1.3
@@ -56,6 +56,10 @@
/**
* $Log: ReaderMgr.cpp,v $
+ * Revision 1.3 2000/01/12 00:15:03 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
+ *
* Revision 1.2 1999/12/18 00:20:00 roddey
* More changes to support the new, completely orthagonal, support for
* intrinsic encodings.
@@ -85,14 +89,14 @@
#include <util/URL.hpp>
#include <util/XMLUni.hpp>
#include <sax/InputSource.hpp>
+#include <framework/LocalFileInputSource.hpp>
+#include <framework/URLInputSource.hpp>
#include <framework/XMLBuffer.hpp>
#include <framework/XMLDocumentHandler.hpp>
#include <framework/XMLEntityDecl.hpp>
#include <framework/XMLEntityHandler.hpp>
#include <internal/EndOfEntityException.hpp>
#include <internal/ReaderMgr.hpp>
-#include <internal/URLInputSource.hpp>
-
// ---------------------------------------------------------------------------
@@ -100,8 +104,7 @@
// ---------------------------------------------------------------------------
ReaderMgr::ReaderMgr() :
- fBasePath(0)
- , fCurEntity(0)
+ fCurEntity(0)
, fCurReader(0)
, fEntityHandler(0)
, fEntityStack(0)
@@ -119,7 +122,6 @@
// does not own its elements either, so deleting it will not delete the
// entities it still references!)
//
- delete [] fBasePath;
delete fCurReader;
delete fReaderStack;
delete fEntityStack;
@@ -520,8 +522,8 @@
XMLBuffer expSysId;
//
- // Allow the entity handler to expand the system id. If we don't
- // have one, or they don't do anything, then just use it as is.
+ // Allow the entity handler to expand the system id if they choose
+ // to do so.
//
if (fEntityHandler)
{
@@ -530,37 +532,7 @@
}
else
{
- //
- // Try to parse it as a URL. If it succeeds, it must be a
- // fully qualified path. Otherwise, its just a file name and
- // could be partial so check and append it to the base path
- // if so.
- //
- URL tmpURL;
- try
- {
- tmpURL.setURL(sysId);
- expSysId.set(tmpURL.getPath());
- }
-
- catch(const MalformedURLException&)
- {
- // Its just a file path
- if (XMLPlatformUtils::isRelative(sysId))
- {
- // Its relative so first store the base directory, if any
- if (fBasePath)
- expSysId.set(fBasePath);
-
- // And then append the relative path
- expSysId.append(sysId);
- }
- else
- {
- // The path is not relative, so just set it directly
- expSysId.set(sysId);
- }
- }
+ expSysId.set(sysId);
}
// Call the entity resolver interface to get an input source
@@ -574,10 +546,32 @@
);
}
- // If they didn't give us anything, then make up a URL input source
+ //
+ // If they didn't create a source via the entity resolver, then we
+ // have to create one on our own.
+ //
if (!srcToFill)
- srcToFill = new URLInputSource(expSysId.getRawBuffer());
+ {
+ LastExtEntityInfo lastInfo;
+ getLastExtEntityInfo(lastInfo);
+
+ try
+ {
+ URL urlTmp(lastInfo.systemId, expSysId.getRawBuffer());
+ srcToFill = new URLInputSource(urlTmp);
+ }
+ catch(const MalformedURLException&)
+ {
+ // Its not a URL, so lets assume its a local file name.
+ srcToFill = new LocalFileInputSource
+ (
+ lastInfo.systemId
+ , expSysId.getRawBuffer()
+ );
+ }
+ }
+
// Put a janitor on the input source
Janitor<InputSource> janSrc(srcToFill);
@@ -601,10 +595,7 @@
if (!retVal)
return 0;
- //
- // Give this reader the next available reader number. And let the input
- // source live to be returned to the caller.
- //
+ // Give this reader the next available reader number and return it
retVal->setReaderNum(fNextReaderNum++);
return retVal;
}
@@ -793,10 +784,6 @@
{
// Reset all of the flags
fThrowEOE = false;
-
- // Delete the base path, which has to be reset each time
- delete [] fBasePath;
- fBasePath = 0;
// Delete the current reader and flush the reader stack
delete fCurReader;
1.3 +5 -12 xml-xerces/c/src/internal/ReaderMgr.hpp
Index: ReaderMgr.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/ReaderMgr.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReaderMgr.hpp 1999/12/15 19:48:03 1.2
+++ ReaderMgr.hpp 2000/01/12 00:15:04 1.3
@@ -56,6 +56,10 @@
/**
* $Log: ReaderMgr.hpp,v $
+ * Revision 1.3 2000/01/12 00:15:04 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
+ *
* Revision 1.2 1999/12/15 19:48:03 roddey
* Changed to use new split of transcoder interfaces into XML transcoders and
* LCP transcoders, and implementation of intrinsic transcoders as pluggable
@@ -212,7 +216,6 @@
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
- void setBasePath(const XMLCh* const path);
void setEntityHandler(XMLEntityHandler* const newHandler);
void setThrowEOE(const bool newValue);
@@ -228,10 +231,6 @@
// -----------------------------------------------------------------------
// Private data members
//
- // fBasePath
- // This is the base path from which all other relative references
- // are based. Its passed on to us from the scanner.
- //
// fCurEntity
// This is the current top of stack entity. We pull it off the stack
// and store it here for efficiency.
@@ -266,7 +265,6 @@
// of entities in the int/ext subsets, so it will turn this flag off
// until it gets into the content usually.
// -----------------------------------------------------------------------
- XMLCh* fBasePath;
XMLEntityDecl* fCurEntity;
XMLReader* fCurReader;
XMLEntityHandler* fEntityHandler;
@@ -355,12 +353,6 @@
if ((nextCh == toSkipPast) || !nextCh)
break;
}
-}
-
-inline void ReaderMgr::setBasePath(const XMLCh* const path)
-{
- delete [] fBasePath;
- fBasePath = XMLString::replicate(path);
}
inline void ReaderMgr::setEntityHandler(XMLEntityHandler* const newHandler)
1.5 +92 -0 xml-xerces/c/src/internal/XMLScanner.cpp
Index: XMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLScanner.cpp 1999/12/08 00:15:06 1.4
+++ XMLScanner.cpp 2000/01/12 00:15:04 1.5
@@ -56,6 +56,10 @@
/**
* $Log: XMLScanner.cpp,v $
+ * Revision 1.5 2000/01/12 00:15:04 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
+ *
* Revision 1.4 1999/12/08 00:15:06 roddey
* Some small last minute fixes to get into the 3.0.1 build that is going to be
* going out anyway for platform fixes.
@@ -87,6 +91,7 @@
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
+#include <util/Janitor.hpp>
#include <util/Mutexes.hpp>
#include <util/PlatformUtils.hpp>
#include <util/RefVectorOf.hpp>
@@ -97,6 +102,8 @@
#include <util/XMLUni.hpp>
#include <sax/InputSource.hpp>
#include <sax/SAXException.hpp>
+#include <framework/LocalFileInputSource.hpp>
+#include <framework/URLInputSource.hpp>
#include <framework/XMLDocumentHandler.hpp>
#include <framework/XMLElementDecl.hpp>
#include <framework/XMLErrorReporter.hpp>
@@ -204,6 +211,52 @@
// ---------------------------------------------------------------------------
// XMLScanner: Main entry point to scan a document
// ---------------------------------------------------------------------------
+void XMLScanner::scanDocument( const XMLCh* const systemId
+ , const bool reuseValidator)
+{
+ //
+ // First we try to parse it as a URL. If that fails, we assume its
+ // a file and try it that way.
+ //
+ InputSource* srcToUse = 0;
+ try
+ {
+ //
+ // Create a temporary URL. Since this is the primary document,
+ // it has to be fully qualified. If not, then assume we are just
+ // mistaking a file for a URL.
+ //
+ URL tmpURL(systemId);
+ if (tmpURL.isRelative())
+ ThrowXML(MalformedURLException, XML4CExcepts::URL_NoProtocolPresent);
+ srcToUse = new URLInputSource(tmpURL);
+ }
+
+ catch(const MalformedURLException&)
+ {
+ srcToUse = new LocalFileInputSource(systemId);
+ }
+
+ catch(...)
+ {
+ // Just rethrow this, since its not our problem
+ throw;
+ }
+
+ Janitor<InputSource> janSrc(srcToUse);
+ scanDocument(*srcToUse, reuseValidator);
+}
+
+void XMLScanner::scanDocument( const char* const systemId
+ , const bool reuseValidator)
+{
+ // We just delegate this to the XMLCh version after transcoding
+ XMLCh* tmpBuf = XMLString::transcode(systemId);
+ ArrayJanitor<XMLCh> janBuf(tmpBuf);
+ scanDocument(tmpBuf, reuseValidator);
+}
+
+
void XMLScanner::scanDocument(const InputSource& src, const bool reuseValidator)
{
//
@@ -359,6 +412,45 @@
// returns false, then the scan of the prolog failed and the token is not
// going to work on subsequent scanNext() calls.
//
+bool XMLScanner::scanFirst( const XMLCh* const systemId
+ , XMLPScanToken& toFill
+ , const bool reuseValidator)
+{
+ //
+ // First we try to parse it as a URL. If that fails, we assume its
+ // a file and try it that way.
+ //
+ InputSource* srcToUse = 0;
+ try
+ {
+ srcToUse = new URLInputSource(XMLUni::fgZeroLenString, systemId);
+ }
+
+ catch(const MalformedURLException&)
+ {
+ srcToUse = new LocalFileInputSource(systemId);
+ }
+
+ catch(...)
+ {
+ // Just rethrow this, since its not our problem
+ throw;
+ }
+
+ Janitor<InputSource> janSrc(srcToUse);
+ return scanFirst(*srcToUse, toFill, reuseValidator);
+}
+
+bool XMLScanner::scanFirst( const char* const systemId
+ , XMLPScanToken& toFill
+ , const bool reuseValidator)
+{
+ // We just delegate this to the XMLCh version after transcoding
+ XMLCh* tmpBuf = XMLString::transcode(systemId);
+ ArrayJanitor<XMLCh> janBuf(tmpBuf);
+ return scanFirst(tmpBuf, toFill, reuseValidator);
+}
+
bool XMLScanner::scanFirst( const InputSource& src
, XMLPScanToken& toFill
, const bool reuseValidator)
1.2 +27 -0 xml-xerces/c/src/internal/XMLScanner.hpp
Index: XMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLScanner.hpp 1999/11/09 01:08:23 1.1
+++ XMLScanner.hpp 2000/01/12 00:15:04 1.2
@@ -56,9 +56,13 @@
/**
* $Log: XMLScanner.hpp,v $
- * Revision 1.1 1999/11/09 01:08:23 twl
- * Initial revision
+ * Revision 1.2 2000/01/12 00:15:04 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
*
+ * Revision 1.1.1.1 1999/11/09 01:08:23 twl
+ * Initial checkin
+ *
* Revision 1.4 1999/11/08 20:44:52 rahul
* Swat for adding in Product name and CVS comment log variable.
*
@@ -232,12 +236,36 @@
const InputSource& src
, const bool reuseValidator = false
);
+ void scanDocument
+ (
+ const XMLCh* const systemId
+ , const bool reuseValidator = false
+ );
+ void scanDocument
+ (
+ const char* const systemId
+ , const bool reuseValidator = false
+ );
+
bool scanFirst
(
const InputSource& src
, XMLPScanToken& toFill
, const bool reuseValidator = false
);
+ bool scanFirst
+ (
+ const XMLCh* const systemId
+ , XMLPScanToken& toFill
+ , const bool reuseValidator = false
+ );
+ bool scanFirst
+ (
+ const char* const systemId
+ , XMLPScanToken& toFill
+ , const bool reuseValidator = false
+ );
+
bool scanNext(XMLPScanToken& toFill);
1.4 +4 -36 xml-xerces/c/src/internal/XMLScanner2.cpp
Index: XMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner2.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XMLScanner2.cpp 1999/12/18 00:20:24 1.3
+++ XMLScanner2.cpp 2000/01/12 00:15:04 1.4
@@ -56,6 +56,10 @@
/**
* $Log: XMLScanner2.cpp,v $
+ * Revision 1.4 2000/01/12 00:15:04 roddey
+ * Changes to deal with multiply nested, relative pathed, entities and to deal
+ * with the new URL class changes.
+ *
* Revision 1.3 1999/12/18 00:20:24 roddey
* Fixed a small reported memory leak
*
@@ -104,7 +108,7 @@
#include <framework/XMLValidator.hpp>
#include <internal/XMLScanner.hpp>
#include <internal/EndOfEntityException.hpp>
-#include <internal/URLInputSource.hpp>
+
// ---------------------------------------------------------------------------
@@ -752,41 +756,6 @@
// Push this read onto the reader manager
fReaderMgr.pushReader(newReader, 0);
-
- //
- // We know that the file is legal now, so lets get the base directory
- // off of it and store it. If there is no directory component on the
- // path, then this returns a null.
- //
- // We have to assume it could be a URL so we create a temporary URL
- // and ask it for the path part of itself. That will insure that if its
- // relative we really see it as a relative path.
- //
- URL tmpURL;
-
- try
- {
- tmpURL.setURL(src.getSystemId());
-
- //
- // Its a valid URL so its assumed to be fully qualified. Get the
- // base part of the path part of the URL.
- //
- XMLCh* basePath = XMLPlatformUtils::getBasePath(tmpURL.getPath());
- ArrayJanitor<XMLCh> pathJan(basePath);
- fReaderMgr.setBasePath(basePath);
- }
-
- catch(const MalformedURLException&)
- {
- //
- // Its not a URL, so assume its just a plain file path and could
- // be partial, so get the complete path.
- //
- XMLCh* basePath = XMLPlatformUtils::getBasePath(src.getSystemId());
- ArrayJanitor<XMLCh> pathJan(basePath);
- fReaderMgr.setBasePath(basePath);
- }
}