2
* Copyright 2012 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: jefftk@google.com (Jeff Kaufman)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_FILE_LOAD_MAPPING_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_FILE_LOAD_MAPPING_H_
22
#include "net/instaweb/util/public/basictypes.h"
23
#include "net/instaweb/util/public/manually_ref_counted.h"
24
#include "net/instaweb/util/public/re2.h"
25
#include "net/instaweb/util/public/string.h"
26
#include "net/instaweb/util/public/string_util.h"
28
namespace net_instaweb {
30
// Class for storing a mapping from a URL to a filesystem path, for use by
32
class FileLoadMapping : public ManuallyRefCounted {
34
virtual ~FileLoadMapping();
36
// If this mapping applies to this url, put the mapped path into filename and
37
// return true. Otherwise return false.
38
virtual bool Substitute(const StringPiece& url,
39
GoogleString* filename) const = 0;
42
class FileLoadMappingRegexp : public FileLoadMapping {
44
FileLoadMappingRegexp(const GoogleString& url_regexp,
45
const GoogleString& filename_prefix)
46
: url_regexp_(url_regexp),
47
url_regexp_str_(url_regexp),
48
filename_prefix_(filename_prefix) {}
50
virtual bool Substitute(const StringPiece& url, GoogleString* filename) const;
53
const RE2 url_regexp_;
54
// RE2s can't be copied, so we need to keep the string around.
55
const GoogleString url_regexp_str_;
56
const GoogleString filename_prefix_;
58
DISALLOW_COPY_AND_ASSIGN(FileLoadMappingRegexp);
61
class FileLoadMappingLiteral : public FileLoadMapping {
63
FileLoadMappingLiteral(const GoogleString& url_prefix,
64
const GoogleString& filename_prefix)
65
: url_prefix_(url_prefix),
66
filename_prefix_(filename_prefix) {}
68
virtual bool Substitute(const StringPiece& url, GoogleString* filename) const;
71
const GoogleString url_prefix_;
72
const GoogleString filename_prefix_;
74
DISALLOW_COPY_AND_ASSIGN(FileLoadMappingLiteral);
77
} // namespace net_instaweb
79
#endif // NET_INSTAWEB_REWRITER_PUBLIC_FILE_LOAD_MAPPING_H_