1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_configmgr.hxx" 29 #include "sal/config.h" 30 31 #include <climits> 32 33 #include "com/sun/star/uno/Reference.hxx" 34 #include "com/sun/star/uno/RuntimeException.hpp" 35 #include "com/sun/star/uno/XInterface.hpp" 36 #include "osl/diagnose.hxx" 37 #include "rtl/string.h" 38 #include "rtl/ustring.h" 39 #include "rtl/ustring.hxx" 40 #include "xmlreader/span.hxx" 41 #include "xmlreader/xmlreader.hxx" 42 43 #include "parsemanager.hxx" 44 #include "xcdparser.hxx" 45 #include "xcsparser.hxx" 46 #include "xcuparser.hxx" 47 #include "xmldata.hxx" 48 49 namespace configmgr { 50 51 namespace { 52 53 namespace css = com::sun::star; 54 55 } 56 57 XcdParser::XcdParser(int layer, Dependencies const & dependencies, Data & data): 58 layer_(layer), dependencies_(dependencies), data_(data), state_(STATE_START) 59 {} 60 61 XcdParser::~XcdParser() {} 62 63 xmlreader::XmlReader::Text XcdParser::getTextMode() { 64 return nestedParser_.is() 65 ? nestedParser_->getTextMode() : xmlreader::XmlReader::TEXT_NONE; 66 } 67 68 bool XcdParser::startElement( 69 xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name) 70 { 71 if (nestedParser_.is()) { 72 OSL_ASSERT(nesting_ != LONG_MAX); 73 ++nesting_; 74 return nestedParser_->startElement(reader, nsId, name); 75 } 76 switch (state_) { 77 case STATE_START: 78 if (nsId == ParseManager::NAMESPACE_OOR && 79 name.equals(RTL_CONSTASCII_STRINGPARAM("data"))) 80 { 81 state_ = STATE_DEPENDENCIES; 82 return true; 83 } 84 break; 85 case STATE_DEPENDENCIES: 86 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE && 87 name.equals(RTL_CONSTASCII_STRINGPARAM("dependency"))) 88 { 89 if (dependency_.getLength() == 0) { 90 xmlreader::Span attrFile; 91 for (;;) { 92 int attrNsId; 93 xmlreader::Span attrLn; 94 if (!reader.nextAttribute(&attrNsId, &attrLn)) { 95 break; 96 } 97 if (attrNsId == xmlreader::XmlReader::NAMESPACE_NONE && 98 //TODO: _OOR 99 attrLn.equals(RTL_CONSTASCII_STRINGPARAM("file"))) 100 { 101 attrFile = reader.getAttributeValue(false); 102 } 103 } 104 if (!attrFile.is()) { 105 throw css::uno::RuntimeException( 106 (rtl::OUString( 107 RTL_CONSTASCII_USTRINGPARAM( 108 "no dependency file attribute in ")) + 109 reader.getUrl()), 110 css::uno::Reference< css::uno::XInterface >()); 111 } 112 dependency_ = attrFile.convertFromUtf8(); 113 if (dependency_.getLength() == 0) { 114 throw css::uno::RuntimeException( 115 (rtl::OUString( 116 RTL_CONSTASCII_USTRINGPARAM( 117 "bad dependency file attribute in ")) + 118 reader.getUrl()), 119 css::uno::Reference< css::uno::XInterface >()); 120 } 121 } 122 if (dependencies_.find(dependency_) == dependencies_.end()) { 123 return false; 124 } 125 state_ = STATE_DEPENDENCY; 126 dependency_ = rtl::OUString(); 127 return true; 128 } 129 state_ = STATE_COMPONENTS; 130 // fall through 131 case STATE_COMPONENTS: 132 if (nsId == ParseManager::NAMESPACE_OOR && 133 name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema"))) 134 { 135 nestedParser_ = new XcsParser(layer_, data_); 136 nesting_ = 1; 137 return nestedParser_->startElement(reader, nsId, name); 138 } 139 if (nsId == ParseManager::NAMESPACE_OOR && 140 name.equals(RTL_CONSTASCII_STRINGPARAM("component-data"))) 141 { 142 nestedParser_ = new XcuParser(layer_ + 1, data_, 0, 0, 0); 143 nesting_ = 1; 144 return nestedParser_->startElement(reader, nsId, name); 145 } 146 break; 147 default: // STATE_DEPENDENCY 148 OSL_ASSERT(false); // this cannot happen 149 break; 150 } 151 throw css::uno::RuntimeException( 152 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad member <")) + 153 name.convertFromUtf8() + 154 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("> in ")) + reader.getUrl()), 155 css::uno::Reference< css::uno::XInterface >()); 156 } 157 158 void XcdParser::endElement(xmlreader::XmlReader const & reader) { 159 if (nestedParser_.is()) { 160 nestedParser_->endElement(reader); 161 if (--nesting_ == 0) { 162 nestedParser_.clear(); 163 } 164 } else { 165 switch (state_) { 166 case STATE_DEPENDENCY: 167 state_ = STATE_DEPENDENCIES; 168 break; 169 case STATE_DEPENDENCIES: 170 case STATE_COMPONENTS: 171 break; 172 default: 173 OSL_ASSERT(false); // this cannot happen 174 break; 175 } 176 } 177 } 178 179 void XcdParser::characters(xmlreader::Span const & text) { 180 if (nestedParser_.is()) { 181 nestedParser_->characters(text); 182 } 183 } 184 185 } 186