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 <precomp.h>
29 #include "cmd_sincedata.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/file.hxx>
34 #include <cosv/tpl/tpltools.hxx>
35 #include "adc_cmds.hxx"
36 
37 
38 
39 namespace autodoc
40 {
41 namespace command
42 {
43 
44 SinceTagTransformationData::SinceTagTransformationData()
45     :   aTransformationTable()
46 {
47 }
48 
49 SinceTagTransformationData::~SinceTagTransformationData()
50 {
51 }
52 
53 bool
54 SinceTagTransformationData::DoesTransform() const
55 {
56     return NOT aTransformationTable.empty();
57 }
58 
59 const String &
60 SinceTagTransformationData::DisplayOf( const String & i_versionNumber ) const
61 {
62     if (DoesTransform())
63     {
64         StreamLock
65             sl(200);
66         sl() << i_versionNumber;
67         sl().strip_frontback_whitespace();
68         String
69             sVersionNumber(sl().c_str());
70 
71         const String *
72             ret = csv::find_in_map(aTransformationTable, sVersionNumber);
73         return ret != 0
74                 ?   *ret
75                 :   String::Null_();
76     }
77     else
78     {
79         return i_versionNumber;
80     }
81 }
82 
83 void
84 SinceTagTransformationData::do_Init( opt_iter &  it,
85 									 opt_iter    itEnd )
86 {
87     ++it;   // Cur is since-file path.
88 
89     CHECKOPT(   it != itEnd ,
90               "file path",
91               C_opt_SinceFile );
92 
93     csv::File           aSinceFile(*it);
94     csv::OpenCloseGuard aSinceFileGuard(aSinceFile);
95     StreamStr           sLine(200);
96 
97     if (aSinceFileGuard)
98     {
99         for ( sLine.operator_read_line(aSinceFile);
100               NOT sLine.empty();
101               sLine.operator_read_line(aSinceFile) )
102         {
103 
104             if (*sLine.begin() != '"')
105                 continue;
106 
107             const char * pVersion = sLine.c_str() + 1;
108             const char * pVersionEnd = strchr(pVersion, '"');
109             if (pVersionEnd == 0)
110                 continue;
111             const char * pDisplay = strchr(pVersionEnd+1, '"');
112             if (pDisplay == 0)
113                 continue;
114             ++pDisplay;
115             const char * pDisplayEnd = strchr(pDisplay, '"');
116             if (pDisplayEnd == 0)
117                 continue;
118 
119             aTransformationTable[ String(pVersion,pVersionEnd) ]
120                                         = String(pDisplay,pDisplayEnd);
121             sLine.clear();
122         }   // end for
123     }   // end if
124 
125     ++it;   // Cur is next option.
126 }
127 
128 }   // namespace command
129 }   // namespace autodoc
130