Page Speed Optimization Libraries
1.2.24.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 00069 private: 00070 void EmitBytes(const StringPiece& str); 00071 00074 void EmitName(const HtmlName& name); 00075 00076 HtmlElement::CloseStyle GetCloseStyle(HtmlElement* element); 00077 00080 void EncodeBytes(const GoogleString& val, int quoteChar); 00081 00082 HtmlParse* html_parse_; 00083 Writer* writer_; 00084 00090 HtmlElement* lazy_close_element_; 00091 00092 int column_; 00093 int max_column_; 00094 int write_errors_; 00095 bool case_fold_; 00096 GoogleString case_fold_buffer_; 00097 00098 DISALLOW_COPY_AND_ASSIGN(HtmlWriterFilter); 00099 }; 00100 00101 } 00102 00103 #endif ///< NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_