|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PrivateAsset.java | - | 90% | 100% | 92.3% |
|
1 |
// Copyright 2004, 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.io.InputStream;
|
|
18 |
import java.net.URL;
|
|
19 |
|
|
20 |
import org.apache.hivemind.util.ClasspathResource;
|
|
21 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
22 |
import org.apache.hivemind.Location;
|
|
23 |
import org.apache.hivemind.Resource;
|
|
24 |
import org.apache.tapestry.IRequestCycle;
|
|
25 |
import org.apache.tapestry.Tapestry;
|
|
26 |
import org.apache.tapestry.engine.IEngineService;
|
|
27 |
import org.apache.tapestry.engine.ILink;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* An implementation of {@link org.apache.tapestry.IAsset}for localizable assets within the JVM's
|
|
31 |
* classpath.
|
|
32 |
* <p>
|
|
33 |
* The localization code here is largely cut-and-paste from {@link ContextAsset}.
|
|
34 |
*
|
|
35 |
* @author Howard Ship
|
|
36 |
*/
|
|
37 |
|
|
38 |
public class PrivateAsset extends AbstractAsset |
|
39 |
{ |
|
40 | 85 |
public PrivateAsset(ClasspathResource resourceLocation, Location location)
|
41 |
{ |
|
42 | 85 |
super(resourceLocation, location);
|
43 |
} |
|
44 |
|
|
45 |
/**
|
|
46 |
* Gets the localized version of the resource. Build the URL for the resource. If possible, the
|
|
47 |
* application's {@link AssetExternalizerImpl}is located, to copy the resource to a directory
|
|
48 |
* visible to the web server.
|
|
49 |
*/
|
|
50 |
|
|
51 | 90 |
public String buildURL(IRequestCycle cycle)
|
52 |
{ |
|
53 | 90 |
IEngineService service = cycle.getEngine().getService(Tapestry.ASSET_SERVICE); |
54 |
|
|
55 | 90 |
String path = getResourceLocation().getPath(); |
56 |
|
|
57 | 90 |
ILink link = service.getLink(cycle, path); |
58 |
|
|
59 | 90 |
return link.getURL();
|
60 |
} |
|
61 |
|
|
62 | 1 |
public InputStream getResourceAsStream(IRequestCycle cycle)
|
63 |
{ |
|
64 | 1 |
Resource location = getResourceLocation(); |
65 |
|
|
66 | 1 |
try
|
67 |
{ |
|
68 | 1 |
URL url = location.getResourceURL(); |
69 |
|
|
70 | 1 |
return url.openStream();
|
71 |
} |
|
72 |
catch (Exception ex)
|
|
73 |
{ |
|
74 | 0 |
throw new ApplicationRuntimeException(Tapestry.format( |
75 |
"PrivateAsset.resource-missing",
|
|
76 |
location), ex); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
} |
|