List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:net.ymate.platform.mvc.web.support.RequestMappingParser.java
/** * @param partStr ?/* ww w . j a v a2 s . c o m*/ * @return '/' */ protected String fixMappingPart(String partStr) { partStr = StringUtils.trimToEmpty(partStr); if (StringUtils.startsWith(partStr, "/")) { partStr = StringUtils.substringAfter(partStr, "/"); } if (StringUtils.endsWith(partStr, "/")) { partStr = StringUtils.substringBeforeLast(partStr, "/"); } return partStr; }
From source file:net.ymate.platform.webmvc.impl.DefaultInterceptorRuleProcessor.java
public PairObject<IView, ResponseCache> processRequest(IWebMvc owner, IRequestContext requestContext) throws Exception { String _mapping = requestContext.getRequestMapping(); InterceptorRuleMeta _ruleMeta = __interceptorRules.get(_mapping); IView _view = null;//from w ww .j ava 2 s . c om if (_ruleMeta == null) { while (StringUtils.countMatches(_mapping, "/") > 1) { _mapping = StringUtils.substringBeforeLast(_mapping, "/"); _ruleMeta = __interceptorRules.get(_mapping); if (_ruleMeta != null && _ruleMeta.isMatchAll()) { break; } } } ResponseCache _responseCache = null; if (_ruleMeta != null) { _responseCache = _ruleMeta.getResponseCache(); InterceptContext _context = new InterceptContext(IInterceptor.Direction.BEFORE, owner.getOwner(), null, null, null, _ruleMeta.getContextParams()); // for (Class<? extends IInterceptor> _interceptClass : _ruleMeta.getBeforeIntercepts()) { IInterceptor _interceptor = _interceptClass.newInstance(); // ??? Object _result = _interceptor.intercept(_context); if (_result != null) { _view = (IView) _result; break; } } } return new PairObject<IView, ResponseCache>(_view, _responseCache); }
From source file:net.ymate.platform.webmvc.support.RequestMappingParser.java
/** * @param partStr ?//from w ww .j a va 2 s .c om * @return '/' */ private String __doFixMappingPart(String partStr) { partStr = StringUtils.trimToEmpty(partStr); if (StringUtils.startsWith(partStr, "/")) { partStr = StringUtils.substringAfter(partStr, "/"); } if (StringUtils.endsWith(partStr, "/")) { partStr = StringUtils.substringBeforeLast(partStr, "/"); } return partStr; }
From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java
private void addFileContent(XMLStreamWriter xmlStreamWriter, String urlString, String type) throws XMLStreamException { xmlStreamWriter.writeStartElement("content"); xmlStreamWriter.writeAttribute("type", type); String content;//from w w w. ja va 2 s . co m try { content = getHtml(urlString); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting file content", e, true); content = null; } if (content != null) { Vector<String> warnMessage = new Vector<String>(); try { if (type.equals("jmsDest") || type.equals("jmsDestConf")) { // AMX - receive (for jmsInboundDest) Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/@name"); if (c1 != null && c1.size() > 0) { if (c1.size() > 1) { warnMessage.add("more then one resourceName found"); } String resourceName = (String) c1.iterator().next(); xmlStreamWriter.writeStartElement("resourceName"); xmlStreamWriter.writeCharacters(resourceName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceName found"); } Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/configuration/@jndiName"); if (c2 != null && c2.size() > 0) { if (c2.size() > 1) { warnMessage.add("more then one resourceJndiName found"); } String resourceJndiName = (String) c2.iterator().next(); xmlStreamWriter.writeStartElement("resourceJndiName"); xmlStreamWriter.writeCharacters(resourceJndiName); xmlStreamWriter.writeEndElement(); } else { warnMessage.add("no resourceJndiName found"); } } else if (type.equals("composite")) { // AMX - receive Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "composite/service/bindingAdjunct/property[@name='JmsInboundDestinationConfig']/@simpleValue"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsInboundDest"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsInboundDest found"); } // AMX - send Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "composite/reference/interface.wsdl/@wsdlLocation"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { String itn = c2it.next(); String wsdl = null; try { URL url = new URL(urlString); URL wsdlUrl = new URL(url, itn); wsdl = getHtml(wsdlUrl.toString()); } catch (Exception e) { error(xmlStreamWriter, "error occured during getting wsdl file content", e, true); wsdl = null; } if (wsdl != null) { Collection<String> c3 = XmlUtils.evaluateXPathNodeSet(wsdl, // "definitions/service/port/targetAddress", // "concat(.,';',../../@name)"); "definitions/service/port/targetAddress"); if (c3 != null && c3.size() > 0) { for (Iterator<String> c3it = c3.iterator(); c3it.hasNext();) { xmlStreamWriter.writeStartElement("targetAddr"); xmlStreamWriter.writeCharacters(c3it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no targetAddr found"); } } else { warnMessage.add("wsdl [" + itn + "] not found"); } } } else { warnMessage.add("no wsdlLocation found"); } } else if (type.equals("process")) { // BW - receive Double d1 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config)"); if (d1 > 0) { Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config/sharedChannels/jmsChannel/JMSTo"); if (c1 != null && c1.size() > 0) { for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapEventSource"); xmlStreamWriter.writeCharacters(c1it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapEventSource"); } } else { warnMessage.add("no soapEventSource found"); } // BW - send Double d2 = XmlUtils.evaluateXPathNumber(content, "count(ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config)"); if (d2 > 0) { Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content, "ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config/sharedChannels/jmsChannel/JMSTo"); if (c2 != null && c2.size() > 0) { for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) { xmlStreamWriter.writeStartElement("jmsTo"); xmlStreamWriter.writeAttribute("type", "soapSendReceiveActivity"); xmlStreamWriter.writeCharacters(c2it.next()); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no jmsTo found for soapSendReceiveActivity"); } } else { warnMessage.add("no soapSendReceiveActivity found"); } } else if (type.equals("substVar")) { String path = StringUtils .substringBeforeLast(StringUtils.substringAfterLast(urlString, "/defaultVars/"), "/"); Map<String, String> m1 = XmlUtils.evaluateXPathNodeSet(content, "repository/globalVariables/globalVariable", "name", "value"); if (m1 != null && m1.size() > 0) { for (Iterator<String> m1it = m1.keySet().iterator(); m1it.hasNext();) { Object key = m1it.next(); Object value = m1.get(key); xmlStreamWriter.writeStartElement("globalVariable"); xmlStreamWriter.writeAttribute("name", (String) key); xmlStreamWriter.writeAttribute("ref", "%%" + path + "/" + key + "%%"); xmlStreamWriter.writeCharacters((String) value); xmlStreamWriter.writeEndElement(); } } else { warnMessage.add("no globalVariable found"); } /* * } else { content = XmlUtils.removeNamespaces(content); * xmlStreamWriter.writeCharacters(content); */ } } catch (Exception e) { error(xmlStreamWriter, "error occured during processing " + type + " file", e, true); } if (warnMessage.size() > 0) { xmlStreamWriter.writeStartElement("warnMessages"); for (int i = 0; i < warnMessage.size(); i++) { xmlStreamWriter.writeStartElement("warnMessage"); xmlStreamWriter.writeCharacters(warnMessage.elementAt(i)); xmlStreamWriter.writeEndElement(); } xmlStreamWriter.writeEndElement(); } } xmlStreamWriter.writeEndElement(); }
From source file:nl.nn.adapterframework.util.FileUtils.java
public static File getFreeFile(File file) { if (file.exists()) { String extension = FileUtils.getFileNameExtension(file.getPath()); int count = 1; while (true) { String newFileName;// w w w. j a v a2s . c om String countStr; if (count < 1000) { countStr = StringUtils.leftPad(("" + count), 3, "0"); } else { countStr = "" + count; } if (extension != null) { newFileName = StringUtils.substringBeforeLast(file.getPath(), ".") + "_" + countStr + "." + extension; } else { newFileName = file.getPath() + "_" + countStr; } File newFile = new File(newFileName); if (newFile.exists()) { count++; } else { return newFile; } } } else { return file; } }
From source file:nl.nn.adapterframework.webcontrol.pipes.Webservices.java
private String doGet(IPipeLineSession session) throws PipeRunException { IbisManager ibisManager = RestListenerUtils.retrieveIbisManager(session); String uri = (String) session.get("uri"); String indent = (String) session.get("indent"); String useIncludes = (String) session.get("useIncludes"); if (StringUtils.isNotEmpty(uri) && (uri.endsWith(getWsdlExtention()) || uri.endsWith(".zip"))) { String adapterName = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(uri, "/"), "."); IAdapter adapter = ibisManager.getRegisteredAdapter(adapterName); if (adapter == null) { throw new PipeRunException(this, getLogPrefix(session) + "adapter [" + adapterName + "] doesn't exist"); }// w ww . j a v a 2 s . c o m try { if (uri.endsWith(getWsdlExtention())) { RestListenerUtils.setResponseContentType(session, "application/xml"); wsdl((Adapter) adapter, session, indent, useIncludes); } else { RestListenerUtils.setResponseContentType(session, "application/octet-stream"); zip((Adapter) adapter, session); } } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on retrieving wsdl", e); } return ""; } else { return list(ibisManager); } }
From source file:nl.tranquilizedquality.itest.cargo.AbstractInstalledContainerUtil.java
/** * Installs the container and the application configuration. It also sets * some system properties so the container can startup properly. Finally it * sets up additional configuration like jndi.proprties files etc. *//*from w w w.ja v a 2 s . c om*/ protected void setupContainer() { if (LOGGER.isInfoEnabled()) { LOGGER.info("Cleaning up " + containerName + "..."); } // In windows the renaming causes problem when: // - The zip file has not the same name of the installed directory. // - The ZipURLInstaller fails. final String operatingSystem = System.getProperty("os.name"); if (operatingSystem != null && !operatingSystem.startsWith("Windows")) { try { new File(containerHome).mkdir(); } catch (final Exception exceptionOnMkDir) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Failed to create the directory: " + containerHome + ". Details: " + exceptionOnMkDir.getMessage(), exceptionOnMkDir); } throw new ConfigurationException("Failed to create the directory: " + containerHome + ". Details: " + exceptionOnMkDir.getMessage(), exceptionOnMkDir); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Installing " + containerName + "..."); LOGGER.info("Downloading container from: " + remoteLocation); LOGGER.info("Container file: " + containerFile); } /* * Download and configure the container. */ final String installDir = StringUtils.substringBeforeLast(StringUtils.chomp(containerHome, "/"), "/"); if (StringUtils.contains(this.remoteLocation, "http")) { try { final URL remoteLocationUrl = new URL(this.remoteLocation + containerFile); final ZipURLInstaller installer = new ZipURLInstaller(remoteLocationUrl, installDir, installDir); installer.install(); } catch (final MalformedURLException e) { throw new DeployException("Failed to download container!", e); } /* * Rename the install directory to the container home directory so * it doesn't matter what the name is of the zip file and avoid case * sensitive issues on Linux. */ final String containerDir = StringUtils.stripEnd(containerFile, ".zip"); final File installedDir = new File(installDir + "/" + containerDir + "/"); final File destenationDir = new File(containerHome); if (LOGGER.isInfoEnabled()) { LOGGER.info("Renaming: " + installedDir.getPath()); LOGGER.info("To: " + destenationDir.getPath()); } final boolean renamed = installedDir.renameTo(destenationDir); if (!renamed) { final String msg = "Failed to rename container install directory to home directory name!"; if (LOGGER.isErrorEnabled()) { LOGGER.error(msg); } throw new ConfigurationException(msg); } } else { final Unzip unzipper = new Unzip(); unzipper.setSrc(new File(this.remoteLocation + containerFile)); unzipper.setDest(new File(containerHome)); unzipper.execute(); } /* * Setup the system properties. */ systemProperties.put("cargo.server.port", containerPort.toString()); }
From source file:org.activiti.designer.property.extension.util.ExtensionPropertyUtil.java
/** * Inspects the provided value and extracts the value for the * {@link PeriodPropertyElement} provided. * // w w w .j av a2 s. com * @param parent * the parent component */ public static final int getPeriodPropertyElementFromValue(final String value, final PeriodPropertyElement propertyElement) { int result = 0; final String[] elementValues = value.split(" "); if (propertyElement != null) { final String stripped = StringUtils.substringBeforeLast(elementValues[propertyElement.getOrder()], propertyElement.getShortFormat()); result = Integer.parseInt(stripped); } return result; }
From source file:org.akaza.openclinica.dao.QueryStore.java
public void init() { String dbFolder = resolveDbFolder(); PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver( resourceLoader);//from w ww .j av a2 s . c om try { Resource resources[] = resourceResolver .getResources("classpath:queries/" + dbFolder + "/**/*.properties"); for (Resource r : resources) { Properties p = new Properties(); p.load(r.getInputStream()); fileByName.put(StringUtils.substringBeforeLast(r.getFilename(), "."), p); } } catch (IOException e) { throw new BeanInitializationException( "Unable to read files from directory 'classpath:queries/" + dbFolder + "'", e); } }
From source file:org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin.java
protected String calculateIndexRemoteUrl(RemoteRepository remoteRepository) { if (StringUtils.startsWith(remoteRepository.getRemoteIndexUrl(), "http")) { String baseUrl = remoteRepository.getRemoteIndexUrl(); return baseUrl.endsWith("/") ? StringUtils.substringBeforeLast(baseUrl, "/") : baseUrl; }/*from www . j a v a 2s. co m*/ String baseUrl = StringUtils.endsWith(remoteRepository.getUrl(), "/") ? StringUtils.substringBeforeLast(remoteRepository.getUrl(), "/") : remoteRepository.getUrl(); baseUrl = StringUtils.isEmpty(remoteRepository.getRemoteIndexUrl()) ? baseUrl + "/.index" : baseUrl + "/" + remoteRepository.getRemoteIndexUrl(); return baseUrl; }