Example usage for org.jdom2 Element Element

List of usage examples for org.jdom2 Element Element

Introduction

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

Prototype

public Element(final String name) 

Source Link

Document

Create a new element with the supplied (local) name and no namespace.

Usage

From source file:br.ufrgs.inf.dsmoura.repository.controller.util.XMLUtil.java

private static List<Element> fromArtifactsToElements(List<? extends Artifactable> artifacts,
        String referencePath) {/*from www  .  jav a 2 s .  c  om*/
    List<Element> elements = new ArrayList<Element>();
    for (Artifactable artifactable : artifacts) {
        Element element = null;

        /* element name */
        if (artifactable instanceof ArtifactDTO) {
            element = new Element(ArtifactType.GENERAL.getXmlName());
        } else if (artifactable instanceof FunctionalRequirementDTO) {
            element = new Element(ArtifactType.FUNCTIONAL_REQ.getXmlName());
        } else if (artifactable instanceof NonFunctionalRequirementDTO) {
            element = new Element(ArtifactType.NON_FUNCTIONAL_REQ.getXmlName());
        } else if (artifactable instanceof SourceCodeDTO) {
            element = new Element(ArtifactType.SOURCE_CODE.getXmlName());
        } else if (artifactable instanceof UserInterfaceDTO) {
            element = new Element(ArtifactType.USER_INTERFACE.getXmlName());
        } else if (artifactable instanceof UseCaseDTO) {
            element = new Element(ArtifactType.USE_CASE.getXmlName());
        } else if (artifactable instanceof WsdlDTO) {
            element = new Element(ArtifactType.WSDL.getXmlName());
        } else {
            throw new IllegalArgumentException(
                    "Class type of artifact unrecognized: " + artifactable.getClass());
        }

        /* id and name */
        element.setAttribute("id", artifactable.getId());
        element.setAttribute("name", artifactable.getName());

        Element description = new Element("description");
        description.addContent(artifactable.getDescription());
        element.addContent(description);

        /* artifact types */
        if (artifactable instanceof ArtifactDTO || artifactable instanceof UseCaseDTO
                || artifactable instanceof WsdlDTO) {
            //nothing
        } else if (artifactable instanceof FunctionalRequirementDTO) {
            if (((FunctionalRequirementDTO) artifactable).getFunctionalRequirementTypeDTO() != null) {
                element.setAttribute("functional_requirement_type",
                        ((FunctionalRequirementDTO) artifactable).getFunctionalRequirementTypeDTO().getName());
            }
        } else if (artifactable instanceof NonFunctionalRequirementDTO) {
            if (((NonFunctionalRequirementDTO) artifactable).getNonFunctionalRequirementTypeDTO() != null) {
                element.setAttribute("non_functional_requirement_type",
                        ((NonFunctionalRequirementDTO) artifactable).getNonFunctionalRequirementTypeDTO()
                                .getName());
            }
        } else if (artifactable instanceof SourceCodeDTO) {
            if (((SourceCodeDTO) artifactable).getSourceCodeTypeDTO() != null) {
                element.setAttribute("source_code_type",
                        ((SourceCodeDTO) artifactable).getSourceCodeTypeDTO().getName());
            }
        } else if (artifactable instanceof UserInterfaceDTO) {
            if (((UserInterfaceDTO) artifactable).getUserInterfaceTypeDTO() != null) {
                element.setAttribute("user_interface_type",
                        ((UserInterfaceDTO) artifactable).getUserInterfaceTypeDTO().getName());
            }
        } else {
            throw new IllegalArgumentException(
                    "Class type of artifact unrecognized: " + artifactable.getClass());
        }

        /* software license */
        if (artifactable.getSoftwareLicenseDTO() != null) {
            element.setAttribute("software_license", artifactable.getSoftwareLicenseDTO().getName());
        }

        /* reference */
        if (artifactable.getFile() == null) {
            element.setAttribute("reference", artifactable.getReference());
        } else {
            element.setAttribute("reference", referencePath + "\\" + artifactable.getName());
        }

        /* artifact dependency */
        for (ArtifactDependencyDTO artifactDependencyDTO : artifactable.getArtifactDependencyDTOs()) {
            Element artifactDependency = new Element("artifact_dependency");
            artifactDependency.setAttribute("artifact_id", artifactDependencyDTO.getArtifactID());
            if (artifactDependencyDTO.getArtifactDependencyTypeDTO() != null) {
                artifactDependency.setAttribute("artifact_dependency_type",
                        artifactDependencyDTO.getArtifactDependencyTypeDTO().getName());
            }
            element.addContent(artifactDependency);
        }

        elements.add(element);
    }
    return elements;
}

From source file:broadwick.graph.writer.GraphMl.java

License:Apache License

/**
 * Add an edge to the graphML document./*from w w  w.j ava 2  s . co m*/
 * @param edge    the edge to be added to the graph element.
 * @param element the graph element of the graphML document
 */
private static void addEdge(final Edge edge, final Element element) {

    final String id = edge.getId();

    final String source = edge.getSource().getId();
    final String target = edge.getDestination().getId();

    final Element elem = new Element("edge");
    elem.setAttribute("id", "e" + id);
    elem.setAttribute("source", source);
    elem.setAttribute("target", target);

    for (final Iterator it = edge.getAttributes().iterator(); it.hasNext();) {
        final EdgeAttribute attr = (EdgeAttribute) it.next();
        final Element data = new Element("data");
        data.setAttribute("key", attr.getName());
        data.setText(attr.getValue());
        elem.addContent(data);
    }

    element.addContent(elem);
}

From source file:broadwick.graph.writer.GraphMl.java

License:Apache License

/**
 * Add a node to the graphML document.// w  ww .  ja  va 2 s.c  om
 * @param vertex  the id of the node.
 * @param element the graph element of the graphML document.
 */
private static void addNode(final Vertex vertex, final Element element) {
    final Element node = new Element("node");
    node.setAttribute("id", vertex.getId());

    for (VertexAttribute attr : vertex.getAttributes()) {
        final Element data = new Element("data");
        data.setAttribute("key", attr.getName());
        data.setText(attr.getValue().toString());
        node.addContent(data);
    }

    element.addContent(node);
}

From source file:ca.mcgill.cs.swevo.jayfx.model.AbstractElement.java

License:Open Source License

@Override
public Element getXML() {
    Element ret = new Element(IElement.class.getSimpleName());
    ret.setAttribute(new Attribute(IElement.ID, this.getId()));
    ret.addContent(this.getCategory().getXML());
    return ret;/*from   ww  w.  j  a  va2  s  .co m*/
}

From source file:ca.mcgill.cs.swevo.jayfx.model.Category.java

License:Open Source License

public Element getXML() {
    Element ret = new Element(this.getClass().getSimpleName());
    ret.setAttribute(TYPE, this.toString());
    return ret;//from  w  w  w  .  j a  va 2s  . c om
}

From source file:ca.mcgill.cs.swevo.jayfx.model.Relation.java

License:Open Source License

/**
 * @return/* w ww. ja v  a2s.c  om*/
 */
public Element getXML() {
    Element ret = new Element(this.getClass().getSimpleName());
    ret.setAttribute(TYPE, this.toString());
    return ret;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a JDOM element from a User object.
 *
 * @param user The User./*w ww .j  a  v a 2  s.c  o  m*/
 * @return A JDOM User representation.
 * @throws WriterException
 */
protected final Element getElement(User user) throws WriterException {
    if (user == null) {
        throw new WriterException("null User");
    }

    // Create the user Element.
    Element userElement = new Element(USER);

    // internalID element
    if (user.getID() != null) {
        userElement.addContent(getElement(user.getID()));
    }

    // identities
    Set<Principal> identities = user.getIdentities();
    if (!identities.isEmpty()) // includes alternate identities
    {
        Element identitiesElement = new Element(IDENTITIES);
        for (Principal identity : identities) {
            identitiesElement.addContent(getElement(identity));
        }
        userElement.addContent(identitiesElement);
    }

    // personalDetails
    if (user.personalDetails != null) {
        userElement.addContent(getElement(user.personalDetails));
    }

    // posixDetails
    if (user.posixDetails != null) {
        userElement.addContent(getElement(user.posixDetails));
    }

    return userElement;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a JDOM element from a UserRequest object.
 *
 * @param userRequest The UserRequest./*www  .  ja v a 2s .co  m*/
 * @return A JDOM UserRequest representation.
 * @throws WriterException
 */
protected final Element getElement(UserRequest userRequest) throws WriterException {
    if (userRequest == null) {
        throw new WriterException("null UserRequest");
    }

    // Create the userRequest Element.
    Element userRequestElement = new Element(USER_REQUEST);

    // user element
    Element userElement = getElement(userRequest.getUser());
    userRequestElement.addContent(userElement);

    // password element
    Element passwordElement = new Element(PASSWORD);
    passwordElement.setText(String.valueOf(userRequest.getPassword()));
    userRequestElement.addContent(passwordElement);

    return userRequestElement;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a JDOM element from a InternalID object.
 *
 * @param internalID The InternalID./*  w  w w.jav  a 2  s .c o  m*/
 * @return A JDOM InternalID representation.
 * @throws WriterException
 */
protected final Element getElement(InternalID internalID) throws WriterException {
    if (internalID == null) {
        throw new WriterException("null InternalID");
    }

    // Create the internalID Element.
    Element internalIDElement = new Element(INTERNAL_ID);

    // uri element
    Element uriElement = new Element(URI);
    uriElement.addContent(internalID.getURI().toString());
    internalIDElement.addContent(uriElement);

    return internalIDElement;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a JDOM element from a Principal object.
 *
 * @param identity The Principal.//  www  .  j av a 2s . c  om
 * @return A JDOM UserDetails representation.
 * @throws WriterException
 */
protected final Element getElement(Principal identity) throws WriterException {
    if (identity == null) {
        String error = "null Principal";
        throw new WriterException(error);
    }

    Element identityElement = new Element(IDENTITY);
    if ((identity instanceof HttpPrincipal)) {
        identityElement.setAttribute(TYPE, IdentityType.USERNAME.getValue());
    } else if ((identity instanceof NumericPrincipal)) {
        identityElement.setAttribute(TYPE, IdentityType.CADC.getValue());
    } else if ((identity instanceof OpenIdPrincipal)) {
        identityElement.setAttribute(TYPE, IdentityType.OPENID.getValue());
    } else if ((identity instanceof X500Principal)) {
        identityElement.setAttribute(TYPE, IdentityType.X500.getValue());
    } else if ((identity instanceof DNPrincipal)) {
        identityElement.setAttribute(TYPE, IdentityType.ENTRY_DN.getValue());
    } else {
        String error = "Unsupported Principal type " + identity.getClass().getSimpleName();
        throw new IllegalArgumentException(error);
    }
    identityElement.setText(identity.getName());

    return identityElement;
}