List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:orca.ndllib.ndl.RequestLoader.java
public void ndlReservation(Resource i, final OntModel m) { request.logger().debug("Reservation: " + i + ", sliceState(Request:ndlReservation) = " + NdlCommons.getGeniSliceStateName(i)); // try to extract the guid out of the URL String u = i.getURI();// ww w . ja v a2s .c o m String guid = StringUtils.removeEnd(StringUtils.removeStart(u, NdlCommons.ORCA_NS), "#"); this.request.setNsGuid(guid); this.slice.setState(NdlCommons.getGeniSliceStateName(i)); /*if (i != null) { reservationDomain = RequestSaver.reverseLookupDomain(NdlCommons.getDomain(i)); this.request.setOFVersion(NdlCommons.getOpenFlowVersion(i)); }*/ }
From source file:orca.ndllib.ndl.RequestSaver.java
/************************************** Helper Function ***************************************/ // use different maps to try to do a reverse lookup private static String reverseLookupDomain_(Resource domain, Map<String, String> m, String suffix) { String domainName = StringUtils.removeStart(domain.getURI(), NdlCommons.ORCA_NS); if (domainName == null) return null; // remove one or the other domainName = StringUtils.removeEnd(domainName, suffix); for (Iterator<Map.Entry<String, String>> domName = m.entrySet().iterator(); domName.hasNext();) { Map.Entry<String, String> e = domName.next(); if (domainName.equals(e.getValue())) return e.getKey(); }//from www. j a v a 2 s. c o m return null; }
From source file:orca.ndllib.ndl.RequestSaver.java
private static String reverseLookupDomain_(String dom, Map<String, String> m, String suffix) { String domainName = StringUtils.removeStart(dom, NdlCommons.ORCA_NS); if (domainName == null) return null; // remove one or the other domainName = StringUtils.removeEnd(domainName, suffix); for (Iterator<Map.Entry<String, String>> domName = m.entrySet().iterator(); domName.hasNext();) { Map.Entry<String, String> e = domName.next(); if (domainName.equals(e.getValue())) return e.getKey(); }/*from w w w . java 2s .co m*/ return null; }
From source file:orca.ndllib.ndl.RequestSaver.java
/** * Do a reverse lookup on domain (NDL -> short name) * @param domain// ww w . j a v a 2s . c om * @return */ public static String reverseLookupDomain(Resource domain) { if (domain == null) return null; // strip off name space and "/Domain" String domainName = StringUtils.removeStart(domain.getURI(), NdlCommons.ORCA_NS); if (domainName == null) return null; // try vm domain, then net domain String mapping = reverseLookupDomain_(domain, domainMap, "/Domain"); if (mapping == null) mapping = reverseLookupDomain_(domain, domainMap, "/Domain/vm"); if (mapping == null) mapping = reverseLookupDomain_(domain, netDomainMap, "/Domain/vlan"); if (mapping == null) mapping = reverseLookupDomain_(domain, domainMap, "/Domain/lun"); return mapping; //return null; }
From source file:orca.ndllib.ndl.RequestSaver.java
public static String reverseLookupDomain(String dom) { if (dom == null) return null; // strip off name space and "/Domain" String domainName = StringUtils.removeStart(dom, NdlCommons.ORCA_NS); if (domainName == null) return null; // try vm domain, then net domain String mapping = reverseLookupDomain_(dom, domainMap, "/Domain"); if (mapping == null) mapping = reverseLookupDomain_(dom, domainMap, "/Domain/vm"); if (mapping == null) mapping = reverseLookupDomain_(dom, netDomainMap, "/Domain/vlan"); return mapping; //return null; }
From source file:org.activiti.designer.kickstart.eclipse.sync.SyncUtil.java
protected static void zipDirectory(final ZipOutputStream out, final File base, final String absoluteDirPathToStrip) throws Exception { File[] reportFiles = base.listFiles(); for (final File file : reportFiles) { if (file.isDirectory()) { zipDirectory(out, file, absoluteDirPathToStrip); continue; }// w w w .j a v a2 s . c o m String entryName = StringUtils.removeStart(file.getAbsolutePath(), absoluteDirPathToStrip); entryName = backlashReplace(entryName); ZipEntry entry = new ZipEntry(entryName); out.putNextEntry(entry); if (file.isFile()) { FileInputStream fin = new FileInputStream(file); byte[] fileContent = new byte[(int) file.length()]; fin.read(fileContent); out.write(fileContent); fin.close(); } out.closeEntry(); } }
From source file:org.apache.apex.malhar.lib.fs.s3.S3InitiateFileUploadOperator.java
/** * Generates the key name from the given file path and output directory path. * @param filePath file path to upload/*from w w w . j a va2 s.c om*/ * @return key name for the given file */ private String getKeyName(String filePath) { return outputDirectoryPath + Path.SEPARATOR + StringUtils.removeStart(filePath, Path.SEPARATOR); }
From source file:org.apache.archiva.admin.model.beans.RemoteRepository.java
public void setCheckPath(String checkPath) { if (checkPath == null) { this.checkPath = ""; } else if (checkPath.startsWith("/")) { this.checkPath = StringUtils.removeStart(checkPath, "/"); while (this.checkPath.startsWith("/")) { this.checkPath = StringUtils.removeStart(checkPath, "/"); }/*from ww w. j a v a 2 s .c o m*/ } else { this.checkPath = checkPath; } }
From source file:org.apache.archiva.web.docs.RestDocsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { logger.debug("docs request to path: {}", req.getPathInfo()); String path = StringUtils.removeStart(req.getPathInfo(), "/"); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); if (StringUtils.endsWith(path, ".xsd")) { StringEscapeUtils.escapeXml(resp.getWriter(), IOUtils.toString(is)); //IOUtils.copy( is, resp.getOutputStream() ); return;/*from w w w . j a v a 2 s . co m*/ } String startPath = StringUtils.substringBefore(path, "/"); // replace all links !! Document document = Jsoup.parse(is, "UTF-8", ""); Element body = document.body().child(0); Elements links = body.select("a[href]"); for (Element link : links) { link.attr("href", "#" + startPath + "/" + link.attr("href")); } Elements datalinks = body.select("[data-href]"); for (Element link : datalinks) { link.attr("data-href", "#" + startPath + "/" + link.attr("data-href")); } Elements codes = body.select("code"); for (Element code : codes) { code.attr("class", code.attr("class") + " nice-code"); } //default generated enunciate use h1/h2/h3 which is quite big so transform to h3/h4/h5 Elements headers = body.select("h1"); for (Element header : headers) { header.tagName("h3"); } headers = body.select("h2"); for (Element header : headers) { header.tagName("h4"); } headers = body.select("h3"); for (Element header : headers) { header.tagName("h5"); } Document res = new Document(""); res.appendChild(body.select("div[id=main]").first()); Elements scripts = body.select("script"); for (Element script : scripts) { res.appendChild(script); } resp.getOutputStream().write(res.outerHtml().getBytes()); }
From source file:org.apache.beam.examples.oozie.OozieAuditLogParser.java
private void applyValueTo(OozieAuditLogObject oozieAuditLogObject, Matcher matcher) throws ParseException { oozieAuditLogObject.timestamp = humanDateToMilliseconds(matcher.group(1)); oozieAuditLogObject.level = matcher.group(2); oozieAuditLogObject.ip = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(6), "["), "]"); oozieAuditLogObject.user = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(9), "["), "]"); oozieAuditLogObject.group = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(12), "["), "]"); oozieAuditLogObject.app = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(15), "["), "]"); oozieAuditLogObject.jobId = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(18), "["), "]"); oozieAuditLogObject.operation = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(21), "["), "]"); oozieAuditLogObject.parameter = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(24), "["), "]"); oozieAuditLogObject.status = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(27), "["), "]"); oozieAuditLogObject.httpcode = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(30), "["), "]"); oozieAuditLogObject.errorcode = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(33), "["), "]"); oozieAuditLogObject.errormessage = StringUtils.removeEnd(StringUtils.removeStart(matcher.group(36), "["), "]"); }