List of usage examples for java.util Objects toString
public static String toString(Object o, String nullDefault)
From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java
/** * Gen http request dump./* w ww . j a v a 2 s .c o m*/ * * @param req the req * @return the string */ @SuppressWarnings("unchecked") public static String genHttpRequestDump(HttpServletRequest req) { StringBuilder sb = new StringBuilder(); sb.append("method: ").append(req.getMethod()).append('\n')// .append("requestURL: ").append(req.getRequestURL()).append('\n')// .append("servletPath: ").append(req.getServletPath()).append('\n')// .append("requestURI: ").append(req.getRequestURI()).append('\n') // .append("queryString: ").append(req.getQueryString()).append('\n') // .append("pathInfo: ").append(req.getPathInfo()).append('\n')// .append("contextPath: ").append(req.getContextPath()).append('\n') // .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') // .append("localName: ").append(req.getLocalName()).append('\n') // .append("contentLength: ").append(req.getContentLength()).append('\n') // ; sb.append("Header:\n"); for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) { String hn = en.nextElement(); sb.append(" ").append(hn).append(": ").append(req.getHeader(hn)).append("\n"); } sb.append("Attr: \n"); Enumeration en = req.getAttributeNames(); for (; en.hasMoreElements();) { String k = (String) en.nextElement(); Object v = req.getAttribute(k); sb.append(" ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n'); } return sb.toString(); }
From source file:org.openhab.action.pushbullet.internal.PushbulletActionService.java
/** * @{inheritDoc}/* ww w . j a v a 2 s. c om*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String defaultAccessToken = Objects.toString(config.get(ACCESS_TOKEN_KEY), null); String botNames = Objects.toString(config.get(BOTS_KEY), null); if (StringUtils.isNotEmpty(botNames)) { String[] bots = botNames.split(","); for (String botName : bots) { botName = botName.trim(); String accessTokenKey = String.format("%s.%s", botName, ACCESS_TOKEN_KEY); String accessToken = Objects.toString(config.get(accessTokenKey), defaultAccessToken); PushbulletAPIConnector.addBot(botName, accessToken); } } // Now, try to configure the default bot just in case we have older configuration around PushbulletAPIConnector.addBot(DEFAULT_BOTNAME, defaultAccessToken); PushbulletAPIConnector.logPushbulletBots(); if (PushbulletAPIConnector.botCount() > 0) { isProperlyConfigured = true; } } logger.debug("Parsing configuration done, configuration is {}", isProperlyConfigured); }
From source file:com.feilong.taglib.common.AbstractContainsSupport.java
/** * {@link Iterator},??<code>value</code>?. * /*from ww w. j a v a 2 s. co m*/ * <p style="color:red"> * ?,{@link java.util.Objects#toString(Object, String)},el function * </p> * * @param iterator * iterator * @param value * value * @return iteratornull/empty,false<br> * ? <code>iterator</code>,?String,? <code>value</code>String,true * @see "org.springframework.util.CollectionUtils#contains(Iterator, Object)" * @see org.apache.commons.collections4.IteratorUtils#contains(Iterator, Object) * @since 1.7.2 */ public static boolean containsByStringValue(Iterator<?> iterator, Object value) { if (isNullOrEmpty(iterator)) { return false; } while (iterator.hasNext()) { Object object = iterator.next(); //?:null,java.util.Objects#toString(Object), "null" java.lang.String#valueOf(Object) // org.apache.commons.lang3.ObjectUtils#toString(Object) "" empty //?equals ,true if (Objects.toString(object, EMPTY).equals(Objects.toString(value, EMPTY))) { return true; } } return false; }
From source file:xbdd.webapp.factory.ServletContextMongoClientFactory.java
public ServletContextMongoClientFactory(@Context final ServletContext context) { this.host = Objects.toString(context.getInitParameter(XBDD_MONGO_HOSTNAME_INIT_PARAMETER), ServerAddress.defaultHost()); this.username = context.getInitParameter(XBDD_MONGO_USERNAME_INIT_PARAMETER); this.password = context.getInitParameter(XBDD_MONGO_PASSWORD_INIT_PARAMETER) != null ? context.getInitParameter(XBDD_MONGO_PASSWORD_INIT_PARAMETER).toCharArray() : null;/*from w w w. ja v a 2 s . c o m*/ this.port = NumberUtils.isNumber(context.getInitParameter(XBDD_MONGO_PORT_INIT_PARAMETER)) ? Integer.parseInt(context.getInitParameter(XBDD_MONGO_PORT_INIT_PARAMETER)) : ServerAddress.defaultPort(); }
From source file:eu.itesla_project.online.tools.OnlineWorkflowTool.java
private void showHelp(String message) { System.err.println(message);//from w w w. j a va 2s . c o m System.err.println(); HelpFormatter formatter = new HelpFormatter(); // it would be nice to have access to the private method eu.itesla_project.commons.tools.Main.printCommandUsage formatter.printHelp(80, getCommand().getName(), "", getCommand().getOptions(), "\n" + Objects.toString(getCommand().getUsageFooter(), ""), true); }
From source file:com.hubspot.jinjava.lib.filter.EscapeFilter.java
@Override public Object filter(Object object, JinjavaInterpreter interpreter, String... arg) { return escapeHtmlEntities(Objects.toString(object, "")); }
From source file:de.micromata.genome.db.jdbc.trace.SqlLiteralArgRenderer.java
@Override public String renderSqlArg(Object arg) { if (arg instanceof String) { // TODO replace with proper SQL escaping return "'" + StringUtils.replace((String) arg, "'", "''") + "'"; }// w w w.j a v a2 s .com if (arg instanceof Integer || arg instanceof Long || arg instanceof Short || arg instanceof Byte) { return Objects.toString(arg, StringUtils.EMPTY); } if (arg instanceof BigDecimal) { return Objects.toString(arg, StringUtils.EMPTY); // TODO } if (arg instanceof Date) { return '#' + sqlDateFormatter.get().format((Date) arg) + '#'; } if (arg instanceof Time) { return '#' + sqlTimeFormatter.get().format((Time) arg) + '#'; } if (arg instanceof Timestamp) { return '#' + sqlTimestampFormatter.get().format((Timestamp) arg) + '#'; } if (arg instanceof java.util.Date) { return '#' + sqlTimestampFormatter.get().format((java.util.Date) arg) + '#'; } // TODO andere typen unterstuetzen return Objects.toString(arg, StringUtils.EMPTY); }
From source file:com.norconex.collector.core.crawler.event.CrawlerEventManager.java
private String getLogMessage(CrawlerEvent event, boolean includeSubject) { StringBuilder b = new StringBuilder(); b.append(StringUtils.leftPad(event.getEventType(), ID_PRINT_WIDTH)); if (event.getCrawlData() != null) { b.append(": "); b.append(event.getCrawlData().getReference()); }//w ww .ja v a 2 s . c om if (includeSubject) { b.append(" (Subject: "); b.append(Objects.toString(event.getSubject(), "none")); b.append(")"); } return b.toString(); }
From source file:com.github.fengtan.sophie.dialogs.EditListValueDialog.java
@Override protected Control createDialogArea(final Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); composite.setLayout(new RowLayout()); // Create list widget. listViewer = new ListViewer(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER); for (Object value : defaultValue) { listViewer.add(Objects.toString(value, StringUtils.EMPTY)); }/*ww w .j av a 2 s. com*/ // Create add/remove buttons. Composite buttonsComposite = new Composite(composite, SWT.NULL); buttonsComposite.setLayout(new FillLayout(SWT.VERTICAL)); Button buttonAdd = new Button(buttonsComposite, SWT.PUSH); buttonAdd.setText("Add"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { InputDialog input = new InputDialog(parent.getShell(), "Add value", "Add value:", null, null); input.open(); if (input.getReturnCode() == IDialogConstants.OK_ID) { listViewer.add(input.getValue()); } } }); Button buttonRemove = new Button(buttonsComposite, SWT.PUSH); buttonRemove.setText("Remove"); buttonRemove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); if (!selection.isEmpty()) { listViewer.remove(selection.toArray()); } } }); return composite; }
From source file:xbdd.webapp.resource.feature.PrintPDF.java
@GET @Path("/{product}/{major}.{minor}.{servicePack}/{build}/") public Response viewPDF(@BeanParam final Coordinates coord, @Context final HttpServletRequest request, @Context final ServletContext context, @QueryParam("view") final String view) throws URISyntaxException { final String urlcontext = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); final String previousPage = request.getHeader("Referer"); final String productString = "/" + coord.getProduct() + "/" + coord.getVersionString() + "/" + coord.getBuild();// w w w .j a v a2 s.c o m final String urlstring = urlcontext + "/print/" + productString; // Getting the location of PHANTOMJS_HOME environment variable final String phantomjsloc = Objects.toString(context.getInitParameter(XBDD_PHANTOMJS_HOME_INIT_PARAMETER), System.getProperty("PHANTOMJS_HOME")); if (phantomjsloc == null) { final URI location = new URI(previousPage + "&phantom=no"); return Response.temporaryRedirect(location).build(); } else { final String username = Objects.toString( context.getInitParameter(XBDD_PHANTOMJS_USERNAME_INIT_PARAMETER), System.getProperty("PHANTOMJS_USER")); final String password = Objects.toString( context.getInitParameter(XBDD_PHANTOMJS_PASSWORD_INIT_PARAMETER), System.getProperty("PHANTOMJS_PASSWORD")); final StreamingOutput stream = createPDFStream(urlstring, phantomjsloc, context.getRealPath("/WEB-INF/rasterize.js"), username, password); String viewType = "inline"; // View in browser or download as attachment if (view != null) { viewType = view; } final ResponseBuilder response = Response.ok(stream); response.type("application/pdf"); response.status(200); response.header("Content-Disposition", viewType + "; filename=\"" + coord.getProduct() + " Version=" + coord.getVersionString() + ", Build=" + coord.getBuild() + ".pdf\""); return response.build(); } }