Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

In this page you can find the example usage for java.lang String toString.

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:org.apache.archiva.redback.rbac.memory.MemoryAuthorizer.java

public AuthorizationResult isAuthorized(AuthorizationDataSource source) throws AuthorizationException {
    String principal = source.getPrincipal();

    String permission = source.getPermission();

    // TODO: Actually use a real permission!
    if ("foo".equals(permission.toString())) {
        return new AuthorizationResult(true, principal, null);
    } else {/*from   w w  w .  j a v  a 2 s.  c o m*/
        return new AuthorizationResult(false, principal, null);
    }
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.QueryMQL.java

public static String encodeMQL(String str) {
    StringBuilder retStr = new StringBuilder();

    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        //         int cp = Character.codePointAt(str, i);
        Matcher matcher = MQLKEY_CHAR_MUSTQUOTE.matcher("" + c);
        if (matcher.find()) {
            retStr.append("$" + toHex("" + c));
        } else//from ww  w .  j a  va2 s .com
            retStr.append(c);
    }
    if (retStr.toString().endsWith("-")) {
        String tmp = retStr.toString();
        int idx = tmp.lastIndexOf("-");
        str = new StringBuilder(tmp).replace(idx, idx + 1, "$002D").toString();
        return str.toString();
    }
    if (retStr.toString().startsWith("-")) {
        String tmp = retStr.toString();
        int idx = tmp.indexOf("-");
        str = new StringBuilder(tmp).replace(idx, idx + 1, "$002D").toString();
        return str.toString();
    }
    return retStr.toString();
}

From source file:com.flipkart.poseidon.api.APILoaderTest.java

@Test
public void testGetBuildableMapCompeteUrl() throws Exception {
    APILoader loader = new APILoader(legoSet, configs, configuration);
    Map<String, Buildable> buildableMap = loader.getBuildableMap();

    String url = "/home/test";
    String method = "POST";
    String completeUrl = ApiHelper.getUrlWithHttpMethod(url, method.toString());

    assertEquals(2, buildableMap.size());
    assertNotNull(buildableMap.get(completeUrl));
    assertTrue(buildableMap.get(completeUrl) instanceof APIBuildable);
    APIBuildable apiBuildable = (APIBuildable) buildableMap.get(completeUrl);
    assertEquals(url, apiBuildable.getPojo().getUrl());
}

From source file:com.flipkart.poseidon.api.APILoaderTest.java

@Test
public void testGetBuildableMapCompeteUrlWithMissingSlash() throws Exception {
    APILoader loader = new APILoader(legoSet, configs, configuration);
    Map<String, Buildable> buildableMap = loader.getBuildableMap();

    String url = "/shop/test";
    String method = "POST";
    String completeUrl = ApiHelper.getUrlWithHttpMethod(url, method.toString());

    assertEquals(2, buildableMap.size());
    assertNotNull(buildableMap.get(completeUrl));
    assertTrue(buildableMap.get(completeUrl) instanceof APIBuildable);
    APIBuildable apiBuildable = (APIBuildable) buildableMap.get(completeUrl);
    assertEquals(url, apiBuildable.getPojo().getUrl());
}

From source file:com.github.jknack.handlebars.MapTemplateLoader.java

@Override
public TemplateSource sourceAt(final String uri) throws FileNotFoundException {
    notNull(uri, "The uri is required.");
    notEmpty(uri.toString(), "The uri is required.");
    String location = resolve(normalize(uri));
    String text = map.get(location);
    if (text == null) {
        throw new FileNotFoundException(location);
    }/*from www. j  a  va 2s .  c  o  m*/
    return new StringTemplateSource(location, text);
}

From source file:org.appverse.web.framework.backend.security.xs.autoconfigure.XssFilterProperties.java

private void addInitParameter(String name, String value) {
    if (value != null) {
        this.initParameters.put(name, value.toString());
    }/*from  w  w  w. ja va2 s.  co m*/
}

From source file:eu.modaclouds.sla.service.rest.MetricsReceiverRest.java

@POST
@Path("/{agreementId}")
@Produces(MediaType.TEXT_PLAIN)//from w  w  w.j a v  a 2s.c o  m
public Response receiveModacloudsMetrics(@PathParam("agreementId") String agreementId, final String metrics) {

    logger.debug("receiveMetrics(agreementId=" + agreementId + ", data=" + metrics.toString());
    IAgreement agreement = agreementDao.getByAgreementId(agreementId);
    logger.debug("agreement=" + agreement.getAgreementId());

    Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = translator.translate(agreement, metrics);
    enforcementService.doEnforcement(agreement, metricsMap);
    return buildResponse(HttpStatus.ACCEPTED, "Metrics received");
}

From source file:eu.planets_project.pp.plato.validators.TreeValidator.java

/**
 * Traverses through the CoreTreeTable and validates each TreeNode in the CoreTreeTable.
 *
 * Overrides {@link eu.planets_project.pp.plato.validators.ITreeValidator#validate(TreeNode, INodeValidator, INodeValidator, List, boolean)}
 *
 * @see eu.planets_project.pp.plato.validators.ITreeValidator#validate(TreeModel, CoreTreeTable, INodeValidator, List, boolean)
 *///from   w w w . j  a  v a2  s . c o  m
public boolean validate(TreeNode node, INodeValidator validator, List<TreeNode> nodes,
        boolean showValidationErrors) {

    List<String> messages = new ArrayList<String>();
    this.validator = validator;
    boolean validates = true;

    validates = validateRow(node, messages, nodes);

    if (showValidationErrors) {
        for (String errorMessage : messages) {
            log.debug("Error at: " + errorMessage.toString());
            FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, errorMessage);
        }
    }

    log.debug(validates);
    return validates;
}

From source file:org.kie.smoke.wb.util.RestUtil.java

public static <T> T postEntity(URL deploymentUrl, String relativeUrl, int status, String user, String password,
        Class[] classes, Object entity, Class<T>... responseTypes) {

    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    String mediaType = MediaType.APPLICATION_XML;
    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);
    XmlResponseHandler xrh = (XmlResponseHandler) rh;

    xrh.addExtraJaxbClasses(classes);//from   w  ww. j  ava  2s  .c  o m
    String entityStr = xrh.serialize(entity);

    HttpEntity bodyEntity = null;
    try {
        bodyEntity = new StringEntity(entityStr);
    } catch (UnsupportedEncodingException uee) {
        logAndFail("Unable to encode serialized " + entity.getClass().getSimpleName() + " entity", uee);
    }

    // @formatter:off
    Request request = Request.Post(uriStr).body(bodyEntity)
            .addHeader(HttpHeaders.CONTENT_TYPE, mediaType.toString())
            .addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:on

    Response resp = null;
    try {
        logOp("POST", entity, uriStr);
        resp = request.execute();
    } catch (Exception e) {
        logAndFail("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        logAndFail("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}

From source file:org.kie.remote.tests.base.RestUtil.java

public static <T> T postEntity(URL deploymentUrl, String relativeUrl, int status, String user, String password,
        Class[] classes, Object entity, Class<T>... responseTypes) {

    String uriStr = createBaseUriString(deploymentUrl, relativeUrl);

    String mediaType = MediaType.APPLICATION_XML;
    ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes);
    XmlResponseHandler xrh = (XmlResponseHandler) rh;

    xrh.addExtraJaxbClasses(classes);/*from  www  .  j  av a2s  . com*/
    String entityStr = xrh.serialize(entity);

    HttpEntity bodyEntity = null;
    try {
        bodyEntity = new StringEntity(entityStr);
    } catch (UnsupportedEncodingException uee) {
        failAndLog("Unable to encode serialized " + entity.getClass().getSimpleName() + " entity", uee);
    }

    // @formatter:off
    Request request = Request.Post(uriStr).body(bodyEntity)
            .addHeader(HttpHeaders.CONTENT_TYPE, mediaType.toString())
            .addHeader(HttpHeaders.ACCEPT, mediaType.toString())
            .addHeader(HttpHeaders.AUTHORIZATION, basicAuthenticationHeader(user, password));
    // @formatter:on

    Response resp = null;
    try {
        logOp("POST", entity, uriStr);
        resp = request.execute();
    } catch (Exception e) {
        failAndLog("[GET] " + uriStr, e);
    }

    try {
        return resp.handleResponse(rh);
    } catch (Exception e) {
        failAndLog("Failed retrieving response from [GET] " + uriStr, e);
    }

    // never happens
    return null;
}