Example usage for org.apache.wicket.util.io Streams readString

List of usage examples for org.apache.wicket.util.io Streams readString

Introduction

In this page you can find the example usage for org.apache.wicket.util.io Streams readString.

Prototype

public static String readString(final Reader in) throws IOException 

Source Link

Document

Reads all input from a reader into a string.

Usage

From source file:com.locke.tricks.x.X.java

License:Apache License

public X() {
    final String filename = "test.xml";
    add(new ResourceLink("downloadLink", new XmlWebResource(filename) {

        protected String getXml() {
            try {
                return Streams.readString(getClass().getResourceAsStream(filename));
            } catch (IOException e) {
                e.printStackTrace();/*from  ww  w.j  a va  2s  . c  o  m*/
                return String.format(getString("xmlNotFound"), filename, e.toString());
            }
        }
    }));
}

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

License:Open Source License

/**
 * {@inheritDoc}/*from ww  w.j a 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;//from w  w  w .  jav  a 2  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.wicketstuff.pageserializer.common.analyze.report.TreeReader.java

License:Apache License

public static ISerializedObjectTree fromResourceWithFilename(Class<?> baseType, String resourceName)
        throws IOException {
    InputStream resourceAsStream = null;
    try {// w w  w .  j av  a 2s  .  c  om
        resourceAsStream = baseType.getResourceAsStream(resourceName);
        return fromString(Streams.readString(resourceAsStream));
    } finally {
        if (resourceAsStream != null)
            resourceAsStream.close();
    }
}