On Thursday 26 June 2008 14:43:22 code dude wrote:
> Hello Guys ,
> I  am trying to  make small application where user can pass a date and
> report ID and html report is returned with graphs (which is flash based
> graphing solution , fusion charts ) which needs certain flash or swf
> objects sent, js and css to included in html and image as response object
> , i have set response media type to HTML.
>
> Problem even though I get html response how to specify path css , image
> files , flash objects which needs to be loaded in order to display graphs
>
>
> Do I have use 3rd party web server to access these static contents
> resources  like flash file ,images ?
I've solved this problem with these two classes (I'm using a jar file that 
embeds a web server and css/js resources):

import org.restlet.data.MediaType;
import org.restlet.resource.InputRepresentation;

public class ClassPathResourceRepresentation extends InputRepresentation {

    private static ClassLoader defaultClassLoader = 
ClassPathResourceRepresentation.class.getClassLoader();

    public ClassPathResourceRepresentation(String resourceName, MediaType 
mediaType) {
        super(defaultClassLoader.getResourceAsStream(resourceName), 
mediaType);
    }

    public ClassPathResourceRepresentation(String resourceName, MediaType 
mediaType, ClassLoader classLoader) {
        super(classLoader.getResourceAsStream(resourceName), mediaType);
    }
}

import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;

public class ClassPathResource extends Resource {

    public ClassPathResource() {
        getVariants().add(new Variant(MediaType.TEXT_JAVASCRIPT));
        getVariants().add(new Variant(MediaType.TEXT_CSS));
    }

    @Override
    public boolean isReadable() {
        return true;
    }

    @Override
    public Representation represent(Variant variant) throws 
ResourceException {
        String resourceName = 
Request.getCurrent().getResourceRef().getPath(true).replaceFirst("/", "");
        return new ClassPathResourceRepresentation(resourceName, 
variant.getMediaType());
    }
}

Hope it helps.

-- 
Best Regards, 
Davide Angelocola
-- 
-- Davide Angelocola

Reply via email to