Example usage for org.jsoup.nodes Attribute Attribute

List of usage examples for org.jsoup.nodes Attribute Attribute

Introduction

In this page you can find the example usage for org.jsoup.nodes Attribute Attribute.

Prototype

public Attribute(String key, String value) 

Source Link

Document

Create a new attribute from unencoded (raw) key and value.

Usage

From source file:com.iorga.iraj.servlet.AgglomeratorServlet.java

private long searchAndAppendAfter(final ServletConfig config, final Element agglomerateElement,
        final String scriptSrc, final String pathPrefix, final String pathSuffix, final String urlAttribute,
        long lastModified) throws MalformedURLException, IOException, URISyntaxException {
    if (mode == Mode.DEVELOPMENT) {
        // add a watch for that directory
        final Path path = Paths.get(config.getServletContext().getRealPath(scriptSrc));
        path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE);
    }//ww  w  .  ja  v a2s .  c  o  m
    final Set<String> childrenPaths = config.getServletContext().getResourcePaths(scriptSrc);
    for (final String path : childrenPaths) {
        if (path.endsWith(pathSuffix)) {
            // add that JS
            final StringBuilder targetScript = new StringBuilder("<");
            targetScript.append(agglomerateElement.tagName());
            // copy all the origin attributes
            for (final Attribute attribute : agglomerateElement.attributes()) {
                final String key = attribute.getKey();
                if (!ATTRIBUTE_NAME.equalsIgnoreCase(key) && !urlAttribute.equalsIgnoreCase(key)
                        && !URL_ATTRIBUTE_ATTRIBUTE_NAME.equalsIgnoreCase(key)) {
                    targetScript.append(" ").append(attribute.html());
                }
            }
            // specify the src path
            final String childUrl = StringUtils.removeStart(path, pathPrefix);
            targetScript.append(" ").append(new Attribute(urlAttribute, childUrl).html()).append(" />");
            agglomerateElement.after(targetScript.toString());
            lastModified = Math.max(
                    config.getServletContext().getResource(childUrl).openConnection().getLastModified(),
                    lastModified);
        } else if (path.endsWith("/")) {
            // it's a directory, recurse search & append
            lastModified = Math.max(searchAndAppendAfter(config, agglomerateElement, path, pathPrefix,
                    pathSuffix, urlAttribute, lastModified), lastModified);
        }
    }
    return lastModified;
}

From source file:org.symphonyoss.client.util.MlMessageParser.java

private void updateMentionUidToEmail(SymphonyClient symClient, List<Node> nodesList) {

    for (Node node : nodesList) {
        String nodeName = node.nodeName();

        if (nodeName.equalsIgnoreCase(NodeTypes.MENTION.toString())) {

            if (node.attributes().hasKey(AttribTypes.UID.toString())) {

                String uid = node.attr(AttribTypes.UID.toString());

                SymUser user = null;//from   ww w  .  j  av  a2  s .c o m
                try {
                    user = symClient.getUsersClient().getUserFromId(Long.parseLong(uid));

                    logger.info("Translated mention uid {} to email {}", uid, user.getEmailAddress());
                } catch (UsersClientException e) {
                    logger.error("Could not identify user email from id", e);
                }

                if (user != null && user.getEmailAddress() != null) {
                    uid = user.getEmailAddress();
                }

                Attribute emailAttribute = new Attribute(AttribTypes.EMAIL.toString(), uid);

                node.attributes().put(emailAttribute);
                node.removeAttr(AttribTypes.UID.toString());

            }

        }
        updateMentionUidToEmail(symClient, node.childNodes());
    }

}