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 #include <stack> 33 34 #include "com/sun/star/uno/Any.hxx" 35 #include "com/sun/star/uno/Reference.hxx" 36 #include "com/sun/star/uno/RuntimeException.hpp" 37 #include "com/sun/star/uno/XInterface.hpp" 38 #include "osl/diagnose.h" 39 #include "osl/file.hxx" 40 #include "rtl/ref.hxx" 41 #include "rtl/strbuf.hxx" 42 #include "rtl/string.h" 43 #include "rtl/ustrbuf.hxx" 44 #include "rtl/ustring.h" 45 #include "rtl/ustring.hxx" 46 #include "sal/types.h" 47 #include "xmlreader/span.hxx" 48 #include "xmlreader/xmlreader.hxx" 49 50 #include "data.hxx" 51 #include "groupnode.hxx" 52 #include "localizedpropertynode.hxx" 53 #include "localizedvaluenode.hxx" 54 #include "node.hxx" 55 #include "nodemap.hxx" 56 #include "parsemanager.hxx" 57 #include "parser.hxx" 58 #include "propertynode.hxx" 59 #include "setnode.hxx" 60 #include "type.hxx" 61 62 namespace configmgr { 63 64 namespace xmldata { 65 66 namespace { 67 68 namespace css = com::sun::star; 69 70 } 71 72 Type parseType( 73 xmlreader::XmlReader const & reader, xmlreader::Span const & text) 74 { 75 OSL_ASSERT(text.is()); 76 sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':'); 77 if (i >= 0) { 78 switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) { 79 case ParseManager::NAMESPACE_OOR: 80 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)). 81 equals(RTL_CONSTASCII_STRINGPARAM("any"))) 82 { 83 return TYPE_ANY; 84 } else if (xmlreader::Span( 85 text.begin + i + 1, text.length - (i + 1)). 86 equals(RTL_CONSTASCII_STRINGPARAM("boolean-list"))) 87 { 88 return TYPE_BOOLEAN_LIST; 89 } else if (xmlreader::Span( 90 text.begin + i + 1, text.length - (i + 1)). 91 equals(RTL_CONSTASCII_STRINGPARAM("short-list"))) 92 { 93 return TYPE_SHORT_LIST; 94 } else if (xmlreader::Span( 95 text.begin + i + 1, text.length - (i + 1)). 96 equals(RTL_CONSTASCII_STRINGPARAM("int-list"))) 97 { 98 return TYPE_INT_LIST; 99 } else if (xmlreader::Span( 100 text.begin + i + 1, text.length - (i + 1)). 101 equals(RTL_CONSTASCII_STRINGPARAM("long-list"))) 102 { 103 return TYPE_LONG_LIST; 104 } else if (xmlreader::Span( 105 text.begin + i + 1, text.length - (i + 1)). 106 equals(RTL_CONSTASCII_STRINGPARAM("double-list"))) 107 { 108 return TYPE_DOUBLE_LIST; 109 } else if (xmlreader::Span( 110 text.begin + i + 1, text.length - (i + 1)). 111 equals(RTL_CONSTASCII_STRINGPARAM("string-list"))) 112 { 113 return TYPE_STRING_LIST; 114 } else if (xmlreader::Span( 115 text.begin + i + 1, text.length - (i + 1)). 116 equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list"))) 117 { 118 return TYPE_HEXBINARY_LIST; 119 } 120 break; 121 case ParseManager::NAMESPACE_XS: 122 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)). 123 equals(RTL_CONSTASCII_STRINGPARAM("boolean"))) 124 { 125 return TYPE_BOOLEAN; 126 } else if (xmlreader::Span( 127 text.begin + i + 1, text.length - (i + 1)). 128 equals(RTL_CONSTASCII_STRINGPARAM("short"))) 129 { 130 return TYPE_SHORT; 131 } else if (xmlreader::Span( 132 text.begin + i + 1, text.length - (i + 1)). 133 equals(RTL_CONSTASCII_STRINGPARAM("int"))) 134 { 135 return TYPE_INT; 136 } else if (xmlreader::Span( 137 text.begin + i + 1, text.length - (i + 1)). 138 equals(RTL_CONSTASCII_STRINGPARAM("long"))) 139 { 140 return TYPE_LONG; 141 } else if (xmlreader::Span( 142 text.begin + i + 1, text.length - (i + 1)). 143 equals(RTL_CONSTASCII_STRINGPARAM("double"))) 144 { 145 return TYPE_DOUBLE; 146 } else if (xmlreader::Span( 147 text.begin + i + 1, text.length - (i + 1)). 148 equals(RTL_CONSTASCII_STRINGPARAM("string"))) 149 { 150 return TYPE_STRING; 151 } else if (xmlreader::Span( 152 text.begin + i + 1, text.length - (i + 1)). 153 equals(RTL_CONSTASCII_STRINGPARAM("hexBinary"))) 154 { 155 return TYPE_HEXBINARY; 156 } 157 break; 158 default: 159 break; 160 } 161 } 162 throw css::uno::RuntimeException( 163 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid type ")) + 164 text.convertFromUtf8()), 165 css::uno::Reference< css::uno::XInterface >()); 166 } 167 168 bool parseBoolean(xmlreader::Span const & text) { 169 OSL_ASSERT(text.is()); 170 if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) { 171 return true; 172 } 173 if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) { 174 return false; 175 } 176 throw css::uno::RuntimeException( 177 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid boolean ")) + 178 text.convertFromUtf8()), 179 css::uno::Reference< css::uno::XInterface >()); 180 } 181 182 rtl::OUString parseTemplateReference( 183 rtl::OUString const & component, bool hasNodeType, 184 rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName) 185 { 186 if (!hasNodeType) { 187 if (defaultTemplateName != 0) { 188 return *defaultTemplateName; 189 } 190 throw css::uno::RuntimeException( 191 rtl::OUString( 192 RTL_CONSTASCII_USTRINGPARAM("missing node-type attribute")), 193 css::uno::Reference< css::uno::XInterface >()); 194 } 195 return Data::fullTemplateName(component, nodeType); 196 } 197 198 } 199 200 } 201