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:com.fluidops.iwb.widget.CodeExecutionWidget.java

/**
 * This is an example static method that could be called,
 * the widget configuration for calling this method is as follows.
 * /*ww w . j  av a 2s  .  c o m*/
 * <code>
*   {{#widget: CodeExecution
* | label = 'Test 7'
* | clazz = 'com.fluidops.iwb.widget.CodeExecutionWidget'
* | method = 'testMe2'
* | args = {{ $this.a$ }}
* | passContext = true
* }}
* </code> 
 */
@SuppressWarnings("deprecation")
@CallableFromWidget
public static void testMe2(CodeExecutionContext ceCtx, String value) {
    ceCtx.parentComponent.doCallback("alert('Clicked on "
            + StringEscapeUtils.escapeHtml(value == null ? "(undefined)" : value.toString()) + "');");
}

From source file:bullioneconomy.bullionchart.java

public static int[] dateget(String i) throws ParseException {
    String inputDateString = i.trim().replaceAll(" ", "-");
    //System.out.println(inputDateString);
    DateFormat dfTo = new SimpleDateFormat("dd-MMM-yyyy");
    Date inputDate = dfTo.parse(inputDateString);
    DateFormat dayf = new SimpleDateFormat("dd");
    DateFormat monthf = new SimpleDateFormat("MM");
    DateFormat yearf = new SimpleDateFormat("yyyy");
    String oDay = dayf.format(inputDate);
    String oMonth = monthf.format(inputDate);
    String oYear = yearf.format(inputDate);
    int[] k = new int[3];
    k[0] = Integer.parseInt(oDay.toString());
    k[1] = Integer.parseInt(oMonth.toString());
    k[2] = Integer.parseInt(oYear.toString());

    return k;/*w w  w .ja v  a  2  s .c  om*/
}

From source file:com.shenit.commons.utils.ShenStrings.java

/**
 * Joins list of string items to a single string, where items are separated
 * with a defined separator.//from   www.  j a  va  2 s.com
 *
 * @param list      to join into string
 * @param separator to be used between elements
 * @return items joined into a single string
 */
public static String joinAll(List<?> list, String separator) {

    if (separator == null || separator.toString().equalsIgnoreCase("")) {
        throw new IllegalArgumentException("Missing separator!");
    }

    String output = "";

    if (list != null && list.size() > 0) {
        for (int i = 1; i <= list.size(); i++) {
            output = output + list.get(i - 1);
            if (i < list.size()) {
                output = output + separator;
            }
        }
    }

    return output;
}

From source file:com.baasbox.service.storage.DocumentService.java

public static ODocument update(String collectionName, String rid, JsonNode bodyJson, PartsParser pp)
        throws MissingNodeException, InvalidCollectionException, InvalidModelException, ODatabaseException,
        IllegalArgumentException, DocumentNotFoundException {
    ODocument od = get(rid);//from w  w  w.  j  av  a 2  s  . com
    if (od == null)
        throw new InvalidParameterException(rid + " is not a valid document");
    ObjectMapper mapper = new ObjectMapper();
    StringBuffer q = new StringBuffer("");

    if (!pp.isMultiField() && !pp.isArray()) {
        q.append("update ").append(collectionName).append(" set ").append(pp.treeFields()).append(" = ")
                .append(bodyJson.get("data").toString());

    } else {
        q.append("update ").append(collectionName).append(" merge ");
        String content = od.toJSON();
        ObjectNode json = null;
        try {
            json = (ObjectNode) mapper.readTree(content.toString());
        } catch (Exception e) {
            throw new RuntimeException("Unable to modify inline json");
        }
        JsonTree.write(json, pp, bodyJson.get("data"));
        q.append(json.toString());
    }
    q.append(" where @rid = ").append(rid);
    try {
        DocumentDao.getInstance(collectionName).updateByQuery(q.toString());
    } catch (OSecurityException e) {
        throw e;
    } catch (InvalidCriteriaException e) {
        throw new RuntimeException(e);
    }
    od = get(collectionName, rid);
    return od;
}

From source file:models.utils.StringUtils.java

public static String purgeNull(String str, String defaultValue) {
    if (defaultValue == null) {
        throw new IllegalArgumentException("default value cannot be null");
    }/*from   ww  w  . j  a  va 2  s .c  om*/
    if (str == null)
        return defaultValue;
    return str.toString();
}

From source file:de.vandermeer.asciithemes.TA_CheckedItem.java

/**
 * Creates a new checked item./* w w w. j a v  a 2 s. c o  m*/
 * @param checked checked label string
 * @param unchecked unckecked label string
 * @param description item description
 * @return new checked item
 */
public static TA_CheckedItem create(final String checked, final String unchecked, final String description) {
    Validate.notNull(checked);
    Validate.notNull(unchecked);
    Validate.notBlank(description);

    return new TA_CheckedItem() {
        @Override
        public String getUncheckedLabel() {
            return unchecked.toString();
        }

        @Override
        public String getCheckedLabel() {
            return checked.toString();
        }

        @Override
        public String getDescription() {
            return description;
        }
    };
}

From source file:io.gravitee.management.service.impl.PageServiceImpl.java

private static Page convert(NewPageEntity newPageEntity) {
    Page page = new Page();

    page.setName(newPageEntity.getName());
    final String type = newPageEntity.getType();
    if (type != null) {
        page.setType(io.gravitee.repository.management.model.PageType.valueOf(type.toString()));
    }/*from   w w w.  j  a v a  2 s.com*/
    page.setContent(newPageEntity.getContent());
    page.setLastContributor(newPageEntity.getLastContributor());
    page.setOrder(newPageEntity.getOrder());
    return page;
}

From source file:cpcc.ros.sim.osm.TileCache.java

/**
 * @param url the URL of the desired file.
 * @param file the path where to store the retrieved data.
 * @throws IOException thrown in case of errors.
 *//*from  ww  w. j  av a2 s . com*/
public static void downloadFile(String url, File file) throws IOException {
    // TODO extract in a service.
    HttpResponse response = null;
    try {
        response = HttpClientBuilder.create().setUserAgent("TileCache/1.0").build().execute(new HttpGet(url));
    } catch (IOException e) {
        LOG.error("Can not load URL '" + url.toString() + "'", e);
        throw e;
    }

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        String msg = String.format("Can not load URL '%s' code=%d (%s)", url.toString(),
                response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
        LOG.error(msg);
        throw new IOException(msg);
    }

    HttpEntity entity = response.getEntity();
    if (entity != null) {
        try (FileOutputStream outStream = new FileOutputStream(file)) {
            IOUtils.copy(entity.getContent(), outStream);
        }
    }
}

From source file:de.l3s.boilerpipe.sax.HTMLFetcher.java

public static HTMLDocument fetch(final String url) throws IOException {
    //DefaultHttpClient httpclient = new DefaultHttpClient();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet request = new HttpGet(url.toString());
    request.setHeader("User-Agent",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36");
    request.setHeader("Referer", "http://www.google.com");

    HttpResponse response = httpclient.execute(request);
    HttpEntity entity = response.getEntity();
    //System.out.println("Response Code: " +
    //response.getStatusLine().getStatusCode());
    ContentType contentType = ContentType.getOrDefault(entity);
    Charset charset = contentType.getCharset();
    if (charset == null) {
        charset = Charset.forName("gb2312");
    }/*  w  w  w  .j av  a 2s  .  c o  m*/

    BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent(), charset));

    StringBuilder builder = new StringBuilder();
    String aux = "";
    Charset cs = Charset.forName("utf8");
    boolean charsetFlag = false;
    while ((aux = rd.readLine()) != null) {
        if (aux != null && !charsetFlag && (aux.contains("http-equiv") || !aux.contains("src"))) {
            Matcher m = PAT_CHARSET_REX.matcher(aux);
            if (m.find()) {
                final String cName = m.group(1);
                charsetFlag = true;
                try {
                    cs = Charset.forName(cName);
                    break;
                } catch (UnsupportedCharsetException e) {
                    // keep default
                }
            }
        }
        //builder.append(aux);
        //System.out.println(builder.toString());
    }

    HttpGet request2 = new HttpGet(url.toString());
    request2.setHeader("User-Agent",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36");
    request2.setHeader("Referer", "http://www.google.com");

    HttpResponse response2 = httpclient.execute(request2);
    HttpEntity entity2 = response2.getEntity();
    contentType = ContentType.getOrDefault(entity2);
    charset = contentType.getCharset();
    if (charset == null)
        charset = cs;
    //if(charset.name().toLowerCase().equals("gb2312"))
    //   charset = Charset.forName("gbk");
    BufferedReader rd2 = new BufferedReader(new InputStreamReader(entity2.getContent(), charset));
    while ((aux = rd2.readLine()) != null) {
        builder.append(aux);
        //System.out.println(builder.toString());
    }

    String text = builder.toString();
    //System.out.println(text);
    rd.close();
    rd2.close();
    return new HTMLDocument(text, cs); //sometimes cs not equal to charset
}

From source file:com.siberhus.web.ckeditor.utils.PathUtils.java

public static String normalizePath(String path) {
    String tokens[] = StringUtils.split(path, File.separator);
    List<String> tokenList = Arrays.asList(tokens);
    Stack<String> tokenStack = new Stack<String>();
    for (String token : tokenList) {
        if (".".equals(token)) {
            // skip
        } else if ("..".equals(token)) {
            tokenStack.pop();// www  .ja  va 2  s. co  m
        } else {
            tokenStack.push(token);
        }
    }
    String result = "";
    if (path.startsWith(File.separator)) {
        result += File.separator;
    }
    result += StringUtils.join(tokenStack, File.separator);
    if (path.endsWith(File.separator)) {
        result += File.separator;
    }
    return result.toString();
}