Example usage for org.apache.wicket.util.lang Packages absolutePath

List of usage examples for org.apache.wicket.util.lang Packages absolutePath

Introduction

In this page you can find the example usage for org.apache.wicket.util.lang Packages absolutePath.

Prototype

public static String absolutePath(final String packageName, final String path) 

Source Link

Document

Takes a package and a path to a resource and returns an absolute path to the resource.

Usage

From source file:fiftyfive.wicket.js.locator.DefaultJavaScriptDependencyLocator.java

License:Apache License

/**
 * Loads the given ResourceReference as an IResourceStream or returns
 * {@code null} if the resource could not be found.
 *//*from   ww w  . j  av a2  s.  c o m*/
private IResourceStream load(ResourceReference ref) {
    IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();

    Class<?> scope = ref.getScope();
    String path = Packages.absolutePath(scope, ref.getName());

    return locator.locate(scope, path);
}

From source file:org.artifactory.common.wicket.util.WicketUtils.java

License:Open Source License

private static String readResourceNoCache(Class scope, String file) {
    InputStream inputStream = null;
    try {//ww w  .j  a v a2 s  . c o  m
        final String path = Packages.absolutePath(scope, file);
        final IResourceStream resourceStream = Application.get().getResourceSettings()
                .getResourceStreamLocator().locate(scope, path);
        inputStream = resourceStream.getInputStream();
        return Streams.readString(inputStream, "utf-8");
    } catch (ResourceStreamNotFoundException e) {
        throw new RuntimeException(String.format("Can't find resource \"%s.%s\"", scope.getName(), file), e);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Can't read resource \"%s.%s\"", scope.getName(), file), e);
    } finally {
        Closeables.closeQuietly(inputStream);
    }
}

From source file:org.odlabs.wiquery.core.commons.merge.WiQueryMergedJavaScriptResourceReference.java

License:Open Source License

/**
 * {@inheritDoc}/*w w  w.ja  v a 2  s.c  o  m*/
 */
@Override
protected Resource newResource() {
    return new Resource() {
        private static final long serialVersionUID = 1L;

        /**
         * {@inheritDoc}
         */
        public IResourceStream getResourceStream() {
            String temp = null;
            Application application = Application.get();
            StringBuffer buffer = new StringBuffer();
            IJavascriptCompressor compressor = application.getResourceSettings().getJavascriptCompressor();

            for (ResourceReference ref : wiQueryHeaderResponse.getJavascript()) {
                // We bind the resources into the SharedResources
                ref.bind(Application.get());

                // We insert the javascript code into the template
                try {
                    IResourceStream resource = Application.get().getResourceSettings()
                            .getResourceStreamLocator().locate(getClass(),
                                    "/" + Packages.absolutePath(ref.getScope(), "") + "/" + ref.getName());
                    if (resource != null)
                        temp = Streams.readString(resource.getInputStream());
                } catch (Exception e) {
                    temp = null;
                    e.printStackTrace();
                    LOGGER.error("error in merged processing", e);
                }

                if (compressor != null && temp != null) {
                    temp = compressor.compress(temp);
                }

                if (temp != null) {
                    buffer.append(temp).append("\r\n");
                }
            }

            Map<String, Object> genJs = new HashMap<String, Object>();
            genJs.put("wiqueryresources", buffer);
            jstemplate.interpolate(genJs);

            return new StringResourceStream(jstemplate.asString(), CONTENT_TYPE);
        }
    };
}

From source file:org.odlabs.wiquery.core.commons.merge.WiQueryMergedStyleSheetResourceReference.java

License:Open Source License

private IResourceStream newResourceStream() {
    String temp = null;/* www . ja  v a2  s.  c o  m*/
    String cssUrl;
    String name;
    String old;
    String match;
    StringBuffer buffer = new StringBuffer();

    HttpServletRequest request = ((WebRequest) RequestCycle.get().getRequest()).getHttpServletRequest();
    String baseHost = request.getRequestURL().toString();
    baseHost = baseHost.substring(0, baseHost.indexOf(request.getRequestURI())) + request.getContextPath()
            + "/resources/";

    for (ResourceReference ref : wiQueryHeaderResponse.getStylesheet()) {
        // We bind the resources into the SharedResources
        ref.bind(Application.get());

        // We insert the javascript code into the template
        try {

            IResourceStream resource = Application.get().getResourceSettings().getResourceStreamLocator()
                    .locate(getClass(), "/" + Packages.absolutePath(ref.getScope(), "") + "/" + ref.getName());
            if (resource != null)
                temp = Streams.readString(resource.getInputStream());

            // Replace of url in the css file (regexp: url\(.*?\) )
            name = ref.getName();
            cssUrl = baseHost + ref.getScope().getName() + "/"
                    + (name.indexOf("/") < 0 ? "" : name.substring(0, name.lastIndexOf("/") + 1));

            Pattern p = Pattern.compile(REGEX);
            Matcher m = p.matcher(temp); // get a matcher object
            int count = 0;
            while (m.find()) {
                count++;
                match = m.group();
                old = getCssUrl(match, cssUrl);

                if (!old.equals(match)) {
                    temp = temp.replace(match, old);
                }
            }

        } catch (Exception e) {
            temp = null;
            e.printStackTrace();
            LOGGER.error("error in merged processing", e);
        }

        if (temp != null) {
            buffer.append(temp).append("\r\n");
        }
    }

    Map<String, Object> genCss = new HashMap<String, Object>();
    genCss.put("wiqueryresources", buffer);
    csstemplate.interpolate(genCss);

    return new StringResourceStream(csstemplate.asString(), CONTENT_TYPE);
}

From source file:org.sturmm.wicketless.coffee.CompilerTest.java

License:Apache License

@Test
public void parseAndGenerateUncompressed() throws IOException {
    String file = Packages.absolutePath(CompilerTest.class, "CoffeeTest.cs");
    CoffeeScriptCompiler.getInstance()/*from   w  w w. ja  va 2  s .  c  om*/
            .compile(IOUtils.toString(CompilerTest.class.getClassLoader().getResourceAsStream(file)), bare);
}

From source file:org.sturmm.wicketless.less.source.ClasspathLessSource.java

License:Apache License

/**
 * Creates a {@link LessSource} with name {@code filename} relative to a
 * given class {@code scope}.<br>// w w  w  .  j  a  va  2  s .c o  m
 * 
 * @param scope
 *            class from relative to this the resource should be loaded.
 * @param filename
 *            the name of the resource relative to class scope
 * @throws ResourceException
 *             if specified resource does'nt exist, or could not be loaded.
 */
public ClasspathLessSource(Class<?> scope, String filename) throws ResourceException {
    this(Packages.absolutePath(scope, filename));
}

From source file:org.sturmm.wicketless.resource.CoffeeScriptResourceReference.java

License:Apache License

private String getFullyQualifiedResourceName() {
    return Packages.absolutePath(getScope(), getName());
}