You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2002/09/23 20:41:00 UTC

cvs commit: xml-xerces/c/src/xercesc/util XMLUri.cpp XMLUri.hpp

tng         2002/09/23 11:41:00

  Modified:    c/src/xercesc/util XMLUri.cpp XMLUri.hpp
  Log:
  DOM L3: Support baseURI.   Add fURIText to XMLUri.   Added by Gareth Reakes and Thomas Ford.
  
  Revision  Changes    Path
  1.4       +106 -4    xml-xerces/c/src/xercesc/util/XMLUri.cpp
  
  Index: XMLUri.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLUri.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLUri.cpp	23 Aug 2002 20:45:24 -0000	1.3
  +++ XMLUri.cpp	23 Sep 2002 18:41:00 -0000	1.4
  @@ -247,6 +247,7 @@
   ,fPath(0)
   ,fQueryString(0)
   ,fFragment(0)
  +,fURIText(0)
   {
       try {
           initialize((XMLUri *)0, uriSpec);
  @@ -268,6 +269,7 @@
   ,fPath(0)
   ,fQueryString(0)
   ,fFragment(0)
  +,fURIText(0)
   {
       try {
           initialize(baseURI, uriSpec);
  @@ -303,6 +305,8 @@
   
       if (getFragment())
           delete[] fFragment;
  +
  +    delete[] fURIText;
   }
   
   void XMLUri::initialize(const XMLUri& toCopy)
  @@ -327,7 +331,7 @@
       // get a trimmed version of uriSpec
       // uriSpec will NO LONGER be used in this function.
       //
  -    XMLCh* const trimedUriSpec = XMLString::replicate(uriSpec);
  +    XMLCh* trimedUriSpec = XMLString::replicate(uriSpec);
       XMLString::trim(trimedUriSpec);
       ArrayJanitor<XMLCh> janName(trimedUriSpec);
       int trimedUriSpecLen = XMLString::stringLen(trimedUriSpec);
  @@ -353,6 +357,7 @@
   	// DOS drive letters ('D:'), so 1-character schemes are not allowed.
       int colonIdx = XMLString::indexOf(trimedUriSpec, chColon);
       int slashIdx = XMLString::indexOf(trimedUriSpec, chForwardSlash);
  +
   	if ((colonIdx < 2)                         ||
           (colonIdx > slashIdx && slashIdx != -1) )
       {
  @@ -486,6 +491,7 @@
   
           // if we get to this point, we need to resolve relative path
           // RFC 2396 5.2 #6
  +
           XMLCh* basePath = XMLString::replicate(baseURI->getPath());
           ArrayJanitor<XMLCh> basePathName(basePath);
   
  @@ -576,6 +582,7 @@
               delete [] fPath;
   
           fPath = XMLString::replicate(path);
  +
       }
   }
   
  @@ -890,7 +897,6 @@
   
       fScheme = XMLString::replicate(newScheme);
       XMLString::lowerCase(fScheme);
  -
   }
   
   //
  @@ -928,7 +934,11 @@
           delete [] fUserInfo;
       }
   
  -    fUserInfo = XMLString::replicate(newUserInfo);
  +    //sometimes we get passed a empty string rather than a null.
  +    //Other procedures rely on it being null
  +    if(XMLString::stringLen(newUserInfo) > 0) {
  +        fUserInfo = XMLString::replicate(newUserInfo);
  +    }
   
   }
   
  @@ -1338,4 +1348,96 @@
       return (getHost() != 0);
   }
   
  +
  +//
  +//  This method will take the broken out parts of the URI and build up the
  +//  full text. We don't do this unless someone asks us to, since its often
  +//  never required.
  +//
  +void XMLUri::buildFullText()
  +{
  +    // Calculate the worst case size of the buffer required
  +    unsigned int bufSize = XMLString::stringLen(fScheme) + 1
  +                           + XMLString::stringLen(fFragment) + 1
  +                           + XMLString::stringLen(fHost) + 2
  +                           + XMLString::stringLen(fPath)
  +                           + XMLString::stringLen(fQueryString) + 1
  +                           + XMLString::stringLen(fUserInfo) + 1
  +                           + 32;
  +
  +    // Clean up the existing buffer and allocate another
  +    delete [] fURIText;
  +    fURIText = new XMLCh[bufSize];
  +    *fURIText = 0;
  +
  +    XMLCh* outPtr = fURIText;
  +    if (fScheme != 0)
  +    {
  +        XMLString::catString(fURIText, getScheme());
  +        outPtr += XMLString::stringLen(fURIText);
  +        *outPtr++ = chColon;
  +        *outPtr++ = chForwardSlash;
  +        *outPtr++ = chForwardSlash;
  +    }
  +
  +    if (fUserInfo)
  +    {
  +        XMLString::copyString(outPtr, fUserInfo);
  +        outPtr += XMLString::stringLen(fUserInfo);
  +
  +
  +        /*REVISIT dont have password field in uri - is this right??
  +        if (fPassword)
  +        {
  +            *outPtr++ = chColon;
  +            XMLString::copyString(outPtr, fPassword);
  +            outPtr += XMLString::stringLen(fPassword);
  +        }
  +        */
  +        *outPtr++ = chAt;
  +    }
  +
  +    if (fHost)
  +    {
  +        XMLString::copyString(outPtr, fHost);
  +        outPtr += XMLString::stringLen(fHost);
  +
  +        //
  +        //  If the port is -1, then we don't put it in. Else we need
  +        //  to because it was explicitly provided.
  +        //
  +        if (fPort != -1)
  +        {
  +            *outPtr++ = chColon;
  +
  +            XMLCh tmpBuf[16];
  +            XMLString::binToText(fPort, tmpBuf, 16, 10);
  +            XMLString::copyString(outPtr, tmpBuf);
  +            outPtr += XMLString::stringLen(tmpBuf);
  +        }
  +    }
  +
  +    if (fPath)
  +    {
  +        XMLString::copyString(outPtr, fPath);
  +        outPtr += XMLString::stringLen(fPath);
  +    }
  +
  +    if (fQueryString)
  +    {
  +        *outPtr++ = chQuestion;
  +        XMLString::copyString(outPtr, fQueryString);
  +        outPtr += XMLString::stringLen(fQueryString);
  +    }
  +
  +    if (fFragment)
  +    {
  +        *outPtr++ = chPound;
  +        XMLString::copyString(outPtr, fFragment);
  +        outPtr += XMLString::stringLen(fFragment);
  +    }
  +
  +    // Cap it off in case the last op was not a string copy
  +    *outPtr = 0;
  +}
   
  
  
  
  1.4       +27 -6     xml-xerces/c/src/xercesc/util/XMLUri.hpp
  
  Index: XMLUri.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLUri.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLUri.hpp	23 Aug 2002 20:45:24 -0000	1.3
  +++ XMLUri.hpp	23 Sep 2002 18:41:00 -0000	1.4
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.4  2002/09/23 18:41:00  tng
  + * DOM L3: Support baseURI.   Add fURIText to XMLUri.   Added by Gareth Reakes and Thomas Ford.
  + *
    * Revision 1.3  2002/08/23 20:45:24  tng
    * .Memory leak fix: XMLUri data not deleted if constructor failed.
    *
  @@ -148,13 +151,14 @@
       virtual ~XMLUri();
   
       // -----------------------------------------------------------------------
  -    //  Operators
  -    // -----------------------------------------------------------------------
  -
  -
  -    // -----------------------------------------------------------------------
       //  Getter methods
       // -----------------------------------------------------------------------
  +    /**
  +     * Get the URI as a string specification. See RFC 2396 Section 5.2.
  +     *
  +     * @return the URI string specification
  +     */
  +    const XMLCh* getUriText() const;
   
       /**
        * Get the scheme for this URI.
  @@ -306,6 +310,9 @@
       static const XMLCh SCHEME_CHARACTERS[];
       static const XMLCh USERINFO_CHARACTERS[];
   
  +    //helper method for getUriText
  +    void buildFullText();
  +
       /**
        * Unimplemented copy ctor
        */
  @@ -455,6 +462,7 @@
       XMLCh*          fPath;
       XMLCh*          fQueryString;
       XMLCh*          fFragment;
  +    XMLCh*          fURIText;
   
   };
   
  @@ -494,6 +502,19 @@
   inline const XMLCh* XMLUri::getFragment() const
   {
   	return fFragment;
  +}
  +
  +inline const XMLCh* XMLUri::getUriText() const
  +{
  +    //
  +    //  Fault it in if not already. Since this is a const method and we
  +    //  can't use mutable members due the compilers we have to support,
  +    //  we have to cast off the constness.
  +    //
  +    if (!fURIText)
  +        ((XMLUri*)this)->buildFullText();
  +
  +    return fURIText;
   }
   
   // ---------------------------------------------------------------------------
  
  
  

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