00001 /* 00002 * Copyright 2011 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_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_ 00020 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_ 00021 00022 #include "net/instaweb/rewriter/public/rewrite_driver_factory.h" 00023 #include "net/instaweb/rewriter/public/rewrite_gflags.h" 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/simple_stats.h" 00026 #include "net/instaweb/util/public/string_util.h" 00027 00028 namespace net_instaweb { 00029 00030 class CacheInterface; 00031 class FileSystem; 00032 class Hasher; 00033 class MessageHandler; 00034 class ResourceManager; 00035 class Statistics; 00036 class Timer; 00037 class UrlAsyncFetcher; 00038 class UrlFetcher; 00039 class Writer; 00040 00047 class FileRewriter : public net_instaweb::RewriteDriverFactory { 00048 public: 00049 FileRewriter(const net_instaweb::RewriteGflags* gflags, 00050 bool echo_errors_to_stdout); 00051 virtual ~FileRewriter(); 00052 virtual net_instaweb::Hasher* NewHasher(); 00053 virtual net_instaweb::UrlFetcher* DefaultUrlFetcher(); 00054 virtual net_instaweb::UrlAsyncFetcher* DefaultAsyncUrlFetcher(); 00055 virtual net_instaweb::MessageHandler* DefaultHtmlParseMessageHandler(); 00056 virtual net_instaweb::MessageHandler* DefaultMessageHandler(); 00057 virtual net_instaweb::FileSystem* DefaultFileSystem(); 00058 virtual net_instaweb::Timer* DefaultTimer(); 00059 virtual net_instaweb::CacheInterface* DefaultCacheInterface(); 00060 virtual net_instaweb::Statistics* statistics(); 00061 00062 private: 00063 const net_instaweb::RewriteGflags* gflags_; 00064 net_instaweb::SimpleStats simple_stats_; 00065 bool echo_errors_to_stdout_; 00066 00067 DISALLOW_COPY_AND_ASSIGN(FileRewriter); 00068 }; 00069 00072 class StaticRewriter { 00073 public: 00074 StaticRewriter(int* argc, char*** argv); 00075 StaticRewriter(); 00076 ~StaticRewriter(); 00077 00078 bool ParseText(const StringPiece& text, 00079 const StringPiece& url, 00080 const StringPiece& id, 00081 const StringPiece& output_dir, 00082 Writer* writer); 00083 00084 FileSystem* file_system(); 00085 MessageHandler* message_handler(); 00086 00087 private: 00088 RewriteGflags gflags_; 00089 FileRewriter file_rewriter_; 00090 ResourceManager* resource_manager_; 00091 00092 DISALLOW_COPY_AND_ASSIGN(StaticRewriter); 00093 }; 00094 00095 } 00096 00097 #endif ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_STATIC_REWRITER_H_