01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.test;
16:
17: import java.io.File;
18: import java.net.MalformedURLException;
19: import java.net.URL;
20: import java.util.List;
21:
22: import org.apache.tapestry.services.Context;
23:
24: public class PageTesterContext implements Context {
25: private final String _contextRoot;
26:
27: public PageTesterContext(String contextRoot) {
28: _contextRoot = contextRoot;
29: }
30:
31: public String getInitParameter(String name) {
32: return null;
33: }
34:
35: public URL getResource(String path) {
36: File f = new File(_contextRoot + path);
37:
38: if (!f.exists() || !f.isFile()) {
39: return null;
40: }
41: try {
42: return f.toURL();
43: } catch (MalformedURLException ex) {
44: throw new RuntimeException(ex);
45: }
46: }
47:
48: public List<String> getResourcePaths(String path) {
49: throw new UnsupportedOperationException(
50: "getResourcePaths() is not supported for ContextForPageTester.");
51: }
52:
53: public Object getAttribute(String name) {
54: throw new UnsupportedOperationException(
55: "getAttribute() is not supported for ContextForPageTester.");
56: }
57:
58: }
|