Example usage for org.jdom2 Element getText

List of usage examples for org.jdom2 Element getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the textual content directly held under this element as a string.

Usage

From source file:com.ohnosequences.xml.model.genome.feature.Feature.java

License:Open Source License

public void appendToSequence(String value) {
    Element seqElem = root.getChild(SEQUENCE_TAG_NAME);
    if (seqElem == null) {
        root.addContent(new Element(SEQUENCE_TAG_NAME));
        seqElem = root.getChild(SEQUENCE_TAG_NAME);
    }//from   w w w  .j a  va2 s .  c  om
    seqElem.setText(seqElem.getText() + value);
}

From source file:com.ohnosequences.xml.model.util.FlexXMLWrapperClassCreator.java

License:Open Source License

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("El programa espera un parametro: \n"
                + "1. Nombre del archivo xml con la descripcion de la clase \n");
    } else {/*from   w  w  w  .  ja  v  a  2s  .c  o m*/
        File inFile = new File(args[0]);

        try {

            BufferedReader reader = new BufferedReader(new FileReader(inFile));
            String line = null;
            StringBuilder stBuilder = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                stBuilder.append(line);
            }
            reader.close();

            XMLElement classes = new XMLElement(stBuilder.toString());
            List<Element> list = classes.getRoot().getChildren(XMLWrapperClass.TAG_NAME);

            for (Element elem : list) {
                XMLWrapperClass wrapper = new XMLWrapperClass(elem);

                //primero creo los directorios del package
                String[] packageSplit = wrapper.getPackage().split("\\.");
                String currentFolder = "./";
                for (int i = 0; i < packageSplit.length; i++) {
                    String string = packageSplit[i];
                    currentFolder += string;
                    System.out.println("currentFolder = " + currentFolder);
                    File tempFile = new File(currentFolder);
                    if (!tempFile.exists()) {
                        tempFile.mkdir();
                        System.out.println("no existe: tempFile = " + tempFile);
                    } else {
                        System.out.println("existe: tempFile = " + tempFile);
                    }
                    currentFolder += "/";

                }

                BufferedWriter outBuff = new BufferedWriter(
                        new FileWriter(new File(currentFolder + wrapper.getClassName() + ".as")));
                outBuff.write("package " + wrapper.getPackage() + "\n{\n");
                outBuff.write(NECESSARY_IMPORTS);
                outBuff.write("\n\npublic class " + wrapper.getClassName() + " extends XMLObject{\n\n");
                outBuff.write("public static const TAG_NAME:String = \"" + wrapper.getTagName() + "\";\n\n");

                HashMap<String, String> varsDeclarationNames = new HashMap<String, String>();
                HashMap<String, String> varsTypes = new HashMap<String, String>();

                List<Element> vars = wrapper.getVars().getChildren();
                for (Element element : vars) {
                    outBuff.write(VARS_PREFIX + " ");
                    String varName = element.getText();
                    String varDeclarationName = "";
                    for (int i = 0; i < varName.length(); i++) {
                        char c = varName.charAt(i);
                        if (Character.isUpperCase(c)) {
                            varDeclarationName += "_" + c;
                        } else {
                            varDeclarationName += ("" + c).toUpperCase();
                        }
                    }
                    varDeclarationName = varDeclarationName + "_TAG_NAME";
                    varsDeclarationNames.put(varName, varDeclarationName);
                    varsTypes.put(varName, element.getName());

                    //En este ciclo cambio la mayuscula del nombre de la variable por '_'
                    String tempTagName = "";
                    for (int i = 0; i < varName.length(); i++) {
                        char c = varName.charAt(i);
                        if (Character.isUpperCase(c)) {
                            tempTagName += "_" + ("" + c).toLowerCase();
                        } else {
                            tempTagName += "" + c;
                        }

                    }

                    outBuff.write(varDeclarationName + ":String = \"" + tempTagName + "\";\n");
                }

                //Ahora la parte de los constructores
                outBuff.write(
                        "\n" + CONSTRUCTORS_STR.replaceAll(CLASS_NAME_CONSTRUCTOR_VAR, wrapper.getClassName()));

                Set<String> varsKeySet = varsDeclarationNames.keySet();
                //A rellenar los getters!
                outBuff.write("\n" + GETTERS_STR);
                for (String key : varsKeySet) {

                    String varType = varsTypes.get(key);
                    String getStr = key;
                    outBuff.write("\npublic function get " + getStr + "():" + varType + "{\treturn ");
                    if (varType.equals("int")) {
                        outBuff.write("parseInt(getTagText(" + varsDeclarationNames.get(key) + "));}");
                    } else if (varType.equals("Number")) {
                        outBuff.write("new Number(getTagText(" + varsDeclarationNames.get(key) + "));}");
                    } else if (varType.equals("String")) {
                        outBuff.write("getTagText(" + varsDeclarationNames.get(key) + ");}");
                    } else if (varType.equals("Boolean")) {
                        outBuff.write("BooleanParser.parseBoolean(getTagText(" + varsDeclarationNames.get(key)
                                + "));}");
                    } else {
                        outBuff.write("getTagText(" + varsDeclarationNames.get(key) + ");}");
                    }

                }

                //A rellenar los setters!
                outBuff.write("\n" + SETTERS_STR);
                for (String key : varsKeySet) {
                    String varType = varsTypes.get(key);
                    String setStr = " set " + key;
                    outBuff.write("\n[Bindable]\npublic function " + setStr + "(value:" + varType
                            + "):void{\t setTagText(" + varsDeclarationNames.get(key) + ", ");
                    if (varType.equals("String")) {
                        outBuff.write("value");
                    } else {
                        outBuff.write("String(value)");
                    }
                    outBuff.write(");}");
                }

                //Llave que cierra la clase
                outBuff.write("\n}\n");
                //Llave que cierra el package
                outBuff.write("\n}\n");

                outBuff.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:com.ohnosequences.xml.model.util.XMLWrapperClassCreator.java

License:Open Source License

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("El programa espera un parametro: \n"
                + "1. Nombre del archivo xml con la descripcion de la clase \n");
    } else {/*from  w w  w  . ja v  a2  s  .c o m*/
        File inFile = new File(args[0]);

        try {

            BufferedReader reader = new BufferedReader(new FileReader(inFile));
            String line = null;
            StringBuilder stBuilder = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                stBuilder.append(line);
            }
            reader.close();

            XMLElement classes = new XMLElement(stBuilder.toString());
            List<Element> list = classes.getRoot().getChildren(XMLWrapperClass.TAG_NAME);

            for (Element elem : list) {
                XMLWrapperClass wrapper = new XMLWrapperClass(elem);

                //primero creo los directorios del package
                String[] packageSplit = wrapper.getPackage().split("\\.");
                String currentFolder = "./";
                for (int i = 0; i < packageSplit.length; i++) {
                    String string = packageSplit[i];
                    currentFolder += string;
                    System.out.println("currentFolder = " + currentFolder);
                    File tempFile = new File(currentFolder);
                    if (!tempFile.exists()) {
                        tempFile.mkdir();
                        System.out.println("no existe: tempFile = " + tempFile);
                    } else {
                        System.out.println("existe: tempFile = " + tempFile);
                    }
                    currentFolder += "/";

                }

                BufferedWriter outBuff = new BufferedWriter(
                        new FileWriter(new File(currentFolder + wrapper.getClassName() + ".java")));
                outBuff.write("package " + wrapper.getPackage() + ";\n\n");
                outBuff.write(NECESSARY_IMPORTS);
                outBuff.write("public class " + wrapper.getClassName() + " extends XMLElement{\n\n");
                outBuff.write("public static final String TAG_NAME = \"" + wrapper.getTagName() + "\";\n\n");

                HashMap<String, String> varsDeclarationNames = new HashMap<String, String>();
                HashMap<String, String> varsTypes = new HashMap<String, String>();

                List<Element> vars = wrapper.getVars().getChildren();
                for (Element element : vars) {
                    outBuff.write(VARS_PREFIX + " ");
                    String varName = element.getText();
                    String varDeclarationName = "";
                    for (int i = 0; i < varName.length(); i++) {
                        char c = varName.charAt(i);
                        if (Character.isUpperCase(c)) {
                            varDeclarationName += "_" + c;
                        } else {
                            varDeclarationName += ("" + c).toUpperCase();
                        }
                    }
                    varDeclarationName = varDeclarationName + "_TAG_NAME";
                    varsDeclarationNames.put(varName, varDeclarationName);
                    varsTypes.put(varName, element.getName());

                    //En este ciclo cambio la mayuscula del nombre de la variable por '_'
                    String tempTagName = "";
                    for (int i = 0; i < varName.length(); i++) {
                        char c = varName.charAt(i);
                        if (Character.isUpperCase(c)) {
                            tempTagName += "_" + ("" + c).toLowerCase();
                        } else {
                            tempTagName += "" + c;
                        }

                    }

                    outBuff.write(varDeclarationName + " = \"" + tempTagName + "\";\n");
                }

                //Ahora la parte de los constructores
                outBuff.write(
                        "\n" + CONSTRUCTORS_STR.replaceAll(CLASS_NAME_CONSTRUCTOR_VAR, wrapper.getClassName()));

                Set<String> varsKeySet = varsDeclarationNames.keySet();
                //A rellenar los getters!
                outBuff.write("\n" + GETTERS_STR);
                for (String key : varsKeySet) {

                    String varType = varsTypes.get(key);
                    String getStr = " get" + key.substring(0, 1).toUpperCase() + key.substring(1);
                    outBuff.write("\npublic " + varType + getStr + "(){\treturn ");
                    if (varType.equals("int")) {
                        outBuff.write("Integer.parseInt(getNodeText(" + varsDeclarationNames.get(key) + "));}");
                    } else if (varType.equals("double")) {
                        outBuff.write(
                                "Double.parseDouble(getNodeText(" + varsDeclarationNames.get(key) + "));}");
                    } else if (varType.equals("float")) {
                        outBuff.write("Float.parseFloat(getNodeText(" + varsDeclarationNames.get(key) + "));}");
                    } else if (varType.equals("String")) {
                        outBuff.write("getNodeText(" + varsDeclarationNames.get(key) + ");}");
                    } else if (varType.equals("boolean")) {
                        outBuff.write(
                                "Boolean.parseBoolean(getNodeText(" + varsDeclarationNames.get(key) + "));}");
                    }

                }

                //A rellenar los setters!
                outBuff.write("\n" + SETTERS_STR);
                for (String key : varsKeySet) {
                    String varType = varsTypes.get(key);
                    String setStr = " set" + key.substring(0, 1).toUpperCase() + key.substring(1);
                    outBuff.write("\npublic void " + setStr + "(" + varType + " value){\t setNodeText("
                            + varsDeclarationNames.get(key) + ", ");
                    if (varType.equals("String")) {
                        outBuff.write("value");
                    } else {
                        outBuff.write("String.valueOf(value)");
                    }
                    outBuff.write(");}");
                }

                //Llave que cierra la clase
                outBuff.write("\n}\n");

                outBuff.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

From source file:com.rhythm.louie.email.MailProperties.java

License:Apache License

public static void processProperties(Element email) {
    for (Element prop : email.getChildren()) {
        String propName = prop.getName().toLowerCase();
        if (null != propName) {
            switch (propName) {
            case JNDI:
                jndi = prop.getText().trim();
                break;
            case CUSTOM:
                for (Element customProp : prop.getChildren()) {
                    props.put(customProp.getName(), customProp.getTextTrim());
                }//w w w.j  av  a 2s  . co m
                break;
            default:
                LoggerFactory.getLogger(MailProperties.class).warn("Unknown Mail Element:{}", propName);
                break;

            }
        }
    }
}

From source file:com.rhythm.louie.jms.MessagingProperties.java

License:Apache License

public static void processMessaging(Element messaging) {
    for (Element prop : messaging.getChildren()) {
        String propName = prop.getName().toLowerCase();
        if (null != propName) {
            switch (propName) {
            case JMSADAPTER:
                adapterClass = prop.getAttributeValue(CLASS, getAdapterClass());
                host = prop.getAttributeValue(JmsAdapter.HOST_KEY, getHost());
                port = prop.getAttributeValue(JmsAdapter.PORT_KEY, getPort());
                failover = prop.getAttributeValue(JmsAdapter.FAILOVER_KEY, getFailover());
                break;
            case SERVER:
                serverPrefix = prop.getAttributeValue(PREFIX, getServerPrefix());
                serverType = prop.getAttributeValue(TYPE, getServerType());
                break;
            case CLIENT:
                clientPrefix = prop.getAttributeValue(PREFIX, getClientPrefix());
                clientType = prop.getAttributeValue(TYPE, getClientType());
                break;
            case UPDATE:
                updatePrefix = prop.getAttributeValue(PREFIX, getUpdatePrefix());
                updateType = prop.getAttributeValue(TYPE, getUpdateType());
                break;
            case CUSTOM:
                for (Element customProp : prop.getChildren()) {
                    String customName = customProp.getName().toLowerCase();
                    CustomProperty custom = new CustomProperty(customName);
                    for (Element child : customProp.getChildren()) {
                        custom.setProperty(child.getName(), child.getText().trim());
                    }/*from   w  w w  . ja  va  2s . c o  m*/
                    customProperties.put(customName, custom);
                }
                break;
            default:
                LoggerFactory.getLogger(MessagingProperties.class).warn("Unknown Message Property:{}",
                        propName);
                break;
            }
        }
    }
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

public static void processProperties(URL configs, String contextGateway) throws Exception {
    loadInternals(); //this code organization is weird but it's from iterations of design

    if (contextGateway != null) {
        //Overrides a default set by internal properties
        Server.setDefaultGateway(contextGateway);
    }// w w  w  .  java2s  .co  m

    Document properties = loadDocument(configs);
    if (properties == null) {
        return;
    }

    Element louie = properties.getRootElement();

    //Check for alternate loading point 
    boolean resetRoot = false;
    for (Element elem : louie.getChildren()) {
        if (ALT_PATH.equalsIgnoreCase(elem.getName())) {
            String altPath = elem.getTextTrim();
            LoggerFactory.getLogger(LouieProperties.class).info("Loading Louie configs from alternate file: {}",
                    altPath);
            //overwrite document with values from alternate config 
            properties = loadDocument(new File(altPath).toURI().toURL());
            if (properties == null)
                return;
            resetRoot = true;
        }
    }
    if (resetRoot) {
        //reset root to new properties obj root
        louie = properties.getRootElement();
    }

    Element groups = louie.getChild(GROUPS);
    if (groups != null) {
        AccessManager.loadGroups(groups);
    }

    boolean serversConfigured = false;
    for (Element elem : louie.getChildren()) {
        String elemName = elem.getName().toLowerCase();

        if (null != elemName)
            switch (elemName) {
            case ALT_PATH:
                LoggerFactory.getLogger(LouieProperties.class)
                        .warn("Extra config_path alternate loading point specified. "
                                + "Only one file-switch can be performed.\n"
                                + "  Please verify what is specified in the embedded xml file.\n"
                                + "  Found: {}", elem.getText());
                break;
            case SERVER_PARENT:
                processServers(elem);
                serversConfigured = true;
                break;
            case SERVICE_PARENT:
                processServices(elem, false);
                break;
            case MESSAGING:
                MessagingProperties.processMessaging(elem);
                break;
            case MAIL:
                MailProperties.processProperties(elem);
                break;
            case SCHEDULER:
                TaskSchedulerProperties.processProperties(elem);
                break;
            case ALERTS:
                AlertProperties.processProperties(elem);
                break;
            case CUSTOM:
                processCustomProperties(elem);
                break;
            case GROUPS:
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected top level property  {}",
                        elemName);
                break;
            }
    }
    if (!serversConfigured)
        processServers(null); //ugly bootstrapping workflow
}

From source file:com.rometools.modules.base.io.CustomTagParser.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    final CustomTags module = new CustomTagsImpl();
    final ArrayList<CustomTag> tags = new ArrayList<CustomTag>();
    final List<Element> elements = element.getChildren();
    final Iterator<Element> it = elements.iterator();
    while (it.hasNext()) {
        final Element child = it.next();
        if (child.getNamespace().equals(NS)) {
            final String type = child.getAttributeValue("type");
            try {
                if (type == null) {
                    continue;
                } else if (type.equals("string")) {
                    tags.add(new CustomTagImpl(child.getName(), child.getText()));
                } else if (type.equals("int")) {
                    tags.add(new CustomTagImpl(child.getName(), new Integer(child.getTextTrim())));
                } else if (type.equals("float")) {
                    tags.add(new CustomTagImpl(child.getName(), new Float(child.getTextTrim())));
                } else if (type.equals("intUnit")) {
                    tags.add(new CustomTagImpl(child.getName(), new IntUnit(child.getTextTrim())));
                } else if (type.equals("floatUnit")) {
                    tags.add(new CustomTagImpl(child.getName(), new FloatUnit(child.getTextTrim())));
                } else if (type.equals("date")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                new ShortDate(GoogleBaseParser.SHORT_DT_FMT.parse(child.getTextTrim()))));
                    } catch (final ParseException e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }//from   w  w w  .java2 s . c o  m
                } else if (type.equals("dateTime")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                GoogleBaseParser.LONG_DT_FMT.parse(child.getTextTrim())));
                    } catch (final ParseException e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }
                } else if (type.equals("dateTimeRange")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(),
                                new DateTimeRange(
                                        GoogleBaseParser.LONG_DT_FMT.parse(
                                                child.getChild("start", CustomTagParser.NS).getText().trim()),
                                        GoogleBaseParser.LONG_DT_FMT.parse(
                                                child.getChild("end", CustomTagParser.NS).getText().trim()))));
                    } catch (final Exception e) {
                        LOG.warn("Unable to parse date type on " + child.getName(), e);
                    }
                } else if (type.equals("url")) {
                    try {
                        tags.add(new CustomTagImpl(child.getName(), new URL(child.getTextTrim())));
                    } catch (final MalformedURLException e) {
                        LOG.warn("Unable to parse URL type on " + child.getName(), e);
                    }
                } else if (type.equals("boolean")) {
                    tags.add(
                            new CustomTagImpl(child.getName(), new Boolean(child.getTextTrim().toLowerCase())));
                } else if (type.equals("location")) {
                    tags.add(new CustomTagImpl(child.getName(), new CustomTagImpl.Location(child.getText())));
                } else {
                    throw new Exception("Unknown type: " + type);
                }
            } catch (final Exception e) {
                LOG.warn("Unable to parse type on " + child.getName(), e);
            }
        }
    }
    module.setValues(tags);
    return module;
}

From source file:com.rometools.modules.base.io.GoogleBaseParser.java

License:Open Source License

private void handleTag(final Element tag, final PropertyDescriptor pd, final GoogleBase module)
        throws Exception {
    Object tagValue = null;/*from w w  w. ja va2 s  .  c o  m*/

    if (pd.getPropertyType() == Integer.class || pd.getPropertyType().getComponentType() == Integer.class) {
        tagValue = new Integer(
                GoogleBaseParser.stripNonValidCharacters(GoogleBaseParser.INTEGER_CHARS, tag.getText()));
    } else if (pd.getPropertyType() == Float.class || pd.getPropertyType().getComponentType() == Float.class) {
        tagValue = new Float(
                GoogleBaseParser.stripNonValidCharacters(GoogleBaseParser.FLOAT_CHARS, tag.getText()));
    } else if (pd.getPropertyType() == String.class
            || pd.getPropertyType().getComponentType() == String.class) {
        tagValue = tag.getText();
    } else if (pd.getPropertyType() == URL.class || pd.getPropertyType().getComponentType() == URL.class) {
        tagValue = new URL(tag.getText().trim());
    } else if (pd.getPropertyType() == Boolean.class
            || pd.getPropertyType().getComponentType() == Boolean.class) {
        tagValue = new Boolean(tag.getText().trim());
    } else if (pd.getPropertyType() == Date.class || pd.getPropertyType().getComponentType() == Date.class) {
        final String text = tag.getText().trim();

        if (text.length() > 10) {
            tagValue = GoogleBaseParser.LONG_DT_FMT.parse(text);
        } else {
            tagValue = GoogleBaseParser.SHORT_DT_FMT.parse(text);
        }
    } else if (pd.getPropertyType() == IntUnit.class
            || pd.getPropertyType().getComponentType() == IntUnit.class) {
        tagValue = new IntUnit(tag.getText());
    } else if (pd.getPropertyType() == FloatUnit.class
            || pd.getPropertyType().getComponentType() == FloatUnit.class) {
        tagValue = new FloatUnit(tag.getText());
    } else if (pd.getPropertyType() == DateTimeRange.class
            || pd.getPropertyType().getComponentType() == DateTimeRange.class) {
        tagValue = new DateTimeRange(
                LONG_DT_FMT.parse(tag.getChild("start", GoogleBaseParser.NS).getText().trim()),
                LONG_DT_FMT.parse(tag.getChild("end", GoogleBaseParser.NS).getText().trim()));
    } else if (pd.getPropertyType() == ShippingType.class
            || pd.getPropertyType().getComponentType() == ShippingType.class) {
        final FloatUnit price = new FloatUnit(tag.getChild("price", GoogleBaseParser.NS).getText().trim());
        ShippingType.ServiceEnumeration service = ShippingType.ServiceEnumeration
                .findByValue(tag.getChild("service", GoogleBaseParser.NS).getText().trim());

        if (service == null) {
            service = ShippingType.ServiceEnumeration.STANDARD;
        }

        final String country = tag.getChild("country", GoogleBaseParser.NS).getText().trim();
        tagValue = new ShippingType(price, service, country);
    } else if (pd.getPropertyType() == PaymentTypeEnumeration.class
            || pd.getPropertyType().getComponentType() == PaymentTypeEnumeration.class) {
        tagValue = PaymentTypeEnumeration.findByValue(tag.getText().trim());
    } else if (pd.getPropertyType() == PriceTypeEnumeration.class
            || pd.getPropertyType().getComponentType() == PriceTypeEnumeration.class) {
        tagValue = PriceTypeEnumeration.findByValue(tag.getText().trim());
    } else if (pd.getPropertyType() == CurrencyEnumeration.class
            || pd.getPropertyType().getComponentType() == CurrencyEnumeration.class) {
        tagValue = CurrencyEnumeration.findByValue(tag.getText().trim());
    } else if (pd.getPropertyType() == GenderEnumeration.class
            || pd.getPropertyType().getComponentType() == GenderEnumeration.class) {
        tagValue = GenderEnumeration.findByValue(tag.getText().trim());
    } else if (pd.getPropertyType() == YearType.class
            || pd.getPropertyType().getComponentType() == YearType.class) {
        tagValue = new YearType(tag.getText().trim());
    } else if (pd.getPropertyType() == Size.class || pd.getPropertyType().getComponentType() == Size.class) {
        tagValue = new Size(tag.getText().trim());
    }

    if (!pd.getPropertyType().isArray()) {
        pd.getWriteMethod().invoke(module, new Object[] { tagValue });
    } else {
        final Object[] current = (Object[]) pd.getReadMethod().invoke(module, (Object[]) null);
        final int newSize = current == null ? 1 : current.length + 1;
        final Object setValue = Array.newInstance(pd.getPropertyType().getComponentType(), newSize);

        int i = 0;

        for (; current != null && i < current.length; i++) {
            Array.set(setValue, i, current[i]);
        }

        Array.set(setValue, i, tagValue);
        pd.getWriteMethod().invoke(module, new Object[] { setValue });
    }
}

From source file:com.rometools.modules.content.io.ContentModuleParser.java

License:Open Source License

@Override
public com.rometools.rome.feed.module.Module parse(final Element element, final Locale locale) {
    boolean foundSomething = false;
    final ContentModule cm = new ContentModuleImpl();
    final List<Element> encodeds = element.getChildren("encoded", CONTENT_NS);
    final ArrayList<String> contentStrings = new ArrayList<String>();
    final ArrayList<String> encodedStrings = new ArrayList<String>();

    if (!encodeds.isEmpty()) {
        foundSomething = true;// w  w w.jav a 2  s.c om

        for (int i = 0; i < encodeds.size(); i++) {
            final Element encodedElement = encodeds.get(i);
            encodedStrings.add(encodedElement.getText());
            contentStrings.add(encodedElement.getText());
        }
    }

    final ArrayList<ContentItem> contentItems = new ArrayList<ContentItem>();
    final List<Element> items = element.getChildren("items", CONTENT_NS);

    for (int i = 0; i < items.size(); i++) {
        foundSomething = true;

        final List<Element> lis = items.get(i).getChild("Bag", RDF_NS).getChildren("li", RDF_NS);

        for (int j = 0; j < lis.size(); j++) {
            final ContentItem ci = new ContentItem();
            final Element li = lis.get(j);
            final Element item = li.getChild("item", CONTENT_NS);
            final Element format = item.getChild("format", CONTENT_NS);
            final Element encoding = item.getChild("encoding", CONTENT_NS);
            final Element value = item.getChild("value", RDF_NS);

            if (value != null) {
                if (value.getAttributeValue("parseType", RDF_NS) != null) {
                    ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS));
                }

                if (ci.getContentValueParseType() != null && ci.getContentValueParseType().equals("Literal")) {
                    ci.setContentValue(getXmlInnerText(value));
                    contentStrings.add(getXmlInnerText(value));
                    ci.setContentValueNamespaces(value.getAdditionalNamespaces());
                } else {
                    ci.setContentValue(value.getText());
                    contentStrings.add(value.getText());
                }

                ci.setContentValueDOM(value.clone().getContent());
            }

            if (format != null) {
                ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue());
            }

            if (encoding != null) {
                ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue());
            }

            if (item != null) {
                final Attribute about = item.getAttribute("about", RDF_NS);

                if (about != null) {
                    ci.setContentAbout(about.getValue());
                }
            }

            contentItems.add(ci);
        }
    }

    cm.setEncodeds(encodedStrings);
    cm.setContentItems(contentItems);
    cm.setContents(contentStrings);

    return foundSomething ? cm : null;
}

From source file:com.rometools.modules.feedburner.io.FeedBurnerModuleParser.java

License:Apache License

@Override
public Module parse(final Element element, final Locale locale) {
    final FeedBurnerImpl fbi = new FeedBurnerImpl();
    boolean returnObj = false;
    Element tag = element.getChild("awareness", FeedBurnerModuleParser.NS);

    if (tag != null) {
        fbi.setAwareness(tag.getText().trim());
        returnObj = true;//  ww  w . j  a va  2 s. c o  m
    }

    tag = element.getChild("origLink", FeedBurnerModuleParser.NS);

    if (tag != null) {
        fbi.setOrigLink(tag.getText().trim());
        returnObj = true;
    }

    tag = element.getChild("origEnclosureLink", FeedBurnerModuleParser.NS);

    if (tag != null) {
        fbi.setOrigEnclosureLink(tag.getText().trim());
        returnObj = true;
    }

    if (returnObj) {
        return fbi;
    }

    return null;
}