00001 // Copyright 2010 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_ 00018 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_ 00019 00020 #include "base/logging.h" 00021 #include "net/instaweb/util/public/basictypes.h" 00022 #include "net/instaweb/util/public/string.h" 00023 #include "net/instaweb/util/public/string_util.h" 00024 00025 namespace net_instaweb { 00026 00027 class ContentType; 00028 class Hasher; 00029 00033 class ResourceNamer { 00034 public: 00037 static const int kOverhead; 00038 00039 ResourceNamer() {} 00040 ~ResourceNamer() {} 00041 00043 00046 bool Decode(const StringPiece& encoded_string); 00047 00050 GoogleString Encode() const; 00051 00058 GoogleString EncodeIdName() const; 00059 00061 00064 int EventualSize(const Hasher& hasher) const; 00065 00067 StringPiece id() const { return id_; } 00068 StringPiece name() const { return name_; } 00069 StringPiece hash() const { return hash_; } 00070 StringPiece ext() const { return ext_; } 00071 00073 void set_id(const StringPiece& p) { p.CopyToString(&id_); } 00074 void set_name(const StringPiece& n) { n.CopyToString(&name_); } 00075 void set_hash(const StringPiece& h) { h.CopyToString(&hash_); } 00076 void set_ext(const StringPiece& e) { 00079 CHECK(e.empty() || e[0] != '.'); 00080 e.CopyToString(&ext_); 00081 } 00082 00084 void ClearHash() { hash_.clear(); } 00085 void CopyFrom(const ResourceNamer& other); 00086 00088 00090 GoogleString PrettyName() const {return InternalEncode(); } 00091 00093 const ContentType* ContentTypeFromExt() const; 00094 00095 private: 00096 GoogleString InternalEncode() const; 00097 bool LegacyDecode(const StringPiece& encoded_string); 00098 00099 GoogleString id_; 00100 GoogleString name_; 00101 GoogleString hash_; 00102 GoogleString ext_; 00103 00104 DISALLOW_COPY_AND_ASSIGN(ResourceNamer); 00105 }; 00106 00107 } 00108 00109 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_