Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2004, 2005 The Apache Software Foundation
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.asset;
import  org.apache.hivemind.ApplicationRuntimeException;
import  org.apache.hivemind.Location;
import  org.apache.hivemind.Resource;
import  org.apache.hivemind.util.Defense;
An asset whose path is relative to the javax.servlet.ServletContext containing the application.

Howard Lewis Ship
public class ContextAsset extends AbstractAsset implements IAsset
    private String _contextPath;
    private String _resolvedURL;
    private IRequestCycle _requestCycle;
    public ContextAsset(String contextPath, Resource resource, Location locationIRequestCycle cycle)
         = contextPath;
         = cycle;

Generates a URL for the client to retrieve the asset. The context path is prepended to the asset path, which means that assets deployed inside web applications will still work (if things are configured properly).
    public String buildURL()
        if ( == null)
             =  + getResourceLocation().getPath();
        return ;
            URL url = getResourceLocation().getResourceURL();
            return url.openStream();
        catch (Exception ex)
            throw new ApplicationRuntimeException(Tapestry.format(
              getResourceLocation()), ex);
New to GrepCode? Check out our FAQ X