Page Speed Optimization Libraries
1.5.27.2
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_ 00020 #define NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_ 00021 00022 #include "net/instaweb/util/public/basictypes.h" 00023 #include "net/instaweb/htmlparse/public/html_element.h" 00024 #include "net/instaweb/htmlparse/public/html_filter.h" 00025 #include "net/instaweb/htmlparse/public/html_name.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 00031 class HtmlCdataNode; 00032 class HtmlCharactersNode; 00033 class HtmlCommentNode; 00034 class HtmlDirectiveNode; 00035 class HtmlIEDirectiveNode; 00036 class HtmlParse; 00037 class Writer; 00038 00040 class HtmlWriterFilter : public HtmlFilter { 00041 public: 00042 explicit HtmlWriterFilter(HtmlParse* html_parse); 00043 00044 void set_writer(Writer* writer) { writer_ = writer; } 00045 virtual ~HtmlWriterFilter(); 00046 00047 virtual void StartDocument(); 00048 virtual void EndDocument(); 00049 virtual void StartElement(HtmlElement* element); 00050 virtual void EndElement(HtmlElement* element); 00051 virtual void Cdata(HtmlCdataNode* cdata); 00052 virtual void Comment(HtmlCommentNode* comment); 00053 virtual void IEDirective(HtmlIEDirectiveNode* directive); 00054 virtual void Characters(HtmlCharactersNode* characters); 00055 virtual void Directive(HtmlDirectiveNode* directive); 00056 virtual void Flush(); 00057 virtual void DetermineEnabled(); 00058 00059 void set_max_column(int max_column) { max_column_ = max_column; } 00060 void set_case_fold(bool case_fold) { case_fold_ = case_fold; } 00061 00062 virtual const char* Name() const { return "HtmlWriter"; } 00063 00064 protected: 00066 virtual void Clear(); 00067 00068 Writer* writer() { return writer_; } 00069 00071 void TerminateLazyCloseElement(); 00072 00073 private: 00074 void EmitBytes(const StringPiece& str); 00075 00078 void EmitName(const HtmlName& name); 00079 00080 HtmlElement::CloseStyle GetCloseStyle(HtmlElement* element); 00081 00084 void EncodeBytes(const GoogleString& val, int quoteChar); 00085 00086 HtmlParse* html_parse_; 00087 Writer* writer_; 00088 00094 HtmlElement* lazy_close_element_; 00095 00096 int column_; 00097 int max_column_; 00098 int write_errors_; 00099 bool case_fold_; 00100 GoogleString case_fold_buffer_; 00101 00102 DISALLOW_COPY_AND_ASSIGN(HtmlWriterFilter); 00103 }; 00104 00105 } 00106 00107 #endif ///< NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_