1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include "unotools/unotoolsdllapi.h" 24 25 #ifndef UNOTOOLS_CONFIGPATHES_HXX_INCLUDED 26 #define UNOTOOLS_CONFIGPATHES_HXX_INCLUDED 27 #include <sal/types.h> 28 29 namespace rtl 30 { 31 class OUString; 32 } 33 34 //---------------------------------------------------------------------------- 35 namespace utl 36 { 37 //---------------------------------------------------------------------------- 38 /** extract the local nodename and the parent nodepath 39 from a configuration path. 40 41 @param _sInPath 42 A configuration path that is not an empty or root path.<BR/> 43 If this is not a valid configuration path, it is interpreted as 44 local name of a node. 45 46 @param _rsOutPath 47 On exit: The configuration path obtained by dropping 48 the last level off <var>_sInPath</var>.<BR/> 49 If <var>_sInPath</var> could not be parsed as a valid 50 configuration path, this is set to an empty string. 51 52 @param _rsLocalName 53 On exit: The plain (non-escaped) name of the node identified by 54 <var>_sInPath</var>. <BR/> 55 If <var>_sInPath</var> could not be parsed as a valid 56 configuration path, this is set to <var>_sInPath</var>. 57 58 @returns 59 <TRUE/>, if a parent path could be set 60 <FALSE/>, if the path was a one-level path or an invalid path 61 62 */ 63 UNOTOOLS_DLLPUBLIC sal_Bool splitLastFromConfigurationPath(::rtl::OUString const& _sInPath, 64 ::rtl::OUString& _rsOutPath, 65 ::rtl::OUString& _rsLocalName); 66 67 //---------------------------------------------------------------------------- 68 /** extract the first nodename from a configuration path. 69 70 @param _sInPath 71 A relative configuration path that is not empty.<BR/> 72 If this is not a valid configuration path, it is interpreted as 73 a single name of a node. 74 75 @param _sOutPath 76 If non-null, contains the remainder of the path upon return. 77 78 @returns 79 The plain (non-escaped) name of the node that is the first step 80 when traversing <var>_sInPath</var>.<BR/> 81 If <var>_sInPath</var> could not be parsed as a valid 82 configuration path, it is returned unaltered. 83 84 */ 85 UNOTOOLS_DLLPUBLIC ::rtl::OUString extractFirstFromConfigurationPath( 86 ::rtl::OUString const& _sInPath, ::rtl::OUString* _sOutPath = 0); 87 88 //---------------------------------------------------------------------------- 89 /** check whether a path is to a nested node with respect to a parent path. 90 91 @param _sNestedPath 92 A configuration path that maybe points to a descendant of the node 93 identified by <var>_sPrefixPath</var>, with both pathes starting 94 from the same node (or both being absolute). 95 96 @param _sPrefixPath 97 A configuration path.<BR/> 98 If this path is absolute, <var>_sNestedPath</var> should be absolute; 99 If this path is relative, <var>_sNestedPath</var> should be relative; 100 If this path is empty, <var>_sNestedPath</var> may start with a '/', 101 which is disregarded. 102 103 @returns 104 <TRUE/>, if <var>_sPrefixPath</var> is a prefix of <var>_sNestedPath</var>; 105 <FALSE/> otherwise.<BR/> 106 If both pathes are equal <TRUE/> is returned. 107 108 */ 109 sal_Bool isPrefixOfConfigurationPath(::rtl::OUString const& _sNestedPath, 110 ::rtl::OUString const& _sPrefixPath); 111 112 //---------------------------------------------------------------------------- 113 /** get the relative path to a nested node with respect to a parent path. 114 115 @param _sNestedPath 116 A configuration path that points to a descendant of the node 117 identified by <var>_sPrefixPath</var>, with both pathes starting 118 from the same node (or both being absolute). 119 120 @param _sPrefixPath 121 A configuration path.<BR/> 122 If this path is absolute, <var>_sNestedPath</var> must be absolute; 123 If this path is relative, <var>_sNestedPath</var> must be relative; 124 If this path is empty, <var>_sNestedPath</var> may start with a '/', 125 which is stripped. 126 127 @returns 128 The remaining relative path from the target of <var>_sPrefixPath</var> 129 to the target of <var>_sNestedPath</var>.<BR/> 130 If <var>_sPrefixPath</var> is not a prefix of <var>_sNestedPath</var>, 131 <var>_sNestedPath</var> is returned unaltered. 132 133 */ 134 UNOTOOLS_DLLPUBLIC ::rtl::OUString dropPrefixFromConfigurationPath(::rtl::OUString const& _sNestedPath, 135 ::rtl::OUString const& _sPrefixPath); 136 137 //---------------------------------------------------------------------------- 138 /** Create a one-level relative configuration path from a set element name 139 without a known set element type. 140 141 @param _sElementName 142 An arbitrary string that is to be interpreted as 143 name of a configuration set element. 144 145 @returns 146 A one-level relative path to the element, of the form 147 "*['<Name>']", where <Name> is properly escaped. 148 149 */ 150 UNOTOOLS_DLLPUBLIC ::rtl::OUString wrapConfigurationElementName(::rtl::OUString const& _sElementName); 151 152 //---------------------------------------------------------------------------- 153 /** Create a one-level relative configuration path from a set element name 154 and a known set element type. 155 156 @param _sElementName 157 An arbitrary string that is to be interpreted as 158 name of a configuration set element. 159 160 @param _sTypeName 161 An string identifying the type of the element. Usually this is be 162 the name of the element-template of the set.<BR/> 163 164 @returns 165 A one-level relative path to the element, of the form 166 "<Type>['<Name>']", where <Name> is properly escaped. 167 168 */ 169 ::rtl::OUString wrapConfigurationElementName(::rtl::OUString const& _sElementName, 170 ::rtl::OUString const& _sTypeName); 171 172 //---------------------------------------------------------------------------- 173 } // namespace utl 174 //---------------------------------------------------------------------------- 175 176 #endif // UNOTOOLS_CONFIGPATHES_HXX_INCLUDED 177 178