List of usage examples for java.lang String toString
public String toString()
From source file:de.vandermeer.skb.interfaces.transformers.String_To_ConditionalBreak.java
/** * Transforms a String to a String[] processing conditional line breaks. * Conditional line breaks are CR LF, CR, LF, <br>, and <br/>. * /*from w w w. j a va 2 s .c om*/ * The method proceeds as follows: * * . replace all line breaks (CR LF, CR, LF) into HTML4 line break entity <br> * . replace all HTML4 line break entities to HTML5 entities (as in self-closing <br/> entity). * . use a `tokenizer` to process the resulting string (not ignoring empty tokens, since they mark required line breaks). * . return the array of the `tokenizer` * * As a result, a string containing 1 line break will be converted into an array length 2: * ---- * String: "paragraph 1\nparagraph 2" * Array: {paragraph 1,paragraph 2} * ---- * * A string containing 2 line breaks will be converted into a string array with 3 entries (first paragraph, additional line break, second paragraph): * ---- * String: "paragraph 1\n\nparagraph 2" * Array: {paragraph 1,,paragraph 2} * ---- * * @param s input string * @return array with conditional line breaks converted to empty entries, `null` if `s` was `null` */ @Override default String[] transform(String s) { IsTransformer.super.transform(s); if ("".equals(s)) { return new String[] { "" }; } String lfRep = StringUtils.replacePattern(s.toString(), "\\r\\n|\\r|\\n", "<br>"); lfRep = StringUtils.replace(lfRep, "<br>", "<br/>"); lfRep = StringUtils.replace(lfRep, "<br/>", "<br />"); StrTokenizer tok = new StrTokenizer(lfRep, "<br />").setIgnoreEmptyTokens(false); return tok.getTokenArray(); }
From source file:it.delli.mwebc.utils.DefaultCastHelper.java
private String toString(String value) { return value.toString(); }
From source file:com.addthis.hydra.data.query.DiskBackedMap.java
@Override public T put(String s, T t) { Object old = db.put(new DBKey(0, s.toString()), new CodableDiskObject(t)); if (old != null) { return (T) ((CodableDiskObject) old).getDiskObject(); } else {//from w w w. jav a2 s. c o m return null; } }
From source file:org.activiti.rest.util.MultipartRequestObject.java
public Integer getInt(String param) { String value = this.request.getParameter(param); try {// www . j av a 2s. co m return Integer.parseInt(value); } catch (NumberFormatException e) { throw ActivitiRequest.getInvalidTypeException(param, value.toString(), INTEGER); } }
From source file:org.kie.smoke.wb.util.RestUtil.java
public static <T> T postEntity(URL deploymentUrl, String relativeUrl, String mediaType, int status, String user, String password, double timeoutInSecs, Object entity, Class<T>... responseTypes) { String uriStr = createBaseUriString(deploymentUrl, relativeUrl); ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); String entityStr = ((AbstractResponseHandler) rh).serialize(entity); HttpEntity bodyEntity = null;/*ww w. j a v a 2 s . co m*/ 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; long before = 0, after = 0; try { logOp("POST", entity, uriStr); before = System.currentTimeMillis(); resp = request.execute(); after = System.currentTimeMillis(); } catch (Exception e) { logAndFail("[GET] " + uriStr, e); } long duration = after - before; assertTrue("Timeout exceeded " + timeoutInSecs + " secs: " + ((double) duration / 1000d) + " secs", duration < timeoutInSecs * 1000); 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, String mediaType, int status, String user, String password, double timeoutInSecs, Object entity, Class<T>... responseTypes) { String uriStr = createBaseUriString(deploymentUrl, relativeUrl); ResponseHandler<T> rh = createResponseHandler(mediaType, status, responseTypes); String entityStr = ((AbstractResponseHandler) rh).serialize(entity); HttpEntity bodyEntity = null;//from ww w. j a v a2 s . c o m 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; long before = 0, after = 0; try { logOp("POST", entity, uriStr); before = System.currentTimeMillis(); resp = request.execute(); after = System.currentTimeMillis(); } catch (Exception e) { failAndLog("[GET] " + uriStr, e); } long duration = after - before; assertTrue("Timeout exceeded " + timeoutInSecs + " secs: " + ((double) duration / 1000d) + " secs", duration < timeoutInSecs * 1000); try { return resp.handleResponse(rh); } catch (Exception e) { failAndLog("Failed retrieving response from [GET] " + uriStr, e); } // never happens return null; }
From source file:br.com.vrbsm.fillup.controller.FillUpController.java
@Override public Object parse(int operationCode, String json) throws Exception { Log.d("***_Result_****", "CODE - " + operationCode); Log.d("***_Result_****", json); if (!json.equals("200")) throw new Exception(json); return json.toString(); }
From source file:fi.koku.services.utility.authorization.impl.GroupServiceLDAPImpl.java
private List<LdapPerson> getPersonDnsByPics(List<String> pics) { SearchControls ctrl = new SearchControls(); ctrl.setReturningAttributes(new String[] { "uid" }); ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE); String q = getPersonsQuery(pics); logger.debug("getPersonDnsByPics: query: " + q.toString()); List<LdapPerson> persons = ldapTemplate.search("", q, ctrl, new LdapPersonMapper(), new DirContextProcessorNoop()); logger.debug("persons: " + persons.size()); return persons; }
From source file:com.mobshep.shepherdlogin.LoggedIn.java
public void submitClicked(View v) { String apiKey = "thisIsTheAPIKey"; ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("mobileKey", apiKey)); try {//from w w w. j a va2 s . co m SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String address = SP.getString("server_preference", "NA"); String res = CustomHttpClient.executeHttpPost(address + "/vulMobileAPI", postParameters); JSONObject jObject = new JSONObject(res.toString()); String response = jObject.getString("LEVELKEY"); response = response.replaceAll("\\s+", ""); Toast responseError = Toast.makeText(LoggedIn.this, response.toString(), Toast.LENGTH_SHORT); responseError.show(); if (res != null) { storedPref = getSharedPreferences("Sessions", MODE_PRIVATE); toEdit = storedPref.edit(); toEdit.putString("LEVELKEY", response); toEdit.commit(); } else { Toast.makeText(getBaseContext(), "Invalid API Key!", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { Toast responseError = Toast.makeText(LoggedIn.this, e.toString(), Toast.LENGTH_LONG); responseError.show(); } }
From source file:com.jaeksoft.searchlib.parser.EmlParser.java
@Override protected void parseContent(StreamLimiter streamLimiter, LanguageEnum lang) throws IOException, SearchLibException { Session session = Session.getDefaultInstance(JAVAMAIL_PROPS); try {//from w ww . ja v a 2 s . c o m MimeMessage mimeMessage = new MimeMessage(session, streamLimiter.getNewInputStream()); MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse(); ParserResultItem result = getNewParserResultItem(); String from = mimeMessageParser.getFrom(); if (from != null) result.addField(ParserFieldEnum.email_display_from, from.toString()); for (Address address : mimeMessageParser.getTo()) result.addField(ParserFieldEnum.email_display_to, address.toString()); for (Address address : mimeMessageParser.getCc()) result.addField(ParserFieldEnum.email_display_cc, address.toString()); for (Address address : mimeMessageParser.getBcc()) result.addField(ParserFieldEnum.email_display_bcc, address.toString()); result.addField(ParserFieldEnum.subject, mimeMessageParser.getSubject()); result.addField(ParserFieldEnum.htmlSource, mimeMessageParser.getHtmlContent()); result.addField(ParserFieldEnum.content, mimeMessageParser.getPlainContent()); result.addField(ParserFieldEnum.email_sent_date, mimeMessage.getSentDate()); result.addField(ParserFieldEnum.email_received_date, mimeMessage.getReceivedDate()); for (DataSource dataSource : mimeMessageParser.getAttachmentList()) { result.addField(ParserFieldEnum.email_attachment_name, dataSource.getName()); result.addField(ParserFieldEnum.email_attachment_type, dataSource.getContentType()); if (parserSelector == null) continue; Parser attachParser = parserSelector.parseStream(getSourceDocument(), dataSource.getName(), dataSource.getContentType(), null, dataSource.getInputStream(), null, null, null); if (attachParser == null) continue; List<ParserResultItem> parserResults = attachParser.getParserResults(); if (parserResults != null) for (ParserResultItem parserResult : parserResults) result.addField(ParserFieldEnum.email_attachment_content, parserResult); } if (StringUtils.isEmpty(mimeMessageParser.getHtmlContent())) result.langDetection(10000, ParserFieldEnum.content); else result.langDetection(10000, ParserFieldEnum.htmlSource); } catch (Exception e) { throw new IOException(e); } }