xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peiyo...@apache.org
Subject cvs commit: xml-xerces/c/src/xercesc/framework LocalFileInputSource.cpp
Date Thu, 24 Apr 2003 02:50:35 GMT
peiyongz    2003/04/23 19:50:35

  Modified:    c/src/xercesc/framework LocalFileInputSource.cpp
  Log:
  Logical Path Resolution
  
  Revision  Changes    Path
  1.3       +86 -8     xml-xerces/c/src/xercesc/framework/LocalFileInputSource.cpp
  
  Index: LocalFileInputSource.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/LocalFileInputSource.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocalFileInputSource.cpp	4 Nov 2002 15:00:21 -0000	1.2
  +++ LocalFileInputSource.cpp	24 Apr 2003 02:50:35 -0000	1.3
  @@ -60,15 +60,67 @@
   // ---------------------------------------------------------------------------
   #include <xercesc/util/BinFileInputStream.hpp>
   #include <xercesc/util/PlatformUtils.hpp>
  +#include <xercesc/util/XMLString.hpp>
  +#include <xercesc/util/XMLUniDefs.hpp>
   #include <xercesc/framework/LocalFileInputSource.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)
  +LocalFileInputSource::LocalFileInputSource( const XMLCh* const basePath
  +                                          , const XMLCh* const relativePath)
   {
       //
       //  If the relative part is really relative, then weave it together
  @@ -81,14 +133,19 @@
           setSystemId(tmpBuf);
           delete [] tmpBuf;
       }
  -     else
  +    else
       {
  -        setSystemId(relativePath);
  +        XMLCh* tmpBuf = XMLString::replicate(relativePath);
  +        XMLPlatformUtils::removeDotSlash(tmpBuf);
  +        setSystemId(tmpBuf);
  +        delete [] tmpBuf;
       }
  +
   }
   
   LocalFileInputSource::LocalFileInputSource(const XMLCh* const filePath)
   {
  +
       //
       //  If the path is relative, then complete it acording to the current
       //  working directory rules of the current platform. Else, just take
  @@ -96,14 +153,35 @@
       //
       if (XMLPlatformUtils::isRelative(filePath))
       {
  -        XMLCh* tmpBuf = XMLPlatformUtils::getFullPath(filePath);
  -        setSystemId(tmpBuf);
  -        delete [] tmpBuf;
  +        XMLCh* curDir = XMLPlatformUtils::getCurrentDirectory();
  +
  +        int    curDirLen = XMLString::stringLen(curDir);
  +        int    filePathLen = XMLString::stringLen(filePath);
  +        XMLCh* fullDir = new XMLCh [ curDirLen + filePathLen + 2];
  +
  +        fullDir[0] = 0;
  +        XMLString::copyString(fullDir, curDir);
  +        fullDir[curDirLen] = chForwardSlash;
  +        fullDir[curDirLen+1] = 0;
  +        XMLString::catString(&fullDir[curDirLen+1], filePath);
  +        fullDir[curDirLen+filePathLen+1] = 0;
  +        
  +        XMLPlatformUtils::removeDotSlash(fullDir);
  +        XMLPlatformUtils::removeDotDotSlash(fullDir);
  +
  +        setSystemId(fullDir);
  +
  +        delete [] curDir;
  +        delete [] fullDir;
       }
        else
       {
  -        setSystemId(filePath);
  +        XMLCh* tmpBuf = XMLString::replicate(filePath);
  +        XMLPlatformUtils::removeDotSlash(tmpBuf);
  +        setSystemId(tmpBuf);
  +        delete [] tmpBuf;
       }
  +
   }
   
   LocalFileInputSource::~LocalFileInputSource()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org


Mime
View raw message