Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
html_writer_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_HTML_HTML_WRITER_FILTER_H_
20 #define PAGESPEED_KERNEL_HTML_HTML_WRITER_FILTER_H_
21 
29 
30 namespace net_instaweb {
31 
32 class HtmlParse;
33 class Writer;
34 
36 class HtmlWriterFilter : public HtmlFilter {
37  public:
38  explicit HtmlWriterFilter(HtmlParse* html_parse);
39 
40  void set_writer(Writer* writer) { writer_ = writer; }
41  virtual ~HtmlWriterFilter();
42 
43  virtual void StartDocument();
44  virtual void EndDocument();
45  virtual void StartElement(HtmlElement* element);
46  virtual void EndElement(HtmlElement* element);
47  virtual void Cdata(HtmlCdataNode* cdata);
48  virtual void Comment(HtmlCommentNode* comment);
49  virtual void IEDirective(HtmlIEDirectiveNode* directive);
50  virtual void Characters(HtmlCharactersNode* characters);
51  virtual void Directive(HtmlDirectiveNode* directive);
52  virtual void Flush();
53  virtual void DetermineEnabled(GoogleString* disabled_reason);
55  virtual bool CanModifyUrls() { return false; }
56  ScriptUsage GetScriptUsage() const override { return kNeverInjectsScripts; }
57 
58  void set_max_column(int max_column) { max_column_ = max_column; }
59  void set_case_fold(bool case_fold) { case_fold_ = case_fold; }
60 
61  virtual const char* Name() const { return "HtmlWriter"; }
62 
63  protected:
65  virtual void Clear();
66 
67  Writer* writer() { return writer_; }
68 
71 
72  private:
73  void EmitBytes(const StringPiece& str);
74 
77  void EmitName(const HtmlName& name);
78 
79  HtmlElement::Style GetElementStyle(HtmlElement* element);
80 
83  void EncodeBytes(const GoogleString& val, int quoteChar);
84 
85  HtmlParse* html_parse_;
86  Writer* writer_;
87 
93  HtmlElement* lazy_close_element_;
94 
95  int column_;
96  int max_column_;
97  int write_errors_;
98  bool case_fold_;
99  GoogleString case_fold_buffer_;
100 
101 
102 };
103 
104 }
105 
106 #endif
Definition: html_filter.h:35
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
Indicates this filter never injects scripts.
Definition: html_filter.h:55
virtual void StartElement(HtmlElement *element)
virtual void IEDirective(HtmlIEDirectiveNode *directive)
Definition: html_parse.h:88
virtual void Characters(HtmlCharactersNode *characters)
Called for raw characters between tags.
Definition: html_element.h:42
virtual bool CanModifyUrls()
This filter will not change urls.
Definition: html_writer_filter.h:55
virtual void DetermineEnabled(GoogleString *disabled_reason)
Leaf node representing an HTML comment.
Definition: html_node.h:193
virtual void Clear()
Clear various variables for rewriting a new html file.
virtual void Cdata(HtmlCdataNode *cdata)
Called for CDATA blocks (e.g. <![CDATA[foobar]]>)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Style
Definition: html_element.h:50
ScriptUsage GetScriptUsage() const override
Definition: html_writer_filter.h:56
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
virtual void Comment(HtmlCommentNode *comment)
Called for HTML comments that aren't IE directives (e.g. ).
Interface for writing bytes to an output stream.
Definition: writer.h:29
Leaf node representing an HTML directive.
Definition: html_node.h:233
Filter that serializes HTML to a Writer stream.
Definition: html_writer_filter.h:36
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: html_writer_filter.h:61
Leaf node representing a CDATA section.
Definition: html_node.h:147
Leaf node representing an HTML IE directive.
Definition: html_node.h:213
void TerminateLazyCloseElement()
Terminates the current lazy close element if it is not already terminated.
virtual void Directive(HtmlDirectiveNode *directive)
Called for HTML directives (e.g. <!doctype foobar>).