List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str, final String defaultStr)
Returns either the passed in String, or if the String is null , the value of defaultStr .
StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"
From source file:architecture.user.spring.config.SecurityConfig.java
@Bean(name = "nonAjaxRequestMatcher") public RequestMatcher nonAjaxRequestMatcher() { return new RequestMatcher() { @Override/*ww w .j ava 2 s . co m*/ public boolean matches(HttpServletRequest request) { if (!"XmlHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) { return true; } OutputFormat format = OutputFormat .stingToOutputFormat(StringUtils.defaultString(request.getParameter("output"), "html")); if (format == OutputFormat.HTML) return true; return false; } }; }
From source file:controllers.modules.SetCoverBuilder.java
@BodyParser.Of(play.mvc.BodyParser.Json.class) public static Result update(final UUID corpus, UUID setcover) { DocumentCorpus corpusObj = null;/* w w w. j a v a 2s . co m*/ if (corpus != null) { corpusObj = fetchResource(corpus, DocumentCorpus.class); } // make sure we have the right combination. DocumentSetCover setCoverObj = null; if (setcover != null) { setCoverObj = fetchResource(setcover, DocumentSetCover.class); if (corpusObj == null) { corpusObj = setCoverObj.getBaseCorpus(); } else if (ObjectUtils.notEqual(corpusObj, setCoverObj.getBaseCorpus())) { throw new IllegalArgumentException(); } } else if (corpusObj == null) { throw new IllegalArgumentException(); } JsonNode jsonBody = request().body().asJson(); if (jsonBody == null && setcover != null) { throw new IllegalArgumentException(); } if (jsonBody == null) { jsonBody = JsonNodeFactory.instance.objectNode(); } DocumentSetCoverModel setCoverVM = null; setCoverVM = Json.fromJson(jsonBody, DocumentSetCoverModel.class); final SetCoverFactory factory = (SetCoverFactory) setCoverVM.toFactory().setOwnerId(getUsername()); // set the default title. if (setcover == null && StringUtils.isEmpty(factory.getTitle())) { factory.setTitle("Optimized " + corpusObj.getTitle()); } SetCoverFactory tmpFactory = (SetCoverFactory) new SetCoverFactory().setStore(corpusObj) .setTitle(factory.getTitle()).setDescription(factory.getDescription()) .setOwnerId(factory.getOwnerId()); // make basic creation/updation first. if (setcover == null) { setCoverObj = tmpFactory.create(); em().persist(setCoverObj); setCoverVM = (DocumentSetCoverModel) createViewModel(setCoverObj); // if this is a simple change, just return from here. if (ObjectUtils.equals( ObjectUtils.defaultIfNull(factory.getTokenizingOptions(), new TokenizingOptions()), new TokenizingOptions()) && factory.getWeightCoverage() == SetCoverFactory.DEFAULT_WEIGHT_COVERAGE) { return created(setCoverVM.asJson()); } setcover = setCoverObj.getIdentifier(); } else if (!StringUtils.equals(StringUtils.defaultString(tmpFactory.getTitle(), setCoverObj.getTitle()), setCoverObj.getTitle()) || !StringUtils.equals( StringUtils.defaultString(tmpFactory.getDescription(), setCoverObj.getDescription()), setCoverObj.getDescription())) { tmpFactory.setEm(em()).setExistingId(setcover); setCoverObj = tmpFactory.create(); em().merge(setCoverObj); setCoverVM = (DocumentSetCoverModel) createViewModel(setCoverObj); setCoverVM.populateSize(em(), setCoverObj); // if this is a simple change, just return from here. if (ObjectUtils.equals( ObjectUtils.defaultIfNull(factory.getTokenizingOptions(), new TokenizingOptions()), ObjectUtils.defaultIfNull(setCoverObj.getTokenizingOptions(), new TokenizingOptions())) && ObjectUtils.equals(factory.getWeightCoverage(), ObjectUtils.defaultIfNull( setCoverObj.getWeightCoverage(), SetCoverFactory.DEFAULT_WEIGHT_COVERAGE))) { return ok(setCoverVM.asJson()); } } // get rid of any old progress observer tokens and create a new one. finalizeProgress(setCoverObj.getId()); createProgressObserverToken(setCoverObj.getId()); watchProgress(factory, "create", setCoverObj.getId()); final Context ctx = Context.current(); final UUID setCoverId = setcover; Akka.future(new Callable<DocumentSetCover>() { @Override public DocumentSetCover call() throws Exception { try { return execute(new SareTxRunnable<DocumentSetCover>() { @Override public DocumentSetCover run(EntityManager em) throws Throwable { bindEntityManager(em); Context.current.set(ctx); DocumentSetCover setCoverObj = null; UUID corpusId = corpus; if (corpusId == null) { setCoverObj = fetchResource(setCoverId, DocumentSetCover.class); corpusId = setCoverObj.getBaseCorpus().getIdentifier(); } factory.setStore(fetchResource(corpusId, DocumentCorpus.class)) .setExistingId(setCoverId).setEm(em); List<SetCoverDocument> oldDocuments = Lists.newArrayList(setCoverObj.getAllDocuments()); setCoverObj = factory.create(); em.flush(); em.merge(setCoverObj); em.getTransaction().commit(); em.clear(); em.getTransaction().begin(); for (SetCoverDocument oldDocument : oldDocuments) { if (Iterables.find(setCoverObj.getAllDocuments(), Predicates.equalTo(oldDocument), null) == null) { SetCoverDocument tmpDocument = em.find(SetCoverDocument.class, oldDocument.getId()); em.remove(tmpDocument); } } return setCoverObj; } }, ctx); } catch (Throwable e) { Logger.error(LoggedAction.getLogEntry(ctx, "failed to build set cover"), e); throw new IllegalArgumentException(e); } finally { setProgressFinished(UuidUtils.toBytes(setCoverId)); } } }); return ok(setCoverVM.asJson()); }
From source file:com.webbfontaine.valuewebb.gtns.TTGTNSSynchronizer.java
protected void updateTTForSentError(TtGen ttGen, List<String> errorMessages) { String errMessage = StringUtils.join(errorMessages.toArray(), '\n'); errMessage = StringUtils.defaultString(StringUtils.trimToNull(errMessage), "N/A"); ttGen.setFcvrCurrentSentError(errMessage); updateTT(ttGen, ERROR_RESPONSE);/*from w w w . j a va 2 s . c o m*/ }
From source file:com.akamai.edgegrid.signer.EdgeGridV1Signer.java
private String getCanonicalizedRequest(Request request, ClientCredential credential) throws RequestSigningException { StringBuilder sb = new StringBuilder(); sb.append(request.getMethod().toUpperCase()); sb.append('\t'); String scheme = StringUtils.defaultString(request.getUriWithQuery().getScheme(), "https"); sb.append(scheme.toLowerCase());/*ww w . jav a2 s .c o m*/ sb.append('\t'); String host = credential.getHost(); sb.append(host.toLowerCase()); sb.append('\t'); String relativePath = getRelativePathWithQuery(request.getUriWithQuery()); String relativeUrl = canonicalizeUri(relativePath); sb.append(relativeUrl); sb.append('\t'); String canonicalizedHeaders = canonicalizeHeaders(request.getHeaders(), credential); sb.append(canonicalizedHeaders); sb.append('\t'); sb.append(getContentHash(request.getMethod(), request.getBody(), credential.getMaxBodySize())); sb.append('\t'); return sb.toString(); }
From source file:io.wcm.handler.mediasource.inline.InlineMediaSource.java
/** * Get resource with media inline data (nt:file node). * @param mediaRequest Media reference/*from w w w .ja v a2s . co m*/ * @return Resource or null if not present */ private Resource getMediaInlineResource(MediaRequest mediaRequest) { Resource resource = mediaRequest.getResource(); if (resource == null) { return null; } // check if resource itself is a nt:file node if (JcrBinary.isNtFileOrResource(resource)) { return resource; } // check if child node exists which is a nt:file node String refProperty = StringUtils.defaultString(mediaRequest.getRefProperty(), MediaNameConstants.NN_MEDIA_INLINE); Resource mediaInlineResource = resource.getChild(refProperty); if (JcrBinary.isNtFileOrResource(mediaInlineResource)) { return mediaInlineResource; } // not found return null; }
From source file:gobblin.source.extractor.utils.Utils.java
/** * Convert joda time to a string in the given format * @param input timestamp//from w w w . j av a 2 s.c om * @param format expected format * @param timezone time zone of timestamp * @return string format of timestamp */ public static String dateTimeToString(DateTime input, String format, String timezone) { String tz = StringUtils.defaultString(timezone, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE); DateTimeZone dateTimeZone = getTimeZone(tz); DateTimeFormatter outputDtFormat = DateTimeFormat.forPattern(format).withZone(dateTimeZone); return outputDtFormat.print(input); }
From source file:gobblin.source.extractor.utils.Utils.java
/** * Get current time - joda//from w w w. j a v a 2 s .com * @param timezone time zone of current time * @return current datetime in the given timezone */ public static DateTime getCurrentTime(String timezone) { String tz = StringUtils.defaultString(timezone, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE); DateTimeZone dateTimeZone = getTimeZone(tz); DateTime currentTime = new DateTime(dateTimeZone); return currentTime; }
From source file:com.mirth.connect.cli.CommandLineInterface.java
private void runShell(String server, String user, String password, String script, boolean debug) { try {// w ww. ja va 2s . com client = new Client(server); this.debug = debug; LoginStatus loginStatus = client.login(user, password); if (loginStatus.getStatus() != LoginStatus.Status.SUCCESS) { error("Could not login to server.", null); return; } String serverVersion = client.getVersion(); try { ObjectXMLSerializer.getInstance().init(serverVersion); } catch (Exception e) { } out.println("Connected to Mirth Connect server @ " + server + " (" + serverVersion + ")"); currentUser = StringUtils.defaultString(loginStatus.getUpdatedUsername(), user); if (script != null) { runScript(script); } else { runConsole(); } client.logout(); client.close(); out.println("Disconnected from server."); } catch (ClientException ce) { ce.printStackTrace(); } catch (IOException ioe) { error("Could not load script file.", ioe); } catch (URISyntaxException e) { error("Invalid server address.", e); } }
From source file:net.sf.jsignpdf.VisibleSignatureDialog.java
/** * stores values from this Form to the instance of {@link SignerOptions} */// w w w . j a v a2 s . c o m private void storeToOptions() { options.setPage(ConvertUtils.toInt(tfPage.getText(), Constants.DEFVAL_PAGE)); options.setPositionLLX(ConvertUtils.toFloat(tfPosLLX.getText(), Constants.DEFVAL_LLX)); options.setPositionLLY(ConvertUtils.toFloat(tfPosLLY.getText(), Constants.DEFVAL_LLY)); options.setPositionURX(ConvertUtils.toFloat(tfPosURX.getText(), Constants.DEFVAL_URX)); options.setPositionURY(ConvertUtils.toFloat(tfPosURY.getText(), Constants.DEFVAL_URY)); options.setBgImgScale(ConvertUtils.toFloat(tfBgImgScale.getText(), Constants.DEFVAL_BG_SCALE)); options.setRenderMode((RenderMode) cbDisplayMode.getSelectedItem()); options.setL2Text( chkbL2TextDefault.isSelected() ? null : StringUtils.defaultString(taL2Text.getText(), "")); options.setL2TextFontSize(ConvertUtils.toFloat(tfL2TextFontSize.getText(), Constants.DEFVAL_L2_FONT_SIZE)); options.setL4Text( chkbL4TextDefault.isSelected() ? null : StringUtils.defaultString(tfL4Text.getText(), "")); options.setImgPath(tfImgPath.getText()); options.setBgImgPath(tfBgImgPath.getText()); options.setAcro6Layers(chkbAcro6Layers.isSelected()); // if there are fixed values update them in the form; updateFromOptions(); }
From source file:com.epam.catgenome.manager.wig.WigManager.java
protected String parseName(final String fileName, final String alternativeName) { boolean supported = false; for (final String ext : WIG_EXTENSIONS) { if (fileName.endsWith(ext)) { supported = true;/*from ww w .j a va2s .com*/ break; } } if (!supported) { throw new IllegalArgumentException( getMessage("error.illegal.file.type", StringUtils.join(WIG_EXTENSIONS, ", "))); } return StringUtils.defaultString(StringUtils.trimToNull(alternativeName), fileName); }