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