Xerces-C++ 3.1.3

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

XMLUri.hpp
Go to the documentation of this file.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * $Id: XMLUri.hpp 557254 2007-07-18 13:28:54Z amassari $
20 */
21
22 #if !defined(XERCESC_INCLUDE_GUARD_XMLURI_HPP)
23 #define XERCESC_INCLUDE_GUARD_XMLURI_HPP
24
25 #include <xercesc/util/XMemory.hpp>
26 #include <xercesc/util/XMLString.hpp>
27
28 #include <xercesc/internal/XSerializable.hpp>
29 #include <xercesc/framework/XMLBuffer.hpp>
30
31 XERCES_CPP_NAMESPACE_BEGIN
32
33 /*
34 * This class is a direct port of Java's URI class, to distinguish
35 * itself from the XMLURL, we use the name XMLUri instead of
36 * XMLURI.
37 *
38 * TODO: how to relate XMLUri and XMLURL since URL is part of URI.
39 *
40 */
41
42 class XMLUTIL_EXPORT XMLUri : public XSerializable, public XMemory
43 {
44 public:
45
46 // -----------------------------------------------------------------------
47 // Constructors and Destructor
48 // -----------------------------------------------------------------------
49
78 XMLUri(const XMLCh* const uriSpec,
79 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
80
97 XMLUri(const XMLUri* const baseURI
98 , const XMLCh* const uriSpec
99 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
100
104 XMLUri(const XMLUri& toCopy);
105 XMLUri& operator=(const XMLUri& toAssign);
106
107 virtual ~XMLUri();
108
109 // -----------------------------------------------------------------------
110 // Getter methods
111 // -----------------------------------------------------------------------
117 const XMLCh* getUriText() const;
118
124 const XMLCh* getScheme() const;
125
131 const XMLCh* getUserInfo() const;
132
133
139 const XMLCh* getHost() const;
140
146 int getPort() const;
147
153 const XMLCh* getRegBasedAuthority() const;
154
161 const XMLCh* getPath() const;
162
170 const XMLCh* getQueryString() const;
171
179 const XMLCh* getFragment() const;
180
181 // -----------------------------------------------------------------------
182 // Setter methods
183 // -----------------------------------------------------------------------
184
192 void setScheme(const XMLCh* const newScheme);
193
201 void setUserInfo(const XMLCh* const newUserInfo);
202
213 void setHost(const XMLCh* const newHost);
214
224 void setPort(int newPort);
225
234 void setRegBasedAuthority(const XMLCh* const newRegAuth);
235
256 void setPath(const XMLCh* const newPath);
257
266 void setQueryString(const XMLCh* const newQueryString);
267
276 void setFragment(const XMLCh* const newFragment);
277
278 // -----------------------------------------------------------------------
279 // Miscellaneous methods
280 // -----------------------------------------------------------------------
281
289 static bool isURIString(const XMLCh* const uric);
290
294 static bool isValidURI( const XMLUri* const baseURI
295 , const XMLCh* const uriStr
296 , bool bAllowSpaces=false);
300 static bool isValidURI( bool haveBaseURI
301 , const XMLCh* const uriStr
302 , bool bAllowSpaces=false);
303
304
305 static void normalizeURI(const XMLCh* const systemURI,
306 XMLBuffer& normalizedURI);
307
308 /***
309 * Support for Serialization/De-serialization
310 ***/
311 DECL_XSERIALIZABLE(XMLUri)
312
313 XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
314
315 private:
316
317 static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
318 static const XMLCh RESERVED_CHARACTERS[];
319 static const XMLCh MARK_CHARACTERS[];
320 static const XMLCh SCHEME_CHARACTERS[];
321 static const XMLCh USERINFO_CHARACTERS[];
322 static const XMLCh REG_NAME_CHARACTERS[];
323 static const XMLCh PATH_CHARACTERS[];
324
325 //helper method for getUriText
326 void buildFullText();
327
328 // -----------------------------------------------------------------------
329 // Private helper methods
330 // -----------------------------------------------------------------------
331
337 static bool isReservedCharacter(const XMLCh theChar);
338
344 static bool isPathCharacter(const XMLCh theChar);
345
351 static bool isUnreservedCharacter(const XMLCh theChar);
352
358 static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
359
367 static bool isConformantSchemeName(const XMLCh* const scheme);
368
374 static void isConformantUserInfo(const XMLCh* const userInfo
375 , MemoryManager* const manager);
376
384 static bool isValidServerBasedAuthority(const XMLCh* const host
385 , const XMLSize_t hostLen
386 , const int port
387 , const XMLCh* const userinfo
388 , const XMLSize_t userLen);
389
397 static bool isValidServerBasedAuthority(const XMLCh* const host
398 , const int port
399 , const XMLCh* const userinfo
400 , MemoryManager* const manager);
401
409 static bool isValidRegistryBasedAuthority(const XMLCh* const authority
410 , const XMLSize_t authLen);
411
419 static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
420
438 static bool isWellFormedAddress(const XMLCh* const addr
439 , MemoryManager* const manager);
440
450 static bool isWellFormedIPv4Address(const XMLCh* const addr, const XMLSize_t length);
451
465 static bool isWellFormedIPv6Reference(const XMLCh* const addr, const XMLSize_t length);
466
482 static int scanHexSequence (const XMLCh* const addr, XMLSize_t index, XMLSize_t end, int& counter);
483
491 bool isGenericURI();
492
493 // -----------------------------------------------------------------------
494 // Miscellaneous methods
495 // -----------------------------------------------------------------------
496
502 void initialize(const XMLUri& toCopy);
503
518 void initialize(const XMLUri* const baseURI
519 , const XMLCh* const uriSpec);
520
527 void initializeScheme(const XMLCh* const uriSpec);
528
536 void initializeAuthority(const XMLCh* const uriSpec);
537
544 void initializePath(const XMLCh* const uriSpec);
545
550 void cleanUp();
551
552 static bool isConformantSchemeName(const XMLCh* const scheme,
553 const XMLSize_t schemeLen);
554 static bool processScheme(const XMLCh* const uriStr, XMLSize_t& index);
555 static bool processAuthority(const XMLCh* const uriStr, const XMLSize_t authLen);
556 static bool isWellFormedAddress(const XMLCh* const addr, const XMLSize_t addrLen);
557 static bool processPath(const XMLCh* const pathStr, const XMLSize_t pathStrLen,
558 const bool isSchemePresent, const bool bAllowSpaces=false);
559
560 // -----------------------------------------------------------------------
561 // Data members
562 //
563 // for all the data member, we own it,
564 // responsible for the creation and/or deletion for
565 // the memory allocated.
566 //
567 // -----------------------------------------------------------------------
568 int fPort;
569 XMLCh* fScheme;
570 XMLCh* fUserInfo;
571 XMLCh* fHost;
572 XMLCh* fRegAuth;
573 XMLCh* fPath;
574 XMLCh* fQueryString;
575 XMLCh* fFragment;
576 XMLCh* fURIText;
577 MemoryManager* fMemoryManager;
578 };
579
580 // ---------------------------------------------------------------------------
581 // XMLUri: Getter methods
582 // ---------------------------------------------------------------------------
583 inline const XMLCh* XMLUri::getScheme() const
584 {
585 return fScheme;
586 }
587
588 inline const XMLCh* XMLUri::getUserInfo() const
589 {
590 return fUserInfo;
591 }
592
593 inline const XMLCh* XMLUri::getHost() const
594 {
595 return fHost;
596 }
597
598 inline int XMLUri::getPort() const
599 {
600 return fPort;
601 }
602
603 inline const XMLCh* XMLUri::getRegBasedAuthority() const
604 {
605 return fRegAuth;
606 }
607
608 inline const XMLCh* XMLUri::getPath() const
609 {
610 return fPath;
611 }
612
613 inline const XMLCh* XMLUri::getQueryString() const
614 {
615 return fQueryString;
616 }
617
618 inline const XMLCh* XMLUri::getFragment() const
619 {
620 return fFragment;
621 }
622
623 inline const XMLCh* XMLUri::getUriText() const
624 {
625 //
626 // Fault it in if not already. Since this is a const method and we
627 // can't use mutable members due the compilers we have to support,
628 // we have to cast off the constness.
629 //
630 if (!fURIText)
631 ((XMLUri*)this)->buildFullText();
632
633 return fURIText;
634 }
635
636 // ---------------------------------------------------------------------------
637 // XMLUri: Helper methods
638 // ---------------------------------------------------------------------------
639 inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
640 {
641 return (XMLString::isAlphaNum(theChar) ||
642 XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
643 }
644
645 inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
646 {
647 return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
648 }
649
650 inline bool XMLUri::isPathCharacter(const XMLCh theChar)
651 {
652 return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
653 }
654
655 inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
656 {
657 return (XMLString::isAlphaNum(theChar) ||
658 XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
659 }
660
661 XERCES_CPP_NAMESPACE_END
662
663 #endif