Package org.apache.marmotta.platform.core.api.modules

Examples of org.apache.marmotta.platform.core.api.modules.ResourceEntry


     * @param relativeURL a URL relative to the web application root of this web application
     * @return the resource identified by the relative URL, or null if it does not exist
     */
    @Override
    public ResourceEntry getResource(String relativeURL) {
        ResourceEntry data = null;

        // check the request path prefix whether it matches with one of the prefixes in the prefix mapping; if yes,
        // lookup the resource as follows:
        // 1. look in the cache using the path of the request url as cache key
        // 2. if not found: look in the jar file by mapping the resource to the correct jar file and retrieving it
        //    from the "web" folder contained therein
        // 3. if not found: proceed with the chain by calling chain.doFilter()
        // TODO: (FIXME) data_cache.get(path) might return null some times even though path is in cache
        if(isCached(relativeURL)) {
            data = getFromCache(relativeURL);
        } else {

            try {
                URL jarUrl = resolveResource(relativeURL);

                if(jarUrl != null) {
                    try {
                        byte[] bytes = ByteStreams.toByteArray(jarUrl.openStream());

                        data = new ResourceEntry(jarUrl,bytes,bytes.length,getMimeType(jarUrl));

                        log.debug("retrieved resource {} (mime type {}, length {} bytes)", jarUrl.toString(), data.getContentType(),data.getLength());
                    } catch (NullPointerException e) {
                        // This happens if a directory is accessed in the jar-file.
                        data = null;
                    }
                    putInCache(relativeURL,data);
View Full Code Here


        long starttime = System.currentTimeMillis();


        if(path != null && adminInterfaceService.isMenuEntry(path)) {

            ResourceEntry data = resourceService.getResource(path);

            // if no: proceed with the chain by calling chain.doFilter()
            if(data != null && data.getLength() > 0) {

                try {
                    byte [] templatedData = adminInterfaceService.process(data.getData(),path);
                    data = new ResourceEntry(data.getLocation(),templatedData,templatedData.length,data.getContentType());

                    HttpServletResponse hresponse = (HttpServletResponse) response;

                    if(configurationService.getBooleanConfiguration("resources.browsercache.enabled",true)) {
                        hresponse.setDateHeader("Expires", System.currentTimeMillis()+configurationService.getIntConfiguration("resources.browsercache.seconds",300)*1000);
                    } else {
                        hresponse.setHeader("Cache-Control", "no-store");
                        hresponse.setHeader("Pragma", "no-cache");
                        hresponse.setDateHeader("Expires", 0);
                    }

                    if(data.getContentType() != null && !data.getContentType().contains("unknown")) {
                        hresponse.setContentType(data.getContentType());
                    }
                    hresponse.setContentLength(data.getLength());

                    hresponse.getOutputStream().write(data.getData());
                    hresponse.getOutputStream().flush();
                    hresponse.getOutputStream().close();

                    if (log.isDebugEnabled()) {
                        log.debug("request for {} took {}ms", url, System.currentTimeMillis() - starttime);
View Full Code Here

     * @param relativeURL a URL relative to the web application root of this web application
     * @return the resource identified by the relative URL, or null if it does not exist
     */
    @Override
    public ResourceEntry getResource(String relativeURL) {
        ResourceEntry data = null;

        // check the request path prefix whether it matches with one of the prefixes in the prefix mapping; if yes,
        // lookup the resource as follows:
        // 1. look in the cache using the path of the request url as cache key
        // 2. if not found: look in the jar file by mapping the resource to the correct jar file and retrieving it
        //    from the "web" folder contained therein
        // 3. if not found: proceed with the chain by calling chain.doFilter()
        // TODO: (FIXME) data_cache.get(path) might return null some times even though path is in cache
        if(isCached(relativeURL)) {
            data = getFromCache(relativeURL);
        } else {

            try {
                URL jarUrl = resolveResource(relativeURL);

                if(jarUrl != null) {
                    try {
                        byte[] bytes = ByteStreams.toByteArray(jarUrl.openStream());

                        data = new ResourceEntry(jarUrl,bytes,bytes.length,getMimeType(jarUrl));

                        log.debug("retrieved resource {} (mime type {}, length {} bytes)", jarUrl.toString(), data.getContentType(),data.getLength());
                    } catch (NullPointerException e) {
                        // This happens if a directory is accessed in the jar-file.
                        data = null;
                    }
                    putInCache(relativeURL,data);
View Full Code Here


        if(path != null) {
            long starttime = System.currentTimeMillis();

            ResourceEntry data = resourceService.getResource(path);


            // if no: proceed with the chain by calling chain.doFilter()
            if(data != null && data.getLength() > 0) {


                HttpServletResponse hresponse = (HttpServletResponse) response;

                if(configurationService.getBooleanConfiguration("resources.browsercache.enabled",true)) {
                    hresponse.setDateHeader("Expires", System.currentTimeMillis()+configurationService.getIntConfiguration("resources.browsercache.seconds",300)*1000);
                } else {
                    hresponse.setHeader("Cache-Control", "no-store");
                    hresponse.setHeader("Pragma", "no-cache");
                    hresponse.setDateHeader("Expires", 0);
                }

                if(data.getContentType() != null && !data.getContentType().contains("unknown")) {
                    hresponse.setContentType(data.getContentType());
                }
                hresponse.setContentLength(data.getLength());

                hresponse.getOutputStream().write(data.getData());
                hresponse.getOutputStream().flush();
                hresponse.getOutputStream().close();

                if (log.isDebugEnabled()) {
                    log.debug("request for {} took {}ms", url, System.currentTimeMillis() - starttime);
View Full Code Here

        long starttime = System.currentTimeMillis();


        if(path != null && adminInterfaceService.isMenuEntry(path)) {

            ResourceEntry data = resourceService.getResource(path);

            // if no: proceed with the chain by calling chain.doFilter()
            if(data != null && data.getLength() > 0) {

                try {
                    byte [] templatedData = adminInterfaceService.process(data.getData(),path);
                    data = new ResourceEntry(data.getLocation(),templatedData,templatedData.length,data.getContentType());

                    HttpServletResponse hresponse = (HttpServletResponse) response;

                    if(configurationService.getBooleanConfiguration("resources.browsercache.enabled",true)) {
                        hresponse.setDateHeader("Expires", System.currentTimeMillis()+configurationService.getIntConfiguration("resources.browsercache.seconds",300)*1000);
                    } else {
                        hresponse.setHeader("Cache-Control", "no-store");
                        hresponse.setHeader("Pragma", "no-cache");
                        hresponse.setDateHeader("Expires", 0);
                    }

                    if(data.getContentType() != null && !data.getContentType().contains("unknown")) {
                        hresponse.setContentType(data.getContentType());
                    }
                    hresponse.setContentLength(data.getLength());

                    hresponse.getOutputStream().write(data.getData());
                    hresponse.getOutputStream().flush();
                    hresponse.getOutputStream().close();

                    if (log.isDebugEnabled()) {
                        log.debug("request for {} took {}ms", url, System.currentTimeMillis() - starttime);
View Full Code Here

TOP

Related Classes of org.apache.marmotta.platform.core.api.modules.ResourceEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.