source: icXML/icXML-devel/src/xercesc/framework/Wrapper4DOMLSInput.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 5.5 KB
Line 
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: Wrapper4DOMLSInput.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/framework/Wrapper4DOMLSInput.hpp>
27#include <xercesc/dom/DOMLSInput.hpp>
28#include <xercesc/dom/DOMLSResourceResolver.hpp>
29#include <xercesc/util/NullPointerException.hpp>
30#include <icxercesc/util/XMLString.hpp>
31#include <xercesc/framework/MemBufInputSource.hpp>
32#include <xercesc/framework/LocalFileInputSource.hpp>
33#include <xercesc/framework/URLInputSource.hpp>
34
35XERCES_CPP_NAMESPACE_BEGIN
36
37// ---------------------------------------------------------------------------
38//  Wrapper4DOMLSInput: Constructor and Destructor
39// ---------------------------------------------------------------------------
40Wrapper4DOMLSInput::Wrapper4DOMLSInput(DOMLSInput* const inputSource,
41                                       DOMLSResourceResolver* entityResolver,
42                                       const bool adoptFlag,
43                                       MemoryManager* const  manager) :
44    InputSource(manager)
45    , fAdoptInputSource(adoptFlag)
46    , fForceXMLChEncoding(false)
47    , fInputSource(inputSource)
48    , fEntityResolver(entityResolver)
49{
50    if (!inputSource)
51        ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, getMemoryManager());
52}
53
54Wrapper4DOMLSInput::~Wrapper4DOMLSInput()
55{
56    if (fAdoptInputSource)
57        delete fInputSource;
58}
59
60
61// ---------------------------------------------------------------------------
62//  Wrapper4DOMLSInput: Getter methods
63// ---------------------------------------------------------------------------
64bool Wrapper4DOMLSInput::getIssueFatalErrorIfNotFound() const
65{
66    return fInputSource->getIssueFatalErrorIfNotFound();
67}
68
69const XMLCh* Wrapper4DOMLSInput::getEncoding() const
70{
71    if(fForceXMLChEncoding)
72        return XMLUni::fgXMLChEncodingString;
73    return fInputSource->getEncoding();
74}
75
76const XMLCh* Wrapper4DOMLSInput::getSystemId() const
77{
78    return fInputSource->getSystemId();
79}
80
81const XMLCh* Wrapper4DOMLSInput::getPublicId() const
82{
83    return fInputSource->getPublicId();
84}
85
86
87// ---------------------------------------------------------------------------
88//  Wrapper4DOMLSInput: Setter methods
89// ---------------------------------------------------------------------------
90void Wrapper4DOMLSInput::setIssueFatalErrorIfNotFound(const bool flag)
91{
92    fInputSource->setIssueFatalErrorIfNotFound(flag);
93}
94
95
96void Wrapper4DOMLSInput::setEncoding(const XMLCh* const encodingStr)
97{
98    fInputSource->setEncoding(encodingStr);
99}
100
101
102void Wrapper4DOMLSInput::setPublicId(const XMLCh* const publicId)
103{
104    fInputSource->setPublicId(publicId);
105}
106
107
108void Wrapper4DOMLSInput::setSystemId(const XMLCh* const systemId)
109{
110    fInputSource->setSystemId(systemId);
111}
112
113
114// ---------------------------------------------------------------------------
115//  Wrapper4DOMLSInput: Stream methods
116// ---------------------------------------------------------------------------
117BinInputStream* Wrapper4DOMLSInput::makeStream() const
118{
119    // The LSParser will use the LSInput object to determine how to read data. The LSParser will look at the different inputs specified in the
120    // LSInput in the following order to know which one to read from, the first one that is not null and not an empty string will be used:
121    //   1. LSInput.characterStream
122    //   2. LSInput.byteStream
123    //   3. LSInput.stringData
124    //   4. LSInput.systemId
125    //   5. LSInput.publicId
126    InputSource* binStream=fInputSource->getByteStream();
127    if(binStream)
128        return binStream->makeStream();
129    const XMLCh* xmlString=fInputSource->getStringData();
130    if(xmlString)
131    {
132        MemBufInputSource is((const XMLByte*)xmlString, XMLString::stringLen(xmlString)*sizeof(XMLCh), "", false, getMemoryManager());
133        is.setCopyBufToStream(false);
134        return is.makeStream();
135    }
136    const XMLCh* szSystemId=fInputSource->getSystemId();
137    if(szSystemId)
138    {
139        XMLURL urlTmp(getMemoryManager());
140        if (urlTmp.setURL(szSystemId, fInputSource->getBaseURI(), urlTmp) && !urlTmp.isRelative())
141        {
142            URLInputSource src(urlTmp, getMemoryManager());
143            return src.makeStream();
144        }         
145        LocalFileInputSource src(szSystemId, getMemoryManager());
146        return src.makeStream();
147    }
148    const XMLCh* szPublicId=fInputSource->getPublicId();
149    if(szPublicId && fEntityResolver)
150    {
151        DOMLSInput* is = fEntityResolver->resolveResource(XMLUni::fgDOMDTDType, 0, szPublicId, 0, fInputSource->getBaseURI());
152        if (is)
153            return Wrapper4DOMLSInput(is, fEntityResolver, true, getMemoryManager()).makeStream();
154    }
155
156    return 0;
157}
158
159XERCES_CPP_NAMESPACE_END
160
Note: See TracBrowser for help on using the repository browser.