GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: Wrapper4DOMLSInput.cpp 471747 2006-11-06 14:31:56Z amassari $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/framework/Wrapper4DOMLSInput.hpp> 00027 #include <xercesc/dom/DOMLSInput.hpp> 00028 #include <xercesc/dom/DOMLSResourceResolver.hpp> 00029 #include <xercesc/util/NullPointerException.hpp> 00030 #include <xercesc/util/XMLString.hpp> 00031 #include <xercesc/framework/MemBufInputSource.hpp> 00032 #include <xercesc/framework/LocalFileInputSource.hpp> 00033 #include <xercesc/framework/URLInputSource.hpp> 00034 00035 XERCES_CPP_NAMESPACE_BEGIN 00036 00037 // --------------------------------------------------------------------------- 00038 // Wrapper4DOMLSInput: Constructor and Destructor 00039 // --------------------------------------------------------------------------- 00040 Wrapper4DOMLSInput::Wrapper4DOMLSInput(DOMLSInput* const inputSource, 00041 DOMLSResourceResolver* entityResolver, 00042 const bool adoptFlag, 00043 MemoryManager* const manager) : 00044 InputSource(manager) 00045 , fAdoptInputSource(adoptFlag) 00046 , fForceXMLChEncoding(false) 00047 , fInputSource(inputSource) 00048 , fEntityResolver(entityResolver) 00049 { 00050 if (!inputSource) 00051 ThrowXMLwithMemMgr(NullPointerException, XMLExcepts::CPtr_PointerIsZero, getMemoryManager()); 00052 } 00053 00054 Wrapper4DOMLSInput::~Wrapper4DOMLSInput() 00055 { 00056 if (fAdoptInputSource) 00057 delete fInputSource; 00058 } 00059 00060 00061 // --------------------------------------------------------------------------- 00062 // Wrapper4DOMLSInput: Getter methods 00063 // --------------------------------------------------------------------------- 00064 bool Wrapper4DOMLSInput::getIssueFatalErrorIfNotFound() const 00065 { 00066 return fInputSource->getIssueFatalErrorIfNotFound(); 00067 } 00068 00069 const XMLCh* Wrapper4DOMLSInput::getEncoding() const 00070 { 00071 if(fForceXMLChEncoding) 00072 return XMLUni::fgXMLChEncodingString; 00073 return fInputSource->getEncoding(); 00074 } 00075 00076 const XMLCh* Wrapper4DOMLSInput::getSystemId() const 00077 { 00078 return fInputSource->getSystemId(); 00079 } 00080 00081 const XMLCh* Wrapper4DOMLSInput::getPublicId() const 00082 { 00083 return fInputSource->getPublicId(); 00084 } 00085 00086 00087 // --------------------------------------------------------------------------- 00088 // Wrapper4DOMLSInput: Setter methods 00089 // --------------------------------------------------------------------------- 00090 void Wrapper4DOMLSInput::setIssueFatalErrorIfNotFound(const bool flag) 00091 { 00092 fInputSource->setIssueFatalErrorIfNotFound(flag); 00093 } 00094 00095 00096 void Wrapper4DOMLSInput::setEncoding(const XMLCh* const encodingStr) 00097 { 00098 fInputSource->setEncoding(encodingStr); 00099 } 00100 00101 00102 void Wrapper4DOMLSInput::setPublicId(const XMLCh* const publicId) 00103 { 00104 fInputSource->setPublicId(publicId); 00105 } 00106 00107 00108 void Wrapper4DOMLSInput::setSystemId(const XMLCh* const systemId) 00109 { 00110 fInputSource->setSystemId(systemId); 00111 } 00112 00113 00114 // --------------------------------------------------------------------------- 00115 // Wrapper4DOMLSInput: Stream methods 00116 // --------------------------------------------------------------------------- 00117 BinInputStream* Wrapper4DOMLSInput::makeStream() const 00118 { 00119 // The LSParser will use the LSInput object to determine how to read data. The LSParser will look at the different inputs specified in the 00120 // 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: 00121 // 1. LSInput.characterStream 00122 // 2. LSInput.byteStream 00123 // 3. LSInput.stringData 00124 // 4. LSInput.systemId 00125 // 5. LSInput.publicId 00126 InputSource* binStream=fInputSource->getByteStream(); 00127 if(binStream) 00128 return binStream->makeStream(); 00129 const XMLCh* xmlString=fInputSource->getStringData(); 00130 if(xmlString) 00131 { 00132 MemBufInputSource is((const XMLByte*)xmlString, XMLString::stringLen(xmlString)*sizeof(XMLCh), "", false, getMemoryManager()); 00133 is.setCopyBufToStream(false); 00134 return is.makeStream(); 00135 } 00136 const XMLCh* szSystemId=fInputSource->getSystemId(); 00137 if(szSystemId) 00138 { 00139 XMLURL urlTmp(getMemoryManager()); 00140 if (urlTmp.setURL(szSystemId, fInputSource->getBaseURI(), urlTmp) && !urlTmp.isRelative()) 00141 { 00142 URLInputSource src(urlTmp, getMemoryManager()); 00143 return src.makeStream(); 00144 } 00145 LocalFileInputSource src(szSystemId, getMemoryManager()); 00146 return src.makeStream(); 00147 } 00148 const XMLCh* szPublicId=fInputSource->getPublicId(); 00149 if(szPublicId && fEntityResolver) 00150 { 00151 DOMLSInput* is = fEntityResolver->resolveResource(XMLUni::fgDOMDTDType, 0, szPublicId, 0, fInputSource->getBaseURI()); 00152 if (is) 00153 return Wrapper4DOMLSInput(is, fEntityResolver, true, getMemoryManager()).makeStream(); 00154 } 00155 00156 return 0; 00157 } 00158 00159 XERCES_CPP_NAMESPACE_END 00160