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:org.ebayopensource.turmeric.eclipse.utils.wsdl.WSDLUtil.java
private static String[] getParentFolder(String fullFileName) { String[] result = new String[2]; final String slash = "/"; if (StringUtils.isNotBlank(fullFileName)) { fullFileName = StringUtils.replaceChars(fullFileName, File.separator, slash); result[0] = fullFileName.indexOf(slash) >= 0 ? StringUtils.substringBeforeLast(fullFileName, slash) : ""; result[1] = StringUtils.substringAfterLast(fullFileName, "/"); }//from w ww . ja v a2 s.c o m return result; }
From source file:org.eclipse.buildship.docs.source.model.ClassMetaData.java
public ClassMetaData(String className) { this(className, StringUtils.substringBeforeLast(className, "."), MetaType.CLASS, false, ""); }
From source file:org.eclipse.buildship.docs.source.TypeNameResolver.java
/** * Resolves a source type name into a fully qualified type name. *//* w w w . ja va 2 s.com*/ public String resolve(String name, ClassMetaData classMetaData) { if (primitiveTypes.contains(name)) { return name; } String candidateClassName; String[] innerNames = name.split("\\."); ClassMetaData pos = classMetaData; for (int i = 0; i < innerNames.length; i++) { String innerName = innerNames[i]; candidateClassName = pos.getClassName() + '.' + innerName; if (!pos.getInnerClassNames().contains(candidateClassName)) { break; } if (i == innerNames.length - 1) { return candidateClassName; } pos = metaDataRepository.get(candidateClassName); } String outerClassName = classMetaData.getOuterClassName(); while (outerClassName != null) { if (name.equals(StringUtils.substringAfterLast(outerClassName, "."))) { return outerClassName; } ClassMetaData outerClass = metaDataRepository.get(outerClassName); candidateClassName = outerClassName + '.' + name; if (outerClass.getInnerClassNames().contains(candidateClassName)) { return candidateClassName; } outerClassName = outerClass.getOuterClassName(); } if (name.contains(".")) { return name; } for (String importedClass : classMetaData.getImports()) { String baseName = StringUtils.substringAfterLast(importedClass, "."); if (baseName.equals("*")) { candidateClassName = StringUtils.substringBeforeLast(importedClass, ".") + "." + name; if (metaDataRepository.find(candidateClassName) != null) { return candidateClassName; } if (importedClass.startsWith("java.") && isVisibleClass(candidateClassName)) { return candidateClassName; } } else if (name.equals(baseName)) { return importedClass; } } candidateClassName = classMetaData.getPackageName() + "." + name; if (metaDataRepository.find(candidateClassName) != null) { return candidateClassName; } candidateClassName = "java.lang." + name; if (isVisibleClass(candidateClassName)) { return candidateClassName; } if (classMetaData.isGroovy()) { candidateClassName = "java.math." + name; if (groovyImplicitTypes.contains(candidateClassName)) { return candidateClassName; } for (String prefix : groovyImplicitImportPackages) { candidateClassName = prefix + name; if (isVisibleClass(candidateClassName)) { return candidateClassName; } } } return name; }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
private void writeSizeBasedRotation(final XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement("rollingPolicy"); writer.writeAttribute("class", FixedWindowRollingPolicy.class.getName()); {/*from www. ja va2s . c o m*/ writer.writeStartElement("fileNamePattern"); writer.writeCharacters(StringUtils.substringBeforeLast(getFileName(), ".")); writer.writeCharacters(".%i"); final String extension = StringUtils.substringAfter(getFileName(), "."); if (StringUtils.isNotBlank(extension)) { writer.writeCharacters("."); writer.writeCharacters(extension); } if (isCompressRotatedLogs()) { writer.writeCharacters(".gz"); } writer.writeEndElement(); writer.writeStartElement("minIndex"); writer.writeCharacters("1"); writer.writeEndElement(); writer.writeStartElement("maxIndex"); writer.writeCharacters("3"); writer.writeEndElement(); } writer.writeEndElement(); writer.writeStartElement("triggeringPolicy"); writer.writeAttribute("class", SizeBasedTriggeringPolicy.class.getName()); { String maxFileSize = getMaxFileSize(); if (StringUtils.isBlank(maxFileSize)) { maxFileSize = "1MB"; } writer.writeStartElement("maxFileSize"); writer.writeCharacters(maxFileSize); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.gyrex.logback.config.model.FileAppender.java
private void writeTimeBasedRotation(final XMLStreamWriter writer, final RotationPolicy policy) throws XMLStreamException { writer.writeStartElement("rollingPolicy"); writer.writeAttribute("class", TimeBasedRollingPolicy.class.getName()); {/*from w w w. j a v a 2s . c o m*/ writer.writeStartElement("fileNamePattern"); writer.writeCharacters(StringUtils.substringBeforeLast(getFileName(), ".")); switch (policy) { case MONTHLY: writer.writeCharacters(".%d{yyyyMM}"); break; case WEEKLY: writer.writeCharacters(".%d{yyyyww}"); break; case DAILY: default: writer.writeCharacters(".%d{yyyyMMdd}"); break; } final String extension = StringUtils.substringAfter(getFileName(), "."); if (StringUtils.isNotBlank(extension)) { writer.writeCharacters("."); writer.writeCharacters(extension); } if (isCompressRotatedLogs()) { writer.writeCharacters(".gz"); } writer.writeEndElement(); writer.writeStartElement("maxHistory"); String maxHistory = getMaxHistory(); if (StringUtils.isBlank(maxHistory)) { maxHistory = policy == RotationPolicy.DAILY ? "30" : policy == RotationPolicy.WEEKLY ? "52" : "12"; } writer.writeCharacters(maxHistory); writer.writeEndElement(); } writer.writeEndElement(); }
From source file:org.eclipse.jubula.client.api.converter.CTDSInfo.java
/** * @param className the class name// ww w . j av a2 s . com * @param packageBasePath the base path of the package * @param project the project * @param language the language */ public CTDSInfo(String className, IProjectPO project, String packageBasePath, Locale language) { m_className = StringUtils.substringBeforeLast(className, ".java"); //$NON-NLS-1$ m_packageBasePath = packageBasePath; m_project = project; m_language = language; }
From source file:org.eclipse.jubula.client.api.converter.NodeInfo.java
/** * @param fqFileName the fully qualified file name * @param node the node//from w ww. j a va 2 s . co m * @param packageBasePath the base path of the package * @param defaultToolkit the default toolkit * @param language the project language */ public NodeInfo(String fqFileName, INodePO node, String packageBasePath, String defaultToolkit, Locale language) { m_fqFileName = fqFileName; m_fileName = StringUtils.substringBeforeLast(m_fqFileName, ".java"); //$NON-NLS-1$ m_className = StringUtils.substringAfterLast(m_fileName, StringConstants.SLASH); m_node = node; m_packageBasePath = packageBasePath; m_defaultToolkit = defaultToolkit; m_language = language; Logger log = LoggerFactory.getLogger(NodeInfo.class); IProjectPO project = null; try { project = ProjectCache.get(node.getParentProjectId()); } catch (JBException e) { Plugin.getDefault().writeErrorLineToConsole("Error while loading project.", true); //$NON-NLS-1$ } try { m_projectName = Utils.translateToPackageName(project); } catch (InvalidNodeNameException e) { log.error(e.getLocalizedMessage()); } m_fqName = Utils.getFullyQualifiedTranslatedName(node, m_packageBasePath, m_projectName); m_packageName = StringUtils.substringBeforeLast(m_fqName, StringConstants.DOT); }
From source file:org.eclipse.mylyn.reviews.connector.ui.EmfRepositorySettingsPage.java
private void browse() { FileDialog browseDialog = new FileDialog(getShell(), SWT.OPEN); String fileName = null;/*from ww w . j a v a 2 s. c om*/ String filterPath; File currentLocation = new File(uriEditor.getText()); if (currentLocation.exists()) { String currentPath = currentLocation.getAbsolutePath(); if (currentLocation.isFile()) { filterPath = StringUtils.substringBeforeLast(currentPath, File.separator); fileName = StringUtils.substringAfterLast(currentPath, File.separator); } else { filterPath = currentPath; } } else { IPath configurationDir = ConfigurationScope.INSTANCE.getLocation(); filterPath = configurationDir.toString(); } browseDialog.setFilterPath(filterPath); if (fileName != null) { browseDialog.setFileName(fileName); } browseDialog.setFilterExtensions(getConnectorUi().getFileNameExtensions()); String browseResult = browseDialog.open(); if (browseResult != null) { uriEditor.setText(browseResult); } }
From source file:org.eclipse.mylyn.reviews.connector.ui.EmfRepositorySettingsPage.java
private void create() { FileDialog browseDialog = new FileDialog(getShell(), SWT.SAVE); String fileName = null;// www. ja v a 2 s . c om String filterPath; File currentLocation = new File(uriEditor.getText()); if (currentLocation.exists()) { String currentPath = currentLocation.getAbsolutePath(); if (currentLocation.isFile()) { filterPath = StringUtils.substringBeforeLast(currentPath, File.separator); fileName = StringUtils.substringAfterLast(currentPath, File.separator); } else { filterPath = currentPath; } } else { IPath configurationDir = ConfigurationScope.INSTANCE.getLocation(); filterPath = configurationDir.toString(); } browseDialog.setFilterPath(filterPath); if (fileName == null) { fileName = StringUtils.deleteWhitespace(labelEditor.getText()); } if (fileName != null) { browseDialog.setFileName(getQualifiedName(fileName)); } browseDialog.setFilterExtensions(getConnectorUi().getFileNameExtensions()); String browseResult = browseDialog.open(); if (browseResult != null) { File checkFile = new File(browseResult); if (checkFile.exists()) { MessageDialog dialog = new MessageDialog(getShell(), "Replace Existing?", null, checkFile.getName() + " already exists. Are you sure you want to replace it?", MessageDialog.WARNING, new String[] { "Yes", "No" }, 1); int open = dialog.open(); if (open == 1) { return; } } ResourceSet resourceSet = new ResourceSetImpl(); URI fileURI = URI.createFileURI(browseResult); Resource resource = resourceSet.createResource(fileURI); EClass eContainingClass = getConnector().getContainerClass(); EObject rootObject = eContainingClass.getEPackage().getEFactoryInstance().create(eContainingClass); if (rootObject != null) { resource.getContents().add(rootObject); rootObject.eSet(getConnector().getContentsNameAttribute(), labelEditor.getText()); Map<Object, Object> options = new HashMap<Object, Object>(); try { resource.save(options); } catch (IOException e) { StatusManager.getManager().handle( new Status(IStatus.WARNING, EmfUiPlugin.PLUGIN_ID, "Couldn't create repository.")); return; } } uriEditor.setText(browseResult); } }
From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.CcuGateway.java
/** * Main method for sending a TclRega script and parsing the XML result. *//*from www. java 2 s . c om*/ @SuppressWarnings("unchecked") private synchronized <T> T sendScript(String script, Class<T> clazz) throws IOException { try { script = StringUtils.trim(script); if (StringUtils.isEmpty(script)) { throw new RuntimeException("Homematic TclRegaScript is empty!"); } if (logger.isTraceEnabled()) { logger.trace("TclRegaScript: {}", script); } StringContentProvider content = new StringContentProvider(script, config.getEncoding()); ContentResponse response = httpClient.POST(config.getTclRegaUrl()).content(content) .timeout(config.getTimeout(), TimeUnit.SECONDS) .header(HttpHeader.CONTENT_TYPE, "text/plain;charset=" + config.getEncoding()).send(); String result = new String(response.getContent(), config.getEncoding()); result = StringUtils.substringBeforeLast(result, "<xml><exec>"); if (logger.isTraceEnabled()) { logger.trace("Result TclRegaScript: {}", result); } return (T) xStream.fromXML(result); } catch (Exception ex) { throw new IOException(ex.getMessage(), ex); } }