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_parser_types.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 class HtmlName; 00031 class Writer; 00032 00033 class HtmlWriterFilter : public HtmlFilter { 00034 public: 00035 explicit HtmlWriterFilter(HtmlParse* html_parse); 00036 00037 void set_writer(Writer* writer) { writer_ = writer; } 00038 virtual ~HtmlWriterFilter(); 00039 00040 virtual void StartDocument(); 00041 virtual void EndDocument(); 00042 virtual void StartElement(HtmlElement* element); 00043 virtual void EndElement(HtmlElement* element); 00044 virtual void Cdata(HtmlCdataNode* cdata); 00045 virtual void Comment(HtmlCommentNode* comment); 00046 virtual void IEDirective(HtmlIEDirectiveNode* directive); 00047 virtual void Characters(HtmlCharactersNode* characters); 00048 virtual void Directive(HtmlDirectiveNode* directive); 00049 virtual void Flush(); 00050 00051 void set_max_column(int max_column) { max_column_ = max_column; } 00052 void set_case_fold(bool case_fold) { case_fold_ = case_fold; } 00053 00054 virtual const char* Name() const { return "HtmlWriter"; } 00055 00056 private: 00057 void EmitBytes(const StringPiece& str); 00058 00061 void EmitName(const HtmlName& name); 00062 00063 HtmlElement::CloseStyle GetCloseStyle(HtmlElement* element); 00064 void Clear(); 00065 00068 void EncodeBytes(const GoogleString& val, int quoteChar); 00069 00070 HtmlParse* html_parse_; 00071 Writer* writer_; 00072 00078 HtmlElement* lazy_close_element_; 00079 00080 int column_; 00081 int max_column_; 00082 int write_errors_; 00083 bool case_fold_; 00084 GoogleString case_fold_buffer_; 00085 00086 DISALLOW_COPY_AND_ASSIGN(HtmlWriterFilter); 00087 }; 00088 00089 } 00090 00091 #endif ///< NET_INSTAWEB_HTMLPARSE_PUBLIC_HTML_WRITER_FILTER_H_