List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:de.tuberlin.uebb.jbop.optimizer.utils.ClassNodeBuilderTextifier.java
/** * Prints a disassembled view of the given annotation. * //w w w. j a v a2 s .co m * @param desc * the class descriptor of the annotation class. * @param visible * <tt>true</tt> if the annotation is visible at runtime. * @return a visitor to visit the annotation values. */ @Override public Textifier visitAnnotation(final String desc, final boolean visible) { buf.setLength(0); buf.append("withAnnotation("); buf.append(StringUtils.replace(StringUtils.removeEnd(StringUtils.removeStart(desc, "L"), ";"), "/", ".")); buf.append(".class"); text.add(buf.toString()); text.add(").//\n"); return createTextifier(); }
From source file:com.norconex.jef4.status.FileJobStatusStore.java
@Override public final IJobStatus read(String suiteName, final String jobId) throws IOException { MutableJobStatus jobStatus = new MutableJobStatus(jobId); File file = getStatusFile(suiteName, jobId); if (LOG.isDebugEnabled()) { LOG.debug("Reading status file: " + file); }//from ww w . j a v a 2 s . co m if (!file.exists()) { return jobStatus; } Properties config = new Properties(); InputStream is = null; try { is = new FileInputStream(file); config.load(is); if (LOG.isDebugEnabled()) { LOG.debug(jobId + " last active time: " + new Date(file.lastModified())); } jobStatus.setLastActivity(new Date(file.lastModified())); jobStatus.setProgress(config.getDouble("progress", 0d)); jobStatus.setNote(config.getString("note", null)); jobStatus.setResumeAttempts(config.getInt("resumeAttempts", 0)); JobDuration duration = new JobDuration(); duration.setResumedStartTime(config.getDate("resumedStartTime", null)); duration.setResumedLastActivity(config.getDate("resumedLastActivity", null)); duration.setStartTime(config.getDate("startTime", null)); duration.setEndTime(config.getDate("endTime", null)); jobStatus.setDuration(duration); jobStatus.setStopRequested(config.getBoolean("stopped", false)); Properties props = jobStatus.getProperties(); for (String key : config.keySet()) { if (key.startsWith("prop.")) { props.put(StringUtils.removeStart("prop.", key), props.get(key)); } } } finally { IOUtils.closeQuietly(is); } return jobStatus; }
From source file:io.cloudex.framework.cloud.entities.VmMetaData.java
/** * Return a map of all the user meta data * @return the user provided attributes/*from ww w. ja v a 2 s .c o m*/ */ public Map<String, String> getUserMetaData() { Map<String, String> userData = new HashMap<>(); String property; for (String key : this.attributes.keySet()) { if (key.startsWith(USER_PREFIX)) { // we strip a user- prefix on the metadata names then // just use the result as the property name property = StringUtils.removeStart(key, USER_PREFIX); userData.put(property, this.getValue(key)); } } return userData; }
From source file:com.nridge.connector.fs.con_fs.core.FileCrawler.java
private boolean documentExistsInIndex(String aDocId) { Logger appLogger = mAppMgr.getLogger(this, "documentExistsInIndex"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); boolean docExists = false; String propertyName = Constants.CFG_PROPERTY_PREFIX + ".publish.upload_enabled"; if (mAppMgr.getBoolean(propertyName)) { propertyName = Constants.CFG_PROPERTY_PREFIX + ".solr.request_uri"; String solrURI = mAppMgr.getString(propertyName); if (StringUtils.isNotEmpty(solrURI)) { propertyName = Constants.CFG_PROPERTY_PREFIX + ".solr.request_handler"; String propertyValue = mAppMgr.getString(propertyName, Constants.SOLR_REQUEST_HANDLER_DEFAULT); String requestHandler = StringUtils.removeStart(propertyValue, "/"); String solrURL = String.format("%s/%s?q=nsd_id%%3A%s&fl=nsd_doc_hash&wt=xml&echoParams=none", solrURI, requestHandler, aDocId); DSCriteria dsCriteria = new DSCriteria("Solr Document Exists"); dsCriteria.add(Solr.FIELD_URL_NAME, Field.Operator.EQUAL, solrURL); try { int docCount = mSolrDS.count(dsCriteria); docExists = docCount > 0; appLogger.debug(String.format("[%d] %s", docCount, solrURL)); } catch (DSException e) { appLogger.error(String.format("%s: %s", solrURL, e.getMessage())); }/*from w ww . j a va 2 s .c o m*/ } } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); return docExists; }
From source file:com.norconex.commons.lang.ClassFinder.java
private static String resolveName(ClassLoader loader, String rawName, Class<?> superClass) { String className = rawName;/*from www . j a va 2s . c o m*/ if (!rawName.endsWith(".class") || className.contains("$")) { return null; } className = className.replaceAll("[\\\\/]", "."); className = StringUtils.removeStart(className, "."); className = StringUtils.removeEnd(className, ".class"); try { Class<?> clazz = loader.loadClass(className); // load only concrete implementations if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers()) && superClass.isAssignableFrom(clazz)) { return clazz.getName(); } } catch (ClassNotFoundException e) { LOG.error("Invalid class: " + className, e); } catch (NoClassDefFoundError e) { LOG.debug("Invalid class: " + className, e); } return null; }
From source file:io.ecarf.core.term.TermUtils.java
License:asdf
/** * Split the provided term into 2 parts using the slash a separator. Uses some rules concerning : and ? * Some examples://from w ww. j a va 2 s . c o m * <http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/PTO/srchnum.htm&r=1&f=G&l=50&s1=6348648.PN.&OS=PN/6348648&RS=PN/6348648/> [patft.uspto.gov/netacgi, nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/PTO/srchnum.htm&r=1&f=G&l=50&s1=6348648.PN.&OS=PN/6348648&RS=PN/6348648/] <http://www.honda.lv/> [www.honda.lv] <http://gmail.com> [gmail.com] <http://gmail.com:8080/Test?id=test> [gmail.com:8080, Test?id=test] <http://web.archive.org/web/20051031200142/http:/www.mkaz.com/ebeab/history/> [web.archive.org/web/20051031200142, http:/www.mkaz.com/ebeab/history/] <http://web.archive.org/web/20051031200142/?http:/www.mkaz.com/ebeab/history/> [web.archive.org/web/20051031200142, ?http:/www.mkaz.com/ebeab/history/] <http://web.archive.org/web/20051031200142/http:/www.mkaz.com?id=ebeab/history/> [web.archive.org/web/20051031200142, http:/www.mkaz.com?id=ebeab/history/] <http://www.hel.fi/wps/portal/Helsinki_en/?WCM_GLOBAL_CONTEXT=/en/Helsinki/> [www.hel.fi/wps/portal/Helsinki_en, ?WCM_GLOBAL_CONTEXT=/en/Helsinki/] <http://dbpedia.org/resource/Team_handball> [dbpedia.org/resource, Team_handball] <http://dbpedia.org/ontology/wikiPageExternalLink> [dbpedia.org/ontology, wikiPageExternalLink] <http://www.nfsa.gov.au/blog/2012/09/28/tasmanian-time-capsule/> [www.nfsa.gov.au/blog/2012/09/28/tasmanian-time-capsule] <http://www.whereis.com/whereis/mapping/renderMapAddress.do?name=&streetNumber=&street=City%20Center&streetType=&suburb=Hobart&state=Tasmania&latitude=-42.881&longitude=147.3265&navId=$01006046X0OL9$&brandId=1&advertiser Id=&requiredZoomLevel=3> [www.whereis.com/whereis/mapping, renderMapAddress.do?name=&streetNumber=&street=City%20Center&streetType=&suburb=Hobart&state=Tasmania&latitude=-42.881&longitude=147.3265&navId=$01006046X0OL9$&brandId=1&advertiserId=&re quiredZoomLevel=3] * @param term * @param splitLocation - the location of the slash * @return */ public static List<String> splitIntoTwo(String term, boolean hasProtocol, int splitLocation) { String path; if (hasProtocol) { String url = term.substring(1, term.length() - 1); path = StringUtils.removeStart(url, TermUtils.HTTP); if (path.length() == url.length()) { path = StringUtils.removeStart(path, TermUtils.HTTPS); } } else { path = term; } // remove trailing slash if (StringUtils.endsWith(path, URI_SEP_STR)) { path = StringUtils.removeEnd(path, URI_SEP_STR); } //System.out.println(path); List<String> parts = new ArrayList<>(); int slashIdx = path.indexOf(TermUtils.URI_SEP); ; switch (splitLocation) { case 0: // the first slash break; case 1: // the second slash slashIdx = path.indexOf(TermUtils.URI_SEP, slashIdx + 1); break; case -1: default: // the last slash slashIdx = path.lastIndexOf(TermUtils.URI_SEP); int colonIdx = path.indexOf(':'); int questionIdx = path.indexOf('?'); if (((colonIdx > -1) && (slashIdx > colonIdx)) || ((questionIdx > -1) && (slashIdx > questionIdx))) { int idx = -1; boolean colonAndQuestion = (colonIdx > -1) && (questionIdx > -1); if ((colonAndQuestion && (colonIdx < questionIdx)) || (colonIdx > -1)) { idx = getCharIdxBeforeOrAfterIdx(path, colonIdx, TermUtils.URI_SEP); } else if ((colonAndQuestion && (colonIdx > questionIdx)) || (questionIdx > -1)) { idx = getCharIdxBeforeOrAfterIdx(path, questionIdx, TermUtils.URI_SEP); } if (idx > -1) { slashIdx = idx; } } } if (slashIdx > -1) { String part = path.substring(0, slashIdx); if (part.length() > 0) { parts.add(part); } slashIdx++; if (slashIdx < path.length()) { parts.add(path.substring(slashIdx)); } } else { parts.add(path); } return parts; }
From source file:gobblin.metrics.event.sla.SlaEventSubmitter.java
/** * {@link SlaEventKeys} have a prefix of {@link SlaEventKeys#EVENT_GOBBLIN_STATE_PREFIX} to keep properties organized * in state. This method removes the prefix before submitting an Sla event. *///ww w . j a v a2 s. c o m private String withoutPropertiesPrefix(String key) { return StringUtils.removeStart(key, SlaEventKeys.EVENT_GOBBLIN_STATE_PREFIX); }
From source file:com.ewcms.site.model.Channel.java
private String removeStartAndEndPathSeparator(final String dir) { String path = dir;/*from w ww . j av a 2 s . co m*/ path = StringUtils.removeStart(path, PATH_SEPARATOR); path = StringUtils.removeEnd(path, PATH_SEPARATOR); return path; }
From source file:com.nuvolect.securesuite.util.OmniFile.java
/** * Return a short path of the file, not including root. * Member vars m_volumeId and m_std_file must be set. * @return// w ww . j ava 2 s.c o m */ public String getPath() { if (m_isRoot) return CConst.ROOT; String absolutePath; if (m_isCryp) absolutePath = m_cry_file.getPath(); else absolutePath = m_std_file.getPath(); String root = Omni.getRoot(this.m_volumeId); String path = ("/" + StringUtils.removeStart(absolutePath, root)).replace("//", "/"); return path; }
From source file:com.nesscomputing.quartz.QuartzJob.java
@SuppressWarnings("PMD.UseStringBufferForStringAppends") public void submitConditional(final Scheduler scheduler, @Named(NESS_JOB_NAME) final Configuration nessJobConfiguration) throws SchedulerException { String conditionalKey = null; final boolean enableJob; if (enabled != null) { enableJob = enabled;//w w w . ja va 2s .c om } else { if (conditional == null) { enableJob = true; LOG.warn("Neither enable nor conditional was set for %s, enabling unconditionally!", name); } else { conditionalKey = StringUtils.removeStart(conditional, NESS_JOB_NAME + "."); conditionalKey = StringUtils.endsWith(conditionalKey, ".enabled") ? conditionalKey : conditionalKey + ".enabled"; enableJob = nessJobConfiguration.getBoolean(conditionalKey, false); } } if (enableJob) { submit(scheduler); } else { scheduler.addJob(getJobDetail(), false); LOG.info("Job '%s is not scheduled (enabled: %s / conditional: %s)", name, enabled == null ? "<unset>" : enabled.toString(), conditional == null ? "<unset>" : conditionalKey); } }