2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jmarantz@google.com (Joshua Marantz)
19
#ifndef NET_INSTAWEB_HTMLPARSE_PUBLIC_FILE_DRIVER_H_
20
#define NET_INSTAWEB_HTMLPARSE_PUBLIC_FILE_DRIVER_H_
22
#include "net/instaweb/htmlparse/public/html_writer_filter.h"
23
#include "net/instaweb/htmlparse/public/logging_html_filter.h"
24
#include "pagespeed/kernel/base/basictypes.h"
25
#include "pagespeed/kernel/base/string.h"
27
namespace net_instaweb {
34
// Framework for reading an input HTML file, running it through
35
// a chain of HTML filters, and writing an output file.
38
FileDriver(HtmlParse* html_parse, FileSystem* file_system);
40
// Return the parser. This can be used to add filters.
41
HtmlParse* html_parse() { return html_parse_; }
43
// Helper function to generate an output .html filename from
44
// an input filename. Given "/a/b/c.html" returns "a/b/c.out.html".
45
// Returns false if the input file does not contain a "."
46
static bool GenerateOutputFilename(
47
const char* infilename, GoogleString* outfilename);
49
// Helper function to generate an output .stats filename from
50
// an input filename. Given "/a/b/c.html" returns "a/b/c.stats".
51
// Returns false if the input file does not contain a "."
52
static bool GenerateStatsFilename(
53
const char* infilename, GoogleString* statsfilename);
55
// Error messages are sent to the message file, true is returned
56
// if the file was parsed successfully.
57
bool ParseFile(const char* infilename,
58
const char* outfilename,
59
const char* statsfilename,
60
MessageHandler* handler);
62
// Indicates that we should Flush the parser every x bytes. Disabled if x<=0.
63
void set_flush_byte_count(int x) { flush_byte_count_ = x; }
66
HtmlParse* html_parse_;
67
LoggingFilter logging_filter_;
68
StatisticsLog* stats_log_;
69
HtmlWriterFilter html_write_filter_;
71
FileSystem* file_system_;
72
int flush_byte_count_;
74
DISALLOW_COPY_AND_ASSIGN(FileDriver);
77
} // namespace net_instaweb
79
#endif // NET_INSTAWEB_HTMLPARSE_PUBLIC_FILE_DRIVER_H_