]> git.donarmstrong.com Git - flightcrew.git/blob - src/FlightCrew/ErrorMessages.cpp
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / FlightCrew / ErrorMessages.cpp
1 /************************************************************************
2 **
3 **  Copyright (C) 2010  Strahinja Markovic
4 **
5 **  This file is part of FlightCrew.
6 **
7 **  FlightCrew is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU Lesser General Public License as published
9 **  by the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  FlightCrew is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU Lesser General Public License for more details.
16 **
17 **  You should have received a copy of the GNU Lesser General Public License
18 **  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.
19 **
20 *************************************************************************/
21
22 #include <stdafx.h>
23 #include "ErrorMessages.h"
24
25 namespace FlightCrew
26 {
27
28 static const std::string NO_MESSAGE_PLACEHOLDER = 
29     "No message available. "
30     "Please report this on the FlightCrew issue tracker.";
31
32 boost::mutex ErrorMessages::s_AccessMutex;
33 ErrorMessages* ErrorMessages::s_Instance = NULL;
34
35 ErrorMessages& ErrorMessages::Instance()
36 {
37     // We use a static local variable
38     // to hold our singleton instance; using a pointer member
39     // variable creates problems with object destruction;
40
41     boost::lock_guard< boost::mutex > locker( s_AccessMutex );
42
43     if ( !s_Instance )
44     {
45         static ErrorMessages messages;
46         s_Instance = &messages;
47     }
48
49     return *s_Instance;
50 }
51
52
53 const std::string ErrorMessages::MessageForId( ResultId error_id )
54 {
55     if ( m_Messages.count( error_id ) )
56
57         return m_Messages[ error_id ];
58
59     return NO_MESSAGE_PLACEHOLDER;
60 }
61
62
63 ErrorMessages::ErrorMessages()
64 {
65     LoadMessages();
66 }
67
68
69 void ErrorMessages::LoadMessages()
70 {
71     // It would be great if these could be read from an external file,
72     // but we don't want a runtime dependency. So we hard-code them.
73     // This would be bad for translations, but since we can't translate the
74     // error messages coming from the schema checkers, we won't be translating
75     // these either. So it's not a problem.
76
77     m_Messages[ ALL_OK ] =
78         "All OK.";
79     m_Messages[ ERROR_GENERIC ] =
80         "Error.";
81     m_Messages[ ERROR_SCHEMA_NOT_SATISFIED ] =
82         "The corresponding schema constraints were not satisfied.";
83
84     m_Messages[ ERROR_EPUB_NOT_VALID_ZIP_ARCHIVE ] =
85         "The epub file is not a valid ZIP archive.";
86     m_Messages[ ERROR_EPUB_NO_CONTAINER_XML ] =
87         "The META-INF/container.xml file was not found.";  
88
89     m_Messages[ ERROR_OCF_CONTAINER_DOESNT_LIST_OPF ] =
90         "An OPF file is not listed as a <rootfile>.";
91     m_Messages[ ERROR_OCF_CONTAINER_SPECIFIED_OPF_DOESNT_EXIST ] =
92         "The specified OPF file \"%1%\" does not exist.";
93     m_Messages[ ERROR_EPUB_MIMETYPE_BYTES_INVALID ] =
94         "Bytes 30-60 of your epub file are invalid. This means that one or more of the following "
95         "rules are not satisfied:\n"
96         "   1. There needs to be a \"mimetype\" file in the root folder.\n"
97         "   2. Its content needs to be *exactly* the ASCII string \"application/epub+zip\".\n"
98         "   3. It needs to be the first file in the epub zip archive.\n"
99         "   4. It needs to be uncompressed.";
100
101     m_Messages[ ERROR_XML_NOT_WELL_FORMED ] =
102         "XML syntax error.";
103     m_Messages[ ERROR_XML_ELEMENT_NOT_PRESENT ] =
104         "The <%1%> element is missing.";
105     m_Messages[ ERROR_XML_WRONG_ELEMENT_COUNT ] =
106         "There needs to be one and only one <%1%> element.";
107     m_Messages[ ERROR_XML_CHILD_NOT_RECOGNIZED ] =
108         "The <%1%> element is not an allowed child of the <%2%> element.";
109     m_Messages[ ERROR_XML_ATTRIBUTE_NOT_RECOGNIZED ] =
110         "The \"%1%\" attribute is not an allowed attribute of the <%2%> element.";  
111     m_Messages[ ERROR_XML_REQUIRED_ATTRIBUTE_MISSING ] =
112         "The required attribute \"%1%\" is missing from the <%2%> element.";
113     m_Messages[ ERROR_XML_ID_NOT_UNIQUE ] =
114         "An element with ID value \"%1%\" already exists in the document.";
115     m_Messages[ ERROR_XML_BAD_ID_VALUE ] =
116         "An ID value of \"%1%\" is not a valid value for an ID.";
117     m_Messages[ ERROR_XML_SPECIFIES_NEITHER_UTF8_NOR_UTF16 ] =
118         "The file declares the use of the \"%1%\" encoding, but only UTF-8 and UTF-16 are allowed."; 
119     m_Messages[ ERROR_XML_BYTESTREAM_NEITHER_UTF8_NOR_UTF16 ] =
120         "The file declares the use of UTF-8 or UTF-16, but the bytestream of the file's contents "
121         "does not match either encoding.";   
122
123     m_Messages[ ERROR_OPF_PACKAGE_NOT_ROOT ] =
124         "The <package> element is not the root element.";
125     m_Messages[ ERROR_OPF_IDREF_ID_DOES_NOT_EXIST ] =
126         "The <itemref> element's \"idref\" attribute is pointing to an <item> with id=\"%1%\" which "
127         "does not exist in the <manifest>.";
128     m_Messages[ ERROR_OPF_IDREF_NOT_UNIQUE ] =
129         "The <itemref> element's \"idref\" attribute has value \"%1%\", but that value is already "
130         "in use in a previous <itemref>.";    
131     m_Messages[ ERROR_OPF_BAD_SPINE_TOC_VALUE ] =
132         "The <spine> element's \"toc\" attribute is pointing to an <item> with id=\"%1%\" which "
133         "does not exist in the <manifest>.";
134     m_Messages[ ERROR_OPF_PACKAGE_UNIQUE_IDENTIFIER_DOES_NOT_EXIST ] =
135         "The <package> element's \"unique-identifier\" attribute is pointing to an <identifier> "
136         "with id=\"%1%\" which does not exist in the <metadata>.";
137     m_Messages[ ERROR_OPF_BAD_PACKAGE_VERSION ] =
138         "The <package> element's \"version\" attribute value needs to be \"%1%\", but is \"%2%\".";
139     m_Messages[ ERROR_OPF_BAD_ITEM_LINEAR_VALUE ] =
140         "The <item> element's \"linear\" attribute has value \"%1%\", but only \"yes\" and \"no\" "
141         "are allowed.";
142     m_Messages[ ERROR_OPF_BAD_ITEM_MEDIA_TYPE_VALUE ] =
143         "The <item> element's \"media-type\" attribute has value \"%1%\", but the file's "
144         "media type is \"%2%\".";    
145     m_Messages[ ERROR_OPF_BAD_CREATOR_OR_CONTRIBUTOR_ROLE_VALUE ] =
146         "The \"role\" value \"%1%\" is not a registered MARC value. Either use a valid MARC "
147         "relator or start your relator with \"oth.\".";
148     m_Messages[ ERROR_OPF_BAD_REFERENCE_TYPE_VALUE ] =
149         "The <reference> element's \"type\" attribute has value \"%1%\" which is not an "
150         "OPF-specified value. Either use a predefined type or start your type with \"other.\".";
151     m_Messages[ ERROR_OPF_BAD_DATE_VALUE ] =
152         "The <date> element's value is \"%1%\", which is not a valid date format.";    
153     m_Messages[ ERROR_OPF_ITEM_HREF_INVALID_URI ] =
154         "The <item> element's \"href\" attribute value is \"%1%\", which is not a valid URI.";
155     m_Messages[ ERROR_OPF_ITEM_HREF_HAS_FRAGMENT ] =
156         "The <item> element's \"href\" attribute value is \"%1%\", which contains "
157         "a fragment identifier.";
158     m_Messages[ ERROR_OPF_ITEM_HREF_NOT_UNIQUE ] =
159         "The <item> element's \"href\" attribute value is \"%1%\" "
160         "which is already in use in a previous <item>.";
161     m_Messages[ ERROR_OPF_ITEM_REQMOD_WITHOUT_REQNS ] =
162         "The <item> element has a \"required-modules\" attribute but doesn't have a "
163         "\"required-namespace\" attribute.";
164     m_Messages[ ERROR_OPF_ITEM_FILE_DOESNT_EXIST ] =
165         "The <item> element's \"href\" attribute points to file \"%1%\" "
166         "which does not exist.";      
167     m_Messages[ ERROR_OPF_NCX_NOT_PRESENT ] =
168         "There is no <item> element in the <manifest> that has the NCX mimetype "
169         "(\"application/x-dtbncx+xml\"). The use of an NCX is mandatory in EPUB.";
170     m_Messages[ ERROR_OPF_REACHABLE_OPS_DOC_NOT_IN_SPINE ] =
171         "This OPS document is reachable but not present in the OPF <spine>. "
172         "\"Reachable\" means that a reference of some kind that points to this resource exists in the epub."; 
173     m_Messages[ ERROR_OPF_REACHABLE_RESOURCE_NOT_IN_MANIFEST ] =
174         "This resource is reachable but not present in the OPF <manifest>. "
175         "\"Reachable\" means that a reference of some kind that points to this resource exists in the epub."; 
176
177     m_Messages[ ERROR_NCX_CONTENT_FILE_DOES_NOT_EXIST ] =
178         "This <content> element's \"src\" attribute value is \"%1%\", but that file does not exist.";
179     m_Messages[ ERROR_NCX_CONTENT_FRAGMENT_DOES_NOT_EXIST ] =
180         "This <content> element's \"src\" attribute value is \"%1%\", but an element with an ID the "
181         "fragment is referring to does not exist in that file.";
182
183     m_Messages[ ERROR_XHTML_BAD_DTD ] =
184         std::string( "The file specifies an incorrect DTD. The correct public ID for the DTD is \"" ) +
185          XHTML11_PUBLIC_ID + "\", while the correct system ID is \"" + XHTML11_SYSTEM_ID + "\". "
186          "Do note that using a DTD is optional; but if used, it must be correct.";
187
188     m_Messages[ WARNING_GENERIC ] =
189         "Warning."; 
190     m_Messages[ WARNING_OPF_RESOURCE_IN_MANIFEST_NOT_REACHABLE ] =
191         "This resource is present in the OPF <manifest>, but it's not reachable (it's unused).";
192 }
193
194 } // namespace FlightCrew