Example usage for com.google.common.io Resources getResource

List of usage examples for com.google.common.io Resources getResource

Introduction

In this page you can find the example usage for com.google.common.io Resources getResource.

Prototype

public static URL getResource(Class<?> contextClass, String resourceName) 

Source Link

Document

Given a resourceName that is relative to contextClass , returns a URL pointing to the named resource.

Usage

From source file:org.sonar.server.issue.ws.AddCommentAction.java

@Override
public void define(WebService.NewController context) {
    WebService.NewAction action = context.createAction(IssuesWsParameters.ACTION_ADD_COMMENT)
            .setDescription("Add a comment.<br/>"
                    + "Requires authentication and the following permission: 'Browse' on the project of the specified issue.<br/>"
                    + "Since 6.3, the response contains the issue with all details, not only the added comment")
            .setSince("3.6").setHandler(this)
            .setResponseExample(Resources.getResource(this.getClass(), "add_comment-example.json"))
            .setPost(true);/*from  w ww.j  a  v  a 2 s.c  o m*/

    action.createParam(PARAM_ISSUE).setDescription("Issue key").setRequired(true)
            .setExampleValue(UUID_EXAMPLE_01);
    action.createParam(PARAM_TEXT).setDescription("Comment text").setRequired(true)
            .setExampleValue("Won't fix because it doesn't apply to the context");
}

From source file:com.nesscomputing.migratory.jdbi.MigratoryStatementLocator.java

@Override
public String locate(final String statementName, final StatementContext context) throws Exception {
    context.setAttribute(MigratoryStatementRewriter.SKIP_REWRITE, null);

    if (StringUtils.isEmpty(statementName)) {
        throw new IllegalStateException("Statement Name can not be empty/null!");
    }/*from  w w w .ja  va  2 s .  c  om*/

    // This is a recorded statement that comes from some loader. This needs
    // to be preregistered using addTemplate, so look there.
    if (statementName.charAt(0) == '@') {
        LOG.trace("Retrieving statement: %s", statementName);
        final String rawSql = sql.get(statementName);

        if (rawSql == null) {
            throw new IllegalStateException("Statement '" + statementName + "' not registered!");
        }

        // @T is a template.
        if (statementName.charAt(1) == 'T') {
            return templatize(rawSql, context);
        } else {
            context.setAttribute(MigratoryStatementRewriter.SKIP_REWRITE, Boolean.TRUE);
            return rawSql;
        }
    }
    // Or is it one of the internal statements used by
    // migratory to do its housekeeping? If yes, load it from the
    // predefined location on the class path.
    else if (statementName.charAt(0) == '#') {
        // Multiple templates can be in a string template group. In that case, the name is #<template-group:<statement name>
        final String[] statementNames = StringUtils.split(statementName.substring(1), ":");

        final String sqlLocation = SQL_LOCATION + context.getAttribute("db_type") + "/" + statementNames[0]
                + ".st";

        LOG.trace("Loading SQL: %s", sqlLocation);
        final URL location = Resources.getResource(MigratoryStatementLocator.class, sqlLocation);
        if (location == null) {
            throw new IllegalArgumentException("Location '" + sqlLocation + "' does not exist!");
        }
        final String rawSql = Resources.toString(location, Charsets.UTF_8);

        if (statementNames.length == 1) {
            // Plain string template file. Just run it.
            return templatize(rawSql, context);
        } else {
            final StringTemplateGroup group = new StringTemplateGroup(new StringReader(rawSql),
                    AngleBracketTemplateLexer.class);
            LOG.trace("Found %s in %s", group.getTemplateNames(), location);

            final StringTemplate template = group.getInstanceOf(statementNames[1]);
            template.setAttributes(context.getAttributes());
            final String sql = template.toString();

            LOG.trace("SQL: %s", sql);
            return sql;
        }
    }
    // Otherwise, it is raw SQL that was run on the database. Pass it through.
    else {
        context.setAttribute(MigratoryStatementRewriter.SKIP_REWRITE, Boolean.TRUE);
        return statementName;
    }
}

From source file:org.sonar.server.platform.ws.StatusAction.java

@Override
public void define(WebService.NewController controller) {
    controller.createAction("status").setDescription("Get the server status:" + "<ul>"
            + "<li>STARTING: SonarQube Web Server is up and serving some Web Services (eg. api/system/status) "
            + "but initialization is still ongoing</li>" + "<li>UP: SonarQube instance is up and running</li>"
            + "<li>DOWN: SonarQube instance is up but not running because SQ can not connect to database or "
            + "migration has failed (refer to WS /api/system/migrate_db for details) or some other reason (check logs).</li>"
            + "<li>RESTARTING: SonarQube instance is still up but a restart has been requested "
            + "(refer to WS /api/system/restart for details).</li>"
            + "<li>DB_MIGRATION_NEEDED: database migration is required. DB migration can be started using WS /api/system/migrate_db.</li>"
            + "<li>DB_MIGRATION_RUNNING: DB migration is running (refer to WS /api/system/migrate_db for details)</li>"
            + "</ul>").setSince("5.2")
            .setResponseExample(Resources.getResource(this.getClass(), "example-status.json")).setHandler(this);
}

From source file:com.facebook.buck.java.intellij.IjProjectWriter.java

private static ST getST(StringTemplateFile file) throws IOException {
    URL templateUrl = Resources.getResource(IjProjectWriter.class, file.getFileName());
    String template = Resources.toString(templateUrl, StandardCharsets.UTF_8);
    return new ST(template, DELIMITER, DELIMITER);
}

From source file:org.isisaddons.wicket.pdfjs.cpt.ui.PdfJsViewerPanel.java

PdfJsViewerPanel(String id, ScalarModel scalarModel) {
    super(id, scalarModel);

    final URL resource = Resources.getResource(PdfJsViewerPanel.class, "PdfJsViewerPanelCallbacks.template.js");
    try {/*from w  w w. j  a v a 2  s. c o m*/
        pdfJsViewerPanelCallbacksTemplateJs = Resources.toString(resource, Charsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}