List of usage examples for org.apache.commons.lang StringUtils trimToNull
public static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning null
if the String is empty ("") after the trim or if it is null
.
From source file:com.bluexml.xforms.generator.forms.renderable.common.field.AbstractRenderableField.java
/** * Gets the error message. This message contains indications (to the user) for all possible * error sources.//from w w w . ja v a 2s . c o m * * @return the error message that is built or an <b>empty string</b> if not defined */ protected String getErrorMessage() { String errMsg = getErrorMsgForLength(); String errMsgRegex = getErrorMsgForRegex(); if (StringUtils.trimToNull(errMsgRegex) != null) { if (StringUtils.trimToNull(errMsg) != null) { errMsg += " "; } errMsg += errMsgRegex; } return errMsg; }
From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.actions.ModelMigrationHelper.java
public void updateProject(final IProject source, IProject target, String libraryId, boolean makeCopy, IProgressMonitor monitor2) throws Exception { System.out.println("ModelMigrationHelper.updateProject() source :" + source.getName()); System.out.println("ModelMigrationHelper.updateProject() target :" + target.getName()); List<File> models = getModels(source); List<File> diagrams = getDiagrams(source); List<File> applicationModels = getApplicationModels(source); List<File> mavenModules = getMavenModules(source); List<File> modelsTarget = getModels(target); // System.out.println("ModelMigrationHelper.updateProject() models :" + models.size()); // System.out.println("ModelMigrationHelper.updateProject() diagrams :" + diagrams.size()); // System.out.println("ModelMigrationHelper.updateProject() applicationModels :" + applicationModels.size()); // System.out.println("ModelMigrationHelper.updateProject() mavenModules :" + mavenModules.size()); // System.out.println("ModelMigrationHelper.updateProject() targetModels :" + modelsTarget.size()); monitor2.beginTask("updating project", models.size() + applicationModels.size() + mavenModules.size() + diagrams.size()); // System.out.println("ModelMigrationHelper.updateProject() models to update :" + models.size()); monitor2.subTask("models references"); for (File file : models) { if (monitor2.isCanceled()) { return; }/*from w ww . java 2 s .c o m*/ updateModel(file, modelsTarget, monitor2); monitor2.worked(1); } monitor2.subTask("diagrams references"); for (File file : diagrams) { if (monitor2.isCanceled()) { return; } updateModel(file, modelsTarget, monitor2); monitor2.worked(1); } monitor2.subTask("application model"); for (File file : applicationModels) { if (monitor2.isCanceled()) { return; } if (makeCopy) { updateApplicationModel(file, libraryId, source); } else { updateApplicationModel(file, libraryId, null); } AntFileGeneratorAction.generate(IFileHelper.getIFile(file)); monitor2.worked(1); } if (makeCopy) { // check update project configuration SIDEBuilderConfiguration conf = new SIDEBuilderConfiguration(source); conf.load(); String applicationRessourcePath = conf.getApplicationRessourcePath(); String match = "(" + Pattern.quote("${workspace_loc:/") + ")" + "([^/]*)" + "(" + Pattern.quote("/") + ".*" + Pattern.quote("}") + ")"; if (applicationRessourcePath.matches(match)) { Pattern p = Pattern.compile(match); Matcher matcher = p.matcher(applicationRessourcePath); matcher.find(); String group1 = matcher.group(1); String group3 = matcher.group(3); String replace = group1 + source.getName() + group3; conf.setApplicationRessourcePath(replace); conf.reload(); conf.persist(); } else { } } monitor2.subTask("maven modules"); ModelLibrary modellib = new ModelLibrary(libraryId); for (File file : mavenModules) { if (!monitor2.isCanceled()) { return; } String newVersion = modellib.getMavenFrameworkVersion(); String newClassifier = modellib.getMavenFrameworkClassifier(); String[] groupIds = modellib.getMavenFrameworkGroup().split(","); if (StringUtils.trimToNull(newClassifier) != null && StringUtils.trimToNull(newVersion) != null && StringUtils.trimToNull(libraryId) != null) { PomMigrationHelper.updateMavenPom(file, groupIds, newVersion, newClassifier); } } }
From source file:eionet.meta.dao.domain.DataElement.java
public String getAttributeLanguage() { return StringUtils.trimToNull(attributeLanguage); }
From source file:com.novartis.pcs.ontology.rest.servlet.OntologiesServlet.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String mediaType = StringUtils.trimToNull(request.getContentType()); String encoding = StringUtils.trimToNull(request.getCharacterEncoding()); String pathInfo = StringUtils.trimToNull(request.getPathInfo()); Curator curator = loadCurator(request); if (mediaType != null && mediaType.indexOf(';') > 0) { mediaType = mediaType.substring(0, mediaType.indexOf(';')); }//from ww w . j ava 2 s . co m if (!StringUtils.equalsIgnoreCase(mediaType, MEDIA_TYPE_OBO) || !StringUtils.equalsIgnoreCase(encoding, "utf-8")) { log("Failed to import ontology: invalid media type or encoding " + mediaType + ";charset=" + encoding); response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); } else if (pathInfo == null || pathInfo.length() <= 1) { log("Failed to import ontology: ontology name not include in path"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else if (curator == null) { log("Failed to import ontology: curator not found in request"); response.setStatus(HttpServletResponse.SC_FORBIDDEN); } else { try { String ontologyName = pathInfo.substring(1); importService.importOntology(ontologyName, request.getInputStream(), curator); response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Cache-Control", "public, max-age=0"); } catch (DuplicateEntityException e) { log("Failed to import ontology: duplicate term", e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } catch (InvalidEntityException e) { log("Failed to import ontology: invalid entity", e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } catch (InvalidFormatException e) { log("Failed to import ontology: invalid format", e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } catch (Exception e) { log("Failed to import ontology: system error", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } response.setContentLength(0); }
From source file:net.sf.eclipsecs.ui.config.configtypes.InternalConfigurationEditor.java
/** * {@inheritDoc}//from w ww . j a v a2 s . c o m */ public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePluginException { mWorkingCopy.setName(mConfigName.getText()); if (mWorkingCopy.getLocation() == null) { String location = "internal_config_" + System.currentTimeMillis() + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$ try { mWorkingCopy.setLocation(location); } catch (CheckstylePluginException e) { if (StringUtils.trimToNull(location) != null && ensureFileExists(location)) { mWorkingCopy.setLocation(location); } else { throw e; } } } mWorkingCopy.setDescription(mDescription.getText()); return mWorkingCopy; }
From source file:mitm.application.djigzo.james.mailets.MailAttributes.java
private void initSerializedAttributes() { serializedAttributes = new HashMap<String, Serializable>(); String[] values = getValues(getConfiguration().getChildren(Parameter.SERIALIZED.name)); if (values != null) { for (String value : values) { value = StringUtils.trimToNull(value); if (value == null) { continue; }// www. j a v a 2 s . c o m String[] nameValue = parseNameValue(value); if (nameValue == null) { throw new IllegalArgumentException(value + " is not a valid name value pair."); } Serializable serialized = (Serializable) SerializationUtils .deserialize(Base64Utils.decode(nameValue[1])); serializedAttributes.put(nameValue[0], serialized); } } }
From source file:com.activecq.tools.auth.impl.CookieAuthenticationImpl.java
/** * Validate the Authentication Cookie/*from w ww . j a v a 2 s .c o m*/ * * @param request * @param cookieName * @param secret * @return */ @Override public SimpleCredentials extractCredentials(HttpServletRequest request) { Cookie cookie = CookieUtil.getCookie(request, cookieName); if (cookie == null) { return null; } // Get and decode cookie data String cookieData; try { if (StringUtils.isBlank(cookie.getValue())) { return null; } final String tmp = new Base64(true).decode(cookie.getValue()).toString(); cookieData = URLDecoder.decode(tmp, cookieEncoding); } catch (UnsupportedEncodingException e) { return null; } // Split the cookie data by the DATA_DELIMITER String[] values = splitCookieData(cookieData); if (values == null) { return null; } final String token = StringUtils.trimToNull(values[0]); final String timestamp = StringUtils.trimToNull(values[1]); final String userId = StringUtils.trimToNull(values[2]); // Could not get a required value from the cookie if (userId == null || token == null || timestamp == null) { return null; } final String expectedData; try { expectedData = encryptData(createDataToEncrypt(userId, timestamp)); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(CookieAuthenticationImpl.class.getName()).log(Level.SEVERE, null, ex); return null; } catch (InvalidKeyException ex) { Logger.getLogger(CookieAuthenticationImpl.class.getName()).log(Level.SEVERE, null, ex); return null; } // If Cookie token and Expected token don't match, return null if (!StringUtils.equals(token, expectedData)) { return null; } // TODO: Handle cookie timestamping more appropriately. // Check if the current time is greater than the acceptable cookie // expiry timestamp // long cookieTimestamp = Long.parseLong(timestamp); // if (System.currentTimeMillis() > cookieTimestamp) { // return null; // } return new SimpleCredentials(userId, "".toCharArray()); }
From source file:eionet.meta.dao.domain.DataElement.java
public void setAttributeLanguage(String attributeLanguage) { this.attributeLanguage = StringUtils.trimToNull(attributeLanguage); }
From source file:mitm.application.djigzo.impl.DLPPropertiesImpl.java
@Override public void setDLPManagers(String... emails) throws HierarchicalPropertiesException { StrBuilder sb = new StrBuilder(); if (emails != null) { for (String email : emails) { email = StringUtils.trimToNull(email); if (email == null) { continue; }/*from w w w .j a v a 2 s .co m*/ /* * Only accept valid email addresses */ if (!EmailAddressUtils.isValid(email)) { throw new HierarchicalPropertiesException("Email address is not valid: " + email); } sb.appendSeparator(", "); sb.append(email); } } setProperty(getFullPropertyName(DLP_MANAGERS), StringUtils.trimToNull(sb.toString()), PropertyRegistry.getInstance().isEncrypted(getFullPropertyName(DLP_MANAGERS))); }
From source file:net.sf.eclipsecs.ui.config.configtypes.ExternalFileConfigurationEditor.java
/** * {@inheritDoc}/*from w w w.j a v a 2s .c om*/ */ public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePluginException { mWorkingCopy.setName(mConfigName.getText()); mWorkingCopy.setDescription(mDescription.getText()); mWorkingCopy.getAdditionalData().put(ExternalFileConfigurationType.KEY_PROTECT_CONFIG, "" + mChkProtectConfig.getSelection()); //$NON-NLS-1$ try { mWorkingCopy.setLocation(mLocation.getText()); } catch (CheckstylePluginException e) { String location = mLocation.getText(); if (StringUtils.trimToNull(location) != null && ensureFileExists(location)) { mWorkingCopy.setLocation(mLocation.getText()); } else { throw e; } } return mWorkingCopy; }