Example usage for com.google.gwt.dev.resource Resource getLocation

List of usage examples for com.google.gwt.dev.resource Resource getLocation

Introduction

In this page you can find the example usage for com.google.gwt.dev.resource Resource getLocation.

Prototype

public abstract String getLocation();

Source Link

Document

Returns the URL-like location of the resource.

Usage

From source file:fr.onevu.gwt.uibinder.rebind.GwtResourceEntityResolver.java

License:Apache License

@Override
public InputSource resolveEntity(String publicId, String systemId) {
    String matchingPrefix = findMatchingPrefix(systemId);

    Resource resource = null;
    Map<String, Resource> map = resourceOracle.getResourceMap();
    if (matchingPrefix != null) {
        resource = map.get(RESOURCES + systemId.substring(matchingPrefix.length()));
    }/*from w  ww.j a v  a  2 s . c o  m*/

    if (resource == null) {
        resource = map.get(pathBase + systemId);
    }

    if (resource != null) {
        String content;
        try {
            InputStream resourceStream = resource.openContents();
            content = Util.readStreamAsString(resourceStream);
        } catch (IOException ex) {
            logger.log(TreeLogger.ERROR, "Error reading resource: " + resource.getLocation());
            throw new RuntimeException(ex);
        }
        InputSource inputSource = new InputSource(new StringReader(content));
        inputSource.setPublicId(publicId);
        inputSource.setSystemId(resource.getPath());
        return inputSource;
    }
    /*
     * Let Sax find it on the interweb.
     */
    return null;
}

From source file:fr.onevu.gwt.uibinder.rebind.UiBinderGenerator.java

License:Apache License

private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime, ResourceOracle resourceOracle,
        String templatePath) throws UnableToCompleteException {

    Resource resource = resourceOracle.getResourceMap().get(templatePath);
    if (null == resource) {
        logger.die("Unable to find resource: " + templatePath);
    }//w  w w.j  a v a 2  s. c o  m

    Document doc = null;
    try {
        String content = designTime.getTemplateContent(templatePath);
        if (content == null) {
            content = Util.readStreamAsString(resource.openContents());
        }
        doc = new W3cDomHelper(logger.getTreeLogger(), resourceOracle).documentFor(content, resource.getPath());
    } catch (IOException iex) {
        logger.die("Error opening resource:" + resource.getLocation(), iex);
    } catch (SAXParseException e) {
        logger.die("Error parsing XML (line " + e.getLineNumber() + "): " + e.getMessage(), e);
    }
    return doc;
}

From source file:org.rstudio.core.rebind.command.CommandBundleGenerator.java

License:Open Source License

private NodeList getConfigDoc(String xpath) throws UnableToCompleteException {
    try {/*  w w w  .  j a va 2  s .  c om*/
        String resourceName = bundleType_.getQualifiedSourceName().replace('.', '/') + ".cmd.xml";
        Resource resource = context_.getResourcesOracle().getResource(resourceName);
        if (resource == null)
            return null;

        Object result = XPathFactory.newInstance().newXPath().evaluate(xpath,
                new InputSource(resource.getLocation()), XPathConstants.NODESET);
        return (NodeList) result;
    } catch (Exception e) {
        logger_.log(TreeLogger.Type.ERROR, "Barf", e);
        throw new UnableToCompleteException();
    }
}