configmgr/source/access.cxx                          |    9 ++
 configmgr/source/access.hxx                          |    2 
 configmgr/source/node.hxx                            |    8 +-
 configmgr/source/xcsparser.cxx                       |    4 -
 configmgr/source/xcsparser.hxx                       |    2 
 cui/source/options/optaboutconfig.cxx                |   66 ++++++++++---------
 offapi/com/sun/star/configuration/XDocumentation.idl |    8 +-
 7 files changed, 58 insertions(+), 41 deletions(-)

New commits:
commit a91892ec4942fc875820ea02dfbe74e986548142
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Nov 16 13:56:06 2023 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Nov 20 11:17:23 2023 +0100

    Use existing types, instead of strings
    
    as suggested in 
https://gerrit.libreoffice.org/c/core/+/158028/comments/b7a803f4_7e5899ca
    
    Change-Id: I7d4c46b24307922b51e463bacdfacfca85956b80
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159524
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx
index 6ef23a40597b..c802f62494f0 100644
--- a/configmgr/source/access.cxx
+++ b/configmgr/source/access.cxx
@@ -66,6 +66,7 @@
 #include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/uno/XWeak.hpp>
 #include <com/sun/star/util/ElementChange.hpp>
+#include <com/sun/star/util/InvalidStateException.hpp>
 #include <comphelper/sequence.hxx>
 #include <comphelper/servicehelper.hxx>
 #include <comphelper/string.hxx>
@@ -455,7 +456,7 @@ OUString Access::getDescriptionByHierarchicalName(OUString 
const & aName)
     return child->getNode()->getDescription();
 }
 
-OUString Access::getTypeByHierarchicalName(OUString const & aName)
+css::uno::Type Access::getTypeByHierarchicalName(OUString const & aName)
 {
     assert(thisIs(IS_ANY));
     osl::MutexGuard g(*lock_);
@@ -465,7 +466,11 @@ OUString Access::getTypeByHierarchicalName(OUString const 
& aName)
         throw css::container::NoSuchElementException(
             aName, getXWeak());
     }
-    return child->getNode()->getType();
+    auto type = child->getNode()->getType();
+    if (type == TYPE_ERROR)
+        throw css::util::InvalidStateException(
+            aName, getXWeak());
+    return mapType(child->getNode()->getType());
 }
 
 sal_Bool Access::hasByHierarchicalName(OUString const & aName)
diff --git a/configmgr/source/access.hxx b/configmgr/source/access.hxx
index 19276e6aca06..a94d20a6bce6 100644
--- a/configmgr/source/access.hxx
+++ b/configmgr/source/access.hxx
@@ -165,7 +165,7 @@ public:
     virtual OUString SAL_CALL getDescriptionByHierarchicalName(
         OUString const & aName) override;
 
-    virtual OUString SAL_CALL getTypeByHierarchicalName(
+    virtual css::uno::Type SAL_CALL getTypeByHierarchicalName(
         OUString const & aName) override;
 
     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) 
override;
diff --git a/configmgr/source/node.hxx b/configmgr/source/node.hxx
index 7961d090a4c0..68664e870e35 100644
--- a/configmgr/source/node.hxx
+++ b/configmgr/source/node.hxx
@@ -27,6 +27,8 @@
 #include <salhelper/simplereferenceobject.hxx>
 #include <xmlreader/span.hxx>
 
+#include "type.hxx"
+
 namespace configmgr {
 
 class NodeMap;
@@ -56,8 +58,8 @@ public:
     void setDescription(OUString const& description) { description_ = 
description; };
     OUString getDescription() { return description_; }
 
-    void setType(OUString const& type) { type_ = type; };
-    OUString getType() { return type_; }
+    void setType(Type const& type) { type_ = type; };
+    Type getType() { return type_; }
 
     rtl::Reference< Node > getMember(OUString const & name);
 
@@ -70,7 +72,7 @@ private:
     int layer_;
     int finalized_;
     OUString description_;
-    OUString type_;
+    Type type_ = TYPE_ERROR;
 };
 
 }
diff --git a/configmgr/source/xcsparser.cxx b/configmgr/source/xcsparser.cxx
index 020cdeaabd82..2acf4125e186 100644
--- a/configmgr/source/xcsparser.cxx
+++ b/configmgr/source/xcsparser.cxx
@@ -313,7 +313,7 @@ void XcsParser::endElement(xmlreader::XmlReader const & 
reader) {
             while (desc.indexOf("  ") != -1)
                 desc = desc.replaceAll("  ", " ");
             top.node->setDescription(desc);
-            top.node->setType(typeName_);
+            top.node->setType(type_);
             if (elements_.empty()) {
                 switch (state_) {
                 case STATE_TEMPLATES:
@@ -489,9 +489,9 @@ void XcsParser::handleProp(xmlreader::XmlReader & reader) {
         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
                    attrLn == "type")
         {
-            typeName_ = reader.getAttributeValue(true).convertFromUtf8();
             valueParser_.type_ = xmldata::parseType(
                 reader, reader.getAttributeValue(true));
+            type_ = valueParser_.type_;
         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
                    attrLn == "localized")
         {
diff --git a/configmgr/source/xcsparser.hxx b/configmgr/source/xcsparser.hxx
index 7d0e6ca44a0a..6e8ff7d2367d 100644
--- a/configmgr/source/xcsparser.hxx
+++ b/configmgr/source/xcsparser.hxx
@@ -96,7 +96,7 @@ private:
     ElementStack elements_;
     bool bIsParsingInfo_;
     OUStringBuffer description_;
-    OUString typeName_;
+    Type type_;
 };
 
 }
diff --git a/cui/source/options/optaboutconfig.cxx 
b/cui/source/options/optaboutconfig.cxx
index bb002d55d0d1..68fa56ccd5ac 100644
--- a/cui/source/options/optaboutconfig.cxx
+++ b/cui/source/options/optaboutconfig.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/uno/Reference.hxx>
 #include <com/sun/star/uno/Type.hxx>
 #include <com/sun/star/uno/TypeClass.hpp>
+#include <com/sun/star/util/InvalidStateException.hpp>
 #include <com/sun/star/util/SearchAlgorithms2.hpp>
 #include <com/sun/star/util/SearchFlags.hpp>
 #include <com/sun/star/util/XChangesBatch.hpp>
@@ -332,6 +333,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
 
             OUString sTooltip;
             OUString sType;
+            css::uno::Type aType = cppu::UnoType<void>::get();
             OUString sDynamicType = aNode.getValueTypeName();
             try
             {
@@ -339,45 +341,48 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                                                                         
UNO_QUERY_THROW);
                 sTooltip
                     = xDocumentation->getDescriptionByHierarchicalName(sPath + 
"/" + sPropertyName);
-                sType = xDocumentation->getTypeByHierarchicalName(sFullPath);
+                aType = xDocumentation->getTypeByHierarchicalName(sFullPath);
             }
             catch (css::container::NoSuchElementException)
             {
             }
+            catch (css::util::InvalidStateException)
+            {
+            }
 
             OUStringBuffer sValue;
 
             // Fall back to dynamic type when this is empty
-            if (sType.isEmpty())
+            if (aType == cppu::UnoType<void>::get())
             {
                 if (sDynamicType == "boolean")
-                    sType = "xs:boolean";
+                    aType = cppu::UnoType<sal_Bool>::get();
                 else if (sDynamicType == "short")
-                    sType = "xs:short";
+                    aType = cppu::UnoType<sal_Int16>::get();
                 else if (sDynamicType == "long")
-                    sType = "xs:int";
+                    aType = cppu::UnoType<sal_Int32>::get();
                 else if (sDynamicType == "hyper")
-                    sType = "xs:long";
+                    aType = cppu::UnoType<sal_Int64>::get();
                 else if (sDynamicType == "double")
-                    sType = "xs:double";
+                    aType = cppu::UnoType<double>::get();
                 else if (sDynamicType == "string")
-                    sType = "xs:string";
+                    aType = cppu::UnoType<OUString>::get();
                 else if (sDynamicType == "[]byte")
-                    sType = "xs:hexBinary";
+                    aType = cppu::UnoType<css::uno::Sequence<sal_Int8>>::get();
                 else if (sDynamicType == "[]boolean")
-                    sType = "oor:boolean-list";
+                    aType = cppu::UnoType<css::uno::Sequence<sal_Bool>>::get();
                 else if (sDynamicType == "[]short")
-                    sType = "oor:short-list";
+                    aType = 
cppu::UnoType<css::uno::Sequence<sal_Int16>>::get();
                 else if (sDynamicType == "[]long")
-                    sType = "oor:int-list";
+                    aType = 
cppu::UnoType<css::uno::Sequence<sal_Int32>>::get();
                 else if (sDynamicType == "[]hyper")
-                    sType = "oor:long-list";
+                    aType = 
cppu::UnoType<css::uno::Sequence<sal_Int64>>::get();
                 else if (sDynamicType == "[]double")
-                    sType = "oor:double-list";
+                    aType = cppu::UnoType<css::uno::Sequence<double>>::get();
                 else if (sDynamicType == "[]string")
-                    sType = "oor:string-list";
+                    aType = cppu::UnoType<css::uno::Sequence<OUString>>::get();
                 else if (sDynamicType == "[][]byte")
-                    sType = "oor:hexBinary-list";
+                    aType = 
cppu::UnoType<css::uno::Sequence<css::uno::Sequence<sal_Int8>>>::get();
             }
 
             if (it != m_modifiedPrefBoxEntries.end())
@@ -388,37 +393,37 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                 {
                     // Skip, no value set
                 }
-                else if (sType == "xs:boolean")
+                else if (aType == cppu::UnoType<sal_Bool>::get())
                 {
                     sValue = OUString::boolean(aNode.get<bool>());
                     sType = "boolean";
                 }
-                else if (sType == "xs:short")
+                else if (aType == cppu::UnoType<sal_Int16>::get())
                 {
                     sValue = OUString::number(aNode.get<sal_Int16>());
                     sType = "short";
                 }
-                else if (sType == "xs:int")
+                else if (aType == cppu::UnoType<sal_Int32>::get())
                 {
                     sValue = OUString::number(aNode.get<sal_Int32>());
                     sType = "int";
                 }
-                else if (sType == "xs:long")
+                else if (aType == cppu::UnoType<sal_Int64>::get())
                 {
                     sValue = OUString::number(aNode.get<sal_Int64>());
                     sType = "long";
                 }
-                else if (sType == "xs:double")
+                else if (aType == cppu::UnoType<double>::get())
                 {
                     sValue = OUString::number(aNode.get<double>());
                     sType = "double";
                 }
-                else if (sType == "xs:string")
+                else if (aType == cppu::UnoType<OUString>::get())
                 {
                     sValue = aNode.get<OUString>();
                     sType = "string";
                 }
-                else if (sType == "xs:hexBinary")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<sal_Int8>>::get())
                 {
                     const uno::Sequence<sal_Int8> seq = 
aNode.get<uno::Sequence<sal_Int8>>();
                     for (sal_Int8 j : seq)
@@ -432,7 +437,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "hexBinary";
                 }
-                else if (sType == "oor:boolean-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<sal_Bool>>::get())
                 {
                     uno::Sequence<sal_Bool> seq = 
aNode.get<uno::Sequence<sal_Bool>>();
                     for (sal_Int32 j = 0; j != seq.getLength(); ++j)
@@ -445,7 +450,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "boolean-list";
                 }
-                else if (sType == "oor:short-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<sal_Int16>>::get())
                 {
                     uno::Sequence<sal_Int16> seq = 
aNode.get<uno::Sequence<sal_Int16>>();
                     for (sal_Int32 j = 0; j != seq.getLength(); ++j)
@@ -458,7 +463,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "short-list";
                 }
-                else if (sType == "oor:int-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<sal_Int32>>::get())
                 {
                     uno::Sequence<sal_Int32> seq = 
aNode.get<uno::Sequence<sal_Int32>>();
                     for (sal_Int32 j = 0; j != seq.getLength(); ++j)
@@ -471,7 +476,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "int-list";
                 }
-                else if (sType == "oor:long-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<sal_Int64>>::get())
                 {
                     uno::Sequence<sal_Int64> seq = 
aNode.get<uno::Sequence<sal_Int64>>();
                     for (sal_Int32 j = 0; j != seq.getLength(); ++j)
@@ -484,7 +489,7 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "long-list";
                 }
-                else if (sType == "oor:double-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<double>>::get())
                 {
                     uno::Sequence<double> seq = 
aNode.get<uno::Sequence<double>>();
                     for (sal_Int32 j = 0; j != seq.getLength(); ++j)
@@ -497,12 +502,13 @@ void CuiAboutConfigTabPage::FillItems(const 
Reference<XNameAccess>& xNameAccess,
                     }
                     sType = "double-list";
                 }
-                else if (sType == "oor:string-list")
+                else if (aType == 
cppu::UnoType<css::uno::Sequence<OUString>>::get())
                 {
                     sValue = 
lcl_StringListToString(aNode.get<uno::Sequence<OUString>>());
                     sType = "string-list";
                 }
-                else if (sType == "oor:hexBinary-list")
+                else if (aType
+                         == 
cppu::UnoType<css::uno::Sequence<css::uno::Sequence<sal_Int8>>>::get())
                 {
                     const uno::Sequence<uno::Sequence<sal_Int8>> seq
                         = aNode.get<uno::Sequence<uno::Sequence<sal_Int8>>>();
diff --git a/offapi/com/sun/star/configuration/XDocumentation.idl 
b/offapi/com/sun/star/configuration/XDocumentation.idl
index 2ed430a72854..f44a107c4508 100644
--- a/offapi/com/sun/star/configuration/XDocumentation.idl
+++ b/offapi/com/sun/star/configuration/XDocumentation.idl
@@ -36,9 +36,13 @@ interface XDocumentation {
 
         @throws NoSuchElementException
             if an element under aName does not exist.
+
+        @throws InvalidStateException
+            when the type of the object could not be resolved.
      */
-    string getTypeByHierarchicalName( [in] string aName )
-            raises( com::sun::star::container::NoSuchElementException );
+    type getTypeByHierarchicalName( [in] string aName )
+            raises( com::sun::star::container::NoSuchElementException,
+                    com::sun::star::util::InvalidStateException );
 };
 
 }; }; }; };

Reply via email to