|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ContextAssetFactory.java | 50% | 77.8% | 80% | 75% |
|
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // 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.asset; | |
16 | ||
17 | import java.util.Locale; | |
18 | ||
19 | import org.apache.hivemind.ApplicationRuntimeException; | |
20 | import org.apache.hivemind.Location; | |
21 | import org.apache.hivemind.Resource; | |
22 | import org.apache.tapestry.IAsset; | |
23 | import org.apache.tapestry.web.WebContext; | |
24 | import org.apache.tapestry.web.WebContextResource; | |
25 | ||
26 | /** | |
27 | * For the moment, all "context:" prefixed asset paths are interpreted relative to the web context | |
28 | * (the web application's root folder). | |
29 | * | |
30 | * @author Howard M. Lewis Ship | |
31 | * @since 4.0 | |
32 | */ | |
33 | public class ContextAssetFactory implements AssetFactory | |
34 | { | |
35 | private WebContext _context; | |
36 | ||
37 | private String _contextPath; | |
38 | ||
39 | private Resource _servletRoot; | |
40 | ||
41 | 5 | public void initializeService() |
42 | { | |
43 | 5 | _servletRoot = new WebContextResource(_context, "/"); |
44 | } | |
45 | ||
46 | 6 | public IAsset createAsset(Resource baseResource, String path, Locale locale, Location location) |
47 | { | |
48 | 6 | Resource assetResource = _servletRoot.getRelativeResource(path); |
49 | 6 | Resource localized = assetResource.getLocalization(locale); |
50 | ||
51 | 6 | if (localized == null) |
52 | 0 | throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, _servletRoot), |
53 | location, null); | |
54 | ||
55 | 6 | return new ContextAsset(_contextPath, localized, location); |
56 | } | |
57 | ||
58 | 0 | public IAsset createAsset(Resource resource, Location location) |
59 | { | |
60 | 0 | return new ContextAsset(resource.getPath(), resource, location); |
61 | } | |
62 | ||
63 | 5 | public void setContext(WebContext context) |
64 | { | |
65 | 5 | _context = context; |
66 | } | |
67 | ||
68 | 5 | public void setContextPath(String contextPath) |
69 | { | |
70 | 5 | _contextPath = contextPath; |
71 | } | |
72 | } |
|