00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(XMLURI_HPP)
00023 #define XMLURI_HPP
00024
00025 #include <xercesc/util/XMemory.hpp>
00026 #include <xercesc/util/XMLString.hpp>
00027
00028 #include <xercesc/internal/XSerializable.hpp>
00029 #include <xercesc/framework/XMLBuffer.hpp>
00030
00031 XERCES_CPP_NAMESPACE_BEGIN
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class XMLUri : public XSerializable, public XMemory
00043 {
00044 public:
00045
00046
00047
00048
00049
00078 XMLUri(const XMLCh* const uriSpec,
00079 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00080
00097 XMLUri(const XMLUri* const baseURI
00098 , const XMLCh* const uriSpec
00099 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00100
00104 XMLUri(const XMLUri& toCopy);
00105 XMLUri& operator=(const XMLUri& toAssign);
00106
00107 virtual ~XMLUri();
00108
00109
00110
00111
00117 const XMLCh* getUriText() const;
00118
00124 const XMLCh* getScheme() const;
00125
00131 const XMLCh* getUserInfo() const;
00132
00133
00139 const XMLCh* getHost() const;
00140
00146 int getPort() const;
00147
00153 const XMLCh* getRegBasedAuthority() const;
00154
00161 const XMLCh* getPath() const;
00162
00170 const XMLCh* getQueryString() const;
00171
00179 const XMLCh* getFragment() const;
00180
00181
00182
00183
00184
00192 void setScheme(const XMLCh* const newScheme);
00193
00201 void setUserInfo(const XMLCh* const newUserInfo);
00202
00213 void setHost(const XMLCh* const newHost);
00214
00224 void setPort(int newPort);
00225
00234 void setRegBasedAuthority(const XMLCh* const newRegAuth);
00235
00256 void setPath(const XMLCh* const newPath);
00257
00266 void setQueryString(const XMLCh* const newQueryString);
00267
00276 void setFragment(const XMLCh* const newFragment);
00277
00278
00279
00280
00281
00289 static bool isURIString(const XMLCh* const uric);
00290
00294 static bool isValidURI( const XMLUri* const baseURI
00295 , const XMLCh* const uriStr);
00299 static bool isValidURI( bool haveBaseURI
00300 , const XMLCh* const uriStr);
00301
00302
00303 static void normalizeURI(const XMLCh* const systemURI,
00304 XMLBuffer& normalizedURI);
00305
00306
00307
00308
00309 DECL_XSERIALIZABLE(XMLUri)
00310
00311 XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00312
00313 private:
00314
00315 static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
00316 static const XMLCh RESERVED_CHARACTERS[];
00317 static const XMLCh MARK_CHARACTERS[];
00318 static const XMLCh SCHEME_CHARACTERS[];
00319 static const XMLCh USERINFO_CHARACTERS[];
00320 static const XMLCh REG_NAME_CHARACTERS[];
00321 static const XMLCh PATH_CHARACTERS[];
00322
00323
00324 void buildFullText();
00325
00326
00327
00328
00329
00335 static bool isReservedCharacter(const XMLCh theChar);
00336
00342 static bool isPathCharacter(const XMLCh theChar);
00343
00349 static bool isUnreservedCharacter(const XMLCh theChar);
00350
00356 static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
00357
00365 static bool isConformantSchemeName(const XMLCh* const scheme);
00366
00372 static void isConformantUserInfo(const XMLCh* const userInfo
00373 , MemoryManager* const manager);
00374
00382 static bool isValidServerBasedAuthority(const XMLCh* const host
00383 , const int hostLen
00384 , const int port
00385 , const XMLCh* const userinfo
00386 , const int userLen);
00387
00395 static bool isValidServerBasedAuthority(const XMLCh* const host
00396 , const int port
00397 , const XMLCh* const userinfo
00398 , MemoryManager* const manager);
00399
00407 static bool isValidRegistryBasedAuthority(const XMLCh* const authority
00408 , const int authLen);
00409
00417 static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
00418
00436 static bool isWellFormedAddress(const XMLCh* const addr
00437 , MemoryManager* const manager);
00438
00448 static bool isWellFormedIPv4Address(const XMLCh* const addr, const int length);
00449
00463 static bool isWellFormedIPv6Reference(const XMLCh* const addr, const int length);
00464
00480 static int scanHexSequence (const XMLCh* const addr, int index, int end, int& counter);
00481
00489 bool isGenericURI();
00490
00491
00492
00493
00494
00500 void initialize(const XMLUri& toCopy);
00501
00516 void initialize(const XMLUri* const baseURI
00517 , const XMLCh* const uriSpec);
00518
00525 void initializeScheme(const XMLCh* const uriSpec);
00526
00534 void initializeAuthority(const XMLCh* const uriSpec);
00535
00542 void initializePath(const XMLCh* const uriSpec);
00543
00548 void cleanUp();
00549
00550 static bool isConformantSchemeName(const XMLCh* const scheme,
00551 const int schemeLen);
00552 static bool processScheme(const XMLCh* const uriStr, int& index);
00553 static bool processAuthority(const XMLCh* const uriStr, const int authLen);
00554 static bool isWellFormedAddress(const XMLCh* const addr, const int addrLen);
00555 static bool processPath(const XMLCh* const pathStr, const int pathStrLen,
00556 const bool isSchemePresent);
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566 int fPort;
00567 XMLCh* fScheme;
00568 XMLCh* fUserInfo;
00569 XMLCh* fHost;
00570 XMLCh* fRegAuth;
00571 XMLCh* fPath;
00572 XMLCh* fQueryString;
00573 XMLCh* fFragment;
00574 XMLCh* fURIText;
00575 MemoryManager* fMemoryManager;
00576 };
00577
00578
00579
00580
00581 inline const XMLCh* XMLUri::getScheme() const
00582 {
00583 return fScheme;
00584 }
00585
00586 inline const XMLCh* XMLUri::getUserInfo() const
00587 {
00588 return fUserInfo;
00589 }
00590
00591 inline const XMLCh* XMLUri::getHost() const
00592 {
00593 return fHost;
00594 }
00595
00596 inline int XMLUri::getPort() const
00597 {
00598 return fPort;
00599 }
00600
00601 inline const XMLCh* XMLUri::getRegBasedAuthority() const
00602 {
00603 return fRegAuth;
00604 }
00605
00606 inline const XMLCh* XMLUri::getPath() const
00607 {
00608 return fPath;
00609 }
00610
00611 inline const XMLCh* XMLUri::getQueryString() const
00612 {
00613 return fQueryString;
00614 }
00615
00616 inline const XMLCh* XMLUri::getFragment() const
00617 {
00618 return fFragment;
00619 }
00620
00621 inline const XMLCh* XMLUri::getUriText() const
00622 {
00623
00624
00625
00626
00627
00628 if (!fURIText)
00629 ((XMLUri*)this)->buildFullText();
00630
00631 return fURIText;
00632 }
00633
00634
00635
00636
00637 inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
00638 {
00639 return (XMLString::isAlphaNum(theChar) ||
00640 XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
00641 }
00642
00643 inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
00644 {
00645 return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
00646 }
00647
00648 inline bool XMLUri::isPathCharacter(const XMLCh theChar)
00649 {
00650 return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
00651 }
00652
00653 inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
00654 {
00655 return (XMLString::isAlphaNum(theChar) ||
00656 XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
00657 }
00658
00659 XERCES_CPP_NAMESPACE_END
00660
00661 #endif