xref: /AOO41X/main/unotools/source/config/docinfohelper.cxx (revision b5088357f810cb81479bbbd0e021cd3c9835ca0d)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_unotools.hxx"
26 
27 #include <rtl/ustrbuf.hxx>
28 #include <tools/inetdef.hxx>
29 #include <unotools/configmgr.hxx>
30 #include <unotools/bootstrap.hxx>
31 #include <unotools/docinfohelper.hxx>
32 
33 using namespace ::com::sun::star;
34 
35 namespace utl
36 {
37 
GetGeneratorString()38 ::rtl::OUString DocInfoHelper::GetGeneratorString()
39 {
40     rtl::OUStringBuffer aResult;
41 
42     // First product: branded name + version
43     // version is <product_versions>_<product_extension>$<platform>
44     utl::ConfigManager* pMgr = utl::ConfigManager::GetConfigManager();
45     if ( pMgr )
46     {
47         // plain product name
48         rtl::OUString aValue;
49         uno::Any aAny = pMgr->GetDirectConfigProperty(
50                                             utl::ConfigManager::PRODUCTNAME);
51         if ( (aAny >>= aValue) && aValue.getLength() )
52         {
53             aResult.append( aValue.replace( ' ', '_' ) );
54             aResult.append( (sal_Unicode)'/' );
55 
56             aAny = pMgr->GetDirectConfigProperty(
57                                         utl::ConfigManager::PRODUCTVERSION);
58             if ( (aAny >>= aValue) && aValue.getLength() )
59             {
60                 aResult.append( aValue.replace( ' ', '_' ) );
61 
62                 aAny = pMgr->GetDirectConfigProperty(
63                                         utl::ConfigManager::PRODUCTEXTENSION);
64                 if ( (aAny >>= aValue) && aValue.getLength() )
65                 {
66                     aResult.append( (sal_Unicode)'_' );
67                     aResult.append( aValue.replace( ' ', '_' ) );
68                 }
69             }
70 
71             aResult.append( (sal_Unicode)'$' );
72             aResult.append( ::rtl::OUString::createFromAscii(
73                                     TOOLS_INETDEF_OS ).replace( ' ', '_' ) );
74 
75             aResult.append( (sal_Unicode)' ' );
76         }
77     }
78 
79     // second product: OpenOffice.org_project/<build_information>
80     // build_information has '(' and '[' encoded as '$', ')' and ']' ignored
81     // and ':' replaced by '-'
82     {
83         aResult.appendAscii( "OpenOffice.org_project/" );
84         ::rtl::OUString aDefault;
85         ::rtl::OUString aBuildId( Bootstrap::getBuildIdData( aDefault ) );
86         for( sal_Int32 i=0; i < aBuildId.getLength(); i++ )
87         {
88             sal_Unicode c = aBuildId[i];
89             switch( c )
90             {
91             case '(':
92             case '[':
93                 aResult.append( (sal_Unicode)'$' );
94                 break;
95             case ')':
96             case ']':
97                 break;
98             case ':':
99                 aResult.append( (sal_Unicode)'-' );
100                 break;
101             default:
102                 aResult.append( c );
103                 break;
104             }
105         }
106     }
107 
108     return aResult.makeStringAndClear();
109 }
110 
111 } // end of namespace utl
112 
113