LibreOffice Module configmgr (master)  1
xmldata.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <cassert>
23 
24 #include <com/sun/star/uno/RuntimeException.hpp>
25 #include <rtl/string.h>
26 #include <rtl/ustring.hxx>
27 #include <sal/types.h>
28 #include <xmlreader/span.hxx>
29 #include <xmlreader/xmlreader.hxx>
30 
31 #include "data.hxx"
32 #include "parsemanager.hxx"
33 #include "type.hxx"
34 #include "xmldata.hxx"
35 
36 namespace configmgr::xmldata {
37 
39  xmlreader::XmlReader const & reader, xmlreader::Span const & text)
40 {
41  assert(text.is());
42  sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
43  if (i >= 0) {
44  xmlreader::Span token(text.begin + i + 1, text.length - (i + 1));
45  switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
47  if (token == "any")
48  {
49  return TYPE_ANY;
50  } else if (token == "boolean-list")
51  {
52  return TYPE_BOOLEAN_LIST;
53  } else if (token == "short-list")
54  {
55  return TYPE_SHORT_LIST;
56  } else if (token == "int-list")
57  {
58  return TYPE_INT_LIST;
59  } else if (token == "long-list")
60  {
61  return TYPE_LONG_LIST;
62  } else if (token == "double-list")
63  {
64  return TYPE_DOUBLE_LIST;
65  } else if (token == "string-list")
66  {
67  return TYPE_STRING_LIST;
68  } else if (token == "hexBinary-list")
69  {
70  return TYPE_HEXBINARY_LIST;
71  }
72  break;
74  if (token == "boolean")
75  {
76  return TYPE_BOOLEAN;
77  } else if (token =="short")
78  {
79  return TYPE_SHORT;
80  } else if (token =="int")
81  {
82  return TYPE_INT;
83  } else if (token =="long")
84  {
85  return TYPE_LONG;
86  } else if (token =="double")
87  {
88  return TYPE_DOUBLE;
89  } else if (token =="string")
90  {
91  return TYPE_STRING;
92  } else if (token =="hexBinary")
93  {
94  return TYPE_HEXBINARY;
95  }
96  break;
97  default:
98  break;
99  }
100  }
101  throw css::uno::RuntimeException(
102  "invalid type " + text.convertFromUtf8());
103 }
104 
105 bool parseBoolean(xmlreader::Span const & text) {
106  assert(text.is());
107  if (text == "true") {
108  return true;
109  }
110  if (text == "false") {
111  return false;
112  }
113  throw css::uno::RuntimeException(
114  "invalid boolean " + text.convertFromUtf8());
115 }
116 
118  OUString const & component, bool hasNodeType,
119  OUString const & nodeType, OUString const * defaultTemplateName)
120 {
121  if (!hasNodeType) {
122  if (defaultTemplateName != nullptr) {
123  return *defaultTemplateName;
124  }
125  throw css::uno::RuntimeException(
126  "missing node-type attribute");
127  }
128  return Data::fullTemplateName(component, nodeType);
129 }
130 
131 }
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString parseTemplateReference(OUString const &component, bool hasNodeType, OUString const &nodeType, OUString const *defaultTemplateName)
Definition: xmldata.cxx:117
char const * begin
bool parseBoolean(xmlreader::Span const &text)
Definition: xmldata.cxx:105
bool is() const
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static OUString fullTemplateName(OUString const &component, OUString const &name)
Definition: data.cxx:150
int i
Type parseType(xmlreader::XmlReader const &reader, xmlreader::Span const &text)
Definition: xmldata.cxx:38
int getNamespaceId(Span const &prefix) const
sal_Int32 length
rtl::OUString convertFromUtf8() const