Example usage for org.apache.commons.lang3 StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.structr.console.tabcompletion.CypherTabCompletionProvider.java

@Override
public List<TabCompletionResult> getTabCompletion(final SecurityContext securityContext, final String line) {

    final List<TabCompletionResult> results = new LinkedList<>();
    final String token = getToken(line, " ");

    results.addAll(getCaseInsensitiveResultsForCollection(words, token, " "));
    results.addAll(getTabCompletionForUUIDs(securityContext, token, ""));

    // node type results
    final Matcher nodeMatcher = nodePattern.matcher(token);
    if (nodeMatcher.matches()) {

        final Set<String> keys = getNodeTypes();
        final String subtoken = StringUtils.substringAfterLast(token, ":");
        final String suffix = "";

        results.addAll(getExactResultsForCollection(keys, subtoken, suffix));
    }/*  w w w.  j  a  v  a 2 s  .c  o m*/

    /*
     * disabled, not possible to get a runtime list of relationship types yet
     *
     *
    final Matcher relMatcher = relPattern.matcher(token);
    if (relMatcher.matches()) {
            
       final Set<String> keys = getRelationshipTypes();
       final String subtoken  = StringUtils.substringAfterLast(token, ":");
       final String suffix    = "";
            
       results.addAll(getExactResultsForCollection(keys, subtoken, suffix));
    }
     */

    Collections.sort(results);

    return results;
}

From source file:org.structr.files.ftp.AbstractStructrFtpFile.java

@Override
public String getName() {
    try (Tx tx = StructrApp.getInstance().tx()) {

        String name = null;/*from   www  .java  2s  .c  o m*/
        if (!("/").equals(newPath)) {
            name = newPath.contains("/") ? StringUtils.substringAfterLast(newPath, "/") : newPath;
        } else {
            if (structrFile != null) {
                name = structrFile.getProperty(File.name);
            }
        }

        tx.success();
        return name == null ? structrFile.getUuid() : name;

    } catch (FrameworkException fex) {
        logger.log(Level.SEVERE, "Error in getName() of abstract ftp file", fex);
    }
    return null;
}

From source file:org.structr.files.ftp.AbstractStructrFtpFile.java

@Override
public boolean move(final FtpFile target) {

    try (Tx tx = StructrApp.getInstance().tx()) {

        logger.log(Level.INFO, "move()");

        final AbstractStructrFtpFile targetFile = (AbstractStructrFtpFile) target;
        final String path = targetFile instanceof StructrFtpFile ? "/" : targetFile.getAbsolutePath();

        try {// w w w  .java  2s  .  c o  m
            if (path.contains("/")) {

                String newParentPath = StringUtils.substringBeforeLast(path, "/");
                AbstractFile newParent = FileHelper
                        .getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newParentPath);

                if (newParent != null && newParent instanceof Folder) {

                    Folder newParentFolder = (Folder) newParent;
                    structrFile.setProperty(AbstractFile.parent, newParentFolder);

                } else {

                    // Move to /
                    structrFile.setProperty(AbstractFile.parent, null);

                }

            }

            if (!("/".equals(path))) {
                final String newName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path;
                structrFile.setProperty(AbstractNode.name, newName);
            }

        } catch (FrameworkException ex) {
            logger.log(Level.SEVERE, "Could not move ftp file", ex);
            return false;
        }

        tx.success();

        return true;
    } catch (FrameworkException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return false;
}

From source file:org.structr.files.ftp.FtpFilePageWrapper.java

@Override
public boolean move(FtpFile target) {
    try (Tx tx = StructrApp.getInstance().tx()) {

        logger.log(Level.INFO, "move()");

        final AbstractStructrFtpFile targetFile = (AbstractStructrFtpFile) target;
        final String path = targetFile instanceof StructrFtpFile ? "/" : targetFile.getAbsolutePath();

        try {//w  w w .j  a  va  2  s.  co m

            if (!("/".equals(path))) {
                final String newName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path;
                page.setProperty(AbstractNode.name, newName);
            }

        } catch (FrameworkException ex) {
            logger.log(Level.SEVERE, "Could not move ftp file", ex);
            return false;
        }

        tx.success();

        return true;
    } catch (FrameworkException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return false;
}

From source file:org.structr.function.IncludeFunction.java

@Override
public Object apply(final ActionContext ctx, final GraphObject entity, final Object[] sources)
        throws FrameworkException {

    if (arrayHasLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof String) {

        final SecurityContext securityContext = entity != null ? entity.getSecurityContext()
                : ctx.getSecurityContext();
        final App app = StructrApp.getInstance(securityContext);
        final RenderContext innerCtx = new RenderContext((RenderContext) ctx);
        final List<DOMNode> nodeList = app.nodeQuery(DOMNode.class).andName((String) sources[0]).getAsList();

        DOMNode node = null;/*from   w ww .  j av a  2s . co m*/

        /**
         * Nodes can be included via their name property These nodes MUST: 1. be unique in name 2. NOT be in the trash => have an ownerDocument AND a parent (public
         * users are not allowed to see the __ShadowDocument__ ==> this check must either be made in a superuser-context OR the __ShadowDocument could be made public?)
         *
         * These nodes can be: 1. somewhere in the pages tree 2. in the shared components 3. both ==> causes a problem because we now have multiple nodes with the same
         * name (one shared component and multiple linking instances of that component)
         *
         * INFOS:
         *
         * - If a DOMNode has "syncedNodes" it MUST BE a shared component - If a DOMNodes "sharedComponent" is set it MUST BE AN INSTANCE of a shared component => Can
         * we safely ignore these? I THINK SO!
         */
        for (final DOMNode n : nodeList) {

            // Ignore nodes in trash
            if (n.getProperty(DOMNode.parent) == null && n.getOwnerDocumentAsSuperUser() == null) {
                continue;
            }

            // IGNORE everything that REFERENCES a shared component!
            if (n.getProperty(DOMNode.sharedComponent) == null) {

                // the DOMNode is either a shared component OR a named node in the pages tree
                if (node == null) {

                    node = n;

                } else {

                    // ERROR: we have found multiple DOMNodes with the same name
                    // TODO: Do we need to remove the nodes from the nodeList which can be ignored? (references to a shared component)
                    return "Ambiguous node name \"" + ((String) sources[0]) + "\" (nodes found: "
                            + StringUtils.join(nodeList, ", ") + ")";

                }

            }

        }

        if (node != null) {

            node.render(innerCtx, 0);

        } else {

            final FileBase file = app.nodeQuery(FileBase.class).andName((String) sources[0]).getFirst();

            if (file != null) {

                final String name = file.getProperty(NodeInterface.name);
                final String contentType = file.getProperty(FileBase.contentType);
                final String charset = StringUtils.substringAfterLast(contentType, "charset=");
                final String extension = StringUtils.substringAfterLast(name, ".");

                if (contentType == null || StringUtils.isBlank(extension)) {

                    return "No valid file type detected. Please make sure " + name
                            + " has a valid content type set or file extension.";

                }

                if (contentType.startsWith("text/css")) {

                    return "<link href=\"" + file.getPath() + "\" rel=\"stylesheet\">";

                } else if (contentType.contains("/javascript")) {

                    return "<script src=\"" + file.getPath() + "\"></script>";

                } else if (contentType.startsWith("image/svg")) {

                    try {
                        final byte[] buffer = new byte[file.getSize().intValue()];
                        IOUtils.read(file.getInputStream(), buffer);
                        return StringUtils.toEncodedString(buffer, Charset.forName(charset));
                    } catch (IOException ex) {
                        logger.log(Level.SEVERE, null, ex);
                    }

                    return "<img alt=\"" + name + "\" src=\"" + file.getPath() + "\">";

                } else if (contentType.startsWith("image/")) {

                    return "<img alt=\"" + name + "\" src=\"" + file.getPath() + "\">";

                } else {

                    return "Don't know how to render content type or extension of  " + name + ".";

                }

            }

        }

        return StringUtils.join(innerCtx.getBuffer().getQueue(), "");
    }

    return usage(ctx.isJavaScriptContext());
}

From source file:org.structr.javaparser.JavaParserModule.java

private void parseJavaFilesAndSolveTypes(final Folder folder) {

    if (ignoreTests && "test".equals(folder.getName())) {
        return;// ww  w.  j  a  v a 2s  .  c om
    }

    for (final File file : folder.getFiles()) {

        if (file.getContentType().equals("text/x-java")) {

            final String javaFileName = file.getName();

            if (javaFileName.equals("package-info.java") || javaFileName.equals("testPackage-info.java")) {

            } else {

                final String javaContent = file.getFavoriteContent();

                ClassOrInterface clsOrIface = null;

                CompilationUnit cu = null;
                try {
                    cu = JavaParser.parse(javaContent);

                    for (final TypeDeclaration type : cu.findAll(TypeDeclaration.class)) {

                        SymbolReference<? extends ResolvedValueDeclaration> decl = facade.solve(type.getName());

                        if (type.isClassOrInterfaceDeclaration()) {

                            org.structr.javaparser.entity.Package pkg = null;
                            if (cu.getPackageDeclaration().isPresent()) {

                                pkg = handlePackage(cu.getPackageDeclaration().get());
                            }

                            clsOrIface = handleClassOrInterface(type, pkg);

                        }
                    }

                    for (final BodyDeclaration t : cu.findAll(BodyDeclaration.class)) {

                        //                        if (t instanceof FieldDeclaration) {
                        //
                        //                           final FieldDeclaration fd = t.asFieldDeclaration();
                        //
                        //                           final String fieldName = fd.getVariable(0).getNameAsString();
                        //                           logger.info("Field found: " + fieldName);
                        //
                        //                           final SymbolReference<ResolvedReferenceTypeDeclaration> fieldRef = typeSolver.tryToSolveType(fieldName);
                        //                           if (fieldRef.isSolved()) {
                        //
                        //                              final ResolvedReferenceTypeDeclaration decl = fieldRef.getCorrespondingDeclaration();
                        //                              if (decl.isField()) {
                        //
                        //                                 final ResolvedFieldDeclaration field = decl.asField();
                        //                                 if (field.isMethod()) {
                        //
                        //                                    logger.info("Solved method found: " + field.asMethod().getName());
                        //
                        //                                 } else if (field.isField()) {
                        //
                        //                                    logger.info("Solved field found: " + field.getName() + ", declared by", field.declaringType().getName());
                        //                                 }
                        //                              }
                        //                           }
                        //                        }

                        if (t instanceof CallableDeclaration) {

                            final CallableDeclaration callable = t.asCallableDeclaration();

                            if (t instanceof ConstructorDeclaration) {

                                //                              final ConstructorDeclaration cd = t.asConstructorDeclaration();
                                //                              logger.info("Constructor found: " + cd.getNameAsString());
                                //
                                //                              final SymbolReference<ResolvedReferenceTypeDeclaration> constructorRef = typeSolver.tryToSolveType(cd.getNameAsString());
                                //                              if (constructorRef.isSolved()) {
                                //
                                //                                 logger.info("Solved constructor: " + cd.getNameAsString());
                                //                                 //final ResolvedReferenceTypeDeclaration decl = constructorRef.getCorrespondingDeclaration();
                                //                              }

                            } else if (t instanceof MethodDeclaration) {

                                final MethodDeclaration md = t.asMethodDeclaration();

                                final String methodName = md.getNameAsString();

                                logger.info("Method found: " + methodName);

                                // Create methods and link to class
                                final PropertyMap identifyingMethodProperties = new PropertyMap();
                                identifyingMethodProperties.put(Method.name, methodName);

                                final PropertyMap methodProperties = new PropertyMap();
                                methodProperties.putAll(identifyingMethodProperties);
                                methodProperties.put(Method.classOrInterface, clsOrIface);
                                methodProperties.put(Method.declaration, md.getDeclarationAsString());

                                final Optional<BlockStmt> block = md.getBody();
                                if (block.isPresent()) {
                                    methodProperties.put(Method.body, block.get().toString());
                                }

                                final String symbolName = StringUtils.substringAfterLast(clsOrIface.getName(),
                                        ".") + "." + md.getNameAsString();
                                //final String fullQualifiedSymbolName = cls.getProperty(JavaClass.packageProp).getName() + "." + symbolName;

                                try {
                                    final SymbolReference<? extends ResolvedValueDeclaration> methodRef = facade
                                            .solve(md.getName());
                                    if (methodRef.isSolved()) {

                                        final ResolvedValueDeclaration decl = methodRef
                                                .getCorrespondingDeclaration();

                                        if (decl.isMethod()) {

                                            final String mName = decl.asMethod().getName();
                                            final String signature = decl.asMethod().getSignature();

                                            logger.info("Solved method: " + methodRef.toString()
                                                    + ", signature: " + signature);

                                            methodProperties.put(Method.resolved, true);
                                        }
                                    }
                                } catch (final UnsolvedSymbolException ignore) {
                                }

                                getOrCreate(Method.class, identifyingMethodProperties, methodProperties);

                                logger.info("Created (or found) method " + symbolName);

                            }

                            //                     final NodeList<Parameter> parameters = callable.getParameters();
                            //
                            //                     List<JsonResult> parameterList = new ArrayList<>();
                            //
                            //                     parameters.forEach((p) -> {
                            //
                            //                        JsonResult param = new JsonResult();
                            //
                            //                        param.addName(p);
                            //                        param.addType(p.getType());
                            //                        param.addModifiers(p);
                            //
                            //                        parameterList.add(param);
                            //                     });

                        }
                    }
                } catch (Throwable ignore) {
                }
            }
        }

    }
}

From source file:org.structr.javaparser.MethodVisitorAdapter.java

@Override
public void visit(final MethodCallExpr methodCall, final Object arg) {

    final Map<String, Object> params = (HashMap) arg;

    final String clsName = (String) params.get("clsName");
    final JavaParserFacade facade = (JavaParserFacade) params.get("facade");
    final App app = (App) params.get("app");

    logger.info("###### " + clsName + ": " + methodCall.getName());

    try {//from   w w  w .j a  v  a2 s.c  o m
        ////// !!!!!!!!!!! Methoden-Aufruf kann in den meisten Fllen nicht aufgelst werden!!
        final SymbolReference<ResolvedMethodDeclaration> ref = facade.solve(methodCall);

        if (ref.isSolved()) {

            final String qualifiedSignature = ref.getCorrespondingDeclaration().getQualifiedSignature();
            //final String scopeString = scope.toString();
            final String parentNodeAsString = methodCall.getParentNode().toString();
            //logger.info("Resolved to " + qualifiedSignature + ", scope: " + scopeString + ", parent node: " + parentNodeAsString);
            logger.info("Resolved to " + qualifiedSignature + ", parent node: " + parentNodeAsString);

            final String calledMethodQualifiedName = StringUtils.replacePattern(qualifiedSignature, "\\(.*\\)",
                    "");
            final String calledMethodQualifiedClassName = StringUtils
                    .substringBeforeLast(calledMethodQualifiedName, ".");
            final String calledMethodName = StringUtils.substringAfterLast(calledMethodQualifiedName, ".");

            Method calledMethod = null;

            final JavaClass calledMethodClass = (JavaClass) app.nodeQuery(JavaClass.class)
                    .and(JavaClass.name, calledMethodQualifiedClassName).getFirst();
            if (calledMethodClass != null) {

                logger.info(" Found called class in graph: " + calledMethodClass.getName());
                calledMethod = (Method) app.nodeQuery(Method.class).and(Method.name, calledMethodName)
                        .and(Method.classOrInterface, calledMethodClass).getFirst();

                if (calledMethod != null) {
                    logger.info(" Found called method in graph: "
                            + calledMethod.getProperty(Method.declaration));

                    final Optional<MethodDeclaration> callingMethod = methodCall
                            .getAncestorOfType(MethodDeclaration.class);
                    if (callingMethod.isPresent()) {

                        final String callingMethodDeclaration = callingMethod.get().getDeclarationAsString();

                        logger.info(" Calling method: " + callingMethodDeclaration);

                        final String callingMethodName = callingMethod.get().getNameAsString();
                        final Optional<TypeDeclaration> typeDecl = callingMethod.get()
                                .getAncestorOfType(TypeDeclaration.class);

                        if (typeDecl.isPresent()) {
                            final String callingMethodClassName = typeDecl.get().getNameAsString();

                            // Find compilation unit
                            final Optional<CompilationUnit> localCU = typeDecl.get()
                                    .getAncestorOfType(CompilationUnit.class);
                            if (localCU.isPresent()) {

                                // Does it have a package declaration?
                                final Optional<PackageDeclaration> packageDecl = localCU.get()
                                        .getPackageDeclaration();
                                if (packageDecl.isPresent()) {

                                    // Assemble qualified class name
                                    final String packageName = packageDecl.get().getNameAsString();
                                    final String fqcn = packageName + "." + callingMethodClassName;

                                    // Find class in graph
                                    final JavaClass callingClass = (JavaClass) app.nodeQuery(JavaClass.class)
                                            .and(JavaClass.name, fqcn).getFirst();
                                    if (callingClass != null) {

                                        final Method method = (Method) app.nodeQuery(Method.class)
                                                .and(Method.name, callingMethodName)
                                                .and(Method.classOrInterface, callingClass).getFirst();
                                        if (method != null) {

                                            logger.info("Found calling method in graph: " + method.getName());

                                            final List<Method> methodsCalled = method
                                                    .getProperty(Method.methodsCalled);
                                            methodsCalled.add(calledMethod);

                                            method.setProperty(Method.methodsCalled, methodsCalled);

                                            logger.info("Added " + calledMethod.getName()
                                                    + " to list of methods called in " + method.getName());
                                        }

                                    }
                                }
                            }

                        }
                    }

                }

            }

        }

    } catch (final Throwable t) {
        logger.info("Unable to resolve " + clsName, t);
    }
}

From source file:org.structr.mail.DynamicFileDataSource.java

public DynamicFileDataSource(final File fileNode) {

    contentType = fileNode.getContentType();
    fileName = fileNode.getName();/*  www .  j a  v  a2 s .  c  om*/

    if (contentType != null) {

        final String charset = StringUtils.substringAfterLast(contentType, "charset=").trim().toUpperCase();
        try {
            if (!"".equals(charset) && Charset.isSupported(charset)) {
                encoding = charset;
            }
        } catch (IllegalCharsetNameException ice) {
            logger.warn("Charset is not supported '{}'. Using 'UTF-8'", charset);
        }
    }

    try {
        fileContent = IOUtils.toString(fileNode.getInputStream(), encoding);
    } catch (IOException ex) {
        logger.warn("Unable to open input stream for {}: {}", fileName, ex.getMessage());
        fileContent = "";
    }
}

From source file:org.structr.media.SetMetadataProcess.java

@Override
public void preprocess() {

    try (final Tx tx = StructrApp.getInstance(securityContext).tx()) {

        // extract file extension
        fileExtension = StringUtils.substringAfterLast(inputVideo.getName(), ".");
        tx.success();//from ww w .  j  ava  2  s. c om

    } catch (FrameworkException fex) {
    }
}

From source file:org.structr.schema.SchemaHelper.java

private static String stem(final String term) {

    String lastWord;//from w  w w .  j  a  va  2  s.c  o m
    String begin = "";

    if (StringUtils.contains(term, WORD_SEPARATOR)) {

        lastWord = StringUtils.substringAfterLast(term, WORD_SEPARATOR);
        begin = StringUtils.substringBeforeLast(term, WORD_SEPARATOR);

    } else {

        lastWord = term;

    }

    lastWord = PlingStemmer.stem(lastWord);

    return begin.concat(WORD_SEPARATOR).concat(lastWord);

}