1 /************************************************************************
\r
3 ** Copyright (C) 2010 Strahinja Markovic
\r
5 ** This file is part of FlightCrew.
\r
7 ** FlightCrew is free software: you can redistribute it and/or modify
\r
8 ** it under the terms of the GNU Lesser General Public License as published
\r
9 ** by the Free Software Foundation, either version 3 of the License, or
\r
10 ** (at your option) any later version.
\r
12 ** FlightCrew is distributed in the hope that it will be useful,
\r
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 ** GNU Lesser General Public License for more details.
\r
17 ** You should have received a copy of the GNU Lesser General Public License
\r
18 ** along with FlightCrew. If not, see <http://www.gnu.org/licenses/>.
\r
20 *************************************************************************/
\r
23 #ifndef REACHABILITYANALYSIS_H
\r
24 #define REACHABILITYANALYSIS_H
\r
26 #include "../XmlValidator.h"
\r
27 #include <boost/unordered/unordered_map_fwd.hpp>
\r
28 #include <boost/unordered/unordered_set_fwd.hpp>
\r
30 namespace FlightCrew
\r
34 * Reports errors with files that are unmanifested or unused and OPS
\r
35 * docs not in the OPF <spine>.
\r
37 class ReachabilityAnalysis : public XmlValidator
\r
42 virtual std::vector< Result > ValidateXml(
\r
43 const xc::DOMDocument &document,
\r
44 const fs::path &filepath = fs::path() );
\r
49 * Returns validation results for problems with OPS docs not present in the OPF spine.
\r
51 * @param document The OPF document.
\r
52 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
53 * values are full paths to those files.
\r
54 * @param reachable_resources A set of full paths to all the reachable files.
\r
55 * @return The validation results.
\r
57 std::vector< Result > ResultsForOpsDocsNotInSpine(
\r
58 const xc::DOMDocument &document,
\r
59 const boost::unordered_map< std::string, fs::path > &manifest_items,
\r
60 const boost::unordered_set< fs::path > &reachable_resources );
\r
63 * Returns validation results for problems with resources not present in the OPF manifest.
\r
65 * @param document The OPF document.
\r
66 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
67 * values are full paths to those files.
\r
68 * @param reachable_resources A set of full paths to all the reachable files.
\r
69 * @return The validation results.
\r
71 std::vector< Result > ResultsForResourcesNotInManifest(
\r
72 const boost::unordered_map< std::string, fs::path > &manifest_items,
\r
73 const boost::unordered_set< fs::path > &reachable_resources );
\r
76 * Returns validation results for problems with resources that are unused but present
\r
77 * in the OPF manifest.
\r
79 * @param document The OPF document.
\r
80 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
81 * values are full paths to those files.
\r
82 * @param reachable_resources A set of full paths to all the reachable files.
\r
83 * @return The validation results.
\r
85 std::vector< Result > ResultsForUnusedResources(
\r
86 const boost::unordered_map< std::string, fs::path > &manifest_items,
\r
87 const boost::unordered_set< fs::path > &reachable_resources );
\r
90 * Determines if the specified file is allowed to be unreachable.
\r
92 * @param filepath The file to analyze.
\r
93 * @return \c true if the file is allowed to be unreachable.
\r
95 bool AllowedToBeNotReachable( const fs::path &filepath );
\r
98 * Returns an ID->fullpath mapping of the manifest items in the OPF document.
\r
100 * @param document The OPF document.
\r
101 * @param opf_folder_path The path to the folder in which the OPF file resides.
\r
102 * @return The manifest items.
\r
104 boost::unordered_map< std::string, fs::path > GetManifestItems(
\r
105 const xc::DOMDocument &document,
\r
106 const fs::path &opf_folder_path );
\r
109 * Returns a set of paths to the starting OPS documents. The starting docs are
\r
110 * the ones that are explicitly listed in the OPF or NCX in some way.
\r
112 * @param document The OPF document.
\r
113 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
114 * values are full paths to those files.
\r
115 * @param opf_folder_path The path to the folder in which the OPF file resides.
\r
116 * @return The starting OPS paths.
\r
118 boost::unordered_set< fs::path > StartingSetOpsPaths(
\r
119 const xc::DOMDocument &document,
\r
120 const boost::unordered_map< std::string, fs::path > &manifest_items,
\r
121 const fs::path &opf_folder_path );
\r
124 * Returns a set of paths listed in the OPF <spine>.
\r
126 * @param document The OPF document.
\r
127 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
128 * values are full paths to those files.
\r
129 * @return The spine paths.
\r
131 boost::unordered_set< fs::path > SpinePaths(
\r
132 const xc::DOMDocument &document,
\r
133 const boost::unordered_map< std::string, fs::path > &manifest_items );
\r
136 * Returns a set of paths listed in the OPF <guide>.
\r
138 * @param document The OPF document.
\r
139 * @param opf_folder_path The path to the folder in which the OPF file resides.
\r
140 * @return The guide paths.
\r
142 boost::unordered_set< fs::path > GuidePaths(
\r
143 const xc::DOMDocument &document,
\r
144 const fs::path &opf_folder_path );
\r
147 * Returns a set of paths listed in the OPF <tours>.
\r
149 * @param document The OPF document.
\r
150 * @param opf_folder_path The path to the folder in which the OPF file resides.
\r
151 * @return The tours paths.
\r
153 boost::unordered_set< fs::path > ToursPaths(
\r
154 const xc::DOMDocument &document,
\r
155 const fs::path &opf_folder_path );
\r
158 * Returns a path to the NCX file.
\r
160 * @param document The OPF document.
\r
161 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
162 * values are full paths to those files.
\r
163 * @return The path to the NCX.
\r
165 fs::path GetPathToNcx(
\r
166 const xc::DOMDocument &document,
\r
167 const boost::unordered_map< std::string, fs::path > &manifest_items );
\r
170 * Returns a set of paths listed in the NCX.
\r
172 * @param document The OPF document.
\r
173 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
174 * values are full paths to those files.
\r
175 * @return The NCX paths.
\r
177 boost::unordered_set< fs::path > NcxPaths(
\r
178 const xc::DOMDocument &document,
\r
179 const boost::unordered_map< std::string, fs::path > &manifest_items );
\r
182 * Returns a set of full paths to all the reachable resources.
\r
184 * @param starting_ops_paths The paths to the starting OPS documents.
\r
185 * @return All the reachable resources.
\r
187 boost::unordered_set< fs::path > DetermineReachableResources(
\r
188 const boost::unordered_set< fs::path > &starting_ops_paths );
\r
191 * Returns a list of all the resources that are directly reachable
\r
192 * (i.e. "one step away") from the provided resources.
\r
194 * @param resources The resources from which reachability of new resources
\r
195 * will be determined.
\r
196 * @return The directly reachable resources.
\r
198 boost::unordered_set< fs::path > GetDirectlyReachableResources(
\r
199 const boost::unordered_set< fs::path > &resources );
\r
202 * From the set of provided resources, returns only the OPS ones.
\r
204 * @param resources The resource set.
\r
205 * @return The OPS resources.
\r
207 boost::unordered_set< fs::path > GetOnlyOpsDocs(
\r
208 const boost::unordered_set< fs::path > &resources );
\r
211 * From the set of provided resources, returns only the CSS ones.
\r
213 * @param resources The resource set.
\r
214 * @return The CSS resources.
\r
216 boost::unordered_set< fs::path > GetOnlyCssDocs(
\r
217 const boost::unordered_set< fs::path > &resources );
\r
220 * For all the provided OPS docs, returns a set of all reachable resources.
\r
222 * @param resources The OPS path set.
\r
223 * @return The reachable resources.
\r
225 boost::unordered_set< fs::path > GetLinkedResourcesFromAllOps(
\r
226 const boost::unordered_set< fs::path > &ops_docs );
\r
229 * For all the provided CSS docs, returns a set of all reachable resources.
\r
231 * @param resources The OPS path set.
\r
232 * @return The reachable resources.
\r
234 boost::unordered_set< fs::path > GetLinkedResourcesFromAllCss(
\r
235 const boost::unordered_set< fs::path > &css_docs );
\r
238 * For the provided OPS doc, returns a set of all reachable resources.
\r
240 * @param resources The OPS path.
\r
241 * @return The reachable resources.
\r
243 boost::unordered_set< fs::path > GetLinkedResourcesFromOps(
\r
244 const fs::path &ops_document );
\r
247 * For the provided CSS doc, returns a set of all reachable resources.
\r
249 * @param resources The CSS path.
\r
250 * @return The reachable resources.
\r
252 boost::unordered_set< fs::path > GetLinkedResourcesFromCss(
\r
253 const fs::path &css_document );
\r
256 * Extracts the paths from map into a set.
\r
258 * @param manifest_items A map of manifest items. The keys are the IDs, the
\r
259 * values are full paths to those files.
\r
260 * @return A set of all the paths.
\r
262 boost::unordered_set< fs::path > GetPathsFromItems(
\r
263 const boost::unordered_map< std::string, fs::path > &manifest_items );
\r
266 * Examines if the provided path points to a file on the filesystem.
\r
267 * (as opposed to a file on the Internet).
\r
269 * @param path The path to inspect.
\r
270 * @return \c true if the path is a filesystem path.
\r
272 bool IsFilesystemPath( const fs::path &path );
\r
275 } // namespace FlightCrew
\r
277 #endif // REACHABILITYANALYSIS_H
\r