Page Speed Optimization Libraries
1.3.25.1
|
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 00039 class HtmlWriterFilter : public HtmlFilter { 00040 public: 00041 explicit HtmlWriterFilter(HtmlParse* html_parse); 00042 00043 void set_writer(Writer* writer) { writer_ = writer; } 00044 virtual ~HtmlWriterFilter(); 00045 00046 virtual void StartDocument(); 00047 virtual void EndDocument(); 00048 virtual void StartElement(HtmlElement* element); 00049 virtual void EndElement(HtmlElement* element); 00050 virtual void Cdata(HtmlCdataNode* cdata); 00051 virtual void Comment(HtmlCommentNode* comment); 00052 virtual void IEDirective(HtmlIEDirectiveNode* directive); 00053 virtual void Characters(HtmlCharactersNode* characters); 00054 virtual void Directive(HtmlDirectiveNode* directive); 00055 virtual void Flush(); 00056 virtual void DetermineEnabled(); 00057 00058 void set_max_column(int max_column) { max_column_ = max_column; } 00059 void set_case_fold(bool case_fold) { case_fold_ = case_fold; } 00060 00061 virtual const char* Name() const { return "HtmlWriter"; } 00062 00063 protected: 00065 virtual void Clear(); 00066 00067 Writer* writer() { return writer_; } 00068 00070 void TerminateLazyCloseElement(); 00071 00072 private: 00073 void EmitBytes(const StringPiece& str); 00074 00077 void EmitName(const HtmlName& name); 00078 00079 HtmlElement::CloseStyle GetCloseStyle(HtmlElement* element); 00080 00083 void EncodeBytes(const GoogleString& val, int quoteChar); 00084 00085 HtmlParse* html_parse_; 00086 Writer* writer_; 00087 00093 HtmlElement* lazy_close_element_; 00094 00095 int column_; 00096 int max_column_; 00097 int write_errors_; 00098 bool case_fold_; 00099 GoogleString case_fold_buffer_; 00100 00101 DISALLOW_COPY_AND_ASSIGN(HtmlWriterFilter); 00102 }; 00103 00104 } 00105 00106 #endif ///< NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_