00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
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 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 class  XMLUri : public XSerializable, public XMemory
00163 {
00164 public:
00165 
00166     
00167     
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     
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     
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     
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 
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     
00440     void buildFullText();
00441 
00442     
00443     
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     
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     
00676     
00677     
00678     
00679     
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 
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     
00741     
00742     
00743     
00744     if (!fURIText)
00745         ((XMLUri*)this)->buildFullText();
00746 
00747     return fURIText;
00748 }
00749 
00750 
00751 
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