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 #include "DOMConfigurationImpl.hpp" 00019 #include "DOMStringListImpl.hpp" 00020 #include <xercesc/dom/DOMErrorHandler.hpp> 00021 #include <xercesc/util/XMLString.hpp> 00022 #include <xercesc/util/XMLUniDefs.hpp> 00023 #include <xercesc/dom/DOMException.hpp> 00024 00025 XERCES_CPP_NAMESPACE_BEGIN 00026 00027 const unsigned short DOMConfigurationImpl::fDEFAULT_VALUES = 0x2596; 00028 00029 DOMConfigurationImpl::DOMConfigurationImpl(MemoryManager* const manager): featureValues(fDEFAULT_VALUES), 00030 fErrorHandler(0), fSchemaType(0), fSchemaLocation(0), 00031 fSupportedParameters(0), fMemoryManager(manager) 00032 { 00033 fSupportedParameters=new (fMemoryManager) DOMStringListImpl(17, fMemoryManager); 00034 fSupportedParameters->add(XMLUni::fgDOMErrorHandler); 00035 fSupportedParameters->add(XMLUni::fgDOMSchemaType); 00036 fSupportedParameters->add(XMLUni::fgDOMSchemaLocation); 00037 fSupportedParameters->add(XMLUni::fgDOMCanonicalForm); 00038 fSupportedParameters->add(XMLUni::fgDOMCDATASections); 00039 fSupportedParameters->add(XMLUni::fgDOMComments); 00040 fSupportedParameters->add(XMLUni::fgDOMDatatypeNormalization); 00041 fSupportedParameters->add(XMLUni::fgDOMWRTDiscardDefaultContent); 00042 fSupportedParameters->add(XMLUni::fgDOMEntities); 00043 fSupportedParameters->add(XMLUni::fgDOMInfoset); 00044 fSupportedParameters->add(XMLUni::fgDOMNamespaces); 00045 fSupportedParameters->add(XMLUni::fgDOMNamespaceDeclarations); 00046 fSupportedParameters->add(XMLUni::fgDOMNormalizeCharacters); 00047 fSupportedParameters->add(XMLUni::fgDOMSplitCDATASections); 00048 fSupportedParameters->add(XMLUni::fgDOMValidate); 00049 fSupportedParameters->add(XMLUni::fgDOMValidateIfSchema); 00050 fSupportedParameters->add(XMLUni::fgDOMElementContentWhitespace); 00051 } 00052 00053 DOMConfigurationImpl::~DOMConfigurationImpl() { 00054 delete fSupportedParameters; 00055 } 00056 00057 void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) { 00058 if(!canSetParameter(name, value)) { 00059 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager); 00060 } 00061 00062 if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) { 00063 fErrorHandler = (DOMErrorHandler*)value; 00064 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) { 00065 fSchemaType = (XMLCh*)value; 00066 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) { 00067 fSchemaLocation = (XMLCh*)value; 00068 } else { // canSetParameter above should take care of this case 00069 throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); 00070 } 00071 00072 } 00073 00074 void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) { 00075 if(!canSetParameter(name, value)) { 00076 throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager); 00077 } 00078 00079 DOMConfigurationFeature whichFlag = getFeatureFlag(name); 00080 if(value) { 00081 featureValues |= whichFlag; 00082 } else { 00083 featureValues &= ~whichFlag; 00084 } 00085 00086 } 00087 00088 // -------------------------------------- 00089 // Getter Methods 00090 // -------------------------------------- 00091 00092 const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const { 00093 DOMConfigurationFeature whichFlag; 00094 try { 00095 whichFlag = getFeatureFlag(name); 00096 if(featureValues & whichFlag) { 00097 return (void*)true; 00098 } else { 00099 return (void*)false; 00100 } 00101 } catch (DOMException&) { 00102 // must not be a boolean parameter 00103 if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) { 00104 return fErrorHandler; 00105 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) { 00106 return fSchemaType; 00107 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) { 00108 return fSchemaLocation; 00109 } else { 00110 throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); 00111 } 00112 } 00113 00114 } 00115 00116 // ----------------------------------------- 00117 // Query Methods 00118 // ----------------------------------------- 00119 00120 bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, const void* /*value*/) const { 00121 00130 if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) { 00131 return true; // required // 00132 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) { 00133 return false; // optional // 00134 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) { 00135 return false; // optional // 00136 } 00137 return false; 00138 } 00139 00140 bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, bool booleanValue) const { 00149 DOMConfigurationFeature whichFlag = getFeatureFlag(name); 00150 switch (whichFlag) { 00151 case FEATURE_CANONICAL_FORM: 00152 if(booleanValue) return false; // optional // 00153 else return true; // required // 00154 case FEATURE_CDATA_SECTIONS: 00155 return true; 00156 case FEATURE_COMMENTS: 00157 return true; 00158 case FEATURE_DATATYPE_NORMALIZATION: 00159 if(booleanValue) return false; // required // 00160 else return true; // required // 00161 case FEATURE_DISCARD_DEFAULT_CONTENT: 00162 if(booleanValue) return false; // required // 00163 else return true; // required // 00164 case FEATURE_ENTITIES: 00165 if(booleanValue) return true; // required // 00166 else return true; // required // 00167 case FEATURE_INFOSET: 00168 if(booleanValue) return false; // required // 00169 else return true; // no effect// 00170 case FEATURE_NAMESPACES: 00171 return true; 00172 case FEATURE_NAMESPACE_DECLARATIONS: 00173 if(booleanValue) return true; // optional // 00174 else return false; // required // 00175 case FEATURE_NORMALIZE_CHARACTERS: 00176 if(booleanValue) return false; // optional // 00177 else return true; // required // 00178 case FEATURE_SPLIT_CDATA_SECTIONS: 00179 //we dont report an error in the false case so we cant claim we do it 00180 if(booleanValue) return false; // required // 00181 else return false; // required // 00182 case FEATURE_VALIDATE: 00183 if(booleanValue) return false; // optional // 00184 else return true; // required // 00185 case FEATURE_VALIDATE_IF_SCHEMA: 00186 if(booleanValue) return false; // optional // 00187 else return true; // required // 00188 00189 case FEATURE_ELEMENT_CONTENT_WHITESPACE: 00190 if(booleanValue) return true; // required // 00191 else return false; // optional // 00192 } 00193 // should never be here 00194 return false; 00195 } 00196 00197 const DOMStringList* DOMConfigurationImpl::getParameterNames() const 00198 { 00199 return fSupportedParameters; 00200 } 00201 00202 // ------------------------------------------- 00203 // Impl methods 00204 // ------------------------------------------- 00205 00206 DOMConfigurationImpl::DOMConfigurationFeature DOMConfigurationImpl::getFeatureFlag(const XMLCh* name) const { 00207 if(XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm)==0) { 00208 return FEATURE_CANONICAL_FORM; 00209 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections )==0) { 00210 return FEATURE_CDATA_SECTIONS; 00211 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMComments)==0) { 00212 return FEATURE_COMMENTS; 00213 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization)==0) { 00214 return FEATURE_DATATYPE_NORMALIZATION; 00215 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMWRTDiscardDefaultContent)==0) { 00216 return FEATURE_DISCARD_DEFAULT_CONTENT; 00217 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities)==0) { 00218 return FEATURE_ENTITIES; 00219 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset)==0) { 00220 return FEATURE_INFOSET; 00221 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces)==0) { 00222 return FEATURE_NAMESPACES; 00223 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations)==0) { 00224 return FEATURE_NAMESPACE_DECLARATIONS; 00225 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters)==0) { 00226 return FEATURE_NORMALIZE_CHARACTERS; 00227 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections)==0) { 00228 return FEATURE_SPLIT_CDATA_SECTIONS; 00229 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate)==0) { 00230 return FEATURE_VALIDATE; 00231 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema)==0) { 00232 return FEATURE_VALIDATE_IF_SCHEMA; 00233 } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace)==0) { 00234 return FEATURE_ELEMENT_CONTENT_WHITESPACE; 00235 } else { 00236 throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); 00237 } 00238 00239 } 00240 00241 DOMErrorHandler* DOMConfigurationImpl::getErrorHandler() const { 00242 return fErrorHandler; 00243 } 00244 00245 const XMLCh* DOMConfigurationImpl::getSchemaType() const { 00246 return fSchemaType; 00247 } 00248 00249 const XMLCh* DOMConfigurationImpl::getSchemaLocation() const { 00250 return fSchemaLocation; 00251 } 00252 00253 void DOMConfigurationImpl::setErrorHandler(DOMErrorHandler *erHandler) { 00254 fErrorHandler = erHandler; 00255 } 00256 00257 void DOMConfigurationImpl::setSchemaType(const XMLCh* st) { 00258 fSchemaType = st; 00259 } 00260 00261 void DOMConfigurationImpl::setSchemaLocation(const XMLCh* sl) { 00262 fSchemaLocation = sl; 00263 } 00264 00265 00266 XERCES_CPP_NAMESPACE_END 00267 00268