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  * 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.16 2004/01/12 22:01:02 cargilld Exp $
00059  * $Log: XMLUri.hpp,v $
00060  * Revision 1.16  2004/01/12 22:01:02  cargilld
00061  * Minor performance change for handling reserved and unreserved characters.
00062  *
00063  * Revision 1.15  2003/12/17 00:18:35  cargilld
00064  * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
00065  *
00066  * Revision 1.14  2003/12/11 22:21:25  neilg
00067  * fixes for the URI implementation to take registry names into account; much thanks to Michael Glavassevich
00068  *
00069  * Revision 1.13  2003/12/02 17:50:21  neilg
00070  * additional fix for bug 25118; once again, thanks to Jeroen Whitmond
00071  *
00072  * Revision 1.12  2003/10/01 00:20:41  knoaman
00073  * Add a static method to check whether a given string is a valid URI.
00074  *
00075  * Revision 1.11  2003/09/25 22:23:25  peiyongz
00076  * Implementation of Serialization/Deserialization
00077  *
00078  * Revision 1.10  2003/07/25 10:15:16  gareth
00079  * Patch by Michael Glavassevich
00080  *
00081  * The patch fixes Bugzilla #19787, #20006, #20009, #20010 and #20287, and
00082  * several other issues. A summary of the changes is listed below:
00083  *
00084  * 1. Added '[' and ']' to reserved characters as per RFC 2732.
00085  * 2. '[' and ']' added in RFC 2732, are not allowed in path segments, but
00086  * may appear in the opaque part.
00087  * 3. No URI can begin with a ':'.
00088  * 4. URI has no scheme if ':' occurs in a URI after '?' or '#', it's part of
00089  * the query string or fragment.
00090  * 5. Whitespace (even escaped as %20) is not permitted in the authority
00091  * portion of a URI.
00092  * 6. IPv4 addresses must match 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "."
00093  * 1*3DIGIT. Since RFC 2732.
00094  * 7. IPv4 addresses are 32-bit, therefore no segment may be larger than 255.
00095  * This isn't expressed by the grammar.
00096  * 8. Hostnames cannot end with a '-'.
00097  * 9. Labels in a hostname must be 63 bytes or less [RFC 1034].
00098  * 10. Hostnames may be no longer than 255 bytes [RFC 1034]. (That
00099  * restriction was already there. I just moved it inwards.
00100  * 11. Added support for IPv6 references added in RFC 2732. URIs such as
00101  * http://[::ffff:1.2.3.4] are valid. The BNF in RFC 2373 isn't correct. IPv6
00102  * addresses are read according to section 2.2 of RFC 2373.
00103  *
00104  * Revision 1.9  2003/05/16 06:01:53  knoaman
00105  * Partial implementation of the configurable memory manager.
00106  *
00107  * Revision 1.8  2003/05/15 19:07:46  knoaman
00108  * Partial implementation of the configurable memory manager.
00109  *
00110  * Revision 1.7  2003/01/06 19:43:18  tng
00111  * New feature StandardUriConformant to force strict standard uri conformance.
00112  *
00113  * Revision 1.6  2002/11/21 15:42:39  gareth
00114  * Implemented copy constructor and operator =. Patch by Jennifer Schachter.
00115  *
00116  * Revision 1.5  2002/11/04 15:22:05  tng
00117  * C++ Namespace Support.
00118  *
00119  * Revision 1.4  2002/09/23 18:41:00  tng
00120  * DOM L3: Support baseURI.   Add fURIText to XMLUri.   Added by Gareth Reakes and Thomas Ford.
00121  *
00122  * Revision 1.3  2002/08/23 20:45:24  tng
00123  * .Memory leak fix: XMLUri data not deleted if constructor failed.
00124  *
00125  * Revision 1.2  2002/02/20 18:17:02  tng
00126  * [Bug 5977] Warnings on generating apiDocs.
00127  *
00128  * Revision 1.1.1.1  2002/02/01 22:22:17  peiyongz
00129  * sane_include
00130  *
00131  * Revision 1.3  2001/08/29 19:03:03  peiyongz
00132  * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
00133  *
00134  * Revision 1.2  2001/08/16 14:09:44  peiyongz
00135  * Removed unused ctors and methods
00136  *
00137  * Revision 1.1  2001/08/10 16:23:41  peiyongz
00138  * XMLUri: creation
00139  *
00140  *
00141  */
00142 
00143 #if !defined(XMLURI_HPP)
00144 #define XMLURI_HPP
00145 
00146 #include <xercesc/util/XMemory.hpp>
00147 #include <xercesc/util/XMLString.hpp>
00148 
00149 #include <xercesc/internal/XSerializable.hpp>
00150 
00151 XERCES_CPP_NAMESPACE_BEGIN
00152 
00153 /*
00154  * This class is a direct port of Java's URI class, to distinguish
00155  * itself from the XMLURL, we use the name XMLUri instead of
00156  * XMLURI.
00157  *
00158  * TODO: how to relate XMLUri and XMLURL since URL is part of URI.
00159  *
00160  */
00161 
00162 class  XMLUri : public XSerializable, public XMemory
00163 {
00164 public:
00165 
00166     // -----------------------------------------------------------------------
00167     //  Constructors and Destructor
00168     // -----------------------------------------------------------------------
00169 
00198     XMLUri(const XMLCh* const    uriSpec,
00199            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00200 
00217     XMLUri(const XMLUri* const  baseURI
00218          , const XMLCh* const   uriSpec
00219          , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00220 
00224     XMLUri(const XMLUri& toCopy);
00225     XMLUri& operator=(const XMLUri& toAssign);
00226 
00227     virtual ~XMLUri();
00228 
00229     // -----------------------------------------------------------------------
00230     //  Getter methods
00231     // -----------------------------------------------------------------------
00237     const XMLCh* getUriText() const;
00238 
00244      const XMLCh* getScheme() const;
00245 
00251      const XMLCh* getUserInfo() const;
00252 
00253 
00259      const XMLCh* getHost() const;
00260 
00266      int getPort() const;
00267      
00273      const XMLCh* getRegBasedAuthority() const;
00274 
00281      const XMLCh* getPath() const;
00282 
00290      const XMLCh* getQueryString() const;
00291 
00299      const XMLCh* getFragment() const;
00300 
00301     // -----------------------------------------------------------------------
00302     //  Setter methods
00303     // -----------------------------------------------------------------------
00304 
00312      void setScheme(const XMLCh* const newScheme);
00313 
00321      void setUserInfo(const XMLCh* const newUserInfo);
00322 
00333      void setHost(const XMLCh* const newHost);
00334 
00344      void setPort(int newPort);
00345      
00354      void setRegBasedAuthority(const XMLCh* const newRegAuth);
00355 
00376      void setPath(const XMLCh* const newPath);
00377 
00386      void setQueryString(const XMLCh* const newQueryString);
00387 
00396      void setFragment(const XMLCh* const newFragment);
00397 
00398      // -----------------------------------------------------------------------
00399     //  Miscellaneous methods
00400     // -----------------------------------------------------------------------
00401 
00409     static bool isURIString(const XMLCh* const uric);
00410 
00414     static bool isValidURI( const XMLUri* const baseURI
00415                           , const XMLCh* const uriStr);
00419     static bool isValidURI( bool haveBaseURI
00420                           , const XMLCh* const uriStr);
00421 
00422     /***
00423      * Support for Serialization/De-serialization
00424      ***/
00425     DECL_XSERIALIZABLE(XMLUri)
00426 
00427     XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00428 
00429 private:
00430 
00431     static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
00432     static const XMLCh RESERVED_CHARACTERS[];
00433     static const XMLCh MARK_CHARACTERS[];
00434     static const XMLCh SCHEME_CHARACTERS[];
00435     static const XMLCh USERINFO_CHARACTERS[];
00436     static const XMLCh REG_NAME_CHARACTERS[];
00437     static const XMLCh PATH_CHARACTERS[];
00438 
00439     //helper method for getUriText
00440     void buildFullText();
00441 
00442     // -----------------------------------------------------------------------
00443     //  Private helper methods
00444     // -----------------------------------------------------------------------
00445 
00451     static bool isReservedCharacter(const XMLCh theChar);
00452     
00458     static bool isPathCharacter(const XMLCh theChar);
00459 
00465     static bool isUnreservedCharacter(const XMLCh theChar);
00466 
00472     static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
00473 
00481     static bool isConformantSchemeName(const XMLCh* const scheme);
00482 
00488     static void isConformantUserInfo(const XMLCh* const userInfo
00489         , MemoryManager* const manager);
00490     
00498     static bool isValidServerBasedAuthority(const XMLCh* const host
00499                                            , const int hostLen
00500                                            , const int port
00501                                            , const XMLCh* const userinfo
00502                                            , const int userLen);
00503                                            
00511     static bool isValidServerBasedAuthority(const XMLCh* const host
00512                                            , const int port
00513                                            , const XMLCh* const userinfo
00514                                            , MemoryManager* const manager);
00515       
00523     static bool isValidRegistryBasedAuthority(const XMLCh* const authority
00524                                              , const int authLen);
00525 
00533     static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
00534 
00552      static bool isWellFormedAddress(const XMLCh* const addr
00553          , MemoryManager* const manager);
00554      
00564      static bool isWellFormedIPv4Address(const XMLCh* const addr, const int length);
00565      
00579      static bool isWellFormedIPv6Reference(const XMLCh* const addr, const int length);
00580      
00596      static int scanHexSequence (const XMLCh* const addr, int index, int end, int& counter);
00597 
00605      bool isGenericURI();
00606 
00607     // -----------------------------------------------------------------------
00608     //  Miscellaneous methods
00609     // -----------------------------------------------------------------------
00610 
00616      void initialize(const XMLUri& toCopy);
00617 
00632      void initialize(const XMLUri* const baseURI
00633                    , const XMLCh*  const uriSpec);
00634 
00641      void initializeScheme(const XMLCh* const uriSpec);
00642 
00650      void initializeAuthority(const XMLCh* const uriSpec);
00651 
00658      void initializePath(const XMLCh* const uriSpec);
00659 
00664      void cleanUp();
00665 
00666     static bool isConformantSchemeName(const XMLCh* const scheme,
00667                                        const int schemeLen);
00668     static bool processScheme(const XMLCh* const uriStr, int& index);
00669     static bool processAuthority(const XMLCh* const uriStr, const int authLen);
00670     static bool isWellFormedAddress(const XMLCh* const addr, const int addrLen);
00671     static bool processPath(const XMLCh* const pathStr, const int pathStrLen,
00672                             const bool isSchemePresent);
00673 
00674     // -----------------------------------------------------------------------
00675     //  Data members
00676     //
00677     //  for all the data member, we own it,
00678     //  responsible for the creation and/or deletion for
00679     //  the memory allocated.
00680     //
00681     // -----------------------------------------------------------------------
00682     XMLCh*          fScheme;
00683     XMLCh*          fUserInfo;
00684     XMLCh*          fHost;
00685     int             fPort;
00686     XMLCh*          fRegAuth;
00687     XMLCh*          fPath;
00688     XMLCh*          fQueryString;
00689     XMLCh*          fFragment;
00690     XMLCh*          fURIText;
00691     MemoryManager*  fMemoryManager;
00692 };
00693 
00694 // ---------------------------------------------------------------------------
00695 //  XMLUri: Getter methods
00696 // ---------------------------------------------------------------------------
00697 inline const XMLCh* XMLUri::getScheme() const
00698 {
00699     return fScheme;
00700 }
00701 
00702 inline const XMLCh* XMLUri::getUserInfo() const
00703 {
00704     return fUserInfo;
00705 }
00706 
00707 inline const XMLCh* XMLUri::getHost() const
00708 {
00709     return fHost;
00710 }
00711 
00712 inline int XMLUri::getPort() const
00713 {
00714     return fPort;
00715 }
00716 
00717 inline const XMLCh* XMLUri::getRegBasedAuthority() const
00718 {
00719     return fRegAuth;
00720 }
00721 
00722 inline const XMLCh* XMLUri::getPath() const
00723 {
00724     return fPath;
00725 }
00726 
00727 inline const XMLCh* XMLUri::getQueryString() const
00728 {
00729     return fQueryString;
00730 }
00731 
00732 inline const XMLCh* XMLUri::getFragment() const
00733 {
00734     return fFragment;
00735 }
00736 
00737 inline const XMLCh* XMLUri::getUriText() const
00738 {
00739     //
00740     //  Fault it in if not already. Since this is a const method and we
00741     //  can't use mutable members due the compilers we have to support,
00742     //  we have to cast off the constness.
00743     //
00744     if (!fURIText)
00745         ((XMLUri*)this)->buildFullText();
00746 
00747     return fURIText;
00748 }
00749 
00750 // ---------------------------------------------------------------------------
00751 //  XMLUri: Helper methods
00752 // ---------------------------------------------------------------------------
00753 inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
00754 {
00755    return (XMLString::isAlphaNum(theChar) ||
00756            XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
00757 }
00758 
00759 inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
00760 {
00761     return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
00762 }
00763 
00764 inline bool XMLUri::isPathCharacter(const XMLCh theChar)
00765 {
00766     return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
00767 }
00768 
00769 inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
00770 {
00771     return (XMLString::isAlphaNum(theChar) ||
00772             XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
00773 }
00774 
00775 XERCES_CPP_NAMESPACE_END
00776 
00777 #endif


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