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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 
31 #ifdef _MSC_VER
32 #pragma warning (disable : 4786 4503)
33 #endif
34 #include "document_statistic.hxx"
35 #include "internal/utilities.hxx"
36 #include "internal/metainforeader.hxx"
37 #include "internal/resource.h"
38 #include "internal/fileextensions.hxx"
39 #include "internal/config.hxx"
40 #include "internal/iso8601_converter.hxx"
41 
42 //#####################################
43 const bool READONLY  = false;
44 const bool WRITEABLE = true;
45 
46 //#####################################
47 document_statistic_reader_ptr create_document_statistic_reader(const std::string& document_name, CMetaInfoReader* meta_info_accessor)
48 {
49     File_Type_t file_type = get_file_type(document_name);
50 
51 	if (WRITER == file_type)
52 	    return document_statistic_reader_ptr(new writer_document_statistic_reader(document_name, meta_info_accessor));
53 	else if (CALC == file_type)
54 	    return document_statistic_reader_ptr(new calc_document_statistic_reader(document_name, meta_info_accessor));
55 	else
56 	    return document_statistic_reader_ptr(new draw_impress_math_document_statistic_reader(document_name, meta_info_accessor));
57 }
58 
59 
60 //#####################################
61 document_statistic_reader::document_statistic_reader(const std::string& document_name, CMetaInfoReader* meta_info_accessor) :
62     document_name_(document_name),
63     meta_info_accessor_(meta_info_accessor)
64 {}
65 
66 //#####################################
67 document_statistic_reader::~document_statistic_reader()
68 {}
69 
70 //#####################################
71 void document_statistic_reader::read(statistic_group_list_t* group_list)
72 {
73 	group_list->clear();
74     fill_description_section(meta_info_accessor_, group_list);
75     fill_origin_section(meta_info_accessor_, group_list);
76 }
77 
78 //#####################################
79 std::string document_statistic_reader::get_document_name() const
80 {
81     return document_name_;
82 }
83 
84 //#####################################
85 void document_statistic_reader::fill_origin_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list)
86 {
87     statistic_item_list_t il;
88 
89     il.push_back(statistic_item(GetResString(IDS_AUTHOR), meta_info_accessor->getTagData( META_INFO_AUTHOR ), READONLY));
90 
91     il.push_back(statistic_item(GetResString(IDS_MODIFIED),
92         iso8601_date_to_local_date(meta_info_accessor->getTagData(META_INFO_MODIFIED )), READONLY));
93 
94     il.push_back(statistic_item(GetResString(IDS_DOCUMENT_NUMBER), meta_info_accessor->getTagData( META_INFO_DOCUMENT_NUMBER ), READONLY));
95 
96     il.push_back(statistic_item(GetResString(IDS_EDITING_TIME),
97         iso8601_duration_to_local_duration(meta_info_accessor->getTagData( META_INFO_EDITING_TIME )), READONLY));
98 
99     group_list->push_back(statistic_group_t(GetResString(IDS_ORIGIN), il));
100 }
101 
102 //#####################################
103 writer_document_statistic_reader::writer_document_statistic_reader(const std::string& document_name, CMetaInfoReader* meta_info_accessor) :
104     document_statistic_reader(document_name, meta_info_accessor)
105 {}
106 
107 //#####################################
108 void writer_document_statistic_reader::fill_description_section(CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list)
109 {
110     statistic_item_list_t il;
111 
112     il.push_back(statistic_item(GetResString(IDS_TITLE),    meta_info_accessor->getTagData( META_INFO_TITLE ),       READONLY));
113     il.push_back(statistic_item(GetResString(IDS_COMMENTS), meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY));
114     il.push_back(statistic_item(GetResString(IDS_SUBJECT),  meta_info_accessor->getTagData( META_INFO_SUBJECT ),     READONLY));
115     il.push_back(statistic_item(GetResString(IDS_KEYWORDS), meta_info_accessor->getTagData(META_INFO_KEYWORDS ),    READONLY));
116     il.push_back(statistic_item(GetResString(IDS_PAGES),    meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PAGES) , READONLY));
117     il.push_back(statistic_item(GetResString(IDS_TABLES), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_TABLES) , READONLY));
118     il.push_back(statistic_item(GetResString(IDS_GRAPHICS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_DRAWS) , READONLY));
119     il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) ,    READONLY));
120     il.push_back(statistic_item(GetResString(IDS_PARAGRAPHS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PARAGRAPHS) , READONLY));
121     il.push_back(statistic_item(GetResString(IDS_WORDS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_WORDS) , READONLY));
122     il.push_back(statistic_item(GetResString(IDS_CHARACTERS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_CHARACTERS) , READONLY));
123 
124     group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il));
125 }
126 
127 //#######################################
128 calc_document_statistic_reader::calc_document_statistic_reader(
129     const std::string& document_name, CMetaInfoReader* meta_info_accessor) :
130     document_statistic_reader(document_name, meta_info_accessor)
131 {}
132 
133 //#######################################
134 void calc_document_statistic_reader::fill_description_section(
135     CMetaInfoReader *meta_info_accessor,statistic_group_list_t* group_list)
136 {
137     statistic_item_list_t il;
138 
139     il.push_back(statistic_item(GetResString(IDS_TITLE),       meta_info_accessor->getTagData( META_INFO_TITLE ),       READONLY));
140     il.push_back(statistic_item(GetResString(IDS_COMMENTS),    meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY));
141     il.push_back(statistic_item(GetResString(IDS_SUBJECT),     meta_info_accessor->getTagData( META_INFO_SUBJECT ),     READONLY));
142     il.push_back(statistic_item(GetResString(IDS_KEYWORDS),    meta_info_accessor->getTagData(META_INFO_KEYWORDS ),    READONLY));
143     il.push_back(statistic_item(GetResString(IDS_TABLES),      meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_TABLES) ,  READONLY));
144     il.push_back(statistic_item(GetResString(IDS_CELLS),       meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_CELLS) ,   READONLY));
145     il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) , READONLY));
146 
147     group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il));
148 }
149 
150 //#######################################
151 draw_impress_math_document_statistic_reader::draw_impress_math_document_statistic_reader(
152     const std::string& document_name, CMetaInfoReader* meta_info_accessor) :
153     document_statistic_reader(document_name, meta_info_accessor)
154 {}
155 
156 //#######################################
157 void draw_impress_math_document_statistic_reader::fill_description_section(
158     CMetaInfoReader *meta_info_accessor, statistic_group_list_t* group_list)
159 {
160     statistic_item_list_t il;
161 
162     il.push_back(statistic_item(GetResString(IDS_TITLE),       meta_info_accessor->getTagData( META_INFO_TITLE ),       READONLY));
163     il.push_back(statistic_item(GetResString(IDS_COMMENTS),    meta_info_accessor->getTagData( META_INFO_DESCRIPTION ), READONLY));
164     il.push_back(statistic_item(GetResString(IDS_SUBJECT),     meta_info_accessor->getTagData( META_INFO_SUBJECT ),     READONLY));
165     il.push_back(statistic_item(GetResString(IDS_KEYWORDS),    meta_info_accessor->getTagData(META_INFO_KEYWORDS ),    READONLY));
166     il.push_back(statistic_item(GetResString(IDS_PAGES),       meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_PAGES) ,   READONLY));
167     il.push_back(statistic_item(GetResString(IDS_OLE_OBJECTS), meta_info_accessor->getTagAttribute( META_INFO_DOCUMENT_STATISTIC,META_INFO_OBJECTS) , READONLY));
168 
169     group_list->push_back(statistic_group_t(GetResString(IDS_DESCRIPTION), il));
170 }
171