Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:com.init.octo.schema.XSDSequence.java

License:Open Source License

/**
 * This method builds a sequence element
 *
 * @param    root - the sequence element that defines this element
 * @param    cache - a list of pre-defined XML types
 *///  w w w . j  a  va  2  s . c o m
public boolean build(Element root, XSDCache cache, String parentName) {

    log.debug("" + indent + ": " + "Build representation of a sequence");

    id = root.getAttributeValue(XSDSchema.ID_ATT);
    maxOccurs = root.getAttributeValue(XSDSchema.MAXOCCURS_ATT);
    minOccurs = root.getAttributeValue(XSDSchema.MINOCCURS_ATT);

    group = new LinkedList<XMLType>();

    Element element;
    String elementName;

    for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) {

        element = (Element) i.next();
        elementName = element.getName();

        log.debug("" + indent + ": " + "Child element <" + elementName + "> found");

        /** process the child elements that define this element...   **/

        if (elementName.equals(XSDSchema.ANNOTATION)) {
            annotation = element.getTextTrim();

        } else if (elementName.equals(XSDSchema.ELEMENT)) {
            log.debug("" + indent + ": " + "Adding element to the list of child elements");
            XSDElement e = new XSDElement(indent + 1);
            if (e.build(element, cache, parentName) != true) {
                log.debug("Error building the element");
                return (false);
            }
            group.add(e);
        } else if (elementName.equals(XSDSchema.GROUP)) {
            log.debug("" + indent + ": " + "Adding group to the list of child elements");
            XSDGroupType g = new XSDElementGroup(indent); // child elements will be at the same level

            if (g.build(element, cache, parentName) != true) {
                log.error("Error building a group");
                return (false);
            }

            group.add(g);
        } else if (elementName.equals(XSDSchema.CHOICE)) {

            log.debug("" + indent + ": " + "Adding choice to the list of child elements");

            XSDChoice c = new XSDChoice(indent); // child elements will be at the same level

            if (c.build(element, cache, parentName) != true) {
                log.error("Error building a choice");
                return (false);
            }

            group.add(c);
        } else if (elementName.equals(XSDSchema.SEQUENCE)) {

            log.debug("" + indent + ": " + "Adding sequence to the list of child elements");

            XSDSequence s = new XSDSequence(indent); // child elements will be at the same level

            if (s.build(element, cache, parentName) != true) {
                log.error("Error building a sequence");
                return (false);
            }

            group.add(s);
        } else {
            log.warn("" + indent + ": " + "Unexpected element <" + elementName + "> found and ignored");
        }

    } // end for all child elements of this <sequence> tag

    log.debug("" + indent + ": " + "Sequence built");

    return (true);

}

From source file:com.izforge.izpack.util.xmlmerge.action.DtdInsertAction.java

License:Open Source License

@Override
public void perform(Element originalElement, Element patchElement, Element outputParentElement)
        throws AbstractXmlMergeException {

    Element element;//from   w  ww  . j av  a2  s  . co  m

    if (originalElement != null) {
        element = (Element) originalElement.clone();
    } else {
        element = (Element) patchElement.clone();
    }

    DTD dtd = getDTD(outputParentElement);

    List<DTDElement> dtdElements = dtd.getItemsByType(DTDElement.class);

    // Find the corresponding element
    DTDElement parentDtdElement = null;
    for (DTDElement dtdElement : dtdElements) {
        if (dtdElement.getName().equals(outputParentElement.getName())) {
            parentDtdElement = dtdElement;
        }
    }

    if (parentDtdElement == null) {
        throw new ElementException(element, "Element " + outputParentElement.getName() + " not defined in DTD");
    } else {

        DTDItem item = parentDtdElement.getContent();

        if (item instanceof DTDAny) {
            // the parent element accepts anything in any order
            outputParentElement.addContent(element);
        } else if (item instanceof DTDContainer) {

            // List existing elements in output parent element
            List<Element> existingChildren = outputParentElement.getChildren();

            if (existingChildren.size() == 0) {
                // This is the first child
                outputParentElement.addContent(element);
            } else {

                List<String> orderedDtdElements = getOrderedDtdElements((DTDContainer) item);

                int indexOfNewElementInDtd = orderedDtdElements.indexOf(element.getName());
                logger.fine("index of element " + element.getName() + ": " + indexOfNewElementInDtd);

                int pos = existingChildren.size();

                // Calculate the position in the parent where we insert the
                // element
                for (int i = 0; i < existingChildren.size(); i++) {
                    String elementName = (existingChildren.get(i)).getName();
                    logger.fine(
                            "index of child " + elementName + ": " + orderedDtdElements.indexOf(elementName));
                    if (orderedDtdElements.indexOf(elementName) > indexOfNewElementInDtd) {
                        pos = i;
                        break;
                    }
                }

                logger.fine("adding element " + element.getName() + " add in pos " + pos);
                outputParentElement.addContent(pos, element);

            }

        }

    }

}

From source file:com.izforge.izpack.util.xmlmerge.action.FullMergeAction.java

License:Open Source License

@Override
public void perform(Element originalElement, Element patchElement, Element outputParentElement)
        throws AbstractXmlMergeException {

    logger.fine("Merging: " + originalElement + " (original) and " + patchElement + " (patch)");

    Mapper mapper = (Mapper) m_mapperFactory.getOperation(originalElement, patchElement);

    if (originalElement == null) {
        outputParentElement.addContent(mapper.map(patchElement));
    } else if (patchElement == null) {
        outputParentElement.addContent((Content) originalElement.clone());
    } else {/*w  w w  .j  av a  2  s .c om*/

        Element workingElement = new Element(originalElement.getName(), originalElement.getNamespacePrefix(),
                originalElement.getNamespaceURI());
        addAttributes(workingElement, originalElement);

        logger.fine("Adding " + workingElement);
        outputParentElement.addContent(workingElement);

        doIt(workingElement, originalElement, patchElement);
    }

}

From source file:com.izforge.izpack.util.xmlmerge.action.OrderedMergeAction.java

License:Open Source License

@Override
public void perform(Element originalElement, Element patchElement, Element outputParentElement)
        throws AbstractXmlMergeException {

    logger.fine("Merging: " + originalElement + " (original) and " + patchElement + "(patch)");

    Mapper mapper = (Mapper) m_mapperFactory.getOperation(originalElement, patchElement);

    if (originalElement == null) {
        outputParentElement.addContent(mapper.map(patchElement));
    } else if (patchElement == null) {
        outputParentElement.addContent((Content) originalElement.clone());
    } else {/*from   www . j  ava2  s  . c  o m*/

        Element workingElement = new Element(originalElement.getName(), originalElement.getNamespacePrefix(),
                originalElement.getNamespaceURI());
        addAttributes(workingElement, originalElement);

        logger.fine("Adding " + workingElement);
        outputParentElement.addContent(workingElement);

        doIt(workingElement, originalElement, patchElement);
    }

}

From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java

License:Open Source License

private static void sortRootChildrenRecursive(Element root) {
    sortRootChildrenRecursive(root, new Comparator<Element>() {
        @Override/*  ww w  .j a va  2 s . c o  m*/
        public int compare(Element o1, Element o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
}

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

License:Apache License

/**
 * Creates a descriptor from a parent and a raw element.
 * /*from w w  w.j av a2 s.  c om*/
 * @param parent
 * @param instanceElement
 */
protected EurekaServiceAmazonDataCenterInfo(EurekaServiceInstanceDescriptor parent, Element instanceElement) {
    this.parent = parent;
    this.name = instanceElement.getChildText("name");
    Element metadata = instanceElement.getChild("metadata");

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

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

License:Apache License

/**
 * Creates a descriptor from a parent and a raw element.
 * /*from ww  w  .j av  a2  s.co  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.lapis.jsfexporter.xml.XMLExportType.java

License:Apache License

@Override
public Element exportRow(IExportRow row) {
    Element currentElement = (Element) row.getParentRowId();
    if (currentElement == null) {
        currentElement = rootElement;/* w  w  w .  j a  v  a2s . c om*/
    }

    for (String namePart : row.getName()) {
        Element subElement = new Element(cleanElementName(namePart));
        currentElement.addContent(subElement);
        currentElement = subElement;
    }

    for (IExportCell cell : row.getCells()) {
        Element cellElement = currentElement;
        for (String namePart : cell.getName()) {
            Element subElement = cellElement.getChild(namePart);
            if (subElement == null) {
                subElement = new Element(cleanElementName(namePart));
                cellElement.addContent(subElement);
            }
            cellElement = subElement;
        }

        if (!cellElement.getText().equals("")) {
            String cellName = cellElement.getName();
            cellElement = cellElement.getParentElement();
            Element newCellElement = new Element(cellName);
            cellElement.addContent(newCellElement);
            cellElement = newCellElement;
        }
        cellElement.setText(cell.getValue());
    }

    return currentElement;
}

From source file:com.ohnosequences.xml.model.Annotation.java

License:Open Source License

public Annotation(Element elem) throws XMLElementException {
    super(elem);/* www .j av  a2s .com*/
    if (!elem.getName().equals(TAG_NAME)) {
        throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem));
    }
}

From source file:com.ohnosequences.xml.model.bio4j.Bio4jNodeIndexXML.java

License:Open Source License

public Bio4jNodeIndexXML(Element elem) throws XMLElementException {
    super(elem);//from   ww  w  .  j  a v a  2 s. c om
    if (!elem.getName().equals(TAG_NAME)) {
        throw new XMLElementException(XMLElementException.WRONG_TAG_NAME, new XMLElement(elem));
    }
}