List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .
StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null
From source file:ca.uhn.fhir.jpa.dao.SearchParamExtractorDstu2.java
@Override public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {//from www . j a va 2 s . co m HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>(); String useSystem = null; if (theResource instanceof ValueSet) { ValueSet vs = (ValueSet) theResource; useSystem = vs.getCodeSystem().getSystem(); } RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); for (RuntimeSearchParam nextSpDef : def.getSearchParams()) { if (nextSpDef.getParamType() != RestSearchParameterTypeEnum.TOKEN) { continue; } String nextPath = nextSpDef.getPath(); if (isBlank(nextPath)) { continue; } boolean multiType = false; if (nextPath.endsWith("[x]")) { multiType = true; } List<String> systems = new ArrayList<String>(); List<String> codes = new ArrayList<String>(); String needContactPointSystem = null; if (nextPath.endsWith("(system=phone)")) { nextPath = nextPath.substring(0, nextPath.length() - "(system=phone)".length()); needContactPointSystem = "phone"; } if (nextPath.endsWith("(system=email)")) { nextPath = nextPath.substring(0, nextPath.length() - "(system=email)".length()); needContactPointSystem = "email"; } for (Object nextObject : extractValues(nextPath, theResource)) { // Patient:language if (nextObject instanceof Patient.Communication) { Communication nextValue = (Patient.Communication) nextObject; nextObject = nextValue.getLanguage(); } if (nextObject instanceof IdentifierDt) { IdentifierDt nextValue = (IdentifierDt) nextObject; if (nextValue.isEmpty()) { continue; } String system = StringUtils.defaultIfBlank(nextValue.getSystemElement().getValueAsString(), null); String value = nextValue.getValueElement().getValue(); if (isNotBlank(value)) { systems.add(system); codes.add(value); } if (isNotBlank(nextValue.getType().getText())) { addStringParam(theEntity, retVal, nextSpDef, nextValue.getType().getText()); } } else if (nextObject instanceof ContactPointDt) { ContactPointDt nextValue = (ContactPointDt) nextObject; if (nextValue.isEmpty()) { continue; } if (isNotBlank(needContactPointSystem)) { if (!needContactPointSystem.equals(nextValue.getSystemElement().getValueAsString())) { continue; } } systems.add(nextValue.getSystemElement().getValueAsString()); codes.add(nextValue.getValueElement().getValue()); } else if (nextObject instanceof BoundCodeDt) { BoundCodeDt<?> obj = (BoundCodeDt<?>) nextObject; String system = extractSystem(obj); String code = obj.getValue(); if (isNotBlank(code)) { systems.add(system); codes.add(code); } } else if (nextObject instanceof IPrimitiveDatatype<?>) { IPrimitiveDatatype<?> nextValue = (IPrimitiveDatatype<?>) nextObject; if (nextValue.isEmpty()) { continue; } if ("ValueSet.codeSystem.concept.code".equals(nextPath)) { systems.add(useSystem); } else { systems.add(null); } codes.add(nextValue.getValueAsString()); } else if (nextObject instanceof CodingDt) { CodingDt nextValue = (CodingDt) nextObject; extractTokensFromCoding(systems, codes, theEntity, retVal, nextSpDef, nextValue); } else if (nextObject instanceof CodeableConceptDt) { CodeableConceptDt nextCC = (CodeableConceptDt) nextObject; if (!nextCC.getTextElement().isEmpty()) { addStringParam(theEntity, retVal, nextSpDef, nextCC.getTextElement().getValue()); } extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); } else if (nextObject instanceof RestSecurity) { // Conformance.security search param points to something kind of useless right now - This should probably // be fixed. RestSecurity sec = (RestSecurity) nextObject; for (BoundCodeableConceptDt<RestfulSecurityServiceEnum> nextCC : sec.getService()) { extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); } } else if (nextObject instanceof Location.Position) { ourLog.warn("Position search not currently supported, not indexing location"); continue; } else { if (!multiType) { throw new ConfigurationException("Search param " + nextSpDef.getName() + " is of unexpected datatype: " + nextObject.getClass()); } else { continue; } } } assert systems.size() == codes.size() : "Systems contains " + systems + ", codes contains: " + codes; Set<Pair<String, String>> haveValues = new HashSet<Pair<String, String>>(); for (int i = 0; i < systems.size(); i++) { String system = systems.get(i); String code = codes.get(i); if (isBlank(system) && isBlank(code)) { continue; } if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) { system = system.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH); } if (code != null && code.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) { code = code.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH); } Pair<String, String> nextPair = Pair.of(system, code); if (haveValues.contains(nextPair)) { continue; } haveValues.add(nextPair); ResourceIndexedSearchParamToken nextEntity; nextEntity = new ResourceIndexedSearchParamToken(nextSpDef.getName(), system, code); nextEntity.setResource(theEntity); retVal.add(nextEntity); } } return retVal; }
From source file:ca.uhn.fhir.model.primitive.IdDt.java
@Override public IIdType setParts(String theBaseUrl, String theResourceType, String theIdPart, String theVersionIdPart) { if (isNotBlank(theVersionIdPart)) { Validate.notBlank(theResourceType, "If theVersionIdPart is populated, theResourceType and theIdPart must be populated"); Validate.notBlank(theIdPart,// w ww. ja va 2s . c om "If theVersionIdPart is populated, theResourceType and theIdPart must be populated"); } if (isNotBlank(theBaseUrl) && isNotBlank(theIdPart)) { Validate.notBlank(theResourceType, "If theBaseUrl is populated and theIdPart is populated, theResourceType must be populated"); } setValue(null); myBaseUrl = theBaseUrl; myResourceType = theResourceType; myUnqualifiedId = theIdPart; myUnqualifiedVersionId = StringUtils.defaultIfBlank(theVersionIdPart, null); myHaveComponentParts = true; return this; }
From source file:com.sonicle.webtop.vfs.Service.java
public void processSetupStoreFtp(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { WebTopSession wts = RunContext.getWebTopSession(); String PROPERTY = "SETUP_FTP"; try {/*from w ww . j a va2s . co m*/ String crud = ServletUtils.getStringParameter(request, "crud", true); if (crud.equals("s1")) { String profileId = ServletUtils.getStringParameter(request, "profileId", true); String scheme = ServletUtils.getStringParameter(request, "scheme", true); String host = ServletUtils.getStringParameter(request, "host", true); Integer port = ServletUtils.getIntParameter(request, "port", null); String username = ServletUtils.getStringParameter(request, "username", true); String password = ServletUtils.getStringParameter(request, "password", null); String path = ServletUtils.getStringParameter(request, "path", null); SetupDataFtp params = new SetupDataFtp(); params.profileId = profileId; params.scheme = scheme; params.host = host; params.port = port; params.username = username; params.password = password; params.path = path; params.buildName(); wts.setProperty(SERVICE_ID, PROPERTY, params); //TODO: controllo connessione new JsonResult(params).printTo(out); } else if (crud.equals("s2")) { String name = ServletUtils.getStringParameter(request, "name", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataFtp params = (SetupDataFtp) wts.getProperty(SERVICE_ID, PROPERTY); Store store = new Store(); store.setProfileId(new UserProfile.Id(params.profileId)); store.setName(StringUtils.defaultIfBlank(name, params.name)); store.setUri(params.generateURI()); manager.addStore(store); wts.clearProperty(SERVICE_ID, PROPERTY); updateFoldersCache(); new JsonResult().printTo(out); } } catch (Exception ex) { logger.error("Error in SetupStoreFtp", ex); new JsonResult(false, ex.getMessage()).printTo(out); } }
From source file:ca.uhn.fhir.jpa.dao.dstu3.SearchParamExtractorDstu3.java
@Override public Set<BaseResourceIndexedSearchParam> extractSearchParamTokens(ResourceTable theEntity, IBaseResource theResource) {// w w w .j av a 2 s .c o m HashSet<BaseResourceIndexedSearchParam> retVal = new HashSet<BaseResourceIndexedSearchParam>(); String useSystem = null; if (theResource instanceof CodeSystem) { CodeSystem cs = (CodeSystem) theResource; useSystem = cs.getUrl(); } RuntimeResourceDefinition def = getContext().getResourceDefinition(theResource); for (RuntimeSearchParam nextSpDef : def.getSearchParams()) { if (nextSpDef.getParamType() != RestSearchParameterTypeEnum.TOKEN) { continue; } String nextPath = nextSpDef.getPath(); if (isBlank(nextPath)) { continue; } boolean multiType = false; if (nextPath.endsWith("[x]")) { multiType = true; } List<String> systems = new ArrayList<String>(); List<String> codes = new ArrayList<String>(); // String needContactPointSystem = null; // if (nextPath.contains(".where(system='phone')")) { // nextPath = nextPath.replace(".where(system='phone')", ""); // needContactPointSystem = "phone"; // } // if (nextPath.contains(".where(system='email')")) { // nextPath = nextPath.replace(".where(system='email')", ""); // needContactPointSystem = "email"; // } for (Object nextObject : extractValues(nextPath, theResource)) { // Patient:language if (nextObject instanceof PatientCommunicationComponent) { PatientCommunicationComponent nextValue = (PatientCommunicationComponent) nextObject; nextObject = nextValue.getLanguage(); } if (nextObject instanceof Identifier) { Identifier nextValue = (Identifier) nextObject; if (nextValue.isEmpty()) { continue; } String system = StringUtils.defaultIfBlank(nextValue.getSystemElement().getValueAsString(), null); String value = nextValue.getValueElement().getValue(); if (isNotBlank(value)) { systems.add(system); codes.add(value); } if (isNotBlank(nextValue.getType().getText())) { addStringParam(theEntity, retVal, nextSpDef, nextValue.getType().getText()); } } else if (nextObject instanceof ContactPoint) { ContactPoint nextValue = (ContactPoint) nextObject; if (nextValue.isEmpty()) { continue; } systems.add(nextValue.getSystemElement().getValueAsString()); codes.add(nextValue.getValueElement().getValue()); } else if (nextObject instanceof Enumeration<?>) { Enumeration<?> obj = (Enumeration<?>) nextObject; String system = extractSystem(obj); String code = obj.getValueAsString(); if (isNotBlank(code)) { systems.add(system); codes.add(code); } } else if (nextObject instanceof IPrimitiveType<?>) { IPrimitiveType<?> nextValue = (IPrimitiveType<?>) nextObject; if (nextValue.isEmpty()) { continue; } if ("CodeSystem.concept.code".equals(nextPath)) { systems.add(useSystem); } else { systems.add(null); } codes.add(nextValue.getValueAsString()); } else if (nextObject instanceof Coding) { Coding nextValue = (Coding) nextObject; extractTokensFromCoding(systems, codes, theEntity, retVal, nextSpDef, nextValue); } else if (nextObject instanceof CodeableConcept) { CodeableConcept nextCC = (CodeableConcept) nextObject; if (!nextCC.getTextElement().isEmpty()) { addStringParam(theEntity, retVal, nextSpDef, nextCC.getTextElement().getValue()); } extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); } else if (nextObject instanceof ConformanceRestSecurityComponent) { // Conformance.security search param points to something kind of useless right now - This should probably // be fixed. ConformanceRestSecurityComponent sec = (ConformanceRestSecurityComponent) nextObject; for (CodeableConcept nextCC : sec.getService()) { extractTokensFromCodeableConcept(systems, codes, nextCC, theEntity, retVal, nextSpDef); } } else if (nextObject instanceof LocationPositionComponent) { ourLog.warn("Position search not currently supported, not indexing location"); continue; } else { if (!multiType) { throw new ConfigurationException("Search param " + nextSpDef.getName() + " is of unexpected datatype: " + nextObject.getClass()); } else { continue; } } } assert systems.size() == codes.size() : "Systems contains " + systems + ", codes contains: " + codes; Set<Pair<String, String>> haveValues = new HashSet<Pair<String, String>>(); for (int i = 0; i < systems.size(); i++) { String system = systems.get(i); String code = codes.get(i); if (isBlank(system) && isBlank(code)) { continue; } if (system != null && system.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) { system = system.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH); } if (code != null && code.length() > ResourceIndexedSearchParamToken.MAX_LENGTH) { code = code.substring(0, ResourceIndexedSearchParamToken.MAX_LENGTH); } Pair<String, String> nextPair = Pair.of(system, code); if (haveValues.contains(nextPair)) { continue; } haveValues.add(nextPair); ResourceIndexedSearchParamToken nextEntity; nextEntity = new ResourceIndexedSearchParamToken(nextSpDef.getName(), system, code); nextEntity.setResource(theEntity); retVal.add(nextEntity); } } return retVal; }
From source file:com.sonicle.webtop.vfs.Service.java
public void processSetupStoreDropbox(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {/* ww w.j a v a2 s.c om*/ WebTopSession wts = RunContext.getWebTopSession(); String PROPERTY = "SETUP_DROPBOX"; String APP_NAME = WT.getPlatformName(); String DROPBOX_APP_KEY = getEnv().getCoreServiceSettings().getDropboxAppKey(); String DROPBOX_APP_SECRET = getEnv().getCoreServiceSettings().getDropboxAppSecret(); String DROPBOX_USER_LOCALE = WT.getUserData(getEnv().getProfileId()).getLanguageTag(); try { String crud = ServletUtils.getStringParameter(request, "crud", true); if (crud.equals("s1")) { String profileId = ServletUtils.getStringParameter(request, "profileId", true); SetupDataDropbox params = new SetupDataDropbox(); params.profileId = profileId; params.authUrl = DropboxApiUtils.getAuthorizationUrl(APP_NAME, DROPBOX_USER_LOCALE, DROPBOX_APP_KEY, DROPBOX_APP_SECRET); wts.setProperty(SERVICE_ID, PROPERTY, params); new JsonResult(params).printTo(out); } else if (crud.equals("s2")) { String code = ServletUtils.getStringParameter(request, "code", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataDropbox params = (SetupDataDropbox) wts.getProperty(SERVICE_ID, PROPERTY); DbxAppInfo appInfo = DropboxApiUtils.createAppInfo(DROPBOX_APP_KEY, DROPBOX_APP_SECRET); DbxRequestConfig reqConfig = DropboxApiUtils.createRequestConfig(APP_NAME, DROPBOX_USER_LOCALE); DbxAuthFinish auth = DropboxApiUtils.exchangeAuthorizationCode(code, reqConfig, appInfo); DbxAccountInfo ai = DropboxApiUtils.getAccountInfo(auth.accessToken, reqConfig); params.accountId = String.valueOf(ai.userId); params.accountName = ai.displayName; params.accessToken = auth.accessToken; params.buildName(); new JsonResult(params).printTo(out); } else if (crud.equals("s3")) { String name = ServletUtils.getStringParameter(request, "name", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataDropbox params = (SetupDataDropbox) wts.getProperty(SERVICE_ID, PROPERTY); Store store = new Store(); store.setProfileId(new UserProfile.Id(params.profileId)); store.setName(StringUtils.defaultIfBlank(name, params.name)); store.setUri(params.generateURI()); store.setParameters(LangUtils.serialize(params.buildParameters(), ParamsDropbox.class)); manager.addStore(store); wts.clearProperty(SERVICE_ID, PROPERTY); updateFoldersCache(); new JsonResult().printTo(out); } } catch (Exception ex) { logger.error("Error in SetupStoreDropbox", ex); new JsonResult(false, ex.getMessage()).printTo(out); } }
From source file:net.sf.jsignpdf.BasicSignerOptions.java
public String getImgPath() { return (imgPath = StringUtils.defaultIfBlank(imgPath, null)); }
From source file:net.sf.jsignpdf.BasicSignerOptions.java
public String getBgImgPath() { return (bgImgPath = StringUtils.defaultIfBlank(bgImgPath, null)); }
From source file:com.sonicle.webtop.vfs.Service.java
public void processSetupStoreGoogleDrive(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {//w w w . ja va2 s.co m WebTopSession wts = RunContext.getWebTopSession(); String PROPERTY = "SETUP_GOOGLEDRIVE"; String APP_NAME = WT.getPlatformName(); String GDRIVE_CLIENT_ID = getEnv().getCoreServiceSettings().getGoogleDriveClientID(); String GDRIVE_CLIENT_SECRET = getEnv().getCoreServiceSettings().getGoogleDriveClientSecret(); try { String crud = ServletUtils.getStringParameter(request, "crud", true); if (crud.equals("s1")) { String profileId = ServletUtils.getStringParameter(request, "profileId", true); GoogleDriveAppInfo appInfo = new GoogleDriveAppInfo(APP_NAME, GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET); SetupDataGoogleDrive params = new SetupDataGoogleDrive(); params.profileId = profileId; params.authUrl = GoogleDriveApiUtils.getAuthorizationUrl(appInfo); wts.setProperty(SERVICE_ID, PROPERTY, params); new JsonResult(params).printTo(out); } else if (crud.equals("s2")) { String code = ServletUtils.getStringParameter(request, "code", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataGoogleDrive params = (SetupDataGoogleDrive) wts.getProperty(SERVICE_ID, PROPERTY); GoogleDriveAppInfo appInfo = new GoogleDriveAppInfo(APP_NAME, GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET); GoogleCredential cred = GoogleDriveApiUtils.exchangeAuthorizationCode(code, appInfo); params.refreshToken = cred.getRefreshToken(); params.accessToken = cred.getAccessToken(); Userinfoplus uip = GoogleDriveApiUtils.getUserInfo(params.accessToken, appInfo); params.accountEmail = uip.getEmail(); params.accountName = uip.getName(); params.buildName(); new JsonResult(params).printTo(out); } else if (crud.equals("s3")) { String name = ServletUtils.getStringParameter(request, "name", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataGoogleDrive params = (SetupDataGoogleDrive) wts.getProperty(SERVICE_ID, PROPERTY); Store store = new Store(); store.setProfileId(new UserProfile.Id(params.profileId)); store.setName(StringUtils.defaultIfBlank(name, params.name)); store.setUri(params.generateURI()); store.setParameters(LangUtils.serialize(params.buildParameters(), ParamsGoogleDrive.class)); manager.addStore(store); wts.clearProperty(SERVICE_ID, PROPERTY); updateFoldersCache(); new JsonResult().printTo(out); } } catch (Exception ex) { logger.error("Error in SetupStoreGoogleDrive", ex); new JsonResult(false, ex.getMessage()).printTo(out); } }
From source file:de.pixida.logtest.engine.Automaton.java
private void initScriptEngine() { final ScriptEngineManager manager = new ScriptEngineManager(); final String language = StringUtils.defaultIfBlank(this.scriptLanguage, DEFAULT_SCRIPTING_LANGUAGE); this.scriptingEngine = manager.getEngineByName(language); if (this.scriptingEngine == null) { final String msg = "Scripting engine for language '" + language + "' could not be initalized"; LOG.error(msg);/*from www . ja va2 s .c om*/ throw new ExecutionException(msg); } else { LOG.debug("Using script language: {}", language); } this.scriptEnvironment = new ScriptEnvironment(); this.scriptingEngine.put("engine", this.scriptEnvironment); }
From source file:com.sonicle.webtop.vfs.Service.java
public void processSetupStoreFile(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { WebTopSession wts = RunContext.getWebTopSession(); String PROPERTY = "SETUP_FILE"; try {/* ww w.ja v a2 s .c o m*/ String crud = ServletUtils.getStringParameter(request, "crud", true); if (crud.equals("s1")) { String profileId = ServletUtils.getStringParameter(request, "profileId", true); String path = ServletUtils.getStringParameter(request, "path", null); SetupDataFile params = new SetupDataFile(); params.profileId = profileId; params.path = path; params.buildName(); wts.setProperty(SERVICE_ID, PROPERTY, params); new JsonResult(params).printTo(out); } else if (crud.equals("s2")) { String name = ServletUtils.getStringParameter(request, "name", true); if (!wts.hasProperty(SERVICE_ID, PROPERTY)) throw new WTException(); SetupDataFile params = (SetupDataFile) wts.getProperty(SERVICE_ID, PROPERTY); Store store = new Store(); store.setProfileId(new UserProfile.Id(params.profileId)); store.setName(StringUtils.defaultIfBlank(name, params.name)); store.setUri(params.generateURI()); manager.addStore(store); wts.clearProperty(SERVICE_ID, PROPERTY); updateFoldersCache(); new JsonResult().printTo(out); } } catch (Exception ex) { logger.error("Error in SetupStoreFile", ex); new JsonResult(false, ex.getMessage()).printTo(out); } }