| API Docs for SAX and DOM |

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# XMLUri.hpp

Go to the documentation of this file.

    00001 /*
    00002  * The Apache Software License, Version 1.1
    00003  *
    00004  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    00005  * reserved.
    00006  *
    00007  * Redistribution and use in source and binary forms, with or without
    00008  * modification, are permitted provided that the following conditions
    00009  * are met:
    00010  *
    00011  * 1. Redistributions of source code must retain the above copyright
    00012  *    notice, this list of conditions and the following disclaimer.
    00013  *
    00014  * 2. Redistributions in binary form must reproduce the above copyright
    00015  *    notice, this list of conditions and the following disclaimer in
    00016  *    the documentation and/or other materials provided with the
    00017  *    distribution.
    00018  *
    00019  * 3. The end-user documentation included with the redistribution,
    00020  *    if any, must include the following acknowledgment:
    00021  *       "This product includes software developed by the
    00022  *        Apache Software Foundation (http://www.apache.org/)."
    00023  *    Alternately, this acknowledgment may appear in the software itself,
    00024  *    if and wherever such third-party acknowledgments normally appear.
    00025  *
    00026  * 4. The names "Xerces" and "Apache Software Foundation" must
    00027  *    not be used to endorse or promote products derived from this
    00028  *    software without prior written permission. For written
    00029  *    permission, please contact apache\@apache.org.
    00030  *
    00031  * 5. Products derived from this software may not be called "Apache",
    00032  *    nor may "Apache" appear in their name, without prior written
    00033  *    permission of the Apache Software Foundation.
    00034  *
    00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00046  * SUCH DAMAGE.
    00047  * ====================================================================
    00048  *
    00049  * This software consists of voluntary contributions made by many
    00050  * individuals on behalf of the Apache Software Foundation, and was
    00051  * originally based on software copyright (c) 1999, International
    00052  * Business Machines, Inc., http://www.ibm.com .  For more information
    00053  * on the Apache Software Foundation, please see
    00054  * <http://www.apache.org/>.
    00055  */
    00056
    00057 /*
    00058  * $Id: XMLUri.hpp,v 1.13 2003/12/02 17:50:21 neilg Exp $
    00059  * $Log: XMLUri.hpp,v $
    00060  * Revision 1.13  2003/12/02 17:50:21  neilg
    00061  * additional fix for bug 25118; once again, thanks to Jeroen Whitmond
    00062  *
    00063  * Revision 1.12  2003/10/01 00:20:41  knoaman
    00064  * Add a static method to check whether a given string is a valid URI.
    00065  *
    00066  * Revision 1.11  2003/09/25 22:23:25  peiyongz
    00067  * Implementation of Serialization/Deserialization
    00068  *
    00069  * Revision 1.10  2003/07/25 10:15:16  gareth
    00070  * Patch by Michael Glavassevich
    00071  *
    00072  * The patch fixes Bugzilla #19787, #20006, #20009, #20010 and #20287, and
    00073  * several other issues. A summary of the changes is listed below:
    00074  *
    00075  * 1. Added '[' and ']' to reserved characters as per RFC 2732.
    00076  * 2. '[' and ']' added in RFC 2732, are not allowed in path segments, but
    00077  * may appear in the opaque part.
    00078  * 3. No URI can begin with a ':'.
    00079  * 4. URI has no scheme if ':' occurs in a URI after '?' or '#', it's part of
    00080  * the query string or fragment.
    00081  * 5. Whitespace (even escaped as %20) is not permitted in the authority
    00082  * portion of a URI.
    00083  * 6. IPv4 addresses must match 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "."
    00084  * 1*3DIGIT. Since RFC 2732.
    00085  * 7. IPv4 addresses are 32-bit, therefore no segment may be larger than 255.
    00086  * This isn't expressed by the grammar.
    00087  * 8. Hostnames cannot end with a '-'.
    00088  * 9. Labels in a hostname must be 63 bytes or less [RFC 1034].
    00089  * 10. Hostnames may be no longer than 255 bytes [RFC 1034]. (That
    00090  * restriction was already there. I just moved it inwards.
    00091  * 11. Added support for IPv6 references added in RFC 2732. URIs such as
    00092  * http://[::ffff:1.2.3.4] are valid. The BNF in RFC 2373 isn't correct. IPv6
    00093  * addresses are read according to section 2.2 of RFC 2373.
    00094  *
    00095  * Revision 1.9  2003/05/16 06:01:53  knoaman
    00096  * Partial implementation of the configurable memory manager.
    00097  *
    00098  * Revision 1.8  2003/05/15 19:07:46  knoaman
    00099  * Partial implementation of the configurable memory manager.
    00100  *
    00101  * Revision 1.7  2003/01/06 19:43:18  tng
    00102  * New feature StandardUriConformant to force strict standard uri conformance.
    00103  *
    00104  * Revision 1.6  2002/11/21 15:42:39  gareth
    00105  * Implemented copy constructor and operator =. Patch by Jennifer Schachter.
    00106  *
    00107  * Revision 1.5  2002/11/04 15:22:05  tng
    00108  * C++ Namespace Support.
    00109  *
    00110  * Revision 1.4  2002/09/23 18:41:00  tng
    00111  * DOM L3: Support baseURI.   Add fURIText to XMLUri.   Added by Gareth Reakes and Thomas Ford.
    00112  *
    00113  * Revision 1.3  2002/08/23 20:45:24  tng
    00114  * .Memory leak fix: XMLUri data not deleted if constructor failed.
    00115  *
    00116  * Revision 1.2  2002/02/20 18:17:02  tng
    00117  * [Bug 5977] Warnings on generating apiDocs.
    00118  *
    00119  * Revision 1.1.1.1  2002/02/01 22:22:17  peiyongz
    00120  * sane_include
    00121  *
    00122  * Revision 1.3  2001/08/29 19:03:03  peiyongz
    00123  * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
    00124  *
    00125  * Revision 1.2  2001/08/16 14:09:44  peiyongz
    00126  * Removed unused ctors and methods
    00127  *
    00128  * Revision 1.1  2001/08/10 16:23:41  peiyongz
    00129  * XMLUri: creation
    00130  *
    00131  *
    00132  */
    00133
    00134 #if !defined(XMLURI_HPP)
    00135 #define XMLURI_HPP
    00136
    00137 #include <xercesc/util/XMemory.hpp>
    00138 #include <xercesc/util/XMLString.hpp>
    00139
    00140 #include <xercesc/internal/XSerializable.hpp>
    00141
    00142 XERCES_CPP_NAMESPACE_BEGIN
    00143
    00144 /*
    00145  * This class is a direct port of Java's URI class, to distinguish
    00146  * itself from the XMLURL, we use the name XMLUri instead of
    00147  * XMLURI.
    00148  *
    00149  * TODO: how to relate XMLUri and XMLURL since URL is part of URI.
    00150  *
    00151  */
    00152
    00153 class  XMLUri : public XSerializable, public XMemory
    00154 {
    00155 public:
    00156
    00157     // -----------------------------------------------------------------------
    00158     //  Constructors and Destructor
    00159     // -----------------------------------------------------------------------
    00160
    00189     XMLUri(const XMLCh* const    uriSpec,
    00190            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00191
    00208     XMLUri(const XMLUri* const  baseURI
    00209          , const XMLCh* const   uriSpec
    00210          , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00211
    00215     XMLUri(const XMLUri& toCopy);
    00216     XMLUri& operator=(const XMLUri& toAssign);
    00217
    00218     virtual ~XMLUri();
    00219
    00220     // -----------------------------------------------------------------------
    00221     //  Getter methods
    00222     // -----------------------------------------------------------------------
    00228     const XMLCh* getUriText() const;
    00229
    00235      const XMLCh* getScheme() const;
    00236
    00242      const XMLCh* getUserInfo() const;
    00243
    00244
    00250      const XMLCh* getHost() const;
    00251
    00257      int getPort() const;
    00258
    00265      const XMLCh* getPath() const;
    00266
    00274      const XMLCh* getQueryString() const;
    00275
    00283      const XMLCh* getFragment() const;
    00284
    00285     // -----------------------------------------------------------------------
    00286     //  Setter methods
    00287     // -----------------------------------------------------------------------
    00288
    00296      void setScheme(const XMLCh* const newScheme);
    00297
    00305      void setUserInfo(const XMLCh* const newUserInfo);
    00306
    00314      void setHost(const XMLCh* const newHost);
    00315
    00325      void setPort(int newPort);
    00326
    00347      void setPath(const XMLCh* const newPath);
    00348
    00357      void setQueryString(const XMLCh* const newQueryString);
    00358
    00367      void setFragment(const XMLCh* const newFragment);
    00368
    00369      // -----------------------------------------------------------------------
    00370     //  Miscellaneous methods
    00371     // -----------------------------------------------------------------------
    00372
    00380     static bool isURIString(const XMLCh* const uric);
    00381
    00385     static bool isValidURI( const XMLUri* const baseURI
    00386                           , const XMLCh* const uriStr);
    00387
    00388     /***
    00389      * Support for Serialization/De-serialization
    00390      ***/
    00391     DECL_XSERIALIZABLE(XMLUri)
    00392
    00393     XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00394
    00395 private:
    00396
    00397     static const XMLCh RESERVED_CHARACTERS[];
    00398     static const XMLCh MARK_CHARACTERS[];
    00399     static const XMLCh SCHEME_CHARACTERS[];
    00400     static const XMLCh USERINFO_CHARACTERS[];
    00401     static const XMLCh PATH_CHARACTERS[];
    00402
    00403     //helper method for getUriText
    00404     void buildFullText();
    00405
    00406     // -----------------------------------------------------------------------
    00407     //  Private helper methods
    00408     // -----------------------------------------------------------------------
    00409
    00415     static bool isReservedCharacter(const XMLCh theChar);
    00416
    00422     static bool isPathCharacter(const XMLCh theChar);
    00423
    00429     static bool isUnreservedCharacter(const XMLCh theChar);
    00430
    00438     static bool isConformantSchemeName(const XMLCh* const scheme);
    00439
    00445     static void isConformantUserInfo(const XMLCh* const userInfo);
    00463      static bool isWellFormedAddress(const XMLCh* const addr);
    00464
    00474      static bool isWellFormedIPv4Address(const XMLCh* const addr, const int length);
    00475
    00489      static bool isWellFormedIPv6Reference(const XMLCh* const addr, const int length);
    00490
    00506      static int scanHexSequence (const XMLCh* const addr, int index, int end, int& counter);
    00507
    00515      bool isGenericURI();
    00516
    00517     // -----------------------------------------------------------------------
    00518     //  Miscellaneous methods
    00519     // -----------------------------------------------------------------------
    00520
    00526      void initialize(const XMLUri& toCopy);
    00527
    00542      void initialize(const XMLUri* const baseURI
    00543                    , const XMLCh*  const uriSpec);
    00544
    00551      void initializeScheme(const XMLCh* const uriSpec);
    00552
    00560      void initializeAuthority(const XMLCh* const uriSpec);
    00561
    00568      void initializePath(const XMLCh* const uriSpec);
    00569
    00574      void cleanUp();
    00575
    00576     static bool isConformantSchemeName(const XMLCh* const scheme,
    00577                                        const int schemeLen);
    00578     static bool processScheme(const XMLCh* const uriStr, int& index);
    00579     static bool processAuthority(const XMLCh* const uriStr, const int authLen);
    00580     static bool isWellFormedAddress(const XMLCh* const addr, const int addrLen);
    00581     static bool processPath(const XMLCh* const pathStr, const int pathStrLen,
    00582                             const bool isSchemePresent);
    00583
    00584     // -----------------------------------------------------------------------
    00585     //  Data members
    00586     //
    00587     //  for all the data member, we own it,
    00588     //  responsible for the creation and/or deletion for
    00589     //  the memory allocated.
    00590     //
    00591     // -----------------------------------------------------------------------
    00592     XMLCh*          fScheme;
    00593     XMLCh*          fUserInfo;
    00594     XMLCh*          fHost;
    00595     int             fPort;
    00596     XMLCh*          fPath;
    00597     XMLCh*          fQueryString;
    00598     XMLCh*          fFragment;
    00599     XMLCh*          fURIText;
    00600     MemoryManager*  fMemoryManager;
    00601 };
    00602
    00603 // ---------------------------------------------------------------------------
    00604 //  XMLUri: Getter methods
    00605 // ---------------------------------------------------------------------------
    00606 inline const XMLCh* XMLUri::getScheme() const
    00607 {
    00608     return fScheme;
    00609 }
    00610
    00611 inline const XMLCh* XMLUri::getUserInfo() const
    00612 {
    00613     return fUserInfo;
    00614 }
    00615
    00616 inline const XMLCh* XMLUri::getHost() const
    00617 {
    00618     return fHost;
    00619 }
    00620
    00621 inline int XMLUri::getPort() const
    00622 {
    00623     return fPort;
    00624 }
    00625
    00626 inline const XMLCh* XMLUri::getPath() const
    00627 {
    00628     return fPath;
    00629 }
    00630
    00631 inline const XMLCh* XMLUri::getQueryString() const
    00632 {
    00633     return fQueryString;
    00634 }
    00635
    00636 inline const XMLCh* XMLUri::getFragment() const
    00637 {
    00638     return fFragment;
    00639 }
    00640
    00641 inline const XMLCh* XMLUri::getUriText() const
    00642 {
    00643     //
    00644     //  Fault it in if not already. Since this is a const method and we
    00645     //  can't use mutable members due the compilers we have to support,
    00646     //  we have to cast off the constness.
    00647     //
    00648     if (!fURIText)
    00649         ((XMLUri*)this)->buildFullText();
    00650
    00651     return fURIText;
    00652 }
    00653
    00654 // ---------------------------------------------------------------------------
    00655 //  XMLUri: Helper methods
    00656 // ---------------------------------------------------------------------------
    00657 inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
    00658 {
    00659     return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
    00660 }
    00661
    00662 inline bool XMLUri::isPathCharacter(const XMLCh theChar)
    00663 {
    00664     return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
    00665 }
    00666
    00667 inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
    00668 {
    00669     return (XMLString::isAlphaNum(theChar) ||
    00670             XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
    00671 }
    00672
    00673 XERCES_CPP_NAMESPACE_END
    00674
    00675 #endif

Copyright © 2003 The Apache Software Foundation. All Rights Reserved.