List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.XstreamPathConverter.java
protected void updatePath(PathTrackingReader reader, Path path, Path currentPath, XstreamPathValueTracker pathValueTracker) { if (doBasicPathsMatch(path, currentPath)) { if (path.toString().contains("@")) { String attributeName = StringUtils.substringAfterLast(path.toString(), "@"); pathValueTracker.add(path, reader.getAttribute(attributeName)); } else {// ww w . j a va2s . co m pathValueTracker.add(path, reader.getValue()); } } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.XstreamTreeWriter.java
public String getAttributeNameFromPath(final Path path) { return StringUtils.substringAfterLast(path.toString(), "@"); }
From source file:org.debux.webmotion.netbeans.completion.WebMotionCompletion.java
@Override public CompletionTask createTask(int queryType, JTextComponent component) { if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) { return null; }//from ww w. j a va 2 s . co m return new AsyncCompletionTask(new AsyncCompletionQuery() { @Override protected void query(CompletionResultSet completionResultSet, Document document, int caretOffset) { String filter = null; int startOffset = caretOffset - 1; int column = 0; try { // Get filter StyledDocument doc = (StyledDocument) document; int lineStartOffset = Utils.getRowFirstNonWhite(doc, caretOffset); char[] line = doc.getText(lineStartOffset, caretOffset - lineStartOffset).toCharArray(); int whiteOffset = Utils.indexOfWhite(line); filter = new String(line, whiteOffset + 1, line.length - whiteOffset - 1); if (whiteOffset > 0) { startOffset = lineStartOffset + whiteOffset + 1; } else { startOffset = lineStartOffset; } // Get position Element lineElement = doc.getParagraphElement(caretOffset); String lineValue = doc.getText(lineElement.getStartOffset(), caretOffset - lineElement.getStartOffset()); Pattern pattern = Pattern.compile("\\s+"); Matcher matcher = pattern.matcher(lineValue); while (matcher.find()) { column++; } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } // Get section Section section = LexerUtils.getSection(document, caretOffset); // Get the package in configuration String packageBase = Utils.getPackageValue("package.base", null); String packageTarget = null; String filterSuperClass = null; String separator = "/"; boolean onlyFolder = false; String onlyMimeType = null; String[] keywords = {}; if (section != null) { if (section == Section.CONFIG) { keywords = KEYWORDS_CONFIG; } else if (section == Section.ERRORS && column % 2 == 0) { keywords = KEYWORDS_ERROR; packageTarget = ""; filterSuperClass = "java.lang.Exception"; } else if (section == Section.ERRORS && column % 2 == 1) { keywords = KEYWORDS_ERROR_ACTION; if (filter.startsWith("view:")) { packageTarget = Utils.getPackageValue("package.views", null); } else if (filter.startsWith("action:") || !filter.contains(":")) { packageTarget = Utils.getPackageValue("package.errors", packageBase); filterSuperClass = "org.debux.webmotion.server.WebMotionController"; } } else if (section == Section.EXTENSIONS && column % 2 == 0) { keywords = KEYWORDS_EXTENSION; } else if (section == Section.EXTENSIONS && column % 2 == 1) { packageTarget = ""; onlyMimeType = WebMotionLanguage.MIME_TYPE; } else if (section == Section.FILTERS && column % 3 == 0) { keywords = KEYWORDS_METHODS; } else if (section == Section.FILTERS && column % 3 == 1) { keywords = KEYWORDS_FILTER; } else if (section == Section.FILTERS && column % 3 == 2) { keywords = KEYWORDS_FILTER_ACTION; packageTarget = Utils.getPackageValue("package.filters", packageBase); filterSuperClass = "org.debux.webmotion.server.WebMotionFilter"; } else if (section == Section.ACTIONS && column % 3 == 0) { keywords = KEYWORDS_METHODS; } else if (section == Section.ACTIONS && column % 3 == 1) { keywords = KEYWORDS_ACTION; } else if (section == Section.ACTIONS && column % 3 == 2) { keywords = KEYWORDS_ACTION_ACTION; if (filter.startsWith("view:")) { packageTarget = Utils.getPackageValue("package.views", null); } else if (filter.startsWith("action:") || !filter.contains(":")) { packageTarget = Utils.getPackageValue("package.actions", packageBase); filterSuperClass = "org.debux.webmotion.server.WebMotionController"; } } else if (section == Section.PROPERTIES) { keywords = KEYWORDS_SECTIONS; } } else { keywords = KEYWORDS_SECTIONS; } // Keywords if (keywords == KEYWORDS_METHODS && filter.contains(",")) { keywords = KEYWORDS_METHOD; startOffset += StringUtils.substringBeforeLast(filter, ",").length(); filter = StringUtils.substringAfterLast(filter, ","); } else if (keywords == KEYWORDS_ERROR && filter.contains("code:")) { keywords = KEYWORDS_ERROR_CODE; startOffset += "code:".length(); filter = filter.substring("code:".length()); packageTarget = null; } else if (filter.startsWith("javac.debug=") || filter.startsWith("server.async=") || filter.startsWith("server.static.autodetect=")) { keywords = KEYWORDS_CONFIG_BOOLEAN; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); } else if (filter.startsWith("server.error.page=")) { keywords = KEYWORDS_CONFIG_ERROR; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); } else if (filter.startsWith("server.controller.scope=")) { keywords = KEYWORDS_CONFIG_SCOPE; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); } else if (filter.startsWith("package.base=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "=").replaceAll("\\.", "/"); packageTarget = ""; filterSuperClass = null; separator = "."; onlyFolder = true; } else if (filter.startsWith("package.views=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "=").replaceAll("\\.", "/"); packageTarget = ""; filterSuperClass = null; separator = "/"; onlyFolder = true; } else if (filter.startsWith("server.listener.class=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); packageTarget = ""; filterSuperClass = "org.debux.webmotion.server.WebMotionServerListener"; } else if (filter.startsWith("server.main.handler.class=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); packageTarget = ""; filterSuperClass = "org.debux.webmotion.server.WebMotionHandler"; } else if (filter.startsWith("default.render=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); packageTarget = ""; filterSuperClass = "org.debux.webmotion.server.render.Render"; } else if (filter.startsWith("package.actions=") || filter.startsWith("package.filters=") || filter.startsWith("package.errors=")) { keywords = KEYWORDS_EMPTY; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); packageTarget = Utils.getPackageValue("package.base", null); filterSuperClass = null; separator = "."; onlyFolder = true; } else if (filter.startsWith("server.encoding=")) { keywords = KEYWORDS_CONFIG_ENCODING; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); } else if (filter.startsWith("server.secret=")) { keywords = new String[] { RandomStringUtils.random(31, true, true) }; startOffset += StringUtils.substringBefore(filter, "=").length() + 1; filter = StringUtils.substringAfter(filter, "="); } else if (filter.startsWith("javac.debug") || filter.startsWith("server.async") || filter.startsWith("server.static.autodetect") || filter.startsWith("server.error.page") || filter.startsWith("server.controller.scope") || filter.startsWith("package.base") || filter.startsWith("package.views") || filter.startsWith("server.listener.class") || filter.startsWith("server.main.handler.class") || filter.startsWith("package.actions") || filter.startsWith("package.filters") || filter.startsWith("package.errors") || filter.startsWith("server.encoding") || filter.startsWith("server.secret")) { keywords = KEYWORDS_CONFIG_EQUAL; startOffset += StringUtils.substringBefore(filter, "=").length(); filter = ""; } for (String keyword : keywords) { if (keyword.startsWith(filter)) { completionResultSet.addItem(new WebMotionCompletionItem(keyword, startOffset, caretOffset)); } } if (packageTarget != null) { // File if (filterSuperClass == null) { String path = packageTarget.replaceAll("\\.", "/"); String filterFile = filter; int startOffsetFile = startOffset; Set<String> names = new HashSet<String>(); if (filter.startsWith("view:")) { filterFile = filter.replaceFirst("view:", ""); startOffsetFile += "view:".length(); } if (filterFile.contains("/")) { String current = StringUtils.substringBeforeLast(filterFile, "/"); path += current; startOffsetFile += current.length() + 1; filterFile = StringUtils.substringAfterLast(filterFile, "/"); } else if (packageTarget.isEmpty() && separator.equals("/")) { String fileName = "WEB-INF"; names.add(fileName); if (fileName.startsWith(filterFile)) { if (!fileName.equals(filterFile)) { completionResultSet.addItem( new WebMotionCompletionItem(fileName, startOffsetFile, caretOffset)); } else { completionResultSet.addItem(new WebMotionCompletionItem(separator, startOffsetFile + fileName.length(), caretOffset)); } } } GlobalPathRegistry registry = GlobalPathRegistry.getDefault(); List<ClassPath> paths = new ArrayList<ClassPath>(); paths.addAll(registry.getPaths(ClassPath.BOOT)); paths.addAll(registry.getPaths(ClassPath.COMPILE)); paths.addAll(registry.getPaths(ClassPath.SOURCE)); for (ClassPath classPath : paths) { FileObject resource = classPath.findResource(path); if (resource != null) { FileObject[] children = resource.getChildren(); for (FileObject child : children) { String fileName = child.getNameExt(); if ((!onlyFolder || onlyFolder && child.isFolder()) && (onlyMimeType == null || child.isFolder() || onlyMimeType != null && child.getMIMEType().equals(onlyMimeType)) && fileName.startsWith(filterFile) && !fileName.startsWith(".")) { if (!names.contains(fileName)) { if (!fileName.equals(filterFile)) { completionResultSet.addItem(new WebMotionCompletionItem(fileName, startOffsetFile, caretOffset)); } else { completionResultSet.addItem(new WebMotionCompletionItem(separator, startOffsetFile + fileName.length(), caretOffset)); } names.add(fileName); } } } } } completionResultSet.finish(); } else { // Class if (filter.contains(":") && !filter.startsWith("code:")) { startOffset += StringUtils.substringBefore(filter, ":").length() + 1; filter = StringUtils.substringAfter(filter, ":"); } int startOffsetClass = startOffset; if (filter.contains(".")) { startOffsetClass += StringUtils.substringBeforeLast(filter, ".").length() + 1; } String fullName = packageTarget + filter; String rootPackage = ""; String filerPackage = fullName; if (fullName.contains(".")) { rootPackage = StringUtils.substringBeforeLast(fullName, "."); filerPackage = StringUtils.substringAfterLast(fullName, "."); } String folderPackage = rootPackage.replaceAll("\\.", "/"); FileObject fo = Utils.getFO(document); ClassPath bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT); ClassPath compileCp = ClassPath.getClassPath(fo, ClassPath.COMPILE); ClassPath sourcePath = ClassPath.getClassPath(fo, ClassPath.SOURCE); ClasspathInfo info = ClasspathInfo.create(bootCp, compileCp, sourcePath); JavaSource src = JavaSource.create(info); final String filterSuperJavaClass = filterSuperClass; final CompletionResultSet completionResultSetClass = completionResultSet; final int startOffsetJavaClass = startOffsetClass; final int caretOffsetClass = caretOffset; // Package names List<FileObject> folders = new ArrayList<FileObject>(); folders.addAll(bootCp.findAllResources(folderPackage)); folders.addAll(compileCp.findAllResources(folderPackage)); folders.addAll(sourcePath.findAllResources(folderPackage)); final String rootPackageFilter = rootPackage; final String filterPackageFilter = filerPackage; final Set<String> names = new HashSet<String>(); for (final FileObject folder : folders) { try { src.runUserActionTask(new CancellableTask<CompilationController>() { @Override public void cancel() { } @Override public void run(CompilationController cu) throws Exception { Types types = cu.getTypes(); Elements elements = cu.getElements(); TypeElement superElement = elements.getTypeElement(filterSuperJavaClass); TypeMirror superType = null; if (superElement != null) { superType = superElement.asType(); } FileObject[] children = folder.getChildren(); for (FileObject child : children) { String name = child.getName(); if (!name.startsWith(".") && name.startsWith(filterPackageFilter)) { if (!names.contains(name)) { names.add(name); TypeElement element; if (rootPackageFilter.isEmpty()) { element = elements.getTypeElement(name); } else { element = elements .getTypeElement(rootPackageFilter + "." + name); } if (name.equals(filterPackageFilter)) { if (element == null || element.getKind() != ElementKind.CLASS || element.getKind() == ElementKind.CLASS && (filterSuperJavaClass.equals( "org.debux.webmotion.server.WebMotionFilter") || filterSuperJavaClass.equals( "org.debux.webmotion.server.WebMotionController"))) { WebMotionCompletionItem item = new WebMotionCompletionItem( ".", startOffsetJavaClass + name.length(), caretOffsetClass); completionResultSetClass.addItem(item); } } else if (child.isFolder()) { WebMotionCompletionItem item = new WebMotionCompletionItem( name, startOffsetJavaClass, caretOffsetClass); completionResultSetClass.addItem(item); } else if (element != null) { Set<Modifier> modifiers = element.getModifiers(); ElementKind kind = element.getKind(); TypeMirror resolveType = element.asType(); if (kind == ElementKind.CLASS && modifiers.contains(Modifier.PUBLIC) && !modifiers.contains(Modifier.ABSTRACT) && superType != null && types.isSubtype(resolveType, superType)) { WebMotionCompletionItem item = new WebMotionCompletionItem( name, cu, element, startOffsetJavaClass, caretOffsetClass); completionResultSetClass.addItem(item); } } } } } } }, false); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } // Method if (filter.contains(".") && (filterSuperJavaClass .equals("org.debux.webmotion.server.WebMotionFilter") || filterSuperJavaClass.equals("org.debux.webmotion.server.WebMotionController"))) { final String className = StringUtils.substringBeforeLast(filter, "."); final String fullClassName = packageTarget + className; final String filterMethod = StringUtils.substringAfterLast(filter, "."); final CompletionResultSet completionResultSetJavaSource = completionResultSet; final int startOffsetJavaSource = startOffset + className.length() + 1; final int caretOffesetJavaSource = caretOffset; try { src.runUserActionTask(new CancellableTask<CompilationController>() { @Override public void cancel() { } @Override public void run(CompilationController cu) throws Exception { cu.toPhase(JavaSource.Phase.PARSED); Elements elements = cu.getElements(); TypeElement classElement = elements.getTypeElement(fullClassName); if (classElement != null) { List<? extends javax.lang.model.element.Element> members = elements .getAllMembers(classElement); for (javax.lang.model.element.Element member : members) { if (member.getKind() == ElementKind.METHOD) { Set<Modifier> modifiers = member.getModifiers(); String methodName = member.getSimpleName().toString(); String className = member.getEnclosingElement().getSimpleName() .toString(); if (!"Object".equals(className) && !"WebMotionController".equals(className) && !"WebMotionFilter".equals(className) && modifiers.contains(Modifier.PUBLIC) && !modifiers.contains(Modifier.STATIC) && methodName.startsWith(filterMethod)) { WebMotionCompletionItem item = new WebMotionCompletionItem( methodName, cu, member, startOffsetJavaSource, caretOffesetJavaSource); completionResultSetJavaSource.addItem(item); } } } } completionResultSetJavaSource.finish(); } }, false); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } else { completionResultSet.finish(); } } } else { completionResultSet.finish(); } } }, component); }
From source file:org.debux.webmotion.netbeans.hints.ActionRule.java
@Override public void run(RuleContext context, final List<Hint> hints) { WebMotionParserResult parserResult = (WebMotionParserResult) context.parserResult; Source source = parserResult.getSnapshot().getSource(); final Document document = source.getDocument(false); final FileObject fileObject = source.getFileObject(); FileObject fo = Utils.getFO(document); ClassPath bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT); ClassPath compileCp = ClassPath.getClassPath(fo, ClassPath.COMPILE); ClassPath sourcePath = ClassPath.getClassPath(fo, ClassPath.SOURCE); ClasspathInfo info = ClasspathInfo.create(bootCp, compileCp, sourcePath); final JavaSource src = JavaSource.create(info); try {//from w w w .j a v a 2 s . co m src.runUserActionTask(new CancellableTask<CompilationController>() { @Override public void cancel() { } @Override public void run(CompilationController cu) throws Exception { String packageBase = Utils.getPackageValue("package.base", null); List<OffsetRange> tokens = LexerUtils.getTokens(document, "FILTER_ACTION"); String packageTarget = Utils.getPackageValue("package.filters", packageBase); String superClass = "org.debux.webmotion.server.WebMotionFilter"; runAction(cu, tokens, packageTarget, superClass); tokens = LexerUtils.getTokens(document, "ERROR_ACTION_JAVA"); packageTarget = Utils.getPackageValue("package.errors", packageBase); superClass = "org.debux.webmotion.server.WebMotionController"; runAction(cu, tokens, packageTarget, superClass); tokens = LexerUtils.getTokens(document, "ACTION_ACTION_IDENTIFIER", "ACTION_ACTION_JAVA_IDENTIFIER", "ACTION_ACTION_JAVA_QUALIFIED_IDENTIFIER", "ACTION_ACTION_JAVA_VARIABLE"); packageTarget = Utils.getPackageValue("package.actions", packageBase); superClass = "org.debux.webmotion.server.WebMotionController"; runAction(cu, tokens, packageTarget, superClass); } protected void runAction(CompilationController cu, List<OffsetRange> tokens, String packageTarget, String superClass) { Elements elements = cu.getElements(); Types types = cu.getTypes(); for (OffsetRange range : tokens) { try { String value = LexerUtils.getText(document, range); String className = StringUtils.substringBeforeLast(value, "."); String methodName = StringUtils.substringAfterLast(value, "."); if (Utils.isNotVariable(className)) { TypeElement classElement = elements.getTypeElement(packageTarget + className); if (classElement != null) { // Check class TypeElement controllerElement = elements.getTypeElement(superClass); if (controllerElement != null) { TypeMirror controllerType = controllerElement.asType(); Set<Modifier> modifiers = classElement.getModifiers(); ElementKind kind = classElement.getKind(); TypeMirror resolveType = classElement.asType(); if (kind == ElementKind.CLASS) { if (!modifiers.contains(Modifier.PUBLIC)) { hints.add(new Hint(ActionRule.this, "The class is not public", fileObject, range, WebMotionHintsProvider.asList( new PublicModifierClassFix(src, classElement)), 100)); } if (modifiers.contains(Modifier.ABSTRACT)) { hints.add(new Hint(ActionRule.this, "The class is abstract", fileObject, range, WebMotionHintsProvider.asList( new AbstractModifierClassFix(src, classElement)), 100)); } if (!types.isSubtype(resolveType, controllerType)) { hints.add(new Hint(ActionRule.this, "Requires super class " + superClass, fileObject, range, WebMotionHintsProvider.asList( new ExtendsClassFix(src, classElement, superClass)), 100)); } } } // Check method if (Utils.isNotVariable(methodName)) { List<? extends Element> members = elements.getAllMembers(classElement); Element method = null; for (Element member : members) { ElementKind kind = member.getKind(); String name = member.getSimpleName().toString(); if (kind == ElementKind.METHOD && name.equals(methodName)) { method = member; break; } } if (method != null) { Set<Modifier> modifiers = method.getModifiers(); String currentClass = method.getEnclosingElement().getSimpleName() .toString(); if ("Object".equals(currentClass) || "WebMotionController".equals(currentClass) || "WebMotionFilter".equals(currentClass)) { hints.add(new Hint(ActionRule.this, "Invalid method", fileObject, range, WebMotionHintsProvider.NO_FIXES, 100)); } if (!modifiers.contains(Modifier.PUBLIC)) { hints.add( new Hint(ActionRule.this, "The method is not public", fileObject, range, WebMotionHintsProvider .asList(new PublicModifierMethodFix(src, classElement, methodName)), 100)); } if (modifiers.contains(Modifier.STATIC)) { hints.add( new Hint(ActionRule.this, "The method is static", fileObject, range, WebMotionHintsProvider .asList(new StaticModifierMethodFix(src, classElement, methodName)), 100)); } } else { hints.add(new Hint(ActionRule.this, "Invalid method", fileObject, range, WebMotionHintsProvider.asList( new MethodClassFix(src, classElement, methodName)), 100)); } } } else { hints.add(new Hint(ActionRule.this, "Invalid class", fileObject, range, WebMotionHintsProvider.asList( new CreateClassFix(src, packageTarget, superClass, className)), 100)); } } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } } }, false); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.debux.webmotion.netbeans.hints.CreateClassFix.java
@Override public void implement() throws Exception { ClasspathInfo classpathInfo = src.getClasspathInfo(); ClassPath classPath = classpathInfo.getClassPath(ClasspathInfo.PathKind.SOURCE); FileObject targetSourceRoot = classPath.findResource(packageTarget.replaceAll("\\.", "/")); String packageName = ""; String simpleName = fullClassName; if (fullClassName.contains(".")) { packageName = StringUtils.substringBeforeLast(fullClassName, "."); simpleName = StringUtils.substringAfterLast(fullClassName, "."); }/* w ww .j a v a 2s.com*/ FileObject pack = FileUtil.createFolder(targetSourceRoot, packageName.replace('.', '/')); // NOI18N FileObject classTemplate = FileUtil.getConfigFile("Templates/Classes/Class.java"); FileObject target; if (classTemplate != null) { DataObject classTemplateDO = DataObject.find(classTemplate); DataObject od = classTemplateDO.createFromTemplate(DataFolder.findFolder(pack), simpleName); target = od.getPrimaryFile(); } else { target = FileUtil.createData(pack, simpleName + ".java"); } JavaSource.forFileObject(target).runModificationTask(new Task<WorkingCopy>() { @Override public void run(WorkingCopy workingCopy) throws Exception { workingCopy.toPhase(JavaSource.Phase.RESOLVED); TreeMaker make = workingCopy.getTreeMaker(); CompilationUnitTree cut = workingCopy.getCompilationUnit(); for (Tree type : cut.getTypeDecls()) { if (Tree.Kind.CLASS == type.getKind()) { ClassTree clazz = (ClassTree) type; TypeElement element = workingCopy.getElements().getTypeElement(superClass); ExpressionTree implementsClause = make.QualIdent(element); ClassTree modifiedClazz = make.setExtends(clazz, implementsClause); workingCopy.rewrite(clazz, modifiedClazz); } } } }).commit(); }
From source file:org.debux.webmotion.netbeans.Utils.java
public static void renameFileObject(FileObject fo, String newName) throws IOException { FileLock lock = null;/*from w w w .j a v a2 s.c o m*/ try { lock = fo.lock(); } catch (FileAlreadyLockedException e) { // Try again later; perhaps display a warning dialog. return; } try { String extension = StringUtils.substringAfterLast(newName, "."); String name = StringUtils.substringBeforeLast(newName, "."); fo.rename(lock, name, extension); } finally { // Always put this in a finally block! lock.releaseLock(); } }
From source file:org.debux.webmotion.netbeans.WebMotionHyperlink.java
@Override public void performClickAction(Document document, int offset) { String packageTarget = Utils.getPackage(document, offset); // Open document OffsetRange range = LexerUtils.getTokens(document, offset, Utils.getAccessibleToken()); if (range != null) { try {/*from w w w.java2s. c o m*/ String target = LexerUtils.getText(document, range); if (LexerUtils.isJavaToken(document, offset)) { FileObject fo = Utils.getFO(document); ClassPath bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT); ClassPath compileCp = ClassPath.getClassPath(fo, ClassPath.COMPILE); ClassPath sourcePath = ClassPath.getClassPath(fo, ClassPath.SOURCE); final ClasspathInfo info = ClasspathInfo.create(bootCp, compileCp, sourcePath); JavaSource src = JavaSource.create(info); final String fullClassName = target.replaceAll("/+", "."); final String packageClassName = packageTarget.replaceAll("/+", "."); final String className = StringUtils.substringBeforeLast(target, "."); final String methodName = StringUtils.substringAfterLast(target, "."); try { src.runUserActionTask(new CancellableTask<CompilationController>() { @Override public void cancel() { } @Override public void run(CompilationController cu) throws Exception { Elements elements = cu.getElements(); TypeElement classElement = elements.getTypeElement(packageClassName + className); if (classElement == null) { classElement = elements.getTypeElement(fullClassName); } if (classElement != null) { ElementHandle<TypeElement> create = ElementHandle.create(classElement); FileObject fo = SourceUtils.getFile(create, info); open(fo, methodName); } } }, false); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } else { packageTarget = packageTarget.replaceAll("\\.+", "/"); GlobalPathRegistry registry = GlobalPathRegistry.getDefault(); FileObject fo = registry.findResource(packageTarget + target); open(fo, null); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }
From source file:org.devproof.portal.module.article.entity.Article.java
private List<String> getSplittedPages(String pages) { String[] splitted = StringUtils.splitByWholeSeparator(pages, "page-break-after"); List<String> result = new ArrayList<String>(); if (splitted.length > 1) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < splitted.length; i++) { String actual = splitted[i]; int open = actual.lastIndexOf('<'); int close = actual.lastIndexOf('>'); if (open < 0 || close > open) { // kein tag buf.append(actual);// w w w.j a va 2s . c o m if (splitted.length - 1 != i) buf.append("page-break-after"); } else { // tag buf.append(StringUtils.substringBeforeLast(actual, "<")); result.add(buf.toString()); buf = new StringBuilder(); String closeTag = StringUtils.substringAfterLast(actual, "<"); closeTag = "</" + StringUtils.substringBefore(closeTag, " ") + ">"; splitted[i + 1] = StringUtils.substringAfter(splitted[i + 1], closeTag); } } if (buf.length() > 0) { result.add(buf.toString()); } } else { result.add(pages); } return result; }
From source file:org.dspace.app.rest.parameter.resolver.SearchFilterResolver.java
public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) throws Exception { List<SearchFilter> result = new LinkedList<>(); Iterator<String> parameterNames = webRequest.getParameterNames(); while (parameterNames != null && parameterNames.hasNext()) { String parameterName = parameterNames.next(); if (parameterName.startsWith(SEARCH_FILTER_PREFIX)) { String filterName = StringUtils.substringAfter(parameterName, SEARCH_FILTER_PREFIX); for (String value : webRequest.getParameterValues(parameterName)) { String filterValue = StringUtils.substringBeforeLast(value, FILTER_OPERATOR_SEPARATOR); String filterOperator = StringUtils.substringAfterLast(value, FILTER_OPERATOR_SEPARATOR); result.add(new SearchFilter(filterName, filterOperator, filterValue)); }//from w w w. ja v a2s . co m } } if (parameter.getParameterType().equals(SearchFilter.class)) { return result.isEmpty() ? null : result.get(0); } else { return result; } }
From source file:org.ebayopensource.turmeric.eclipse.codegen.model.GenTypeServiceMetadataProps.java
@Override public Map<String, String> getCodeGenOptions() { Map<String, String> result = new TreeMap<String, String>(); if (getAdminName() != null) result.put(PARAM_ADMIN_NAME, getAdminName()); if (getNamespace() != null) result.put(PARAM_NAMESPACE, getNamespace()); if (getServiceLayerFile() != null) result.put(PARAM_SERVICE_LAYER_FILE, getServiceLayer()); if (getProjectRoot() != null) result.put(PARAM_PR, getProjectRoot()); if (getServiceName() != null) result.put(PARAM_SERVICE_NAME, getServiceName()); if (getServiceImplClassName() != null) { result.put(PARAM_SICN, getServiceImplClassName()); }/*from www.ja va 2s. c o m*/ if (getServiceVersion() != null) result.put(PARAM_SCV, getServiceVersion()); if (getServiceLayer() != null) result.put(PARAM_SLAYER, getServiceLayer()); if (StringUtils.isNotBlank(getOriginalWsdlUrl())) { result.put(PARAM_WSDL, getOriginalWsdlUrl()); if (getServiceInterface().contains(".")) result.put(PARAM_GIP, StringUtils.substringBeforeLast(getServiceInterface(), ".")); result.put(PARAM_GIN, StringUtils.substringAfterLast(getServiceInterface(), ".")); } else { result.put(PARAM_INTERFACE, getServiceInterface()); } result.put(PARAM_GENTYPE, getGenType()); return result; }