http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

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  * Copyright 2001-2004 The Apache Software Foundation.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * $Id: XMLUri.hpp,v 1.18 2004/09/08 13:56:25 peiyongz Exp $
00019  * $Log: XMLUri.hpp,v $
00020  * Revision 1.18  2004/09/08 13:56:25  peiyongz
00021  * Apache License Version 2.0
00022  *
00023  * Revision 1.17  2004/05/25 18:11:47  peiyongz
00024  * normalizeURI() added
00025  *
00026  * Revision 1.16  2004/01/12 22:01:02  cargilld
00027  * Minor performance change for handling reserved and unreserved characters.
00028  *
00029  * Revision 1.15  2003/12/17 00:18:35  cargilld
00030  * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
00031  *
00032  * Revision 1.14  2003/12/11 22:21:25  neilg
00033  * fixes for the URI implementation to take registry names into account; much thanks to Michael Glavassevich
00034  *
00035  * Revision 1.13  2003/12/02 17:50:21  neilg
00036  * additional fix for bug 25118; once again, thanks to Jeroen Whitmond
00037  *
00038  * Revision 1.12  2003/10/01 00:20:41  knoaman
00039  * Add a static method to check whether a given string is a valid URI.
00040  *
00041  * Revision 1.11  2003/09/25 22:23:25  peiyongz
00042  * Implementation of Serialization/Deserialization
00043  *
00044  * Revision 1.10  2003/07/25 10:15:16  gareth
00045  * Patch by Michael Glavassevich
00046  *
00047  * The patch fixes Bugzilla #19787, #20006, #20009, #20010 and #20287, and
00048  * several other issues. A summary of the changes is listed below:
00049  *
00050  * 1. Added '[' and ']' to reserved characters as per RFC 2732.
00051  * 2. '[' and ']' added in RFC 2732, are not allowed in path segments, but
00052  * may appear in the opaque part.
00053  * 3. No URI can begin with a ':'.
00054  * 4. URI has no scheme if ':' occurs in a URI after '?' or '#', it's part of
00055  * the query string or fragment.
00056  * 5. Whitespace (even escaped as %20) is not permitted in the authority
00057  * portion of a URI.
00058  * 6. IPv4 addresses must match 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "."
00059  * 1*3DIGIT. Since RFC 2732.
00060  * 7. IPv4 addresses are 32-bit, therefore no segment may be larger than 255.
00061  * This isn't expressed by the grammar.
00062  * 8. Hostnames cannot end with a '-'.
00063  * 9. Labels in a hostname must be 63 bytes or less [RFC 1034].
00064  * 10. Hostnames may be no longer than 255 bytes [RFC 1034]. (That
00065  * restriction was already there. I just moved it inwards.
00066  * 11. Added support for IPv6 references added in RFC 2732. URIs such as
00067  * http://[::ffff:1.2.3.4] are valid. The BNF in RFC 2373 isn't correct. IPv6
00068  * addresses are read according to section 2.2 of RFC 2373.
00069  *
00070  * Revision 1.9  2003/05/16 06:01:53  knoaman
00071  * Partial implementation of the configurable memory manager.
00072  *
00073  * Revision 1.8  2003/05/15 19:07:46  knoaman
00074  * Partial implementation of the configurable memory manager.
00075  *
00076  * Revision 1.7  2003/01/06 19:43:18  tng
00077  * New feature StandardUriConformant to force strict standard uri conformance.
00078  *
00079  * Revision 1.6  2002/11/21 15:42:39  gareth
00080  * Implemented copy constructor and operator =. Patch by Jennifer Schachter.
00081  *
00082  * Revision 1.5  2002/11/04 15:22:05  tng
00083  * C++ Namespace Support.
00084  *
00085  * Revision 1.4  2002/09/23 18:41:00  tng
00086  * DOM L3: Support baseURI.   Add fURIText to XMLUri.   Added by Gareth Reakes and Thomas Ford.
00087  *
00088  * Revision 1.3  2002/08/23 20:45:24  tng
00089  * .Memory leak fix: XMLUri data not deleted if constructor failed.
00090  *
00091  * Revision 1.2  2002/02/20 18:17:02  tng
00092  * [Bug 5977] Warnings on generating apiDocs.
00093  *
00094  * Revision 1.1.1.1  2002/02/01 22:22:17  peiyongz
00095  * sane_include
00096  *
00097  * Revision 1.3  2001/08/29 19:03:03  peiyongz
00098  * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
00099  *
00100  * Revision 1.2  2001/08/16 14:09:44  peiyongz
00101  * Removed unused ctors and methods
00102  *
00103  * Revision 1.1  2001/08/10 16:23:41  peiyongz
00104  * XMLUri: creation
00105  *
00106  *
00107  */
00108 
00109 #if !defined(XMLURI_HPP)
00110 #define XMLURI_HPP
00111 
00112 #include <xercesc/util/XMemory.hpp>
00113 #include <xercesc/util/XMLString.hpp>
00114 
00115 #include <xercesc/internal/XSerializable.hpp>
00116 #include <xercesc/framework/XMLBuffer.hpp>
00117 
00118 XERCES_CPP_NAMESPACE_BEGIN
00119 
00120 /*
00121  * This class is a direct port of Java's URI class, to distinguish
00122  * itself from the XMLURL, we use the name XMLUri instead of
00123  * XMLURI.
00124  *
00125  * TODO: how to relate XMLUri and XMLURL since URL is part of URI.
00126  *
00127  */
00128 
00129 class  XMLUri : public XSerializable, public XMemory
00130 {
00131 public:
00132 
00133     // -----------------------------------------------------------------------
00134     //  Constructors and Destructor
00135     // -----------------------------------------------------------------------
00136 
00165     XMLUri(const XMLCh* const    uriSpec,
00166            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00167 
00184     XMLUri(const XMLUri* const  baseURI
00185          , const XMLCh* const   uriSpec
00186          , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00187 
00191     XMLUri(const XMLUri& toCopy);
00192     XMLUri& operator=(const XMLUri& toAssign);
00193 
00194     virtual ~XMLUri();
00195 
00196     // -----------------------------------------------------------------------
00197     //  Getter methods
00198     // -----------------------------------------------------------------------
00204     const XMLCh* getUriText() const;
00205 
00211      const XMLCh* getScheme() const;
00212 
00218      const XMLCh* getUserInfo() const;
00219 
00220 
00226      const XMLCh* getHost() const;
00227 
00233      int getPort() const;
00234      
00240      const XMLCh* getRegBasedAuthority() const;
00241 
00248      const XMLCh* getPath() const;
00249 
00257      const XMLCh* getQueryString() const;
00258 
00266      const XMLCh* getFragment() const;
00267 
00268     // -----------------------------------------------------------------------
00269     //  Setter methods
00270     // -----------------------------------------------------------------------
00271 
00279      void setScheme(const XMLCh* const newScheme);
00280 
00288      void setUserInfo(const XMLCh* const newUserInfo);
00289 
00300      void setHost(const XMLCh* const newHost);
00301 
00311      void setPort(int newPort);
00312      
00321      void setRegBasedAuthority(const XMLCh* const newRegAuth);
00322 
00343      void setPath(const XMLCh* const newPath);
00344 
00353      void setQueryString(const XMLCh* const newQueryString);
00354 
00363      void setFragment(const XMLCh* const newFragment);
00364 
00365      // -----------------------------------------------------------------------
00366     //  Miscellaneous methods
00367     // -----------------------------------------------------------------------
00368 
00376     static bool isURIString(const XMLCh* const uric);
00377 
00381     static bool isValidURI( const XMLUri* const baseURI
00382                           , const XMLCh* const uriStr);
00386     static bool isValidURI( bool haveBaseURI
00387                           , const XMLCh* const uriStr);
00388 
00389 
00390     static void normalizeURI(const XMLCh*     const systemURI,
00391                                    XMLBuffer&       normalizedURI);
00392 
00393     /***
00394      * Support for Serialization/De-serialization
00395      ***/
00396     DECL_XSERIALIZABLE(XMLUri)
00397 
00398     XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00399 
00400 private:
00401 
00402     static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
00403     static const XMLCh RESERVED_CHARACTERS[];
00404     static const XMLCh MARK_CHARACTERS[];
00405     static const XMLCh SCHEME_CHARACTERS[];
00406     static const XMLCh USERINFO_CHARACTERS[];
00407     static const XMLCh REG_NAME_CHARACTERS[];
00408     static const XMLCh PATH_CHARACTERS[];
00409 
00410     //helper method for getUriText
00411     void buildFullText();
00412 
00413     // -----------------------------------------------------------------------
00414     //  Private helper methods
00415     // -----------------------------------------------------------------------
00416 
00422     static bool isReservedCharacter(const XMLCh theChar);
00423     
00429     static bool isPathCharacter(const XMLCh theChar);
00430 
00436     static bool isUnreservedCharacter(const XMLCh theChar);
00437 
00443     static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
00444 
00452     static bool isConformantSchemeName(const XMLCh* const scheme);
00453 
00459     static void isConformantUserInfo(const XMLCh* const userInfo
00460         , MemoryManager* const manager);
00461     
00469     static bool isValidServerBasedAuthority(const XMLCh* const host
00470                                            , const int hostLen
00471                                            , const int port
00472                                            , const XMLCh* const userinfo
00473                                            , const int userLen);
00474                                            
00482     static bool isValidServerBasedAuthority(const XMLCh* const host
00483                                            , const int port
00484                                            , const XMLCh* const userinfo
00485                                            , MemoryManager* const manager);
00486       
00494     static bool isValidRegistryBasedAuthority(const XMLCh* const authority
00495                                              , const int authLen);
00496 
00504     static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
00505 
00523      static bool isWellFormedAddress(const XMLCh* const addr
00524          , MemoryManager* const manager);
00525      
00535      static bool isWellFormedIPv4Address(const XMLCh* const addr, const int length);
00536      
00550      static bool isWellFormedIPv6Reference(const XMLCh* const addr, const int length);
00551      
00567      static int scanHexSequence (const XMLCh* const addr, int index, int end, int& counter);
00568 
00576      bool isGenericURI();
00577 
00578     // -----------------------------------------------------------------------
00579     //  Miscellaneous methods
00580     // -----------------------------------------------------------------------
00581 
00587      void initialize(const XMLUri& toCopy);
00588 
00603      void initialize(const XMLUri* const baseURI
00604                    , const XMLCh*  const uriSpec);
00605 
00612      void initializeScheme(const XMLCh* const uriSpec);
00613 
00621      void initializeAuthority(const XMLCh* const uriSpec);
00622 
00629      void initializePath(const XMLCh* const uriSpec);
00630 
00635      void cleanUp();
00636 
00637     static bool isConformantSchemeName(const XMLCh* const scheme,
00638                                        const int schemeLen);
00639     static bool processScheme(const XMLCh* const uriStr, int& index);
00640     static bool processAuthority(const XMLCh* const uriStr, const int authLen);
00641     static bool isWellFormedAddress(const XMLCh* const addr, const int addrLen);
00642     static bool processPath(const XMLCh* const pathStr, const int pathStrLen,
00643                             const bool isSchemePresent);
00644 
00645     // -----------------------------------------------------------------------
00646     //  Data members
00647     //
00648     //  for all the data member, we own it,
00649     //  responsible for the creation and/or deletion for
00650     //  the memory allocated.
00651     //
00652     // -----------------------------------------------------------------------
00653     XMLCh*          fScheme;
00654     XMLCh*          fUserInfo;
00655     XMLCh*          fHost;
00656     int             fPort;
00657     XMLCh*          fRegAuth;
00658     XMLCh*          fPath;
00659     XMLCh*          fQueryString;
00660     XMLCh*          fFragment;
00661     XMLCh*          fURIText;
00662     MemoryManager*  fMemoryManager;
00663 };
00664 
00665 // ---------------------------------------------------------------------------
00666 //  XMLUri: Getter methods
00667 // ---------------------------------------------------------------------------
00668 inline const XMLCh* XMLUri::getScheme() const
00669 {
00670     return fScheme;
00671 }
00672 
00673 inline const XMLCh* XMLUri::getUserInfo() const
00674 {
00675     return fUserInfo;
00676 }
00677 
00678 inline const XMLCh* XMLUri::getHost() const
00679 {
00680     return fHost;
00681 }
00682 
00683 inline int XMLUri::getPort() const
00684 {
00685     return fPort;
00686 }
00687 
00688 inline const XMLCh* XMLUri::getRegBasedAuthority() const
00689 {
00690     return fRegAuth;
00691 }
00692 
00693 inline const XMLCh* XMLUri::getPath() const
00694 {
00695     return fPath;
00696 }
00697 
00698 inline const XMLCh* XMLUri::getQueryString() const
00699 {
00700     return fQueryString;
00701 }
00702 
00703 inline const XMLCh* XMLUri::getFragment() const
00704 {
00705     return fFragment;
00706 }
00707 
00708 inline const XMLCh* XMLUri::getUriText() const
00709 {
00710     //
00711     //  Fault it in if not already. Since this is a const method and we
00712     //  can't use mutable members due the compilers we have to support,
00713     //  we have to cast off the constness.
00714     //
00715     if (!fURIText)
00716         ((XMLUri*)this)->buildFullText();
00717 
00718     return fURIText;
00719 }
00720 
00721 // ---------------------------------------------------------------------------
00722 //  XMLUri: Helper methods
00723 // ---------------------------------------------------------------------------
00724 inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
00725 {
00726    return (XMLString::isAlphaNum(theChar) ||
00727            XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
00728 }
00729 
00730 inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
00731 {
00732     return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
00733 }
00734 
00735 inline bool XMLUri::isPathCharacter(const XMLCh theChar)
00736 {
00737     return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
00738 }
00739 
00740 inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
00741 {
00742     return (XMLString::isAlphaNum(theChar) ||
00743             XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
00744 }
00745 
00746 XERCES_CPP_NAMESPACE_END
00747 
00748 #endif


Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.