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.actions.WorkflowTransitionAction.java
/** * Updates the next task(s) so that the workflow instance appears as * assigned to a user and/or//from w w w .jav a 2 s .c om * group. <br/> * This updating is COMPULSORY: Alfresco will not do it automatically as one * could expect. * * @param transaction * @param taskProperties */ private TransitionResultBean reassignWorkflow(AlfrescoTransaction transaction, HashMap<QName, Serializable> taskProperties) { TransitionResultBean result = new TransitionResultBean(); HashMap<QName, Serializable> properties; List<String> tasks; try { tasks = controller.workflowGetCurrentTasksInfo(transaction, currentPage.getWkflwInstanceId()); } catch (Exception e) { logger.debug("Error getting the current tasks", e); tasks = null; } if (tasks == null) { navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_SERVER)); return result; } if (tasks.size() == 0) { // the workflow is completed, no more tasks are available navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_SUCCESS_END)); result.setSuccess(true); return result; } List<String> failedAssignmentTasks = new Vector<String>(); for (String taskInfoString : tasks) { String taskId = getIdFromTaskIdNameTitle(taskInfoString); String taskName = getNameFromTaskIdNameTitle(taskInfoString); WorkflowTaskInfoBean taskBean = controller.getWorkflowTaskInfoBeanByTaskId(taskName); if (taskBean == null) { // oups sorry try to get it taskBean = controller.getWorkflowTaskInfoBean(taskName); } String pooledActors = taskBean.getPooledActors(); String actorIds = taskBean.getActorId(); if ((StringUtils.trimToNull(pooledActors) != null) || (StringUtils.trimToNull(actorIds) != null)) { // we got some user(s)/group(s) to assign the task to // the list of users/groups allowed to manage the task List<NodeRef> refToActors = new Vector<NodeRef>(); properties = new HashMap<QName, Serializable>(); if (StringUtils.trimToNull(actorIds) == null && StringUtils.trimToNull(pooledActors) == null) { navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_NO_ACTOR)); return result; } if (StringUtils.trimToNull(pooledActors) != null) { // #1514: support for multiple groups/users via comma-separated list String[] actors = StringUtils.split(pooledActors, ","); for (String anActor : actors) { anActor = StringUtils.trim(anActor); anActor = resolveActorId(anActor, taskProperties); NodeRef nodeRef = controller.systemGetNodeRefForGroup(transaction, anActor); addActor(refToActors, nodeRef); } } if (StringUtils.trimToNull(actorIds) != null) { String[] actors = StringUtils.split(actorIds, ","); for (String anActor : actors) { anActor = StringUtils.trim(anActor); anActor = resolveActorId(anActor, taskProperties); NodeRef nodeRef = controller.systemGetNodeRefForUser(transaction, anActor); addActor(refToActors, nodeRef); } } if (refToActors.size() == 0) { navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_ASSIGN)); return result; } // perform the task assignment to the user(s)/group(s) properties.put(WorkflowModel.ASSOC_POOLED_ACTORS, (Serializable) refToActors); try { controller.workflowUpdateTask(transaction, taskId, properties); } catch (Exception e) { logger.debug("Error affecting the next tasks (id=" + taskId + ", name=" + taskName + ")", e); failedAssignmentTasks.add(taskInfoString); } } } // all workflow tasks except the end task should lead to at least one successful rea int nbFailedAssignments = failedAssignmentTasks.size(); if (nbFailedAssignments > 0) { String names = StringUtils.join(failedAssignmentTasks, ", "); navigationPath.setStatusMsg(MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_FAIL_ASSIGN_TASKS, "" + nbFailedAssignments, "" + tasks.size(), names)); return result; } String nextTasksTitles = buildNextTasksTitles(tasks); String msg = MsgPool.getMsg(MsgId.MSG_STATUS_WKFLW_SUCCESS, nextTasksTitles, currentPage.getWkflwInstanceId()); navigationPath.setStatusMsg(msg); result.setTasks(tasks); result.setSuccess(true); logger.debug("Workflow reassignment of task(s) '" + nextTasksTitles + "' is successful."); return result; }
From source file:adalid.util.meta.sql.MetaPlatformSql.java
private void readFile(WriterContext templateWriterContext, TemplateBean templateBean) { File templatePropertiesFile = templateBean.getPropertiesFile(); VelocityContext fileContext = templateWriterContext.getVelocityContextClone(); Properties properties = mergeProperties(fileContext, templatePropertiesFile); putStrings(fileContext, properties); String userPath = pathString(USER_DIR); String temptype = StringUtils.defaultIfBlank(properties.getProperty(TP_TYPE), TP_TYPE_VELOCITY); String template = StringUtils.trimToNull(properties.getProperty(TP_TEMPLATE)); String filePath = StringUtils.trimToNull(properties.getProperty(TP_PATH)); String filePack = StringUtils.trimToNull(properties.getProperty(TP_PACKAGE)); String fileName = StringUtils.trimToNull(properties.getProperty(TP_FILE)); String preserve = StringUtils.trimToNull(properties.getProperty(TP_PRESERVE)); String charset1 = StringUtils.trimToNull(properties.getProperty(TP_ENCODING)); String charset2 = StringUtils.trimToNull(properties.getProperty(TP_CHARSET)); String disabled = properties.getProperty(TP_DISABLED, Boolean.FALSE.toString()); String disabledMissing = properties.getProperty(TP_DISABLED_MISSING); String executeCommand = StringUtils.trimToNull(properties.getProperty(TP_EXECUTE_COMMAND)); String executeDirectory = StringUtils.trimToNull(properties.getProperty(TP_EXECUTE_DIRECTORY)); String forEach = StringUtils.trimToNull(properties.getProperty(TP_FOR_EACH)); String hint = ", check property \"{0}\" at file \"{1}\""; if (ArrayUtils.contains(TP_TYPE_ARRAY, temptype)) { } else {//from w w w . ja va 2 s .c o m String pattern = "failed to obtain a valid template type" + hint; String message = MessageFormat.format(pattern, TP_TYPE, templatePropertiesFile); logger.error(message); errors++; return; } if (template == null) { String pattern = "failed to obtain a valid template name" + hint; String message = MessageFormat.format(pattern, TP_TEMPLATE, templatePropertiesFile); logger.error(message); errors++; return; } if (fileName == null) { String pattern = "failed to obtain a valid file name" + hint; String message = MessageFormat.format(pattern, TP_FILE, templatePropertiesFile); logger.error(message); errors++; return; } String templatePathString = pathString(template); String templatePath = StringUtils.substringBeforeLast(templatePathString, FILE_SEPARATOR); fileContext.put(VC_TEMPLATE, StringEscapeUtils.escapeJava(templatePathString)); fileContext.put(VC_TEMPLATE_PATH, StringUtils.replace(templatePath, FILE_SEPARATOR, "/")); fileContext.put(VC_FILE, fileName); if (filePath == null) { filePath = userPath; } else { filePath = pathString(filePath); if (isRelativePath(filePath)) { if (filePath.startsWith(FILE_SEPARATOR)) { filePath = userPath + filePath; } else { filePath = userPath + FILE_SEPARATOR + filePath; } } } fileContext.put(VC_PATH, StringEscapeUtils.escapeJava(filePath)); if (filePack != null) { filePath += FILE_SEPARATOR + pathString(StringUtils.replace(filePack, ".", "/")); fileContext.put(VC_PACKAGE, dottedString(filePack)); } File path = new File(filePath); String fullname = path.getPath() + FILE_SEPARATOR + fileName; fileContext.put(VC_FILE_PATH, StringEscapeUtils.escapeJava(filePath)); fileContext.put(VC_FILE_NAME, StringEscapeUtils.escapeJava(fileName)); fileContext.put(VC_FILE_PATH_NAME, StringEscapeUtils.escapeJava(fullname)); fileContext.put(VC_FILE_PATH_FILE, path); /**/ templateBean.setPath(templatePathString); templateBean.setType(temptype); templateBean.setEncoding(charset1); templateBean.setForEach(forEach); templateBean.setTargetPath(filePath); templateBean.setTargetPackage(filePack); templateBean.setTargetFile(fileName); templateBean.setTargetFileEncoding(charset2); templateBean.setExecuteCommand(executeCommand); templateBean.setExecuteDirectory(executeDirectory); templateBean.setDisabled(BitUtils.valueOf(disabled)); templateBean.setDisabledWhenMissing(BitUtils.valueOf(disabledMissing)); templateBean.setPreserveExistingFile(BitUtils.valueOf(preserve)); templateBean.setBytes(0); templateBean.setLines(0); }
From source file:ch.entwine.weblounge.common.impl.request.RequestUtils.java
/** * Checks if the parameter <code>parameter</code> is present in the request * and is not equal to the empty string. * /*from w w w .j ava 2 s.c o m*/ * @param request * the weblounge request * @param parameter * the parameter index * @return <code>true</code> if the parameter is available */ public static boolean parameterExists(WebloungeRequest request, Action action, int parameter) { String p = getParameter(request, action, parameter); return StringUtils.trimToNull(p) != null; }
From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java
/** * @param req/*from w ww . j a va 2 s .com*/ * @param sessionId * @param pageId * @param statusDisplayedMsg * @param currentPage * @return * @throws IOException * @throws ServletException * @throws DOMException */ private Document loadXFormsDocument(HttpServletRequest req, String sessionId, String pageId, String statusDisplayedMsg, Page currentPage) throws IOException, ServletException, DOMException { String xformsString; String dataType = currentPage.getFormName(); FormTypeEnum formType = currentPage.getFormType(); boolean dataTypeSet = currentPage.isDataTypeSet(); String templateId = currentPage.getTemplate(); String pageLanguage = currentPage.getLanguage(); Map<String, String> initParams = currentPage.getInitParams(); xformsString = getXFormsString(formType, dataType, dataTypeSet, templateId, sessionId, pageId, req.getContextPath(), pageLanguage, initParams, req); Document doc; // try { // doc = org.chiba.xml.dom.DOMUtil.parseString(xformsString, true, false); // } catch (ParserConfigurationException e) { // throw new ServletException(e); // } catch (SAXException e) { // throw new ServletException(e); // } doc = DOMUtil.getDocumentFromString(xformsString); if (doc == null) { throw new RuntimeException("Unable to build the XForms document"); } Element docElt = doc.getDocumentElement(); // add CSS file if one is provided if (StringUtils.trimToNull(controller.getCssUrl()) != null) { Element head = DOMUtil.getChild(docElt, "xhtml:head"); Element css = doc.createElementNS("http://www.w3.org/1999/xhtml", "link"); css.setAttribute("rel", "stylesheet"); css.setAttribute("type", "text/css"); css.setAttribute("href", controller.getCssUrl()); head.appendChild(css); } // hide buttons if applicable if (currentPage.isShowSubmitButtons() == false) { String tagName = MsgId.INT_SUBMIT_BUTTONS_GROUP_ID.getText(); DOMUtil.removeEltInDescentByAttrValue(docElt, "id", tagName); } else { // #1181: individual hiding of submission buttons if (currentPage.isShowCancel() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_CANCEL); } if (currentPage.isShowDelete() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_DELETE); } if (currentPage.isShowValidate() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_SUBMIT); } } // add status message String statusMsg = statusDisplayedMsg; if (statusMsg != null) { String tagVal = MsgId.INT_CSS_STATUS_BAR_ID.getText(); Element status = DOMUtil.getEltInDescentByAttrValue(docElt, "id", tagVal); status.setTextContent(statusMsg); } return doc; }
From source file:com.foya.noms.service.st.ST009Service.java
private TbSiteWork getSiteWorkBySiteBuildApplyDTO(SiteBuildApplyDTO siteBuildApply, String workId) { TbSiteWork siteWork = workDao.findByPk(siteBuildApply.getWorkId()); if (siteWork == null) { siteWork = new TbSiteWork(); }// ww w . j ava2s.co m // siteWork.setEQP_TYPE_ID(siteBuildApply.getEqpTypeId()); // siteWork.setWORK_ID(workId); // siteWork.setWORK_TYPE(WorkType.SGL.name()); // siteWork.setWORK_STATUS(siteBuildApply.getWorkStatus()); // siteWork.setSR_LON(siteBuildApply.getLon()); // siteWork.setSR_LAT(siteBuildApply.getLat()); // ?? siteWork.setPRIORITY(StringUtils.trimToNull(siteBuildApply.getPriority())); // WORK_DESC siteWork.setWORK_DESC(StringUtils.trimToNull(siteBuildApply.getWorkDesc())); // SITE_ID siteWork.setSITE_ID(siteBuildApply.getSiteId()); // ? siteWork.setBTS_SITE_ID(StringUtils.trimToNull(siteBuildApply.getBtsSiteId())); // ? if (StringUtils.isNotEmpty(siteBuildApply.getFeqId())) { siteWork.setFEQ_ID(siteBuildApply.getFeqId().split(",")[0]); } // ??? siteWork.setSITE_NAME(siteBuildApply.getSiteName()); // ? siteWork.setPREDICE_END_DATE(siteBuildApply.getPrediceEndDate()); // siteWork.setLOCATION_ID(siteBuildApply.getLocationId()); // ?? siteWork.setADDR(siteBuildApply.getADDR()); siteWork.setCITY(siteBuildApply.getCITY()); siteWork.setAREA(siteBuildApply.getAREA()); siteWork.setZIP(siteBuildApply.getZIP()); siteWork.setVILLAGE(siteBuildApply.getVILLAGE()); siteWork.setADJACENT(siteBuildApply.getADJACENT()); siteWork.setROAD(siteBuildApply.getROAD()); siteWork.setLANE(siteBuildApply.getLANE()); siteWork.setALLEY(siteBuildApply.getALLEY()); siteWork.setSUB_ALLEY(siteBuildApply.getSUB_ALLEY()); siteWork.setDOOR_NO(siteBuildApply.getDOOR_NO()); siteWork.setDOOR_NO_EX(siteBuildApply.getDOOR_NO_EX()); siteWork.setFLOOR(siteBuildApply.getFLOOR()); siteWork.setFLOOR_EX(siteBuildApply.getFLOOR_EX()); siteWork.setROOM(siteBuildApply.getROOM()); siteWork.setADD_OTHER(siteBuildApply.getADD_OTHER()); // siteWork.setOS_TYPE(siteBuildApply.getOsType()); // (?)SA??? siteWork.setAPP_DEPT(getLoginUser().getDeptId()); siteWork.setLICENSE_NO(siteBuildApply.getLicenseNo()); siteWork.setCPL_NO(siteBuildApply.getCplNo()); siteWork.setPERMIT_NO(siteBuildApply.getPermitNo()); siteWork.setEQP_TYPE_ID(siteBuildApply.getEqpTypeId()); if (StringUtils.equals(siteBuildApply.getStartSiteStatus(), "S02") || StringUtils.equals(siteBuildApply.getStartSiteStatus(), "S04")) { siteWork.setEND_SITE_STATUS(siteBuildApply.getSiteStatusValue()); } else { siteWork.setEND_SITE_STATUS(siteBuildApply.getAllSiteStatus()); } siteWork.setSTART_SITE_STATUS(siteBuildApply.getStartSiteStatus()); return siteWork; }
From source file:com.haulmont.cuba.core.sys.AbstractMessages.java
@Nullable protected String searchIncludes(Properties properties, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) { String includesProperty = properties.getProperty("@include"); if (includesProperty != null) { // multiple includes separated by comma String[] includes = StringUtils.split(includesProperty, " ,"); if (includes != null && includes.length > 0) { ArrayUtils.reverse(includes); for (String includePath : includes) { includePath = StringUtils.trimToNull(includePath); if (includePath != null) { String message = searchMessage(includePath, key, locale, truncatedLocale, passedPacks); if (message != null) { return message; }//from ww w. j a v a2s .co m } } } } return null; }
From source file:au.org.ala.biocache.web.MapController.java
/** * This method creates and renders a density map for a species. * // w w w .j a va2 s.c om * @throws Exception */ @RequestMapping(value = { "/density/map", "/occurrences/static" }, method = RequestMethod.GET) public @ResponseBody void speciesDensityMap(SpatialSearchRequestParams requestParams, @RequestParam(value = "forceRefresh", required = false, defaultValue = "false") boolean forceRefresh, @RequestParam(value = "forcePointsDisplay", required = false, defaultValue = "false") boolean forcePointsDisplay, @RequestParam(value = "pointColour", required = false, defaultValue = "0000ff") String pointColour, @RequestParam(value = "colourByFq", required = false, defaultValue = "") String colourByFqCSV, @RequestParam(value = "colours", required = false, defaultValue = "") String coloursCSV, @RequestParam(value = "pointHeatMapThreshold", required = false, defaultValue = "500") Integer pointHeatMapThreshold, @RequestParam(value = "opacity", required = false, defaultValue = "1.0") Float opacity, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("image/png"); File outputDir = new File(heatmapOutputDir); if (!outputDir.exists()) { FileUtils.forceMkdir(outputDir); } //output heatmap path String outputHMFile = getOutputFile(request); String[] facetValues = null; String[] facetColours = null; if (StringUtils.trimToNull(colourByFqCSV) != null && StringUtils.trimToNull(coloursCSV) != null) { facetValues = colourByFqCSV.split(","); facetColours = coloursCSV.split(","); if (facetValues.length == 0 || facetValues.length != facetColours.length) { throw new IllegalArgumentException( String.format("Mismatch in facet values and colours. Values: %d, Colours: %d", facetValues.length, facetColours.length)); } } //Does file exist on disk? File f = new File(outputDir + "/" + outputHMFile); if (!f.isFile() || !f.exists() || forceRefresh) { logger.debug("Regenerating heatmap image"); //If not, generate generateStaticHeatmapImages(requestParams, false, forcePointsDisplay, pointHeatMapThreshold, pointColour, facetValues, facetColours, opacity, request); } else { logger.debug("Heatmap file already exists on disk, sending file back to user"); } try { //read file off disk and send back to user File file = new File(outputDir + "/" + outputHMFile); BufferedImage img = ImageIO.read(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image.", e); } }
From source file:com.bluexml.xforms.generator.mapping.MappingGenerator.java
/** * Writes a dictionary of all user-given styles in a file. If no styles were * indicated, the file//from w ww . j a v a 2 s . c o m * is not created. * * @throws IOException */ private void writeSkeletonCSS() throws IOException { if (CSSCollector.size() > 0) { FileWriter fw = new FileWriter(CSSFile); PrintWriter pw = new PrintWriter(fw); int nbClasses = 0; pw.println("/* ************************ */"); pw.println("/* BlueXML XForms Generator */"); pw.println("/* Generated CSS Template */"); pw.println("/* ************************ */"); pw.println("/* Modify this template as suits your needs.*/"); pw.println("/* If this file is available as 'resources/styles/custom.css' under */"); pw.println("/* your webapp's folder, it will be used by the client browsers.*/"); pw.println("/* Otherwise, indicating its location via a URL parameter will be */"); pw.println("/* necessary. See the SIDE documentation for further details.*/"); pw.println("\n\n"); pw.println("/* CLASSES */"); for (String elt : CSSCollector) { if (StringUtils.trimToNull(elt) != null) { if (!(elt.charAt(0) == '#')) { nbClasses++; pw.println("." + elt + " {"); pw.println("}"); pw.println(); } } } pw.println(); pw.println("/* ID's */"); for (String elt : CSSCollector) { if (StringUtils.trimToNull(elt) != null) { if ((elt.charAt(0) == '#')) { pw.println(elt + " {"); pw.println("}"); pw.println(); } } } pw.close(); } }
From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToForms.java
/** * Adds the section corresponding to a model choice into an XForms instance document. * //from www.jav a 2 s. c o m * @param formInstance * the XForms instance document being filled * @param modelChoiceReference * the parent node (its tag name is field id) that will receive the section created * here; the parent may end up having several sections (in which case the model * choice is multiple). * @param modelChoice * the description for the model choice in the mapping file * @param id * the id * @param label * the label * @param nodeDataType * the qualified name of the node as returned by Alfresco * @param at * @param an * @param initParams * @param formIsReadOnly * whether the form whose instance is being provided is read only * @param isMassTagging */ private void addModelChoiceItem(Document formInstance, Element modelChoiceReference, ModelChoiceType modelChoice, String id, String label, String nodeDataType, AlfrescoTransaction at, Map<String, GenericClass> an, Map<String, String> initParams, boolean formIsReadOnly, boolean isMassTagging) { Node subNode = formInstance.createElement(MsgId.INT_INSTANCE_ASSOCIATION_ITEM.getText()); if (isInline(modelChoice)) { Node formNode = null; if (StringUtils.trimToNull(id) == null) { formNode = newForm(getFormType(modelChoice.getTarget().get(0).getName()), formInstance, at, an, initParams, formIsReadOnly, isMassTagging); subNode.appendChild(formNode); } else { try { formNode = getForm(at, getFormType(modelChoice.getTarget().get(0).getName()), id, an, formInstance, initParams, formIsReadOnly); subNode.appendChild(formNode); } catch (ServletException e) { logger.error( "Error getting the instance section for model choice '" + modelChoice.getDisplayLabel() + "' supporting association '" + modelChoice.getAlfrescoName() + "'", e); } } } else { Element eltId = formInstance.createElement(MsgId.INT_INSTANCE_SIDEID.getText()); eltId.setTextContent(id); subNode.appendChild(eltId); Element eltLabel = formInstance.createElement(MsgId.INT_INSTANCE_SIDELABEL.getText()); eltLabel.setTextContent(StringUtils.trimToEmpty(label)); subNode.appendChild(eltLabel); Element eltEdit = formInstance.createElement(MsgId.INT_INSTANCE_SIDEEDIT.getText()); eltEdit.setTextContent(""); subNode.appendChild(eltEdit); // ** #1485 Element eltType = formInstance.createElement(MsgId.INT_INSTANCE_SIDETYPE.getText()); eltType.setTextContent(nodeDataType); subNode.appendChild(eltType); // ** #1485 } modelChoiceReference.appendChild(subNode); }
From source file:com.egt.web.configuracion.basica.FragmentoFiltro.java
public String getValorTextoFiltro1() { return StringUtils.trimToNull(this.getRecursoDataProvider().getCodigoFuncionSelect()); }