XMLURL.hpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:10k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Id: XMLURL.hpp,v 1.9 2003/05/18 14:02:05 knoaman Exp $
  58.  */
  59. #if !defined(XMLURL_HPP)
  60. #define XMLURL_HPP
  61. #include <xercesc/util/PlatformUtils.hpp>
  62. XERCES_CPP_NAMESPACE_BEGIN
  63. class BinInputStream;
  64. //
  65. //  This class supports file, http, and ftp style URLs. All others are
  66. //  rejected
  67. //
  68. class XMLUTIL_EXPORT XMLURL : public XMemory
  69. {
  70. public:
  71.     // -----------------------------------------------------------------------
  72.     //  Class types
  73.     //
  74.     //  And they must remain in this order because they are indexes into an
  75.     //  array internally!
  76.     // -----------------------------------------------------------------------
  77.     enum Protocols
  78.     {
  79.         File
  80.         , HTTP
  81.         , FTP
  82.         , Protocols_Count
  83.         , Unknown
  84.     };
  85.     // -----------------------------------------------------------------------
  86.     //  Public static methods
  87.     // -----------------------------------------------------------------------
  88.     static Protocols lookupByName(const XMLCh* const protoName);
  89.     // -----------------------------------------------------------------------
  90.     //  Constructors and Destructor
  91.     // -----------------------------------------------------------------------
  92.     XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
  93.     XMLURL
  94.     (
  95.         const   XMLCh* const    baseURL
  96.         , const XMLCh* const    relativeURL
  97.         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
  98.     );
  99.     XMLURL
  100.     (
  101.         const   XMLCh* const    baseURL
  102.         , const char* const     relativeURL
  103.         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
  104.     );
  105.     XMLURL
  106.     (
  107.         const   XMLURL&         baseURL
  108.         , const XMLCh* const    relativeURL
  109.     );
  110.     XMLURL
  111.     (
  112.         const   XMLURL&         baseURL
  113.         , const char* const     relativeURL
  114.     );
  115.     XMLURL
  116.     (
  117.         const   XMLCh* const    urlText
  118.         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
  119.     );
  120.     XMLURL
  121.     (
  122.         const   char* const     urlText
  123.         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
  124.     );
  125.     XMLURL(const XMLURL& toCopy);
  126.     virtual ~XMLURL();
  127.     // -----------------------------------------------------------------------
  128.     //  Operators
  129.     // -----------------------------------------------------------------------
  130.     XMLURL& operator=(const XMLURL& toAssign);
  131.     bool operator==(const XMLURL& toCompare) const;
  132.     bool operator!=(const XMLURL& toCompare) const;
  133.     // -----------------------------------------------------------------------
  134.     //  Getter methods
  135.     // -----------------------------------------------------------------------
  136.     const XMLCh* getFragment() const;
  137.     const XMLCh* getHost() const;
  138.     const XMLCh* getPassword() const;
  139.     const XMLCh* getPath() const;
  140.     unsigned int getPortNum() const;
  141.     Protocols getProtocol() const;
  142.     const XMLCh* getProtocolName() const;
  143.     const XMLCh* getQuery() const;
  144.     const XMLCh* getURLText() const;
  145.     const XMLCh* getUser() const;
  146.     MemoryManager* getMemoryManager() const;
  147.     // -----------------------------------------------------------------------
  148.     //  Setter methods
  149.     // -----------------------------------------------------------------------
  150.     void setURL(const XMLCh* const urlText);
  151.     void setURL
  152.     (
  153.         const   XMLCh* const    baseURL
  154.         , const XMLCh* const    relativeURL
  155.     );
  156.     void setURL
  157.     (
  158.         const   XMLURL&         baseURL
  159.         , const XMLCh* const    relativeURL
  160.     );
  161.     // -----------------------------------------------------------------------
  162.     //  Miscellaneous methods
  163.     // -----------------------------------------------------------------------
  164.     bool isRelative() const;
  165.     bool hasInvalidChar() const;
  166.     BinInputStream* makeNewStream() const;
  167.     void makeRelativeTo(const XMLCh* const baseURLText);
  168.     void makeRelativeTo(const XMLURL& baseURL);
  169. private:
  170.     // -----------------------------------------------------------------------
  171.     //  Private helper methods
  172.     // -----------------------------------------------------------------------
  173.     void buildFullText();
  174.     void cleanup();
  175.     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
  176.     void parse
  177.     (
  178.         const   XMLCh* const    urlText
  179.     );
  180.     // -----------------------------------------------------------------------
  181.     //  Data members
  182.     //
  183.     //  fFragment
  184.     //      The fragment part of the URL, if any. If none, its a null.
  185.     //
  186.     //  fHost
  187.     //      The host part of the URL that was parsed out. This one will often
  188.     //      be null (or "localhost", which also means the current machine.)
  189.     //
  190.     //  fPassword
  191.     //      The password found, if any. If none then its a null.
  192.     //
  193.     //  fPath
  194.     //      The path part of the URL that was parsed out, if any. If none,
  195.     //      then its a null.
  196.     //
  197.     //  fPortNum
  198.     //      The port that was indicated in the URL. If no port was provided
  199.     //      explicitly, then its left zero.
  200.     //
  201.     //  fProtocol
  202.     //      Indicates the type of the URL's source. The text of the prefix
  203.     //      can be gotten from this.
  204.     //
  205.     //  fQuery
  206.     //      The query part of the URL, if any. If none, then its a null.
  207.     //
  208.     //  fUser
  209.     //      The username found, if any. If none, then its a null.
  210.     //
  211.     //  fURLText
  212.     //      This is a copy of the URL text, after it has been taken apart,
  213.     //      made relative if needed, canonicalized, and then put back
  214.     //      together. Its only created upon demand.
  215.     //
  216.     //  fHasInvalidChar
  217.     //      This indicates if the URL Text contains invalid characters as per
  218.     //      RFC 2396 standard.
  219.     // -----------------------------------------------------------------------
  220.     MemoryManager*  fMemoryManager;
  221.     XMLCh*          fFragment;
  222.     XMLCh*          fHost;
  223.     XMLCh*          fPassword;
  224.     XMLCh*          fPath;
  225.     unsigned int    fPortNum;
  226.     Protocols       fProtocol;
  227.     XMLCh*          fQuery;
  228.     XMLCh*          fUser;
  229.     XMLCh*          fURLText;
  230.     bool            fHasInvalidChar;
  231. };
  232. // ---------------------------------------------------------------------------
  233. //  XMLURL: Public operators
  234. // ---------------------------------------------------------------------------
  235. inline bool XMLURL::operator!=(const XMLURL& toCompare) const
  236. {
  237.     return !operator==(toCompare);
  238. }
  239. // ---------------------------------------------------------------------------
  240. //  XMLURL: Getter methods
  241. // ---------------------------------------------------------------------------
  242. inline const XMLCh* XMLURL::getFragment() const
  243. {
  244.     return fFragment;
  245. }
  246. inline const XMLCh* XMLURL::getHost() const
  247. {
  248.     return fHost;
  249. }
  250. inline const XMLCh* XMLURL::getPassword() const
  251. {
  252.     return fPassword;
  253. }
  254. inline const XMLCh* XMLURL::getPath() const
  255. {
  256.     return fPath;
  257. }
  258. inline XMLURL::Protocols XMLURL::getProtocol() const
  259. {
  260.     return fProtocol;
  261. }
  262. inline const XMLCh* XMLURL::getQuery() const
  263. {
  264.     return fQuery;
  265. }
  266. inline const XMLCh* XMLURL::getUser() const
  267. {
  268.     return fUser;
  269. }
  270. inline const XMLCh* XMLURL::getURLText() const
  271. {
  272.     //
  273.     //  Fault it in if not already. Since this is a const method and we
  274.     //  can't use mutable members due the compilers we have to support,
  275.     //  we have to cast off the constness.
  276.     //
  277.     if (!fURLText)
  278.         ((XMLURL*)this)->buildFullText();
  279.     return fURLText;
  280. }
  281. inline MemoryManager* XMLURL::getMemoryManager() const
  282. {
  283.     return fMemoryManager;
  284. }
  285. MakeXMLException(MalformedURLException, XMLUTIL_EXPORT)
  286. XERCES_CPP_NAMESPACE_END
  287. #endif