List of usage examples for org.apache.commons.lang3 StringUtils defaultIfEmpty
public static <T extends CharSequence> T defaultIfEmpty(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is empty or null , the value of defaultStr .
StringUtils.defaultIfEmpty(null, "NULL") = "NULL" StringUtils.defaultIfEmpty("", "NULL") = "NULL" StringUtils.defaultIfEmpty(" ", "NULL") = " " StringUtils.defaultIfEmpty("bat", "NULL") = "bat" StringUtils.defaultIfEmpty("", null) = null
From source file:org.jbpm.formModeler.designer.integration.impl.BPMNFormBuilderServiceImpl.java
public Set<DataHolder> getDataHolders(Definitions source, Path context, String resourceId) { if (source == null || context == null) return null; Map<String, DataHolderBuildConfig> associations = new HashMap<String, DataHolderBuildConfig>(); List<RootElement> rootElements = source.getRootElements(); String contextUri = Paths.convert(context).toUri().toString(); for (RootElement re : rootElements) { if (re instanceof org.eclipse.bpmn2.Process) { Process process = (Process) re; if (process != null && process.getId() != null && process.getId().length() > 0) { List<Property> processProperties = process.getProperties(); // if resourceId is null we want to create the process starting form, so we only check process vars. if (StringUtils.isEmpty(resourceId)) return getProcessDataHolders(processProperties, contextUri); String[] colors = dataHolderManager.getHolderColors().keySet().toArray(new String[0]); int index = 0; for (Property prop : processProperties) { String holderClass = StringUtils.defaultIfEmpty(prop.getItemSubjectRef().getStructureRef(), "java.lang.Object"); DataHolderBuildConfig config = new DataHolderBuildConfig(prop.getId(), "", "", colors[index], holderClass); config.addAttribute("path", contextUri); associations.put(prop.getId(), config); if (index == colors.length - 1) index = 0;/*from www . j a v a 2 s. c o m*/ else index++; } getDataHoldersFromElements(process, resourceId, associations); } } } Set<DataHolder> result = new TreeSet<DataHolder>(); for (Iterator it = associations.keySet().iterator(); it.hasNext();) { DataHolderBuildConfig config = associations.get(it.next()); DataHolder dataHolder = createDataHolder(config); if (dataHolder != null) result.add(dataHolder); } return result; }
From source file:org.jbpm.formModeler.designer.integration.impl.BPMNFormBuilderServiceImpl.java
private Set<DataHolder> getProcessDataHolders(List<Property> processProperties, String path) { Set<DataHolder> result = new TreeSet<DataHolder>(); String[] colors = dataHolderManager.getHolderColors().keySet().toArray(new String[0]); int index = 0; for (Property prop : processProperties) { String propertyName = prop.getId(); String propertyType = StringUtils.defaultIfEmpty(prop.getItemSubjectRef().getStructureRef(), "java.lang.Object"); DataHolderBuildConfig config = new DataHolderBuildConfig(propertyName, "", propertyName, colors[index], propertyType);/* w ww . j a va 2 s . co m*/ config.addAttribute("path", path); DataHolder dataHolder = createDataHolder(config); if (dataHolder != null) result.add(dataHolder); if (index == colors.length - 1) index = 0; else index++; } return result; }
From source file:org.jbpm.formModeler.panels.modeler.backend.indexing.FormIndexVisitor.java
protected void visit(Field field, Resource res) { DataHolder holder = field.getForm().getDataHolderByField(field); res.addPart(field.getFieldName(), PartType.FORM_FIELD); if (holder != null) { if (holder.canHaveChildren()) { String bindingExpression = StringUtils.defaultIfEmpty(field.getInputBinding(), field.getOutputBinding()); int slash = bindingExpression.indexOf("/"); String holderFieldId = bindingExpression.substring(slash + 1); DataFieldHolder holderField = holder.getDataFieldHolderById(holderFieldId); if (holderField != null) { addResourceReference(holderField.getClassName(), ResourceType.JAVA); } else { // any references to parts or other resources here? }/*from w w w . ja va2 s.co m*/ } } else { FieldType type = field.getFieldType(); if (type != null) { String fieldClass = type.getFieldClass(); if (fieldClass != null && !fieldClass.isEmpty()) { addResourceReference(fieldClass, ResourceType.JAVA); } } else { // empty type.. do we do anything here? } } if (!StringUtils.isEmpty(field.getDefaultSubform())) { addResourceReference(field.getDefaultSubform(), ResourceType.FORM); } if (!StringUtils.isEmpty(field.getPreviewSubform())) { addResourceReference(field.getDefaultSubform(), ResourceType.FORM); } if (!StringUtils.isEmpty(field.getTableSubform())) { addResourceReference(field.getDefaultSubform(), ResourceType.FORM); } }
From source file:org.jbpm.formModeler.panels.modeler.backend.indexing.FormVisitor.java
protected void visit(Field field) { DataHolder holder = field.getForm().getDataHolderByField(field); FieldIndexGenerator indexGenerator;/* w w w .ja va2s . com*/ if (holder != null) { ValueDataHolderIndexTerm holderIndexTerm = new ValueDataHolderIndexTerm(holder.getUniqeId()); if (holder.canHaveChildren()) { String bindingExpression = StringUtils.defaultIfEmpty(field.getInputBinding(), field.getOutputBinding()); int slash = bindingExpression.indexOf("/"); String holderFieldId = bindingExpression.substring(slash + 1); DataFieldHolder holderField = holder.getDataFieldHolderById(holderFieldId); if (holderField != null) { indexGenerator = new FieldIndexGenerator(new ValueFieldIndexTerm(field.getFieldName()), new ValueFieldTypeIndexTerm(holderField.getClassName()), holderIndexTerm, new ValueDataHolderFieldIndexTerm(holderFieldId)); } else { indexGenerator = new FieldIndexGenerator(new ValueFieldIndexTerm(field.getFieldName()), new ValueFieldTypeIndexTerm(holder.getInfo()), holderIndexTerm); } } else { indexGenerator = new FieldIndexGenerator(new ValueFieldIndexTerm(field.getFieldName()), new ValueFieldTypeIndexTerm(holder.getInfo()), holderIndexTerm); } } else { indexGenerator = new FieldIndexGenerator(new ValueFieldIndexTerm(field.getFieldName()), new ValueFieldTypeIndexTerm(field.getFieldType().getFieldClass())); } if (!StringUtils.isEmpty(field.getDefaultSubform())) indexGenerator.setDefaultSubform(new ValueSubFormIndexTerm(field.getDefaultSubform())); if (!StringUtils.isEmpty(field.getPreviewSubform())) indexGenerator.setPreviewSubform(new ValueSubFormIndexTerm(field.getPreviewSubform())); if (!StringUtils.isEmpty(field.getTableSubform())) indexGenerator.setTableSubform(new ValueSubFormIndexTerm(field.getTableSubform())); builder.addGenerator(indexGenerator); }
From source file:org.jc.exercicios.download.DownloadServlet.java
/** * Realiza o download de uma nota fiscal previamente emitida. Para encontrar * uma nota fiscal, so necessrios o cpf/cnpj do cliente (cpf_cnpj), a data * de emisso (dt_emissao) e o nmero da nota (num_nf). Somente a verso em * xml da nota fiscal permanece disponvel para download. * * @param req/*from www. j av a 2 s . co m*/ * @param resp * @throws ServletException * @throws IOException */ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { boolean authenticated = req.authenticate(resp); if (authenticated) { String identificacao = StringUtils.defaultIfEmpty(req.getParameter("cpf_cnpj"), ""); String data = StringUtils.defaultIfEmpty(req.getParameter("dt_emissao"), ""); String numero = StringUtils.defaultIfEmpty(req.getParameter("num_nf"), ""); File dir = new File(System.getProperty("nfe.dir")); if (identificacao.matches("\\d+") && numero.matches("\\d+") && data.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}")) { File nfe = new File(new File(dir, identificacao), data + '_' + numero + ".xml"); if (nfe.exists()) { resp.setContentType("text/xml"); try (BufferedReader reader = new BufferedReader(new FileReader(nfe)); PrintWriter writer = resp.getWriter();) { String line; while ((line = reader.readLine()) != null) { writer.write(line); // writer.println(); } writer.flush(); } resp.setStatus(HttpServletResponse.SC_OK); } } else { String msg = String.format( "Prezado cliente %s, no encontramos a nota nmero %s," + " na data %s.", identificacao, numero, data); resp.sendError(HttpServletResponse.SC_NOT_FOUND, msg); } } else { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Voc no pode fazer download de notas fiscais!"); } }
From source file:org.jpos.qi.system.SQLQueryObject.java
@Override public String toString() { try {/*from ww w . ja va 2 s . com*/ Object res = DB.exec(db -> { StringBuilder sb = new StringBuilder(""); for (int n = 0; n < queries.length; n++) { String query = queries[n]; String title = titles[n]; int mxrows = maxRows[n]; sb.append(' ').append(title).append("\n\n"); db.session().doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { PreparedStatement stmt = connection.prepareStatement(query); ResultSet rs = stmt.executeQuery(); ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); String[] header = new String[cols]; int[] colsize = new int[cols]; for (int i = 1; i <= cols; i++) { header[i - 1] = StringUtils.defaultIfEmpty(md.getColumnLabel(i), md.getColumnName(i)); colsize[i - 1] = header[i - 1].length(); } int rows = 0; String[][] out = new String[mxrows][cols]; while (rs.next() && rows < mxrows) { for (int i = 1; i <= cols; i++) { out[rows][i - 1] = rs.getString(i); if (out[rows][i - 1] == null) out[rows][i - 1] = " "; int l = out[rows][i - 1].length(); if (colsize[i - 1] < l) colsize[i - 1] = l; } rows++; } rs.close(); stmt.close(); StringBuilder sbSep = new StringBuilder(" "); sb.append(' '); for (int i = 1; i <= cols; i++) { if (isNumericDataType(md.getColumnType(i))) sb.append(StringUtils.leftPad(header[i - 1], colsize[i - 1])); else sb.append(StringUtils.rightPad(header[i - 1], colsize[i - 1])); sbSep.append(StringUtils.repeat('-', colsize[i - 1])); sb.append(' '); sbSep.append(' '); } sb.append('\n'); sbSep.append('\n'); sb.append(sbSep); for (int j = 0; j < rows; j++) { sb.append(' '); for (int i = 1; i <= cols; i++) { if (isNumericDataType(md.getColumnType(i))) sb.append(StringUtils.leftPad(out[j][i - 1], colsize[i - 1])); else sb.append(StringUtils.rightPad(out[j][i - 1], colsize[i - 1])); sb.append(' '); } sb.append('\n'); } sb.append(sbSep).append('\n'); } }); } sb.append(" Last refreshed at ").append(new Date()); return sb; }); return res.toString(); } catch (Exception e) { QI.getQI().getLog().error(e); return e.toString(); } }
From source file:org.kie.workbench.common.forms.jbpm.service.bpmn.util.BPMNVariableUtils.java
public static String getRealTypeForInput(String inputType) { String type = StringUtils.defaultIfEmpty(inputType, "java.lang.String"); if (!type.contains(".")) { if ("Object".equals(type)) { return String.class.getName(); }/* www . j a v a 2 s . com*/ if ("String".equals(type)) { return String.class.getName(); } if ("Integer".equals(type)) { return Integer.class.getName(); } if ("Short".equals(type)) { return Short.class.getName(); } if ("Long".equals(type)) { return Long.class.getName(); } if ("Float".equals(type)) { return Float.class.getName(); } if ("Double".equals(type)) { return Double.class.getName(); } if ("Boolean".equals(type)) { return Boolean.class.getName(); } if ("Date".equals(type)) { return Date.class.getName(); } if ("BigDecimal".equals(type)) { return BigDecimal.class.getName(); } if ("BigInteger".equals(type)) { return BigInteger.class.getName(); } } return type; }
From source file:org.ligoj.app.plugin.req.squash.SquashPluginResource.java
/** * Return all Squash TM projects without limit and an optional criteria. *//*w ww .ja va 2 s.co m*/ @SuppressWarnings("unchecked") protected List<SquashProject> getProjectsDataTables(final Map<String, String> parameters, final String criteria) throws IOException { return ((TableItem<SquashProject>) new ObjectMapper() .readValue( StringUtils.defaultIfEmpty( getResource(parameters, "generic-projects?sEcho=4&iDisplayStart=0&iDisplayLength=100000" + (criteria == null ? "" : "&sSearch=" + criteria)), "{\"aaData\":[]}"), VALUE_TYPE_REF)).getAaData(); }
From source file:org.ligoj.app.plugin.req.squash.SquashPluginResource.java
@Override public String getLastVersion() throws IOException { try (CurlProcessor curl = new CurlProcessor()) { final String tagsAsJson = curl.get(publicServer + "/2.0/repositories/nx/squashtest-tm/refs/tags?pagelen=1&q=name~%22squash-tm-%22&sort=-target.date", "Content-Type:application/json"); return StringUtils.removeStart(new ObjectMapper() .readValue(StringUtils.defaultIfEmpty(tagsAsJson, "{\"values\":[]}"), BitBucketTags.class) .getValues().stream().findFirst().map(BitBucketTag::getName).orElse("squash-tm-"), "squash-tm-"); }// ww w. ja v a 2s. c o m }
From source file:org.ligoj.app.plugin.vm.aws.VmAwsPluginResource.java
/** * Get all instances visible for given AWS access key. * * @param parameters//from ww w . ja v a2s. c o m * Subscription parameters. * @param filter * Optional instance identifier to find. For sample : * "&Filter.1.Name=instance-id&Filter.1.Value.1=my_insance_id" * @param parser * The mapper from {@link Element} to {@link AwsVm}. * @return The matching instances. * @throws Exception * When AWS content cannot be read. */ private List<AwsVm> getDescribeInstances(final Map<String, String> parameters, final String filter, final Function<Element, AwsVm> parser) throws Exception { String query = "Action=DescribeInstances"; if (StringUtils.isNotEmpty(filter)) { query += filter; } final String response = StringUtils.defaultIfEmpty(processEC2(parameters, query), "<DescribeInstancesResponse><reservationSet><item><instancesSet></instancesSet></item></reservationSet></DescribeInstancesResponse>"); return toVms(response, parser); }