List of usage examples for org.apache.commons.lang StringUtils indexOf
public static int indexOf(String str, String searchStr)
Finds the first index within a String, handling null
.
From source file:org.nekorp.workflow.desktop.view.binding.MonedaBindableJTextField.java
@Override public Object getModelValue() { try {/*from ww w.j a v a2 s .c o m*/ return MonedaVB.valueOf(this.getText()); } catch (IllegalArgumentException e) { String value = this.getText(); int indexPoint = StringUtils.indexOf(value, "."); if (indexPoint == -1) { throw e; } else { if (indexPoint + 1 == value.length()) { value = StringUtils.remove(value, '.'); } else { value = StringUtils.substring(value, 0, indexPoint + 3); } } return MonedaVB.valueOf(value); } }
From source file:org.okj.commons.net.FtpUtils.java
/** * FTP/*from w w w . jav a 2 s . co m*/ * @param path */ public void changeWorkingDirectory(String path) { try { boolean flag = ftp.changeWorkingDirectory(path); if (flag) { // return; } else { // if (StringUtils.startsWith(path, File.separator)) { path = StringUtils.substring(path, 1); } String[] dirs = StringUtils.split(path, File.separator); if (dirs.length <= 0) { // return; } else { boolean success = ftp.changeWorkingDirectory(dirs[0]); if (LOGGER.isInfoEnabled()) { LOGGER.info("[FTPHelper] current.path=" + dirs[0] + ", success=" + success + ", working.dir=" + ftp.printWorkingDirectory()); } // String next = StringUtils.substring(path, StringUtils.indexOf(path, dirs[0]) + dirs[0].length()); changeWorkingDirectory(next); } } } catch (IOException ex) { LogUtils.error(LOGGER, "", ex); } }
From source file:org.okj.commons.net.FtpUtils.java
/** * FTP//from w w w. j a va2s.c o m * @param path */ public void createDirectory(String path) { try { boolean flag = ftp.changeWorkingDirectory(path); if (flag) { // return; } else { // if (StringUtils.startsWith(path, File.separator)) { path = StringUtils.substring(path, 1); } String[] dirs = StringUtils.split(path, File.separator); if (dirs.length <= 0) { // return; } else { if (!ftp.changeWorkingDirectory(dirs[0])) { ftp.makeDirectory(dirs[0]); ftp.changeWorkingDirectory(dirs[0]); // } // String next = StringUtils.substring(path, StringUtils.indexOf(path, dirs[0]) + dirs[0].length()); createDirectory(next); } } } catch (IOException ex) { LogUtils.error(LOGGER, "", ex); } }
From source file:org.okj.commons.web.taglib.template.impl.CheckboxTemplate.java
/** * name//w ww . ja va 2 s .c o m * @param name * @param index * @return */ private String getIndexName(String name, int index) { String indexName = "[" + index + "]"; String checkboxName = ""; // if (StringUtils.indexOf(name, "[]") >= 0) { checkboxName = StringUtils.replace(name, "[]", indexName); } checkboxName = name + indexName; if (StringUtils.isNotBlank(attribute.getListValue())) { checkboxName += "." + attribute.getListValue(); } return checkboxName; }
From source file:org.onehippo.forge.content.pojo.model.BinaryValue.java
/** * Converts the given {@code dataUri} which is supposed to be a <code>data:</code> URL * to a {@link BinaryValue} object./*from w w w . j a v a 2 s. co m*/ * @param dataUri a <code>data:</code> URL * @return a {@link BinaryValue} object converted from the given {@code dataUri} */ public static BinaryValue fromDataURI(String dataUri) { if (!StringUtils.startsWith(dataUri, "data:")) { throw new IllegalArgumentException("Invalid data uri."); } int offset = StringUtils.indexOf(dataUri, ','); if (offset == -1) { throw new IllegalArgumentException("Invalid data uri."); } String mediaType = null; String charset = null; String metadata = dataUri.substring(5, offset); String[] tokens = StringUtils.split(metadata, ";"); if (tokens != null) { for (String token : tokens) { if (token.startsWith("charset=")) { charset = token.substring(8); } else if (!token.equals("base64")) { mediaType = token; } } } String dataString = dataUri.substring(offset + 1); byte[] data = Base64.getDecoder().decode(dataString); BinaryValue binaryValue = new BinaryValue(data, mediaType, charset); return binaryValue; }
From source file:org.openhab.io.neeo.internal.servletservices.NeeoBrainSearchService.java
/** * Does the search of all things and returns the results * * @param queryString the non-null, possibly empty query string * @param resp the non-null response to write to * @throws IOException Signals that an I/O exception has occurred. *//*from w w w . ja v a2 s . co m*/ private void doSearch(String queryString, HttpServletResponse resp) throws IOException { Objects.requireNonNull(queryString, "queryString cannot be null"); Objects.requireNonNull(resp, "resp cannot be null"); final int idx = StringUtils.indexOf(queryString, '='); if (idx >= 0 && idx + 1 < queryString.length()) { final String search = NeeoUtil.decodeURIComponent(queryString.substring(idx + 1)); final List<JsonObject> ja = new ArrayList<>(); search(search).stream().sorted(Comparator.comparing(TokenScoreResult<NeeoDevice>::getScore).reversed()) .forEach(item -> { final JsonObject jo = (JsonObject) gson.toJsonTree(item); // transfer id from tokenscoreresult to neeodevice (as per NEEO API) final int id = jo.getAsJsonPrimitive("id").getAsInt(); jo.remove("id"); jo.getAsJsonObject("item").addProperty("id", id); ja.add(jo); }); final String itemStr = gson.toJson(ja); logger.debug("Search '{}', response: {}", search, itemStr); NeeoUtil.write(resp, itemStr); } }
From source file:org.opentestsystem.authoring.testauth.publish.BasePublisherHelper.java
protected List<TestBlueprintElement> setupBlueprintData(final Assessment assessment, final List<Item> itemList, final List<Segment> segmentList, final List<BlueprintElement> blueprintElementList, final List<AffinityGroup> affinityGroupList) { final List<TestBlueprintElement> blueprintList = Lists.newArrayList(); int testLevelOpMin = 0, testLevelOpMax = 0, testLevelFtMin = 0, testLevelFtMax = 0, testLevelOpItemCount = 0, testLevelFtItemCount = 0; // roll up all totals per segment final Map<String, ItemCountSummary> masterItemCounts = new HashMap<String, ItemCountSummary>(); final List<TestBlueprintElement> segmentBlueprintList = Lists.newArrayList(); for (final Segment segment : segmentList) { final boolean isFixedFormSegment = segment.getItemSelectionAlgorithm().getItemSelectionAlgorithmType() .equals(ItemSelectionAlgorithmType.FIXEDFORM); final Map<String, ItemCountSummary> blueprintItemCountsBySegment = getBlueprintItemCounts(assessment, itemList, segment.getId(), blueprintElementList, isFixedFormSegment); // in order to avoid multiple adding int segmentLevelOpItemCount = 0, segmentLevelFtItemCount = 0; final Map<String, ItemCountSummary> blueprintItemCountsBySegmentByStrands = getBlueprintItemCountsByStrands( assessment, itemList, segment.getId(), blueprintElementList, isFixedFormSegment); for (final Entry<String, ItemCountSummary> blueprintElementCount : blueprintItemCountsBySegmentByStrands .entrySet()) {/*from w ww .j a v a 2 s .c o m*/ segmentLevelOpItemCount = segmentLevelOpItemCount + blueprintElementCount.getValue().getOpCount(); segmentLevelFtItemCount = segmentLevelFtItemCount + blueprintElementCount.getValue().getFtCount(); } for (final Entry<String, ItemCountSummary> blueprintElementCount : blueprintItemCountsBySegment .entrySet()) { // roll up totals by blueprint standard for master level ItemCountSummary masterBpElementItemCounts = masterItemCounts.get(blueprintElementCount.getKey()); if (masterBpElementItemCounts == null) { masterBpElementItemCounts = new ItemCountSummary(); masterItemCounts.put(blueprintElementCount.getKey(), masterBpElementItemCounts); } final int newOpCount = TestAuthUtil.safeParseInt(masterBpElementItemCounts.getOpCount()) + blueprintElementCount.getValue().getOpCount(); masterBpElementItemCounts.setOpCount(newOpCount); final int newFtCount = TestAuthUtil.safeParseInt(masterBpElementItemCounts.getFtCount()) + blueprintElementCount.getValue().getFtCount(); masterBpElementItemCounts.setFtCount(newFtCount); } // segment level // AK: if there is only one segment segment uniqueid must be equal test(assessment) uniqueid segmentBlueprintList.add(new TestBlueprintElement( new Identifier( (segmentList.size() == 1) ? buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()).getUniqueId() : segment.getId(), segment.getLabel(), segment.getLabel(), DEFAULT_VERSION), "segment", buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()) .getUniqueId(), segment.getMinOpItems(), segment.getMaxOpItems(), segment.getMinFtItems(), segment.getMaxFtItems(), segmentLevelOpItemCount, segmentLevelFtItemCount)); testLevelOpMin = testLevelOpMin + segment.getMinOpItems(); testLevelOpMax = testLevelOpMax + segment.getMaxOpItems(); testLevelFtMin = testLevelFtMin + segment.getMinFtItems(); testLevelFtMax = testLevelFtMax + segment.getMaxFtItems(); testLevelOpItemCount = testLevelOpItemCount + segmentLevelOpItemCount; testLevelFtItemCount = testLevelFtItemCount + segmentLevelFtItemCount; } // master bp elemenets String name = null; final List<TestBlueprintElement> masterBlueprintList = Lists.newArrayList(); for (final BlueprintElement blueprintElement : blueprintElementList) { // StandardKey at this point has 'client' as prefix; 'name' element does not need this prefix int pubEndPos = StringUtils.indexOf(blueprintElement.getStandardKey(), "-"); if (pubEndPos > 0) name = StringUtils.substring(blueprintElement.getStandardKey(), pubEndPos + 1); masterBlueprintList.add(new TestBlueprintElement( new Identifier(blueprintElement.getStandardKey(), name, null, DEFAULT_VERSION), blueprintElement.getElementTypeName(), blueprintElement.getParentKey(), blueprintElement.getMasterValue().getOperationalItemMinValue(), blueprintElement.getMasterValue().getOperationalItemMaxValue(), blueprintElement.getMasterValue().getFieldTestItemMinValue(), blueprintElement.getMasterValue().getFieldTestItemMaxValue(), masterItemCounts.get(blueprintElement.getStandardKey()).getOpCount(), masterItemCounts.get(blueprintElement.getStandardKey()).getFtCount())); } // top/test level final List<TestBlueprintElement> testBlueprintList = Lists.newArrayList(); // this change has to fix null -> uniqueid for bpelement with type = 'test' // this uniqueid must be the same as testspecificationUniqueid TestBlueprintElement tbp = new TestBlueprintElement( buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()), "test", null, testLevelOpMin, testLevelOpMax, testLevelFtMin, testLevelFtMax, testLevelOpItemCount, testLevelFtItemCount); tbp.getIdentifier().setName(assessment.getName() + '-' + assessment.getVersion()); testBlueprintList.add(tbp); final List<TestBlueprintElement> affinityGroupBlueprintList = Lists.newArrayList(); for (final AffinityGroup affinityGroup : affinityGroupList) { affinityGroupBlueprintList.add(new TestBlueprintElement( buildIdentifier(affinityGroup.getGroupName(), null, DEFAULT_VERSION), "affinitygroup", buildIdentifier(assessment.getName(), assessment.getLabel(), assessment.getVersion()) .getUniqueId())); } blueprintList.addAll(testBlueprintList); blueprintList.addAll(segmentBlueprintList); blueprintList.addAll(masterBlueprintList); blueprintList.addAll(affinityGroupBlueprintList); return blueprintList; }
From source file:org.opentestsystem.authoring.testauth.publish.PublisherUtil.java
protected static final Integer versionTransformer(final String version) { try {//from w w w . java 2s .c o m int decimalSeparatorPosition = StringUtils.indexOf(version, DECIMALSEPARATOR); String fraction = StringUtils.substring(version, decimalSeparatorPosition + 1); String integerPart = version.substring(0, decimalSeparatorPosition); Integer fracPart = Integer.valueOf(fraction); Integer intPart = Integer.valueOf(integerPart); return intPart * MAXIMUMMINORVERSIONS + fracPart; } catch (Exception e) { return 0; } }
From source file:org.opentestsystem.authoring.testauth.service.impl.BlueprintElementServiceImpl.java
private String convertIntoBlueprintCompatible(String client, String standardKey) { //EF: we have CoreStandards as "SBAC-ELA-v1:2-W" and need to transform to "SBAC-2-W" to match // what we store in BlueprintElement collection int pubEndPos = StringUtils.indexOf(standardKey, ":"); if (pubEndPos > 0) return (client.concat("-").concat(StringUtils.substring(standardKey, pubEndPos + 1))); else//from ww w.j av a 2 s. c o m return (client.concat("-").concat(standardKey)); }
From source file:org.sakaiproject.jsf.roster.HtmlSortHeaderRenderer.java
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException { // If this is a currently sorted sort header, always give it the "currentSort" CSS style class if (component instanceof HtmlCommandSortHeader) { HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader) component; String styleClass = StringUtils.trimToNull(getStyleClass(facesContext, component)); String newStyleClass;/*from ww w . ja v a 2s . c om*/ String unStyleClass; if (sortHeader.findParentDataTable().getSortColumn().equals(sortHeader.getColumnName())) { newStyleClass = CURRENT_SORT_STYLE; unStyleClass = NOT_CURRENT_SORT_STYLE; } else { newStyleClass = NOT_CURRENT_SORT_STYLE; unStyleClass = CURRENT_SORT_STYLE; } if (StringUtils.indexOf(styleClass, newStyleClass) == -1) { if (StringUtils.indexOf(styleClass, unStyleClass) != -1) { styleClass = StringUtils.replace(styleClass, unStyleClass, newStyleClass); } else if (styleClass != null) { styleClass = (new StringBuilder(styleClass)).append(' ').append(newStyleClass).toString(); } else { styleClass = newStyleClass; } sortHeader.setStyleClass(styleClass); } } super.encodeBegin(facesContext, component); //check for NP }