List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:com.doculibre.constellio.services.AutocompleteServicesImpl.java
@SuppressWarnings("unchecked") static private NamedList<Object> suggest(String q, String fieldName, SolrServer server, Boolean isStringField) { NamedList<Object> returnList = new NamedList<Object>(); // escape special characters SolrQuery query = new SolrQuery(); /*/*from w w w . ja v a2 s . c om*/ * // * Set terms.lower to the input term * query.setParam(TermsParams.TERMS_LOWER, q); // * Set terms.prefix to * the input term query.setParam(TermsParams.TERMS_PREFIX, q); // * Set * terms.lower.incl to false * query.setParam(TermsParams.TERMS_LOWER_INCLUSIVE, "false"); // * Set * terms.fl to the name of the source field * query.setParam(TermsParams.TERMS_FIELD, fieldName); */ query.setParam(TermsParams.TERMS_FIELD, fieldName);// query.addTermsField("spell"); query.setParam(TermsParams.TERMS_LIMIT, TERMS_LIMIT);// query.setTermsLimit(MAX_TERMS); query.setParam(TermsParams.TERMS, "true");// query.setTerms(true); query.setParam(TermsParams.TERMS_LOWER, q);// query.setTermsLower(q); query.setParam(TermsParams.TERMS_PREFIX, q);// query.setTermsPrefix(q); query.setParam(TermsParams.TERMS_MINCOUNT, TERMS_MINCOUNT); query.setRequestHandler(SolrServices.AUTOCOMPLETE_QUERY_NAME); try { QueryResponse qr = server.query(query); NamedList<Object> values = qr.getResponse(); NamedList<Object> terms = (NamedList<Object>) values.get("terms");// TermsResponse // resp // = // qr.getTermsResponse(); NamedList<Object> suggestions = (NamedList<Object>) terms.get(fieldName);// items // = // resp.getTerms("spell"); if (!isStringField) { q = AnalyzerUtils.analyzePhrase(q, false); } for (int i = 0; i < suggestions.size(); i++) { String currentSuggestion = suggestions.getName(i); // System.out.println(currentSuggestion); if (isStringField) { if (currentSuggestion.contains(q)) { // String suffix = // StringUtils.substringAfter(currentSuggestion, q); // if (suffix.isEmpty() && // !currentSuggestion.equals(q)){ // //q n est pas dans currentSuggestion // break; // } if (currentSuggestion.contains(SPECIAL_CHAR)) { // le resultat de recherche retourne des fois une // partie de la valeur existant // dans le champ! currentSuggestion = StringUtils.substringAfter(currentSuggestion, SPECIAL_CHAR); } returnList.add(currentSuggestion, suggestions.getVal(i)); } } else { currentSuggestion = AnalyzerUtils.analyzePhrase(currentSuggestion, false); if (currentSuggestion.contains(q)) { returnList.add(currentSuggestion, suggestions.getVal(i)); } } } } catch (SolrServerException e) { throw new RuntimeException(e); } return returnList; }
From source file:biz.netcentric.cq.tools.actool.installationhistory.impl.AcHistoryServiceImpl.java
private void persistInstalledConfigurations(final Session session, final Node historyNode, AcInstallationHistoryPojo history) { try {// ww w.ja v a2s . c o m Map<String, String> configFileContentsByName = history.getConfigFileContentsByName(); if (configFileContentsByName == null) { return; } String commonPrefix = StringUtils.getCommonPrefix( configFileContentsByName.keySet().toArray(new String[configFileContentsByName.size()])); for (String fullConfigFilePath : configFileContentsByName.keySet()) { File targetPathFile = new File(INSTALLED_CONFIGS_NODE_NAME + "/" + StringUtils.substringAfter(fullConfigFilePath, commonPrefix)); File targetPathParentDir = targetPathFile.getParentFile(); Node configFolder = JcrUtils.getOrCreateByPath(historyNode, targetPathParentDir != null ? targetPathParentDir.getPath() : targetPathFile.getPath(), false, JcrConstants.NT_FOLDER, JcrConstants.NT_FOLDER, false); ByteArrayInputStream configFileInputStream = new ByteArrayInputStream( configFileContentsByName.get(fullConfigFilePath).getBytes()); JcrUtils.putFile(configFolder, targetPathFile.getName(), "text/yaml", configFileInputStream); } history.addVerboseMessage("Saved installed configuration files under : " + historyNode.getPath() + "/" + INSTALLED_CONFIGS_NODE_NAME); } catch (RepositoryException e) { String message = e.toString(); history.addError(message); LOG.error("Exception while saving history node " + historyNode + ": " + message, e); } }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
private void insertSnapshot(Path snapshotPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(snapshotPath.toString(), Path.SEPARATOR); String snapshotName = StringUtils.substringAfterLast(snapshotPath.toString(), Path.SEPARATOR); long ts = Long.parseLong(StringUtils.substringBefore(snapshotName, "-PT-")); long recordCount = Long.parseLong(StringUtils.substringAfter(snapshotName, "-PT-")); PreparedStatement insert = connection.prepareStatement("INSERT INTO Snapshots VALUES (?, ?, ?, ?, ?)"); insert.setString(1, datasetPath);/*from ww w.j a va 2s .c o m*/ insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }
From source file:info.magnolia.importexport.BootstrapUtil.java
/** * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> it will return <code>/server</code>. *//* ww w. java 2s . c o m*/ public static String getPathnameFromResource(final String resourcePath) { String resourceName = StringUtils.replace(resourcePath, "\\", "/"); String name = getFilenameFromResource(resourceName, ".xml"); String fullPath = DataTransporter.revertExportPath(name); String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(fullPath, "/"), "/"); if (!pathName.startsWith("/")) { pathName = "/" + pathName; } return pathName; }
From source file:cool.pandora.modeller.ui.handlers.common.NodeMap.java
/** * getWordIdMap./*w ww. j a v a 2 s . com*/ * * @param hocr hOCRData * @param lineIdList List * @return Map */ public static Map<String, List<String>> getWordIdMap(final hOCRData hocr, final List<String> lineIdList) { final Map<String, List<String>> nodemap = new HashMap<>(); List<String> wordIdList; for (String lineId : lineIdList) { wordIdList = getWordIdListforLine(hocr, lineId); for (int i = 0; i < wordIdList.size(); i++) { final String wordId = StringUtils.substringAfter(wordIdList.get(i), "_"); wordIdList.set(i, wordId); } lineId = StringUtils.substringAfter(lineId, "_"); nodemap.put(lineId, wordIdList); } return nodemap; }
From source file:com.edgenius.wiki.render.macro.CodeMacro.java
@Override protected void replaceHTML(HTMLNode node, ListIterator<HTMLNode> iter, RenderContext context) { if (node.getPair() == null) { log.warn("Unexpect case: No close div tag for " + this.getClass().getName()); return;// w w w . ja va2 s . c om } //remove all HTML tag, as any these tag must from RichEditor, which is invalid to add style to code macro part... HTMLNode subnode; StringBuffer sb = new StringBuffer(); //!!! Here changes ListIterator cursor position!!! for (; iter.hasNext();) { subnode = iter.next(); if (subnode == node.getPair()) break; if (!subnode.isTextNode()) { subnode.reset("", true); if (subnode.getPair() != null) subnode.getPair().reset("", true); } else { sb.append(subnode.getText()); } } //do reverse replace, refer to CodeHandler... if (sb.length() > 0) { String code = sb.toString(); code = code.replaceAll("<", "<"); code = code.replaceAll("&", "&"); //if code content is not empty, node must has next() node.next().reset(code, true); String src = ""; if (node.getAttributes() != null && node.getAttributes().get(NameConstants.CLASS) != null) { String srcName = StringUtils.substringAfter(node.getAttributes().get(NameConstants.CLASS), ":"); if (!DEFAULT_CODE.equalsIgnoreCase(srcName)) { src = "|" + NameConstants.SRC + "=" + srcName; } } //as above Iterator cursor already move to end of pair node, so move them back and restore around insertMarkup method moveIteratorCursorTo(node, iter, false); //move from end to start resetMacroMarkup(TIDY_STYLE_BLOCK, node, iter, "{code" + src + "}", "{code}"); moveIteratorCursorTo(node.getPair(), iter, true); // move from start to end } }
From source file:com.hangum.tadpole.rdb.core.editors.main.function.MainEditorBrowserFunctionService.java
/** * parse last object // w w w .j av a 2s . c o m */ private String parseLastObject(String obj) { String strObject = StringUtils.remove((String) obj, ","); if (StringUtils.contains(strObject, '(')) { strObject = StringUtils.substringBefore(strObject, "("); } if (StringUtils.contains(strObject, ')')) { strObject = StringUtils.substringAfter(strObject, ")"); } return strObject; }
From source file:info.magnolia.cms.util.LinkUtil.java
/** * Make a absolute path relative. It adds ../ until the root is reached * @param absolutePath absolute path/*from w w w . ja va 2s .c o m*/ * @param page page to be relative to * @return relative path */ public static String makeRelativePath(String absolutePath, Content page) { StringBuffer relativePath = new StringBuffer(); int level; try { level = page.getLevel(); } catch (RepositoryException e) { level = 0; } for (int i = 1; i < level; i++) { relativePath.append("../"); //$NON-NLS-1$ } if (absolutePath.startsWith("/")) { relativePath.append(StringUtils.substringAfter(absolutePath, "/")); } else { relativePath.append(absolutePath); } relativePath.append(".html"); //$NON-NLS-1$ return relativePath.toString(); }
From source file:info.magnolia.importexport.PropertiesImportExport.java
protected Object convertNodeDataStringToObject(String valueStr) { if (contains(valueStr, ':')) { final String type = StringUtils.substringBefore(valueStr, ":"); final String value = StringUtils.substringAfter(valueStr, ":"); // there is no beanUtils converter for Calendar if (type.equalsIgnoreCase("date")) { return ISO8601.parse(value); } else if (type.equalsIgnoreCase("binary")) { return new ByteArrayInputStream(value.getBytes()); } else {//w ww . j a va2 s. c o m try { final Class<?> typeCl; if (type.equals("int")) { typeCl = Integer.class; } else { typeCl = Class.forName("java.lang." + StringUtils.capitalize(type)); } return ConvertUtils.convert(value, typeCl); } catch (ClassNotFoundException e) { // possibly a stray :, let's ignore it for now return valueStr; } } } // no type specified, we assume it's a string, no conversion return valueStr; }
From source file:net.contextfw.web.application.internal.servlet.UriMappingFactory.java
private Split getVariableSplit(String path, String split, Pattern verifier) { if (!verifier.matcher(split).matches()) { throw new WebApplicationException("Variable '" + split + "' in path '" + path + "' is not valid."); }//from w w w . j a v a2 s . co m String def = split.substring(1, split.length() - 1); String name = StringUtils.substringBefore(def, ":"); String value = StringUtils.substringAfter(def, ":"); if (StringUtils.isBlank(value)) { value = "[^/]+"; } return new Split(value, name); }