Example usage for org.jdom2 Attribute Attribute

List of usage examples for org.jdom2 Attribute Attribute

Introduction

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

Prototype

public Attribute(final String name, final String value) 

Source Link

Document

This will create a new Attribute with the specified (local) name and value, and does not place the attribute in a Namespace .

Usage

From source file:com.cybernostics.jsp2thymeleaf.api.elements.AttributeValueElementConverter.java

Attribute transform(JSPParser.HtmlAttributeContext attribute) {
    final JSPParser.JspElementContext jspElement = attribute.jspElement();
    if (jspElement != null) {
        throw new UnsupportedOperationException("TODO");
    }//from   w  w w.j  a  v a 2s .  co  m
    final JSPParser.ScriptletContext scriptlet = attribute.scriptlet();
    if (scriptlet != null) {
        throw new UnsupportedOperationException("TODO");
    }
    final JSPParser.HtmlAttributeNameContext name = attribute.name;
    final JSPParser.HtmlAttributeValueContext value = attribute.value;
    String nameStr = name.getText();
    PrefixedName prefixedName = prefixedNameFor(nameStr);
    //        if (prefixedName.getPrefix().equals("c"))
    //        {
    //            if (prefixedName.getName().equals("url"))
    //            {
    //                Optional<JSPAttributeNode> value = getAttribute(treeValue, "value");
    //
    //                return new Attribute(attName, "@{" + value.get().getValue() + "}");
    //            }
    //        }
    return new Attribute(nameStr, "Unknown tag:" + ((value == null) ? "null" : value.toStringTree()));

}

From source file:com.cybernostics.jsp2thymeleaf.api.elements.CopyElementConverter.java

protected Optional<Attribute> createAttribute(HtmlAttributeContext jspNodeAttribute,
        JSPElementNodeConverter context) {
    final JSPParser.JspElementContext jspElement = jspNodeAttribute.jspElement();
    if (jspElement != null) {
        // do something here
        throw new UnsupportedOperationException("element converter needed here.TODO");
    }/*from   ww w . j  a  va 2  s.c o  m*/

    final JSPParser.HtmlAttributeValueContext value = jspNodeAttribute.value;
    String attributeValueText = "";

    if (value != null) {

        final JSPParser.HtmlAttributeValueExprContext exprValue = jspNodeAttribute.value
                .htmlAttributeValueExpr();
        if (exprValue != null) {
            if (context == null) {
                throw new RuntimeException("Cannot convert expression - null context:" + exprValue.getText());
            }
            try {
                attributeValueText = ELExpressionConverter.convert(exprValue.getText(),
                        context.getScopedConverters());
            } catch (org.apache.commons.el.parser.ParseException exception) {
                throw new JSP2ThymeleafExpressionParseException(exception, exprValue.start.getLine(),
                        exprValue.start.getCharPositionInLine());
            }

        } else {
            final JSPParser.HtmlAttributeValueConstantContext constant = jspNodeAttribute.value
                    .htmlAttributeValueConstant();
            if (constant != null) {
                attributeValueText = constant.getText();
            }

        }

    } else {
        attributeValueText = jspNodeAttribute.name.getText();
    }

    return Optional.of(new Attribute(jspNodeAttribute.name.getText(), attributeValueText));

}

From source file:com.dexterapps.android.translator.TranslateAndSaveAndroid.java

License:Apache License

private void generateXMLForCountry(String countryCode, List<String> translatedText,
        ArrayList<AndroidStringMapping> stringXmlDOM, HashMap<String, Integer> baseStringResourcesMapping,
        String outPutFolder) {//from  w  ww .  java  2 s.c om
    Element resources = new Element("resources");
    Document doc = new Document(resources);

    //System.out.println("Generating XML");

    //int totalNumberOfStrings = 0;
    for (int i = 0; i < stringXmlDOM.size(); i++) {
        AndroidStringMapping stringMapping = stringXmlDOM.get(i);

        if (stringMapping.getType().equalsIgnoreCase("string")) {
            Element string = new Element("string");
            string.setAttribute(new Attribute("name", stringMapping.getAttributeName()));

            //To get the attribute value, use the hasmap and then string array
            int translatedTextIndex = baseStringResourcesMapping.get(stringMapping.getAttributeValue());
            string.setText(translatedText.get(translatedTextIndex));

            //Add element to root
            doc.getRootElement().addContent(string);
        } else if (stringMapping.getType().equalsIgnoreCase("string-array")) {
            Element stringArray = new Element("string-array");
            stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName()));

            //Since this is String array it will have a list of string items, get the list of string items

            ArrayList<String> stringArrayItems = (ArrayList<String>) stringMapping.getAttributeValue();

            for (int j = 0; j < stringArrayItems.size(); j++) {
                int translatedTextIndex = baseStringResourcesMapping.get(stringArrayItems.get(j));
                stringArray.addContent(new Element("item").setText(translatedText.get(translatedTextIndex)));
            }

            //Add element to root
            doc.getRootElement().addContent(stringArray);
        } else {
            Element stringArray = new Element("plurals");
            stringArray.setAttribute(new Attribute("name", stringMapping.getAttributeName()));

            //Since this is plurals it will have a list of string items with values, get the list of string items

            ArrayList<AndroidStringPlurals> stringPluralItems = (ArrayList<AndroidStringPlurals>) stringMapping
                    .getAttributeValue();

            for (int j = 0; j < stringPluralItems.size(); j++) {

                int translatedTextIndex = baseStringResourcesMapping
                        .get(stringPluralItems.get(j).getAttributeValue());
                Element pluralItem = new Element("item");
                pluralItem.setAttribute("quantity", stringPluralItems.get(j).getAttributeName());
                pluralItem.setText(translatedText.get(translatedTextIndex));

                stringArray.addContent(pluralItem);
            }

            //Add element to root
            doc.getRootElement().addContent(stringArray);
        }
    }

    // new XMLOutputter().output(doc, System.out);
    XMLOutputter xmlOutput = new XMLOutputter();

    try {
        // System.out.println("Saving File");
        Format format = Format.getPrettyFormat();
        format.setEncoding("UTF-8");
        xmlOutput.setFormat(format);

        File file = new File(outPutFolder + "/values-" + countryCode);
        if (!file.exists()) {
            file.mkdir();
        }

        file = new File(outPutFolder + "/values-" + countryCode + "/strings.xml");
        FileOutputStream fop = new FileOutputStream(file);
        xmlOutput.output(doc, fop);
        System.out.println("Translation Successful !!");

        // System.out.println("File Saved!");
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.facebook.buck.ide.intellij.projectview.ProjectView.java

License:Apache License

private static Attribute attribute(String name, String value) {
    return new Attribute(name, value);
}

From source file:com.rometools.modules.atom.io.AtomModuleGenerator.java

License:Apache License

private Element generateLink(Link link) {
    Element linkElement = new Element("link", NS);

    if (link.getHref() != null) {
        Attribute href = new Attribute(AtomLinkAttribute.HREF, link.getHref());
        linkElement.setAttribute(href);/* w  w w .j a v  a 2  s.  c om*/
    }
    if (link.getType() != null) {
        Attribute type = new Attribute(AtomLinkAttribute.TYPE, link.getType());
        linkElement.setAttribute(type);
    }
    if (link.getRel() != null) {
        Attribute rel = new Attribute(AtomLinkAttribute.REL, link.getRel());
        linkElement.setAttribute(rel);
    }

    if (link.getHreflang() != null) {
        final Attribute hreflangAttribute = new Attribute(AtomLinkAttribute.HREF_LANG, link.getHreflang());
        linkElement.setAttribute(hreflangAttribute);
    }

    if (link.getTitle() != null) {
        final Attribute title = new Attribute(AtomLinkAttribute.TITLE, link.getTitle());
        linkElement.setAttribute(title);
    }

    if (link.getLength() != 0) {
        final Attribute length = new Attribute(AtomLinkAttribute.LENGTH, Long.toString(link.getLength()));
        linkElement.setAttribute(length);
    }

    return linkElement;
}

From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleGenerator.java

License:Apache License

protected Element generateQueryElement(final OSQuery query) {

    final Element qElement = new Element("Query", OS_NS);

    if (query.getRole() != null) {
        final Attribute roleAttribute = new Attribute("role", query.getRole());
        qElement.setAttribute(roleAttribute);
    } else {//  w w w .  ja va  2 s.  c  o m
        throw new RequiredAttributeMissingException(
                "If declaring a Query element, the field 'role' must be be specified");
    }

    if (query.getOsd() != null) {
        final Attribute osd = new Attribute("osd", query.getOsd());
        qElement.setAttribute(osd);
    }

    if (query.getSearchTerms() != null) {
        final Attribute searchTerms = new Attribute("searchTerms", query.getSearchTerms());
        qElement.setAttribute(searchTerms);
    }

    if (query.getStartPage() > -1) {
        final int startPage = query.getStartPage() != 0 ? query.getStartPage() : 1;
        final Attribute sp = new Attribute("startPage", Integer.toString(startPage));
        qElement.setAttribute(sp);
    }

    if (query.getTitle() != null) {
        qElement.setAttribute(new Attribute("title", query.getTitle()));
    }

    if (query.getTotalResults() > -1) {
        qElement.setAttribute(new Attribute("totalResults", Integer.toString(query.getTotalResults())));
    }

    return qElement;
}

From source file:com.rometools.modules.opensearch.impl.OpenSearchModuleGenerator.java

License:Apache License

protected Element generateLinkElement(final Link link) {
    final Element linkElement = new Element("link", OS_NS);

    if (link.getRel() != null) {
        final Attribute relAttribute = new Attribute("rel", "search");
        linkElement.setAttribute(relAttribute);
    }//www.  ja  v  a  2s .com

    if (link.getType() != null) {
        final Attribute typeAttribute = new Attribute("type", link.getType());
        linkElement.setAttribute(typeAttribute);
    }

    if (link.getHref() != null) {
        final Attribute hrefAttribute = new Attribute("href", link.getHref());
        linkElement.setAttribute(hrefAttribute);
    }

    if (link.getHreflang() != null) {
        final Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang());
        linkElement.setAttribute(hreflangAttribute);
    }
    return linkElement;
}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Element createRootElement(final Feed feed) {
    final Element root = new Element("feed", getFeedNamespace());
    root.addNamespaceDeclaration(getFeedNamespace());
    final Attribute version = new Attribute("version", getVersion());
    root.setAttribute(version);//from w w  w . j a v  a 2  s  . co m
    generateModuleNamespaceDefs(root);
    return root;
}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Element generateLinkElement(final Link link) {

    final Element linkElement = new Element("link", getFeedNamespace());

    final String rel = link.getRel();
    if (rel != null) {
        final Attribute relAttribute = new Attribute("rel", rel.toString());
        linkElement.setAttribute(relAttribute);
    }/*  w  w w.j a  va 2s .  c om*/

    final String type = link.getType();
    if (type != null) {
        final Attribute typeAttribute = new Attribute("type", type);
        linkElement.setAttribute(typeAttribute);
    }

    final String href = link.getHref();
    if (href != null) {
        final Attribute hrefAttribute = new Attribute("href", href);
        linkElement.setAttribute(hrefAttribute);
    }

    return linkElement;

}

From source file:com.rometools.rome.io.impl.Atom03Generator.java

License:Open Source License

protected Element generateTagLineElement(final Content tagline) {

    final Element taglineElement = new Element("tagline", getFeedNamespace());

    final String type = tagline.getType();
    if (type != null) {
        final Attribute typeAttribute = new Attribute("type", type);
        taglineElement.setAttribute(typeAttribute);
    }//  ww w. j a  va2  s.  c o m

    final String value = tagline.getValue();
    if (value != null) {
        taglineElement.addContent(value);
    }

    return taglineElement;

}