Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname, final Namespace ns) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within the given Namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.converter.mathml2html.DOMFormulaConverter.java

License:Open Source License

/**
 * Recursive function to render all FormulaElements
 * Converts MathML to HTML//from  w ww.  ja va  2  s.  c  om
 *
 * @param cur the current processed MathML JDOM2 Element (a node or leaf inside MathML's DOM tree)
 * @return an object which implements the FormulaElement interface, so it can be rendered to HTML
 */
private FormulaElement renderElement(Element cur) {

    String name = cur.getName();
    String mathvariant = null;
    FormulaElement output;

    // Based on the MathML tag a corresponding class will be chosen and output will be rendered
    switch (name.toLowerCase()) {

    // Superscripts
    case "msup":
        Msup msup = new Msup();
        msup.setBase(renderElement(cur.getChildren().get(0)));
        msup.setSuperscript(renderElement(cur.getChildren().get(1)));
        output = msup;
        break;

    // Subscripts
    case "msub":
        Msub msub = new Msub();
        msub.setBase(renderElement(cur.getChildren().get(0)));
        msub.setSubscript(renderElement(cur.getChildren().get(1)));
        output = msub;
        break;

    // Subscript-superscript Pairs
    case "msubsup":
        Msubsup msubsup = new Msubsup();
        msubsup.setBase(renderElement(cur.getChildren().get(0)));
        msubsup.setSubscript(renderElement(cur.getChildren().get(1)));
        msubsup.setSuperscript(renderElement(cur.getChildren().get(2)));
        output = msubsup;
        break;

    // Rows
    case "mrow":
        Mrow mrow = new Mrow();
        Iterator<Element> iterator = cur.getChildren().iterator();

        while (iterator.hasNext()) {
            Element element = iterator.next();
            FormulaElement rowElement = renderElement(element);
            mrow.addElement(rowElement);
        }

        output = mrow;
        break;

    // operators
    case "mo":
        Mo mo;
        String operator = cur.getText();

        // find operator in dictionary
        mo = MathmlCharacterDictionary.findOperator(operator, cur.getAttributeValue("form", "infix"));

        if (mo == null) {
            mo = new Mo();
            mo.setValue(operator);

            // Parse attributes
            mo.setAccent(Boolean.parseBoolean(cur.getAttributeValue("accent", "false")));
            mo.setSeparator(Boolean.parseBoolean(cur.getAttributeValue("separator", "false")));
            mo.setFence(Boolean.parseBoolean(cur.getAttributeValue("fence", "false")));
            mo.setMovablelimits(Boolean.parseBoolean(cur.getAttributeValue("movablelimits", "false")));
            mo.setLargeop(Boolean.parseBoolean(cur.getAttributeValue("largeop", "false")));
            mo.setStretchy(Boolean.parseBoolean(cur.getAttributeValue("stretchy", "false")));

            mo.setLspace(Unit.parse(cur.getAttributeValue("lspace", "thickmathspace")));
            mo.setRspace(Unit.parse(cur.getAttributeValue("rspace", "thickmathspace")));
            mo.setMinsize(Unit.parse(cur.getAttributeValue("minsize")));
            mo.setMaxsize(Unit.parse(cur.getAttributeValue("maxsize")));
        }
        output = mo;
        break;

    // numbers
    case "mn":
        Mn mn = new Mn();
        mn.setValue(cur.getText());
        output = mn;
        break;

    // identifiers
    case "mi":
        Mi mi = new Mi();
        mi.setValue(cur.getText());
        mathvariant = cur.getAttributeValue("mathvariant");
        if (mathvariant != null && mathvariant.isEmpty() == false) {
            mi.setMathvariant(mathvariant);
            mathvariant = null;
        }
        output = mi;
        break;

    // fractions
    case "mfrac":
        Mfrac mfrac = new Mfrac();
        mfrac.setNumerator(renderElement(cur.getChildren().get(0)));
        mfrac.setDenominator(renderElement(cur.getChildren().get(1)));

        String linethickness = cur.getAttributeValue("linethickness");
        if (linethickness != null) {
            mfrac.setLinethickness(linethickness);
        }

        output = mfrac;
        break;

    // Expression Inside Pair of Fences
    case "mfenced":
        Mfenced mfenced = new Mfenced();
        mfenced.setOpened(cur.getAttributeValue("open"));
        mfenced.setClosed(cur.getAttributeValue("close"));
        mfenced.setSeparators(cur.getAttributeValue("separators"));

        List<Element> children = cur.getChildren();
        if (children.isEmpty() == false) {
            List<FormulaElement> renderedChildren = new ArrayList<>();
            for (Element child : children) {
                FormulaElement renderedChild = renderElement(child);
                renderedChildren.add(renderedChild);
            }
            mfenced.setContent(renderedChildren);
        }
        output = mfenced;
        break;

    // Space
    case "mspace":
        Mspace mspace = new Mspace();

        // Parse attributes
        String widthAttribute = cur.getAttributeValue("width");
        if (widthAttribute != null) {
            mspace.setWidth(Unit.parse(widthAttribute));
        }
        String heightAttribute = cur.getAttributeValue("height");
        if (heightAttribute != null) {
            mspace.setHeight(Unit.parse(heightAttribute));
        }

        // linebreaks will be ignored for now

        output = mspace;
        break;

    // Square root
    case "msqrt":
        Mroot msqrt = new Mroot();
        msqrt.setBase(renderElement(cur.getChildren().get(0)));
        // no index
        output = msqrt;
        break;

    // Root
    case "mroot":
        Mroot mroot = new Mroot();
        mroot.setBase(renderElement(cur.getChildren().get(0)));
        mroot.setDegree(renderElement(cur.getChildren().get(1)));
        output = mroot;
        break;

    // String literal
    case "ms":
        Ms ms = new Ms();
        ms.setValue(cur.getText());
        output = ms;
        break;

    // Text
    case "mtext":
        Mtext mtext = new Mtext();
        mtext.setValue(cur.getText());
        output = mtext;
        break;

    // Style change
    case "mstyle":
        Mstyle mstyle = new Mstyle();

        mathvariant = cur.getAttributeValue("mathvariant");
        if (mathvariant != null && mathvariant.isEmpty() == false) {
            mstyle.setStyle(mathvariant);
            mathvariant = null;
        }

        Iterator<Element> mstyleIterator = cur.getChildren().iterator();
        while (mstyleIterator.hasNext()) {
            mstyle.addBaseElement(renderElement(mstyleIterator.next()));
        }
        output = mstyle;
        break;

    // Overscript
    case "mover":
        Mover mover = new Mover();
        mover.setBase(renderElement(cur.getChildren().get(0)));
        mover.setOverscript(renderElement(cur.getChildren().get(1)));
        output = mover;
        break;

    // Underscript
    case "munder":
        Munder munder = new Munder();
        munder.setBase(renderElement(cur.getChildren().get(0)));
        munder.setUnderscript(renderElement(cur.getChildren().get(1)));
        output = munder;
        break;

    // Matrices & tables
    case "mtable":
        Mtable mtable = new Mtable();
        Iterator<Element> mRowIterator = cur.getChildren().iterator();
        while (mRowIterator.hasNext()) {
            Mtr mtr = (Mtr) renderElement(mRowIterator.next());
            mtable.getRows().add(mtr);
        }
        output = mtable;
        break;

    // Table rows
    case "mtr":
        Mtr mtr = new Mtr();
        Iterator<Element> mCellIterator = cur.getChildren().iterator();
        while (mCellIterator.hasNext()) {
            Mtd mtd = (Mtd) renderElement(mCellIterator.next());
            mtr.getTds().add(mtd);
        }
        output = mtr;
        break;

    // Table cells
    case "mtd":
        Mtd mtd = new Mtd();
        Mrow tdContent = new Mrow();
        Iterator<Element> mContentIterator = cur.getChildren().iterator();
        while (mContentIterator.hasNext()) {
            tdContent.addElement(renderElement(mContentIterator.next()));
        }
        mtd.setContent(tdContent);
        output = mtd;
        break;
    default:
        logger.info("MathML conversion of element <" + cur.getName() + "> NOT YET IMPLEMENTED");
        output = null;
        break;

    }

    return output;
}

From source file:ca.nrc.cadc.vosi.TableReader.java

License:Open Source License

static TableDesc toTable(String schemaName, Element te, Namespace xsi) {
    String tn = te.getChildTextTrim("name");
    TableDesc td = new TableDesc(schemaName, tn);
    List<Element> cols = te.getChildren("column");
    for (Element ce : cols) {
        String cn = ce.getChildTextTrim("name");
        Element dte = ce.getChild("dataType");
        String dtt = dte.getAttributeValue("type", xsi);
        String dtv = dte.getTextTrim();
        if (TAP_TYPE.equals(dtt))
            dtv = "adql:" + dtv;
        else if (VOT_TYPE.equals(dtt))
            dtv = "vot:" + dtv;
        Integer arraysize = null;
        String as = dte.getAttributeValue("size");
        if (as != null)
            arraysize = new Integer(as);
        ColumnDesc cd = new ColumnDesc(tn, cn, dtv, arraysize);
        td.getColumnDescs().add(cd);/*from  w w w. j a v  a 2  s.  co m*/
    }

    List<Element> keys = te.getChildren("foreignKey");
    int i = 1;
    for (Element fk : keys) {
        String keyID = tn + "_key" + i;
        String tt = fk.getChildTextTrim("targetTable");
        KeyDesc kd = new KeyDesc(keyID, tn, tt);
        List<Element> fkcols = fk.getChildren("fkColumn");
        for (Element fkc : fkcols) {
            String fc = fkc.getChildTextTrim("fromColumn");
            String tc = fkc.getChildTextTrim("targetColumn");
            KeyColumnDesc kcd = new KeyColumnDesc(keyID, fc, tc);
            kd.getKeyColumnDescs().add(kcd);
        }
        td.getKeyDescs().add(kd);
    }

    return td;
}

From source file:com.ardor3d.extension.model.collada.jdom.ColladaAnimUtils.java

License:Open Source License

/**
 * Retrieve a name to use for the skin node based on the element names.
 * /*from w  ww. j  a va 2 s. com*/
 * @param ic
 *            instance_controller element.
 * @param controller
 *            controller element
 * @return name.
 * @see SkinData#SkinData(String)
 */
private String getSkinStoreName(final Element ic, final Element controller) {
    final String controllerName = controller.getAttributeValue("name", (String) null) != null
            ? controller.getAttributeValue("name", (String) null)
            : controller.getAttributeValue("id", (String) null);
    final String instanceControllerName = ic.getAttributeValue("name", (String) null) != null
            ? ic.getAttributeValue("name", (String) null)
            : ic.getAttributeValue("sid", (String) null);
    final String storeName = (controllerName != null ? controllerName : "")
            + (controllerName != null && instanceControllerName != null ? " : " : "")
            + (instanceControllerName != null ? instanceControllerName : "");
    return storeName;
}

From source file:com.ardor3d.extension.model.collada.jdom.ColladaMeshUtils.java

License:Open Source License

/**
 * Builds a mesh from a Collada geometry element. Currently supported mesh types: mesh, polygons, polylist,
 * triangles, lines. Not supported yet: linestrips, trifans, tristrips. If no meshtype is found, a pointcloud is
 * built.// www  . j a  v a 2  s  .  c om
 * 
 * @param colladaGeometry
 * @return a Node containing all of the Ardor3D meshes we've parsed from this geometry element.
 */
public Node buildMesh(final Element colladaGeometry) {
    if (colladaGeometry.getChild("mesh") != null) {
        final Element cMesh = colladaGeometry.getChild("mesh");
        final Node meshNode = new Node(colladaGeometry.getAttributeValue("name", colladaGeometry.getName()));

        // Grab all mesh types (polygons, triangles, etc.)
        // Create each as an Ardor3D Mesh, and attach to node
        boolean hasChild = false;
        if (cMesh.getChild("polygons") != null) {
            for (final Element p : cMesh.getChildren("polygons")) {
                final Mesh child = buildMeshPolygons(colladaGeometry, p);
                if (child != null) {
                    if (child.getName() == null) {
                        child.setName(meshNode.getName() + "_polygons");
                    }
                    meshNode.attachChild(child);
                    hasChild = true;
                }
            }
        }
        if (cMesh.getChild("polylist") != null) {
            for (final Element p : cMesh.getChildren("polylist")) {
                final Mesh child = buildMeshPolylist(colladaGeometry, p);
                if (child != null) {
                    if (child.getName() == null) {
                        child.setName(meshNode.getName() + "_polylist");
                    }
                    meshNode.attachChild(child);
                    hasChild = true;
                }
            }
        }
        if (cMesh.getChild("triangles") != null) {
            for (final Element t : cMesh.getChildren("triangles")) {
                final Mesh child = buildMeshTriangles(colladaGeometry, t);
                if (child != null) {
                    if (child.getName() == null) {
                        child.setName(meshNode.getName() + "_triangles");
                    }
                    meshNode.attachChild(child);
                    hasChild = true;
                }
            }
        }
        if (cMesh.getChild("lines") != null) {
            for (final Element l : cMesh.getChildren("lines")) {
                final Line child = buildMeshLines(colladaGeometry, l);
                if (child != null) {
                    if (child.getName() == null) {
                        child.setName(meshNode.getName() + "_lines");
                    }
                    meshNode.attachChild(child);
                    hasChild = true;
                }
            }
        }
        if (cMesh.getChild("linestrips") != null) {
            logger.warning("<linestrips> not currently supported.");
            hasChild = true;
            // TODO: Add support
        }
        if (cMesh.getChild("trifans") != null) {
            logger.warning("<trifan> not currently supported.");
            hasChild = true;
            // TODO: Add support
        }
        if (cMesh.getChild("tristrips") != null) {
            logger.warning("<tristrip> not currently supported.");
            hasChild = true;
            // TODO: Add support
        }

        // If we did not find a valid child, the spec says to add verts as a "cloud of points"
        if (!hasChild) {
            logger.warning("No valid child found, creating 'cloud of points'");
            final Point points = buildPoints(colladaGeometry, cMesh);
            if (points != null) {
                if (points.getName() == null) {
                    points.setName(meshNode.getName() + "_points");
                }
                meshNode.attachChild(points);
            }
        }

        return meshNode;
    }
    return null;
}

From source file:com.ardor3d.extension.model.collada.jdom.ColladaMeshUtils.java

License:Open Source License

private Point buildPoints(final Element colladaGeometry, final Element mesh) {
    if (mesh == null || mesh.getChild("vertices") == null
            || mesh.getChild("vertices").getChild("input") == null) {
        return null;
    }// w ww  . j a  v  a 2 s. c o m
    final Point points = new Point();
    points.setName(mesh.getAttributeValue("name", mesh.getName()));

    // Find POSITION vertices source
    final Element source = _colladaDOMUtil.getPositionSource(mesh.getChild("vertices"));
    if (source == null) {
        return null;
    }

    if (source.getChild("float_array") != null) {
        // Turn into Floatbuffer if we have float array data
        final Element floatArray = source.getChild("float_array");
        if ("0".equals(floatArray.getAttributeValue("count"))) {
            return null;
        }
        final FloatBuffer vertices = BufferUtils.createFloatBuffer(_colladaDOMUtil.parseFloatArray(floatArray));
        // Add to points
        points.getMeshData().setVertexBuffer(vertices);
    } else if (source.getChild("int_array") != null) {
        // Turn into Floatbuffer if we have int array data
        final Element intArray = source.getChild("int_array");
        if ("0".equals(intArray.getAttributeValue("count"))) {
            return null;
        }
        final int[] data = _colladaDOMUtil.parseIntArray(intArray);
        final FloatBuffer vertices = BufferUtils.createFloatBuffer(data.length);
        for (final int i : data) {
            vertices.put(i);
        }
        // Add to points
        points.getMeshData().setVertexBuffer(vertices);
    }

    // Add to vert mapping
    final int[] indices = new int[points.getMeshData().getVertexCount()];
    for (int i = 0; i < indices.length; i++) {
        indices[i] = i;
    }
    final MeshVertPairs mvp = new MeshVertPairs(points, indices);
    _dataCache.getVertMappings().put(colladaGeometry, mvp);

    if (_optimizeMeshes) {
        final VertMap map = _geometryTool.minimizeVerts(points, _optimizeSettings);
        _dataCache.setMeshVertMap(points, map);
    }

    // Update bound
    points.updateModelBound();

    // return
    return points;
}

From source file:com.izforge.izpack.util.xmlmerge.factory.AttributeOperationFactory.java

License:Open Source License

@Override
public Operation getOperation(Element originalElement, Element modifiedElement)
        throws AbstractXmlMergeException {

    if (modifiedElement == null) {
        return m_defaultOperation;
    }/*from ww  w  .j a v a 2  s .  c o m*/

    String operationString = modifiedElement.getAttributeValue(m_keyword, m_namespace);

    if (operationString != null) {
        return m_resolver.resolve(operationString);
    } else {
        return m_defaultOperation;
    }

}

From source file:com.kixeye.scout.eureka.EurekaServiceInstanceDescriptor.java

License:Apache License

/**
 * Creates a descriptor from a parent and a raw element.
 * /*from   w  ww  .jav a 2  s.c  o m*/
 * @param parent
 * @param instanceElement
 */
protected EurekaServiceInstanceDescriptor(EurekaApplication parent, Element instanceElement) {
    this.parent = parent;

    this.app = instanceElement.getChildText("app");
    this.ipAddress = instanceElement.getChildText("ipAddr");
    this.hostname = instanceElement.getChildText("hostName");
    this.vipAddress = instanceElement.getChildText("vipAddress");

    int lastUpdatedTimestampRaw;
    try {
        lastUpdatedTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastUpdatedTimestamp"));
    } catch (Exception e) {
        lastUpdatedTimestampRaw = -11;
    }

    this.lastUpdatedTimestamp = lastUpdatedTimestampRaw;

    int lastDirtyTimestampRaw;
    try {
        lastDirtyTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastDirtyTimestamp"));
    } catch (Exception e) {
        lastDirtyTimestampRaw = -11;
    }

    this.lastDirtyTimestamp = lastDirtyTimestampRaw;

    Element port = instanceElement.getChild("port");

    if (port != null) {
        this.isPortEnabled = Boolean.valueOf(port.getAttributeValue("enabled", "true"));
        this.port = Integer.valueOf(port.getTextTrim());
    } else {
        this.isPortEnabled = false;
        this.port = -1;
    }

    Element securePort = instanceElement.getChild("securePort");

    if (securePort != null) {
        this.isSecurePortEnabled = Boolean.valueOf(securePort.getAttributeValue("enabled", "true"));
        this.securePort = Integer.valueOf(securePort.getTextTrim());
    } else {
        this.isSecurePortEnabled = false;
        this.securePort = -1;
    }

    Element statusElement = instanceElement.getChild("status");
    ServiceStatus status = null;

    if (statusElement != null) {
        switch (statusElement.getTextTrim()) {
        case "UP":
            status = ServiceStatus.UP;
            break;
        case "DOWN":
            status = ServiceStatus.DOWN;
            break;
        default:
            status = ServiceStatus.UNKNOWN;
        }
    }

    this.status = status;

    Element overridenStatusElement = instanceElement.getChild("overriddenstatus");
    ServiceStatus overridenStatus = null;

    if (overridenStatusElement != null) {
        switch (overridenStatusElement.getTextTrim()) {
        case "UP":
            overridenStatus = ServiceStatus.UP;
            break;
        case "DOWN":
            overridenStatus = ServiceStatus.DOWN;
            break;
        default:
            overridenStatus = ServiceStatus.UNKNOWN;
        }
    }

    this.overridenStatus = overridenStatus;

    Element metadata = instanceElement.getChild("metadata");

    if (metadata != null) {
        for (Element element : metadata.getChildren()) {
            this.metadata.put(element.getName(), element.getText());
        }
    }

    Element dataCenterInfo = instanceElement.getChild("dataCenterInfo");

    if (dataCenterInfo != null) {
        Attribute dataCenterInfoClass = instanceElement.getAttribute("class");

        if (dataCenterInfoClass != null && dataCenterInfoClass.getValue() != null) {
            switch (dataCenterInfoClass.getValue()) {
            case EurekaServiceAmazonDataCenterInfo.DATA_CENTER_INFO_CLASS:
                this.dataCenterInfo = new EurekaServiceAmazonDataCenterInfo(this, dataCenterInfo);
                break;
            default:
                this.dataCenterInfo = null;
            }
        } else {
            this.dataCenterInfo = null;
        }
    } else {
        this.dataCenterInfo = null;
    }
}

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   ww  w . j a v a 2s  . c  o  m
                    customProperties.put(customName, custom);
                }
                break;
            default:
                LoggerFactory.getLogger(MessagingProperties.class).warn("Unknown Message Property:{}",
                        propName);
                break;
            }
        }
    }
}

From source file:com.rometools.modules.cc.io.ModuleParserRSS1.java

License:Open Source License

@Override
public Module parse(final Element element, final Locale locale) {
    final CreativeCommonsImpl module = new CreativeCommonsImpl();
    {/*www.j a v  a  2 s  . c o m*/
        // Parsing Channel level.
        Element root = element;
        while (root.getParentElement() != null) {
            root = root.getParentElement();
        }
        final List<Element> licenseList = root.getChildren("License", NS);
        final ArrayList<License> licenses = new ArrayList<License>();
        final Iterator<Element> it = licenseList.iterator();
        while (it.hasNext()) {
            final Element licenseTag = it.next();
            final String licenseURI = licenseTag.getAttributeValue("about", RDF);
            if (licenseURI == null) {
                continue;
            }
            License license = License.findByValue(licenseURI);
            {
                final ArrayList<Behaviour> permitsValues = new ArrayList<Behaviour>();
                final ArrayList<Behaviour> requiresValues = new ArrayList<Behaviour>();
                final List<Element> permitsTags = licenseTag.getChildren("permits", NS);
                Iterator<Element> sit = permitsTags.iterator();
                while (sit.hasNext()) {
                    final Element permitTag = sit.next();
                    permitsValues
                            .add(License.Behaviour.findByValue(permitTag.getAttributeValue("resource", RDF)));
                }
                final List<Element> requiresTags = licenseTag.getChildren("requires", NS);
                sit = requiresTags.iterator();
                while (sit.hasNext()) {
                    final Element requireTag = sit.next();
                    requiresValues
                            .add(License.Behaviour.findByValue(requireTag.getAttributeValue("resource", RDF)));
                }
                license = new License(licenseURI,
                        requiresValues.toArray(new License.Behaviour[requiresValues.size()]),
                        permitsValues.toArray(new License.Behaviour[permitsValues.size()]));

            }

            licenses.add(license);
        }
        module.setAllLicenses(licenses.toArray(new License[0]));
    }
    final ArrayList<License> licenses = new ArrayList<License>();
    final List<Element> licenseTags = element.getChildren("license", NS);
    final Iterator<Element> lit = licenseTags.iterator();
    while (lit.hasNext()) {
        final Element licenseTag = lit.next();
        licenses.add(License.findByValue(licenseTag.getAttributeValue("resource", RDF)));
    }

    if (!licenses.isEmpty()) {
        module.setLicenses(licenses.toArray(new License[licenses.size()]));
    }

    if (module.getLicenses() != null || module.getAllLicenses() != null) {
        return module;
    } else {
        return null;
    }
}

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;//from   w  ww  .  j ava2s .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;
}