XMLUri.hpp
Go to the documentation of this file.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id$
*/
#if !defined(XERCESC_INCLUDE_GUARD_XMLURI_HPP)
#define XERCESC_INCLUDE_GUARD_XMLURI_HPP
#include <xercesc/util/XMemory.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/internal/XSerializable.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
XERCES_CPP_NAMESPACE_BEGIN
/*
* This class is a direct port of Java's URI class, to distinguish
* itself from the XMLURL, we use the name XMLUri instead of
* XMLURI.
*
* TODO: how to relate XMLUri and XMLURL since URL is part of URI.
*
*/
class XMLUTIL_EXPORT XMLUri : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
XMLUri(const XMLCh* const uriSpec,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XMLUri(const XMLUri* const baseURI
, const XMLCh* const uriSpec
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XMLUri(const XMLUri& toCopy);
XMLUri& operator=(const XMLUri& toAssign);
virtual ~XMLUri();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const XMLCh* getUriText() const;
const XMLCh* getScheme() const;
const XMLCh* getUserInfo() const;
const XMLCh* getHost() const;
int getPort() const;
const XMLCh* getRegBasedAuthority() const;
const XMLCh* getPath() const;
const XMLCh* getQueryString() const;
const XMLCh* getFragment() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setScheme(const XMLCh* const newScheme);
void setUserInfo(const XMLCh* const newUserInfo);
void setHost(const XMLCh* const newHost);
void setPort(int newPort);
void setRegBasedAuthority(const XMLCh* const newRegAuth);
void setPath(const XMLCh* const newPath);
void setQueryString(const XMLCh* const newQueryString);
void setFragment(const XMLCh* const newFragment);
// -----------------------------------------------------------------------
// Miscellaneous methods
// -----------------------------------------------------------------------
static bool isURIString(const XMLCh* const uric);
static bool isValidURI( const XMLUri* const baseURI
, const XMLCh* const uriStr
, bool bAllowSpaces=false);
static bool isValidURI( bool haveBaseURI
, const XMLCh* const uriStr
, bool bAllowSpaces=false);
static void normalizeURI(const XMLCh* const systemURI,
XMLBuffer& normalizedURI);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XMLUri)
XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private:
static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
static const XMLCh RESERVED_CHARACTERS[];
static const XMLCh MARK_CHARACTERS[];
static const XMLCh SCHEME_CHARACTERS[];
static const XMLCh USERINFO_CHARACTERS[];
static const XMLCh REG_NAME_CHARACTERS[];
static const XMLCh PATH_CHARACTERS[];
//helper method for getUriText
void buildFullText();
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
static bool isReservedCharacter(const XMLCh theChar);
static bool isPathCharacter(const XMLCh theChar);
static bool isUnreservedCharacter(const XMLCh theChar);
static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
static bool isConformantSchemeName(const XMLCh* const scheme);
static void isConformantUserInfo(const XMLCh* const userInfo
, MemoryManager* const manager);
static bool isValidServerBasedAuthority(const XMLCh* const host
, const XMLSize_t hostLen
, const int port
, const XMLCh* const userinfo
, const XMLSize_t userLen);
static bool isValidServerBasedAuthority(const XMLCh* const host
, const int port
, const XMLCh* const userinfo
, MemoryManager* const manager);
static bool isValidRegistryBasedAuthority(const XMLCh* const authority
, const XMLSize_t authLen);
static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
static bool isWellFormedAddress(const XMLCh* const addr
, MemoryManager* const manager);
static bool isWellFormedIPv4Address(const XMLCh* const addr, const XMLSize_t length);
static bool isWellFormedIPv6Reference(const XMLCh* const addr, const XMLSize_t length);
static int scanHexSequence (const XMLCh* const addr, XMLSize_t index, XMLSize_t end, int& counter);
bool isGenericURI();
// -----------------------------------------------------------------------
// Miscellaneous methods
// -----------------------------------------------------------------------
void initialize(const XMLUri& toCopy);
void initialize(const XMLUri* const baseURI
, const XMLCh* const uriSpec);
void initializeScheme(const XMLCh* const uriSpec);
void initializeAuthority(const XMLCh* const uriSpec);
void initializePath(const XMLCh* const uriSpec);
void cleanUp();
static bool isConformantSchemeName(const XMLCh* const scheme,
const XMLSize_t schemeLen);
static bool processScheme(const XMLCh* const uriStr, XMLSize_t& index);
static bool processAuthority(const XMLCh* const uriStr, const XMLSize_t authLen);
static bool isWellFormedAddress(const XMLCh* const addr, const XMLSize_t addrLen);
static bool processPath(const XMLCh* const pathStr, const XMLSize_t pathStrLen,
const bool isSchemePresent, const bool bAllowSpaces=false);
// -----------------------------------------------------------------------
// Data members
//
// for all the data member, we own it,
// responsible for the creation and/or deletion for
// the memory allocated.
//
// -----------------------------------------------------------------------
int fPort;
XMLCh* fScheme;
XMLCh* fUserInfo;
XMLCh* fHost;
XMLCh* fRegAuth;
XMLCh* fPath;
XMLCh* fQueryString;
XMLCh* fFragment;
XMLCh* fURIText;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// XMLUri: Getter methods
// ---------------------------------------------------------------------------
inline const XMLCh* XMLUri::getScheme() const
{
return fScheme;
}
inline const XMLCh* XMLUri::getUserInfo() const
{
return fUserInfo;
}
inline const XMLCh* XMLUri::getHost() const
{
return fHost;
}
inline int XMLUri::getPort() const
{
return fPort;
}
inline const XMLCh* XMLUri::getRegBasedAuthority() const
{
return fRegAuth;
}
inline const XMLCh* XMLUri::getPath() const
{
return fPath;
}
inline const XMLCh* XMLUri::getQueryString() const
{
return fQueryString;
}
inline const XMLCh* XMLUri::getFragment() const
{
return fFragment;
}
inline const XMLCh* XMLUri::getUriText() const
{
//
// Fault it in if not already. Since this is a const method and we
// can't use mutable members due the compilers we have to support,
// we have to cast off the constness.
//
if (!fURIText)
(const_cast<XMLUri *>(this))->buildFullText();
return fURIText;
}
// ---------------------------------------------------------------------------
// XMLUri: Helper methods
// ---------------------------------------------------------------------------
inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
{
return (XMLString::isAlphaNum(theChar) ||
XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
}
inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
{
return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
}
inline bool XMLUri::isPathCharacter(const XMLCh theChar)
{
return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
}
inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
{
return (XMLString::isAlphaNum(theChar) ||
XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
}
XERCES_CPP_NAMESPACE_END
#endif
XMLString.hpp
XMemory.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition XercesDefs.hpp:112
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition XercesDefs.hpp:113
XMLSize_t
size_t XMLSize_t
Definition Xerces_autoconf_config.hpp:112
XMLCh
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
MemoryManager
Configurable memory manager.
Definition MemoryManager.hpp:40
XMLPlatformUtils
Utilities that must be implemented in a platform-specific way.
Definition PlatformUtils.hpp:69
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
XMLString::isAlphaNum
static bool isAlphaNum(XMLCh const theChar)
Checks whether a character is within [0-9a-zA-Z].
XMLString::indexOf
static int indexOf(const char *const toSearch, const char ch)
Provides the index of the first occurrence of a character within a string.
XMLUri
Definition XMLUri.hpp:43
XMLUri::setFragment
void setFragment(const XMLCh *const newFragment)
Set the fragment for this URI.
XMLUri::getHost
const XMLCh * getHost() const
Get the host for this URI.
Definition XMLUri.hpp:593
XMLUri::normalizeURI
static void normalizeURI(const XMLCh *const systemURI, XMLBuffer &normalizedURI)
XMLUri::setUserInfo
void setUserInfo(const XMLCh *const newUserInfo)
Set the userinfo for this URI.
XMLUri::isValidURI
static bool isValidURI(bool haveBaseURI, const XMLCh *const uriStr, bool bAllowSpaces=false)
Determine whether a given string is a valid URI.
XMLUri::setPath
void setPath(const XMLCh *const newPath)
Set the path for this URI.
XMLUri::operator=
XMLUri & operator=(const XMLUri &toAssign)
XMLUri::XMLUri
XMLUri(const XMLUri *const baseURI, const XMLCh *const uriSpec, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Construct a new URI from a base URI and a URI specification string.
XMLUri::setRegBasedAuthority
void setRegBasedAuthority(const XMLCh *const newRegAuth)
Sets the registry based authority for this URI.
XMLUri::getUserInfo
const XMLCh * getUserInfo() const
Get the userinfo for this URI.
Definition XMLUri.hpp:588
XMLUri::getPort
int getPort() const
Get the port for this URI.
Definition XMLUri.hpp:598
XMLUri::getQueryString
const XMLCh * getQueryString() const
Get the query string for this URI.
Definition XMLUri.hpp:613
XMLUri::isValidURI
static bool isValidURI(const XMLUri *const baseURI, const XMLCh *const uriStr, bool bAllowSpaces=false)
Determine whether a given string is a valid URI.
XMLUri::setPort
void setPort(int newPort)
Set the port for this URI.
XMLUri::isURIString
static bool isURIString(const XMLCh *const uric)
Determine whether a given string contains only URI characters (also called "uric" in RFC 2396).
XMLUri::XMLUri
XMLUri(const XMLUri &toCopy)
Copy constructor.
XMLUri::~XMLUri
virtual ~XMLUri()
XMLUri::XMLUri
XMLUri(const XMLCh *const uriSpec, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Construct a new URI from a URI specification string.
XMLUri::setScheme
void setScheme(const XMLCh *const newScheme)
Set the scheme for this URI.
XMLUri::setQueryString
void setQueryString(const XMLCh *const newQueryString)
Set the query string for this URI.
XMLUri::getFragment
const XMLCh * getFragment() const
Get the fragment for this URI.
Definition XMLUri.hpp:618
XMLUri::getUriText
const XMLCh * getUriText() const
Get the URI as a string specification.
Definition XMLUri.hpp:623
XMLUri::getRegBasedAuthority
const XMLCh * getRegBasedAuthority() const
Get the registry based authority for this URI.
Definition XMLUri.hpp:603
XMLUri::getPath
const XMLCh * getPath() const
Get the path for this URI.
Definition XMLUri.hpp:608
XMLUri::setHost
void setHost(const XMLCh *const newHost)
Set the host for this URI.
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition XMemory.hpp:41