List of usage examples for org.jdom2 Element setAttribute
public Element setAttribute(final String name, final String value)
This sets an attribute value for this element.
From source file:br.ufrgs.inf.dsmoura.repository.controller.util.XMLUtil.java
public static InputStream fromAssetToRassetXML(Asset asset) { // Order by RAS: // 1. profile // 2. description // 3. classification // 4. solution // 5. usage//from w w w. java 2 s .c o m // 6. relatedAsset /* GENERAL */ Element ecp = new Element("Asset"); ecp.setAttribute("name", asset.getName()); ecp.setAttribute("id", asset.getId()); if (asset.getType() != null) { ecp.setAttribute("type", asset.getType().getName()); if (FieldsUtil.isValidType(asset.getType()) && asset.getType().getName().equalsIgnoreCase("Other")) { ecp.setAttribute("other_type", asset.getOtherType()); } } if (asset.getState() != null) { ecp.setAttribute("state", asset.getState().getName()); } if (asset.getSoftwareLicenseDTO() != null) { ecp.setAttribute("software_license", asset.getSoftwareLicenseDTO().getName()); if (FieldsUtil.isValidSoftwareLicense(asset.getSoftwareLicenseDTO()) && asset.getSoftwareLicenseDTO().getName().equalsIgnoreCase("Other")) { ecp.setAttribute("other_software_license", asset.getOtherSoftwareLicense()); } } ecp.setAttribute("version", asset.getVersion()); ecp.setAttribute("date", asset.getStrDate()); ecp.setAttribute("creation_date", asset.getStrCreationDate()); ecp.setAttribute("access_rights", asset.getAccessRights()); ecp.setAttribute("short_description", asset.getShortDescription()); Element description = new Element("description"); description.addContent(asset.getDescription()); ecp.addContent(description); /* CLASSIFICATION */ Element classification = new Element("classification"); ecp.addContent(classification); /* Application Domains */ for (ApplicationSubdomain as : asset.getClassification().getApplicationSubdomains()) { Element applicationSubdomain = new Element("application_subdomain"); applicationSubdomain.setAttribute("name", as.getName()); Element applicationDomain = new Element("application_domain"); applicationDomain.setAttribute("name", as.getApplicationDomain().getName()); if (FieldsUtil.isValidApplicationSubdomain(as) && as.getName().equalsIgnoreCase("Other")) { applicationDomain.setAttribute("name", asset.getClassification().getOtherApplicationDomain()); applicationSubdomain.setAttribute("name", asset.getClassification().getOtherApplicationSubdomain()); } applicationSubdomain.addContent(applicationDomain); classification.addContent(applicationSubdomain); } /* Projects */ for (ProjectDTO proj : asset.getClassification().getProjectDTOs()) { Element project = new Element("project"); project.setAttribute("name", proj.getName()); classification.addContent(project); Element organization = new Element("organization"); organization.setAttribute("name", proj.getOrganizationDTO().getName()); project.addContent(organization); } /* Tags */ for (TagDTO t : asset.getClassification().getTagDTOs()) { Element tag = new Element("tag"); tag.setAttribute("name", t.getName()); classification.addContent(tag); } /* Group Descriptors */ for (DescriptorGroupDTO groupDTO : asset.getClassification().getDescriptorGroupDTOs()) { Element group = new Element("descriptor_group"); group.setAttribute("name", groupDTO.getName()); classification.addContent(group); /* Descriptors */ for (FreeFormDescriptorDTO descriptorDTO : groupDTO.getFreeFormDescriptorDTOs()) { Element descriptor = new Element("free_form_escriptor"); descriptor.setAttribute("name", descriptorDTO.getName()); descriptor.setAttribute("value", descriptorDTO.getFreeFormValue()); group.addContent(descriptor); } } /* SOLUTION */ Element solution = new Element("solution"); ecp.addContent(solution); /* EFFORT */ Element effort = new Element("effort"); solution.addContent(effort); if (asset.getEffortDTO().getEstimatedTime() != null) { effort.setAttribute("estimated_time", asset.getEffortDTO().getEstimatedTime().toString()); } if (asset.getEffortDTO().getRealTime() != null) { effort.setAttribute("real_time", asset.getEffortDTO().getRealTime().toString()); } if (asset.getEffortDTO().getMonetary() != null) { effort.setAttribute("monetary", asset.getEffortDTO().getMonetary().toString()); } if (asset.getEffortDTO().getTeamMembers() != null) { effort.setAttribute("team_members", asset.getEffortDTO().getTeamMembers().toString()); } if (asset.getEffortDTO().getLinesOfCode() != null) { effort.setAttribute("linesOfCode", asset.getEffortDTO().getLinesOfCode().toString()); } /* REQUIREMENTS */ Element requirements = new Element("requirements"); solution.addContent(requirements); requirements.addContent( fromArtifactsToElements(asset.getSolution().getRequirements().getFunctionalRequirementDTOs(), RequirementsMB.FUNCTIONAL_REQ_REFERENCE_PATH)); requirements.addContent(fromArtifactsToElements(asset.getSolution().getRequirements().getUseCaseDTOs(), RequirementsMB.USE_CASE_REFERENCE_PATH)); requirements .addContent(fromArtifactsToElements(asset.getSolution().getRequirements().getUserInterfaceDTOs(), RequirementsMB.USER_INTERFACE_REFERENCE_PATH)); requirements.addContent( fromArtifactsToElements(asset.getSolution().getRequirements().getNonFunctionalRequirementDTOs(), RequirementsMB.NON_FUNCTIONAL_REQ_REFERENCE_PATH)); /* Internationalization */ for (InternationalizationTypeDTO i : asset.getSolution().getRequirements() .getInternationalizationTypeDTOs()) { Element internat = new Element("language"); internat.setAttribute("name", i.getName()); requirements.addContent(internat); } /* Operational Systems */ for (OperationalSystemTypeDTO o : asset.getSolution().getRequirements().getOperationalSystemTypeDTOs()) { Element operSyst = new Element("operational_system"); operSyst.setAttribute("name", o.getName()); requirements.addContent(operSyst); } /* ANALYSIS */ Element analysis = new Element("analysis"); solution.addContent(analysis); /* Interface Specs */ for (InterfaceSpecDTO intSpecDTO : asset.getSolution().getAnalysis().getInterfaceSpecDTOs()) { Element interfaceSpec = new Element("interface_spec"); if (intSpecDTO.getDescription() != null) { interfaceSpec.setAttribute("description", intSpecDTO.getDescription()); } interfaceSpec.setAttribute("name", intSpecDTO.getName()); analysis.addContent(interfaceSpec); /* Descriptors */ for (OperationDTO operationDTO : intSpecDTO.getOperationDTOs()) { Element operation = new Element("operation"); operation.setAttribute("name", operationDTO.getName()); operation.setAttribute("initiates_transaction", operationDTO.getInitiatesTransaction().toString()); if (operationDTO.getDescription() != null) { operation.setAttribute("description", operationDTO.getDescription()); } interfaceSpec.addContent(operation); } } /* Use Case */ analysis.addContent(fromArtifactsToElements(asset.getSolution().getAnalysis().getUseCaseDTOs(), AnalysisMB.USE_CASE_REFERENCE_PATH)); /* User Interfaces */ analysis.addContent(fromArtifactsToElements(asset.getSolution().getAnalysis().getUserInterfaceDTOs(), AnalysisMB.USER_INTERFACE_REFERENCE_PATH)); /* General Artifacts */ analysis.addContent(fromArtifactsToElements(asset.getSolution().getAnalysis().getArtifactDTOs(), AnalysisMB.GENERAL_ARTIFACT_REFERENCE_PATH)); /* DESIGN */ Element design = new Element("design"); solution.addContent(design); /* Interface Specs */ for (InterfaceSpecDTO intSpecDTO : asset.getSolution().getDesign().getInterfaceSpecDTOs()) { Element interfaceSpec = new Element("interface_spec"); interfaceSpec.setAttribute("name", intSpecDTO.getName()); if (intSpecDTO.getDescription() != null) { interfaceSpec.setAttribute("description", intSpecDTO.getDescription()); } design.addContent(interfaceSpec); /* Descriptors */ for (OperationDTO operationDTO : intSpecDTO.getOperationDTOs()) { Element operation = new Element("operation"); operation.setAttribute("name", operationDTO.getName()); operation.setAttribute("initiates_transaction", operationDTO.getInitiatesTransaction().toString()); if (operationDTO.getDescription() != null) { operation.setAttribute("description", operationDTO.getDescription()); } interfaceSpec.addContent(operation); } } /* Design Patterns */ for (DesignPatternDTO dp : asset.getSolution().getDesign().getDesignPatternDTOs()) { Element designPat = new Element("design_pattern"); designPat.setAttribute("name", dp.getName()); design.addContent(designPat); } /* User Interfaces */ design.addContent(fromArtifactsToElements(asset.getSolution().getDesign().getUserInterfaceDTOs(), DesignMB.USER_INTERFACE_REFERENCE_PATH)); /* General Artifacts */ design.addContent(fromArtifactsToElements(asset.getSolution().getDesign().getArtifactDTOs(), DesignMB.GENERAL_ARTIFACT_REFERENCE_PATH)); /* IMPLEMENTATION */ Element implementation = new Element("implementation"); solution.addContent(implementation); /* Programming Languages */ for (ProgrammingLanguageDTO pl : asset.getSolution().getImplementation().getProgrammingLanguageDTOs()) { Element progLang = new Element("programming_language"); progLang.setAttribute("name", pl.getName()); if (FieldsUtil.isValidProgrammingLanguage(pl) && pl.getName().equalsIgnoreCase("Other")) { progLang.setAttribute("other_name", asset.getSolution().getImplementation().getOtherProgrammingLanguage()); } implementation.addContent(progLang); } /* Design Patterns */ for (DesignPatternDTO dp : asset.getSolution().getImplementation().getDesignPatternDTOs()) { Element designPat = new Element("design_pattern"); designPat.setAttribute("name", dp.getName()); implementation.addContent(designPat); } /* Source Codes */ implementation .addContent(fromArtifactsToElements(asset.getSolution().getImplementation().getSourceCodeDTOs(), ImplementationMB.SOURCE_CODE_REFERENCE_PATH)); /* User Interfaces */ implementation .addContent(fromArtifactsToElements(asset.getSolution().getImplementation().getUserInterfaceDTOs(), ImplementationMB.USER_INTERFACE_REFERENCE_PATH)); /* WSDL */ implementation.addContent(fromArtifactsToElements(asset.getSolution().getImplementation().getWsdlDTOs(), ImplementationMB.WSDL_REFERENCE_PATH)); /* General Artifacts */ implementation.addContent(fromArtifactsToElements(asset.getSolution().getImplementation().getArtifactDTOs(), ImplementationMB.GENERAL_ARTIFACT_REFERENCE_PATH)); /* TEST */ Element test = new Element("test"); solution.addContent(test); /* Test Type */ for (TestTypeDTO tt : asset.getSolution().getTest().getTestTypeDTOs()) { Element testMethod = new Element("test_type"); testMethod.setAttribute("name", tt.getName()); test.addContent(testMethod); } /* Test Method Type */ for (TestMethodTypeDTO tmt : asset.getSolution().getTest().getTestMethodTypeDTOs()) { Element testMethod = new Element("test_method_type"); testMethod.setAttribute("name", tmt.getName()); test.addContent(testMethod); } /* Programming Languages */ for (ProgrammingLanguageDTO pl : asset.getSolution().getTest().getProgrammingLanguageDTOs()) { Element progLang = new Element("programming_language"); progLang.setAttribute("name", pl.getName()); if (FieldsUtil.isValidProgrammingLanguage(pl) && pl.getName().equalsIgnoreCase("Other")) { progLang.setAttribute("other_name", asset.getSolution().getTest().getOtherProgrammingLanguage()); } test.addContent(progLang); } /* Design Patterns */ for (DesignPatternDTO dp : asset.getSolution().getTest().getDesignPatternDTOs()) { Element designPat = new Element("design_pattern"); designPat.setAttribute("name", dp.getName()); test.addContent(designPat); } /* Source Codes */ test.addContent(fromArtifactsToElements(asset.getSolution().getTest().getSourceCodeDTOs(), TestMB.SOURCE_CODE_REFERENCE_PATH)); /* General Artifacts */ test.addContent(fromArtifactsToElements(asset.getSolution().getTest().getArtifactDTOs(), TestMB.GENERAL_ARTIFACT_REFERENCE_PATH)); /* USAGE */ Element usage = new Element("usage"); ecp.addContent(usage); Element usageDescription = new Element("description"); usageDescription.addContent(asset.getUsage().getDescription()); usage.addContent(usageDescription); usage.addContent(fromArtifactsToElements(asset.getUsage().getArtifactDTOs(), UsageMB.GENERAL_ARTIFACT_REFERENCE_PATH)); /* Author User */ Element author = new Element("author"); author.setAttribute("username", asset.getUsage().getAuthorUserDTO().getUsername()); author.setAttribute("name", asset.getUsage().getAuthorUserDTO().getName()); usage.addContent(author); usage.setAttribute("authorship_date", asset.getUsage().getStrAuthorshipDate()); usage.setAttribute("creator_name", asset.getUsage().getCreatorUsername()); /* Certifier User */ if (asset.getUsage().getCertifierUserDTO() != null) { Element certifier = new Element("certifier"); certifier.setAttribute("username", asset.getUsage().getCertifierUserDTO().getUsername()); certifier.setAttribute("name", asset.getUsage().getCertifierUserDTO().getName()); usage.addContent(certifier); } if (asset.getUsage().getCertificationDate() != null) { usage.setAttribute("certification_date", asset.getUsage().getStrCertificationDate()); } /* Feedbacks */ for (FeedbackDTO feedbackDTO : asset.getFeedbackDTOs()) { if (feedbackDTO.getHasFeedback()) { Element feedback = new Element("feedback"); feedback.setAttribute("date", feedbackDTO.getStrDate()); feedback.setAttribute("comment", feedbackDTO.getComment()); /* Feedback User */ Element user = new Element("feedback_user"); user.setAttribute("username", feedbackDTO.getFeedbackUserDTO().getUsername()); user.setAttribute("name", feedbackDTO.getFeedbackUserDTO().getName()); feedback.addContent(user); /* Scores */ feedback.setAttribute("general_score", feedbackDTO.getGeneralScore().toString()); Element qualityInUse = new Element("quality_in_use"); if (feedbackDTO.getQualityInUseDTO().getContextCoverageScore() != null) { qualityInUse.setAttribute("context_coverage_score", feedbackDTO.getQualityInUseDTO().getContextCoverageScore().toString()); } if (feedbackDTO.getQualityInUseDTO().getEfficiencyScore() != null) { qualityInUse.setAttribute("efficiency_score", feedbackDTO.getQualityInUseDTO().getEfficiencyScore().toString()); } if (feedbackDTO.getQualityInUseDTO().getEffectivenessScore() != null) { qualityInUse.setAttribute("effectiveness_score", feedbackDTO.getQualityInUseDTO().getEffectivenessScore().toString()); } if (feedbackDTO.getQualityInUseDTO().getSafetyScore() != null) { qualityInUse.setAttribute("safety_score", feedbackDTO.getQualityInUseDTO().getSafetyScore().toString()); } if (feedbackDTO.getQualityInUseDTO().getSatisfactionScore() != null) { qualityInUse.setAttribute("satisfaction_score", feedbackDTO.getQualityInUseDTO().getSatisfactionScore().toString()); } feedback.addContent(qualityInUse); Element softProdQuality = new Element("software_product_quality"); if (feedbackDTO.getSoftwareProductQualityDTO().getCompatibilityScore() != null) { softProdQuality.setAttribute("compatibility_score", feedbackDTO.getSoftwareProductQualityDTO().getCompatibilityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getFunctionalSuitabilityScore() != null) { softProdQuality.setAttribute("functional_suitability_score", feedbackDTO.getSoftwareProductQualityDTO().getFunctionalSuitabilityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getMaintainabilityScore() != null) { softProdQuality.setAttribute("maintainability_score", feedbackDTO.getSoftwareProductQualityDTO().getMaintainabilityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getPerformanceEfficiencyScore() != null) { softProdQuality.setAttribute("performance_efficiency_score", feedbackDTO.getSoftwareProductQualityDTO().getPerformanceEfficiencyScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getPortabilityScore() != null) { softProdQuality.setAttribute("portability_score", feedbackDTO.getSoftwareProductQualityDTO().getPortabilityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getReliabilityScore() != null) { softProdQuality.setAttribute("reliability_score", feedbackDTO.getSoftwareProductQualityDTO().getReliabilityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getSecurityScore() != null) { softProdQuality.setAttribute("security_score", feedbackDTO.getSoftwareProductQualityDTO().getSecurityScore().toString()); } if (feedbackDTO.getSoftwareProductQualityDTO().getUsabilityScore() != null) { softProdQuality.setAttribute("usability_score", feedbackDTO.getSoftwareProductQualityDTO().getUsabilityScore().toString()); } feedback.addContent(softProdQuality); usage.addContent(feedback); } } /* Adjustments */ for (AdjustmentDTO adjustmentDTO : asset.getUsage().getAdjustmentDTOs()) { Element adjustment = new Element("adjustment"); adjustment.setAttribute("date", adjustmentDTO.getStrDate()); Element user = new Element("adjuster_user"); user.setAttribute("username", adjustmentDTO.getAdjusterUserDTO().getUsername()); user.setAttribute("name", adjustmentDTO.getAdjusterUserDTO().getName()); adjustment.addContent(user); Element adjustmentDescription = new Element("description"); adjustmentDescription.addContent(adjustmentDTO.getDescription()); adjustment.addContent(adjustmentDescription); usage.addContent(adjustment); } /* Consumptions */ for (ConsumptionDTO consumptionDTO : asset.getUsage().getConsumptionDTOs()) { Element consumption = new Element("consumption"); consumption.setAttribute("date", consumptionDTO.getStrDate()); Element user = new Element("comsumer_user"); user.setAttribute("username", consumptionDTO.getConsumerUserDTO().getUsername()); user.setAttribute("name", consumptionDTO.getConsumerUserDTO().getName()); consumption.addContent(user); usage.addContent(consumption); } /* User Comments */ for (UserCommentDTO userCommentDTO : asset.getUsage().getUserCommentDTOs()) { Element consumption = new Element("user_comment"); consumption.setAttribute("date", userCommentDTO.getStrDate()); Element user = new Element("user"); user.setAttribute("username", userCommentDTO.getUserDTO().getUsername()); user.setAttribute("name", userCommentDTO.getUserDTO().getName()); consumption.addContent(user); Element comment = new Element("comment"); comment.addContent(userCommentDTO.getComment()); consumption.addContent(comment); usage.addContent(consumption); } /* RELATED ASSETS */ Element relatedAssets = new Element("related_assets"); ecp.addContent(relatedAssets); for (RelatedAsset ra : asset.getRelatedAssets()) { Element relatedAsset = new Element("related_asset"); relatedAsset.setAttribute("id", ra.getId()); relatedAsset.setAttribute("name", ra.getName()); relatedAsset.setAttribute("version", ra.getVersion()); relatedAsset.setAttribute("reference", ra.getReference()); if (ra.getRelatedAssetTypeDTO() != null) { relatedAsset.setAttribute("relationshipType", ra.getRelatedAssetTypeDTO().getName()); } relatedAssets.addContent(relatedAsset); } /* Generate XML */ Document doc = new Document(); doc.setRootElement(ecp); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); try { xmlOut.output(doc, outputStream); } catch (IOException e) { e.printStackTrace(); } InputStream is = new ByteArrayInputStream(outputStream.toByteArray()); return is; }
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. j a v a2 s .c o m*/ 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
/** * Get the string representation of the network. * @param network the network object to be written. * @param directed a boolean flag, true if the network is directed. * @return a string representing a document. *//* www .j a va 2s.c o m*/ public static String toString(final Graph<? extends Vertex, ? extends Edge<?>> network, final boolean directed) { // graphml document header final Element graphml = new Element("graphml", "http://graphml.graphdrawing.org/xmlns"); final Document document = new Document(graphml); final Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); final Namespace schemLocation = Namespace.getNamespace("schemLocation", "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0rc/graphml.xsd"); // add Namespace graphml.addNamespaceDeclaration(xsi); graphml.addNamespaceDeclaration(schemLocation); // keys for graphic representation for (VertexAttribute attr : network.getVertexAttributes()) { final Element element = new Element("key"); element.setAttribute("id", attr.getName()); element.setAttribute("for", "node"); element.setAttribute("attr.name", attr.getName()); element.setAttribute("attr.type", attr.getType().getName()); if (attr.getDefaultValue() != null) { final Element defaultValueElement = new Element("default"); defaultValueElement.addContent(attr.getDefaultValue().toString()); element.addContent(defaultValueElement); } graphml.addContent(element); } for (EdgeAttribute attr : network.getEdgeAttributes()) { final Element element = new Element("key"); element.setAttribute("id", attr.getName()); element.setAttribute("for", "edge"); element.setAttribute("attr.name", attr.getName()); element.setAttribute("attr.type", attr.getType().getName()); if (attr.getDefaultValue() != null) { final Element defaultValueElement = new Element("default"); defaultValueElement.addContent(attr.getDefaultValue()); element.addContent(defaultValueElement); } graphml.addContent(element); } final Element graph = new Element("graph"); graph.setAttribute("id", "G"); if (directed) { graph.setAttribute("edgedefault", "directed"); } else { graph.setAttribute("edgedefault", "undirected"); } graphml.addContent(graph); final ImmutableList<Vertex> vertices = ImmutableList.copyOf(network.getVertices()); final Iterator<Vertex> vertexIterator = vertices.iterator(); while (vertexIterator.hasNext()) { final Vertex vertex = vertexIterator.next(); addNode(vertex, graph); } final ImmutableList<Edge<? extends Vertex>> edges; edges = (ImmutableList<Edge<? extends Vertex>>) ImmutableList.copyOf(network.getEdges()); final UnmodifiableIterator<Edge<? extends Vertex>> edgeIterator = edges.iterator(); while (edgeIterator.hasNext()) { addEdge(edgeIterator.next(), graph); } final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); return outputter.outputString(document).replaceAll("xmlns=\"\" ", ""); }
From source file:broadwick.graph.writer.GraphMl.java
License:Apache License
/** * Add an edge to the graphML document./*from w w w .j a va2 s . c o 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.// ww w . j a va 2s . co m * @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.Category.java
License:Open Source License
public Element getXML() { Element ret = new Element(this.getClass().getSimpleName()); ret.setAttribute(TYPE, this.toString()); return ret;/*www . ja v a 2 s .c o m*/ }
From source file:ca.mcgill.cs.swevo.jayfx.model.Relation.java
License:Open Source License
/** * @return/* w w w . j a va 2 s .c o m*/ */ 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 Principal object. * * @param identity The Principal.//from w w w . j ava2 s .c o m * @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; }
From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java
License:Open Source License
/** * Get a JDOM element from a GroupProperty object. * * @param property The GroupProperty./*from w ww . j a v a 2 s . c om*/ * @return A JDOM GroupProperty representation. * @throws WriterException */ protected final Element getElement(GroupProperty property) throws WriterException { if (property == null) { throw new WriterException("null GroupProperty"); } Element propertyElement = new Element(PROPERTY); propertyElement.setAttribute(KEY, property.getKey()); if (property.isReadOnly()) { propertyElement.setAttribute(READ_ONLY, Boolean.TRUE.toString()); } Object value = property.getValue(); if ((value instanceof String)) { propertyElement.setAttribute(TYPE, STRING); } else if ((value instanceof Integer)) { propertyElement.setAttribute(TYPE, INTEGER); } else { String error = "Unsupported value type: " + value.getClass().getSimpleName(); throw new IllegalArgumentException(error); } propertyElement.setText(String.valueOf(property.getValue())); return propertyElement; }
From source file:ca.nrc.cadc.conformance.vos.InvalidTypeNodeWriter.java
License:Open Source License
/** * Returns the root JDOM Element of the node, with an invalid xsi:type * attribute./*from ww w .j av a 2s . com*/ * * @param node the Node. * @return the root element. */ @Override protected Element getRootElement(Node node) { // Create the root element (node). Element root = new Element("node", NodeWriter.vosNamespace); root.addNamespaceDeclaration(NodeWriter.vosNamespace); root.addNamespaceDeclaration(NodeWriter.xsiNamespace); root.setAttribute("uri", node.getUri().toString()); root.setAttribute("type", "vos:invalid_type" + "Type", NodeWriter.xsiNamespace); return root; }