Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/remove_comments_filter.h
Go to the documentation of this file.
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_REWRITER_PUBLIC_REMOVE_COMMENTS_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REMOVE_COMMENTS_FILTER_H_
00021 
00022 #include "net/instaweb/htmlparse/public/empty_html_filter.h"
00023 
00024 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/util/public/scoped_ptr.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027 #include "pagespeed/kernel/util/fast_wildcard_group.h"
00028 
00029 namespace net_instaweb {
00030 class HtmlCommentNode;
00031 class HtmlParse;
00032 
00037 class RemoveCommentsFilter : public EmptyHtmlFilter {
00038  public:
00043   class OptionsInterface {
00044    public:
00045     OptionsInterface() {}
00046     virtual ~OptionsInterface();
00047 
00050     virtual bool IsRetainedComment(const StringPiece& comment) const = 0;
00051 
00052    private:
00053     DISALLOW_COPY_AND_ASSIGN(OptionsInterface);
00054   };
00055 
00057   class OptionsImpl : public OptionsInterface {
00058    public:
00059     OptionsImpl() {}
00060 
00061     void RetainComment(const StringPiece& comment) {
00062       retain_comments_.Allow(comment);
00063     }
00064 
00065     virtual bool IsRetainedComment(const StringPiece& comment) const {
00066       return retain_comments_.Match(comment, false);
00067     }
00068 
00069    private:
00070     FastWildcardGroup retain_comments_;
00071 
00072     DISALLOW_COPY_AND_ASSIGN(OptionsImpl);
00073   };
00074 
00075   explicit RemoveCommentsFilter(HtmlParse* html_parse)
00076       : html_parse_(html_parse) {}
00077 
00081   RemoveCommentsFilter(HtmlParse* html_parse,
00082                        const OptionsInterface* options)
00083       : html_parse_(html_parse),
00084         options_(options) {
00085   }
00086 
00087   virtual ~RemoveCommentsFilter();
00088 
00089   virtual void Comment(HtmlCommentNode* comment);
00090   virtual const char* Name() const { return "RemoveComments"; }
00091 
00092  private:
00093   HtmlParse* html_parse_;
00094   scoped_ptr<const OptionsInterface> options_;
00095 
00096   DISALLOW_COPY_AND_ASSIGN(RemoveCommentsFilter);
00097 };
00098 
00099 }  
00100 
00101 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_REMOVE_COMMENTS_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines