List of usage examples for org.jdom2 Attribute Attribute
@Deprecated public Attribute(final String name, final String value, final int type)
Attribute
with the specified (local) name, value and type, and does not place the attribute in a Namespace
. From source file:com.rometools.rome.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Utility method to generate an element for a subject. * <p>//from w ww . ja v a 2s.c o m * * @param subject the subject to generate an element for. * @return the element for the subject. */ protected final Element generateSubjectElement(final DCSubject subject) { final Element subjectElement = new Element("subject", getDCNamespace()); final String taxonomyUri = subject.getTaxonomyUri(); final String value = subject.getValue(); if (taxonomyUri != null) { final Attribute resourceAttribute = new Attribute("resource", taxonomyUri, getRDFNamespace()); final Element topicElement = new Element("topic", getTaxonomyNamespace()); topicElement.setAttribute(resourceAttribute); final Element descriptionElement = new Element("Description", getRDFNamespace()); descriptionElement.addContent(topicElement); if (value != null) { final Element valueElement = new Element("value", getRDFNamespace()); valueElement.addContent(value); descriptionElement.addContent(valueElement); } subjectElement.addContent(descriptionElement); } else { subjectElement.addContent(value); } return subjectElement; }
From source file:com.sun.syndication.io.impl.DCModuleGenerator.java
License:Open Source License
/** * Utility method to generate an element for a subject. * <p>//from w ww. j a va 2 s . c o m * @param subject the subject to generate an element for. * @return the element for the subject. */ protected final Element generateSubjectElement(DCSubject subject) { Element subjectElement = new Element("subject", getDCNamespace()); if (subject.getTaxonomyUri() != null) { Element descriptionElement = new Element("Description", getRDFNamespace()); Element topicElement = new Element("topic", getTaxonomyNamespace()); Attribute resourceAttribute = new Attribute("resource", subject.getTaxonomyUri(), getRDFNamespace()); topicElement.setAttribute(resourceAttribute); descriptionElement.addContent(topicElement); if (subject.getValue() != null) { Element valueElement = new Element("value", getRDFNamespace()); valueElement.addContent(subject.getValue()); descriptionElement.addContent(valueElement); } subjectElement.addContent(descriptionElement); } else { subjectElement.addContent(subject.getValue()); } return subjectElement; }
From source file:fr.rt.acy.locapic.gps.TrackService.java
License:Open Source License
/** * Methode pour creer le document JDOM de base pour le fichier GPX * Prend en parametre des valeurs pour les metadonnees GPX (contenues dans la balise <metadata>) * @param name - Nom du fichier gpx (pour les metadonnees GPX) * @param desc - Description du fichier gpx (pour les metadonnees GPX) * @param authorsName - Nom de l'autheur de la trace (pour les metadonnees GPX) * @param authorsEmail - Email de l'autheur de la trace (pour les metadonnees GPX) * @param keywords - Mots-cle pour les metadonnees GPX * @return document - Le document JDOM servant de base GPX */// ww w .j a v a 2 s. c o m public Document createGpxDocTree(String name, String desc, String authorsName, String authorsEmail, String keywords) { /* Pour la date */ Calendar calendar = Calendar.getInstance(); Date date = calendar.getTime(); // Format de la date SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); StringBuilder dateBuilder = new StringBuilder(dateFormat.format(date)); // Pour le format GPX, T apres la date et avant l'heure, et Z a la fin dateBuilder.append("Z"); dateBuilder.insert(10, "T"); // Conversion builder => string String formattedDate = dateBuilder.toString(); Log.v(TAG, "TIME => " + formattedDate); /* Pour le reste des metadonnees perso */ String mailId; String mailDomain; if (name == null) name = "LocaPic track"; if (desc == null) desc = "GPS track logged on an Android device with an application from a project by Samuel Beaurepaire & Virgile Beguin for IUT of Annecy (Fr), RT departement."; if (authorsName == null) authorsName = "Samuel Beaurepaire"; if (authorsEmail == null) { mailId = "sjbeaurepaire"; mailDomain = "orange.fr"; } else { String[] mail = authorsEmail.split("@", 2); mailId = mail[0]; mailDomain = mail[1]; } // xsi du namespace a indique seulement pour la racine (addNamespaceDeclaratin()) Namespace XSI = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Creation de la racine du fichier gpx (<gpx></gpx>) sous forme d'objet de classe Element avec le namespace gpx Element xml_gpx = new Element("gpx", ns); // Namespace XSI et attributs xml_gpx.addNamespaceDeclaration(XSI); xml_gpx.setAttribute(new Attribute("schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd", XSI)); xml_gpx.setAttribute(new Attribute("creator", "LocaPic")); xml_gpx.setAttribute(new Attribute("version", "1.1")); // On cree un nouveau Document JDOM base sur la racine que l'on vient de creer Document document = new Document(xml_gpx); // ~~~~~~~~~~~~~~~~ <metadata> ~~~~~~~~~~~~~~~~ Element xml_metadata = new Element("metadata", ns); xml_gpx.addContent(xml_metadata); // ~~~~~~~~~~~~~~~~ <name> ~~~~~~~~~~~~~~~~ Element xml_metadata_name = new Element("name", ns); xml_metadata_name.addContent(name); xml_metadata.addContent(xml_metadata_name); // ~~~~~~~~~~~~~~~~ <desc> ~~~~~~~~~~~~~~~~ Element xml_metadata_desc = new Element("desc", ns); xml_metadata_desc.addContent(desc); xml_metadata.addContent(xml_metadata_desc); // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~ Element xml_metadata_author = new Element("author", ns); // ~~~~~~~~~~~~~~~~ <author> ~~~~~~~~~~~~~~~~ Element xml_metadata_author_name = new Element("name", ns); xml_metadata_author_name.addContent(authorsName); xml_metadata_author.addContent(xml_metadata_author_name); // ~~~~~~~~~~~~~~~~ <email> ~~~~~~~~~~~~~~~~ Element xml_metadata_author_email = new Element("email", ns); xml_metadata_author_email.setAttribute("id", mailId); xml_metadata_author_email.setAttribute("domain", mailDomain); xml_metadata_author.addContent(xml_metadata_author_email); xml_metadata.addContent(xml_metadata_author); // ~~~~~~~~~~~~~~~~ <time> ~~~~~~~~~~~~~~~~ Element xml_metadata_time = new Element("time", ns); xml_metadata_time.addContent(formattedDate); xml_metadata.addContent(xml_metadata_time); // ~~~~~~~~~~~~~~~~ <keywords> ~~~~~~~~~~~~~~~~ if (keywords != null) { Element xml_keywords = new Element("keywords", ns); xml_keywords.addContent(keywords); xml_metadata.addContent(xml_keywords); } // ~~~~~~~~~~~~~~~~ <trk> ~~~~~~~~~~~~~~~~ Element xml_trk = new Element("trk", ns); // ~~~~~~~~~~~~~~~~ <number> ~~~~~~~~~~~~~~~~ Element xml_trk_number = new Element("number", ns); xml_trk_number.addContent("1"); xml_trk.addContent(xml_trk_number); // ~~~~~~~~~~~~~~~~ <trkseg> ~~~~~~~~~~~~~~~~ Element xml_trk_trkseg = new Element("trkseg", ns); xml_trk.addContent(xml_trk_trkseg); xml_gpx.addContent(xml_trk); return document; }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method creates a new xml document with process metadata * //w w w . ja v a 2 s . com * @param process the process to export * @return a new xml document * @throws ConfigurationException */ public Document createDocument(Process process, boolean addNamespace) { Element processElm = new Element("process"); Document doc = new Document(processElm); processElm.setAttribute("processID", String.valueOf(process.getId())); Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile"); processElm.setNamespace(xmlns); // namespace declaration if (addNamespace) { Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); processElm.addNamespaceDeclaration(xsi); Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi); processElm.setAttribute(attSchema); } // process information ArrayList<Element> processElements = new ArrayList<>(); Element processTitle = new Element("title", xmlns); processTitle.setText(process.getTitel()); processElements.add(processTitle); Element project = new Element("project", xmlns); project.setText(process.getProjekt().getTitel()); processElements.add(project); Element date = new Element("time", xmlns); date.setAttribute("type", "creation date"); date.setText(String.valueOf(process.getErstellungsdatum())); processElements.add(date); Element ruleset = new Element("ruleset", xmlns); ruleset.setText(process.getRegelsatz().getDatei()); processElements.add(ruleset); Element comment = new Element("comments", xmlns); List<LogEntry> log = process.getProcessLog(); for (LogEntry entry : log) { Element commentLine = new Element("comment", xmlns); commentLine.setAttribute("type", entry.getType().getTitle()); commentLine.setAttribute("user", entry.getUserName()); commentLine.setText(entry.getContent()); if (StringUtils.isNotBlank(entry.getSecondContent())) { comment.setAttribute("secondField", entry.getSecondContent()); } if (StringUtils.isNotBlank(entry.getThirdContent())) { comment.setAttribute("thirdField", entry.getThirdContent()); } comment.addContent(commentLine); } processElements.add(comment); if (process.getBatch() != null) { Element batch = new Element("batch", xmlns); batch.setText(String.valueOf(process.getBatch().getBatchId())); if (StringUtils.isNotBlank(process.getBatch().getBatchName())) { batch.setAttribute("batchName", process.getBatch().getBatchName()); } if (process.getBatch().getStartDate() != null) { batch.setAttribute("startDate", Helper.getDateAsFormattedString(process.getBatch().getStartDate())); } if (process.getBatch().getEndDate() != null) { batch.setAttribute("endDate", Helper.getDateAsFormattedString(process.getBatch().getEndDate())); } processElements.add(batch); } List<Element> processProperties = new ArrayList<>(); List<ProcessProperty> propertyList = PropertyParser.getInstance().getPropertiesForProcess(process); for (ProcessProperty prop : propertyList) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getName()); if (prop.getValue() != null) { property.setAttribute("value", prop.getValue()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getName()); property.addContent(label); processProperties.add(property); } if (processProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(processProperties); processElements.add(properties); } // step information Element steps = new Element("steps", xmlns); List<Element> stepElements = new ArrayList<>(); for (Step s : process.getSchritteList()) { Element stepElement = new Element("step", xmlns); stepElement.setAttribute("stepID", String.valueOf(s.getId())); Element steptitle = new Element("title", xmlns); steptitle.setText(s.getTitel()); stepElement.addContent(steptitle); Element state = new Element("processingstatus", xmlns); state.setText(s.getBearbeitungsstatusAsString()); stepElement.addContent(state); Element begin = new Element("time", xmlns); begin.setAttribute("type", "start time"); begin.setText(s.getBearbeitungsbeginnAsFormattedString()); stepElement.addContent(begin); Element end = new Element("time", xmlns); end.setAttribute("type", "end time"); end.setText(s.getBearbeitungsendeAsFormattedString()); stepElement.addContent(end); if (s.getBearbeitungsbenutzer() != null && s.getBearbeitungsbenutzer().getNachVorname() != null) { Element user = new Element("user", xmlns); user.setText(s.getBearbeitungsbenutzer().getNachVorname()); stepElement.addContent(user); } Element editType = new Element("edittype", xmlns); editType.setText(s.getEditTypeEnum().getTitle()); stepElement.addContent(editType); stepElements.add(stepElement); } if (stepElements != null) { steps.addContent(stepElements); processElements.add(steps); } // template information Element templates = new Element("originals", xmlns); List<Element> templateElements = new ArrayList<>(); for (Template v : process.getVorlagenList()) { Element template = new Element("original", xmlns); template.setAttribute("originalID", String.valueOf(v.getId())); List<Element> templateProperties = new ArrayList<>(); for (Templateproperty prop : v.getEigenschaftenList()) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getTitel()); if (prop.getWert() != null) { property.setAttribute("value", prop.getWert()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getTitel()); property.addContent(label); templateProperties.add(property); if (prop.getTitel().equals("Signatur")) { Element secondProperty = new Element("property", xmlns); secondProperty.setAttribute("propertyIdentifier", prop.getTitel() + "Encoded"); if (prop.getWert() != null) { secondProperty.setAttribute("value", "vorl:" + prop.getWert()); Element secondLabel = new Element("label", xmlns); secondLabel.setText(prop.getTitel()); secondProperty.addContent(secondLabel); templateProperties.add(secondProperty); } } } if (templateProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(templateProperties); template.addContent(properties); } templateElements.add(template); } if (templateElements != null) { templates.addContent(templateElements); processElements.add(templates); } // digital document information Element digdoc = new Element("digitalDocuments", xmlns); List<Element> docElements = new ArrayList<>(); for (Masterpiece w : process.getWerkstueckeList()) { Element dd = new Element("digitalDocument", xmlns); dd.setAttribute("digitalDocumentID", String.valueOf(w.getId())); List<Element> docProperties = new ArrayList<>(); for (Masterpieceproperty prop : w.getEigenschaftenList()) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getTitel()); if (prop.getWert() != null) { property.setAttribute("value", prop.getWert()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getTitel()); property.addContent(label); docProperties.add(property); } if (docProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(docProperties); dd.addContent(properties); } docElements.add(dd); } if (docElements != null) { digdoc.addContent(docElements); processElements.add(digdoc); } // history List<HistoryEvent> eventList = HistoryManager.getHistoryEvents(process.getId()); if (eventList != null && !eventList.isEmpty()) { List<Element> eventElementList = new ArrayList<>(eventList.size()); for (HistoryEvent event : eventList) { Element element = new Element("historyEvent", xmlns); element.setAttribute("id", "" + event.getId()); element.setAttribute("date", Helper.getDateAsFormattedString(event.getDate())); element.setAttribute("type", event.getHistoryType().getTitle()); if (event.getNumericValue() != null) { element.setAttribute("numeric_value", "" + event.getNumericValue()); } if (event.getStringValue() != null) { element.setText(event.getStringValue()); } eventElementList.add(element); } if (!eventElementList.isEmpty()) { Element metadataElement = new Element("history", xmlns); metadataElement.addContent(eventElementList); processElements.add(metadataElement); } } // metadata List<StringPair> metadata = MetadataManager.getMetadata(process.getId()); if (metadata != null && !metadata.isEmpty()) { List<Element> mdlist = new ArrayList<>(); for (StringPair md : metadata) { String name = md.getOne(); String value = md.getTwo(); if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(name)) { Element element = new Element("metadata", xmlns); element.setAttribute("name", name); element.addContent(value); mdlist.add(element); } } if (!mdlist.isEmpty()) { Element metadataElement = new Element("metadatalist", xmlns); metadataElement.addContent(mdlist); processElements.add(metadataElement); } } // METS information Element metsElement = new Element("metsInformation", xmlns); List<Element> metadataElements = new ArrayList<>(); try { String filename = process.getMetadataFilePath(); Document metsDoc = new SAXBuilder().build(filename); Document anchorDoc = null; String anchorfilename = process.getMetadataFilePath().replace("meta.xml", "meta_anchor.xml"); Path anchorFile = Paths.get(anchorfilename); if (StorageProvider.getInstance().isFileExists(anchorFile) && StorageProvider.getInstance().isReadable(anchorFile)) { anchorDoc = new SAXBuilder().build(anchorfilename); } List<Namespace> namespaces = getNamespacesFromConfig(); HashMap<String, String> fields = getMetsFieldsFromConfig(false); for (String key : fields.keySet()) { List<Element> metsValues = getMetsValues(fields.get(key), metsDoc, namespaces); for (Element element : metsValues) { Element ele = new Element("property", xmlns); ele.setAttribute("name", key); ele.addContent(element.getTextTrim()); metadataElements.add(ele); } } if (anchorDoc != null) { fields = getMetsFieldsFromConfig(true); for (String key : fields.keySet()) { List<Element> metsValues = getMetsValues(fields.get(key), anchorDoc, namespaces); for (Element element : metsValues) { Element ele = new Element("property", xmlns); ele.setAttribute("name", key); ele.addContent(element.getTextTrim()); metadataElements.add(ele); } } } if (metadataElements != null) { metsElement.addContent(metadataElements); processElements.add(metsElement); } } catch (SwapException e) { logger.error(e); } catch (DAOException e) { logger.error(e); } catch (IOException e) { logger.error(e); } catch (InterruptedException e) { logger.error(e); } catch (JDOMException e) { logger.error(e); } catch (JaxenException e) { logger.error(e); } processElm.setContent(processElements); return doc; }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata for al list of processes as a single file to a given stream. * /*from www .j av a 2 s . c o m*/ * @param processList * @param outputStream * @param xslt */ public void startExport(List<Process> processList, OutputStream outputStream, String xslt) { Document answer = new Document(); Element root = new Element("processes"); answer.setRootElement(root); Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile"); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addNamespaceDeclaration(xsi); root.setNamespace(xmlns); Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi); root.setAttribute(attSchema); for (Process p : processList) { Document doc = createDocument(p, false); Element processRoot = doc.getRootElement(); processRoot.detach(); root.addContent(processRoot); } XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getPrettyFormat()); try { outp.output(answer, outputStream); } catch (IOException e) { } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { outputStream = null; } } } }
From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata for al list of processes as a * single file to a given stream.//from ww w.j av a 2 s. c om * * @param docketDataList * a list of Docket data * @param outputStream * The output stream, to write the docket to. */ void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) { Document answer = new Document(); Element root = new Element("processes"); answer.setRootElement(root); Namespace xmlns = Namespace.getNamespace(NAMESPACE); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addNamespaceDeclaration(xsi); root.setNamespace(xmlns); Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi); root.setAttribute(attSchema); for (DocketData docketData : docketDataList) { Document doc = createDocument(docketData, false); Element processRoot = doc.getRootElement(); processRoot.detach(); root.addContent(processRoot); } XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat()); try { outp.output(answer, outputStream); } catch (IOException e) { logger.error("Generating XML Output failed.", e); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error("Closing the output stream failed.", e); } } } }
From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method creates a new xml document with process metadata. * * @param docketData//w ww.j a va 2 s . c o m * the docketData to export * @return a new xml document */ private Document createDocument(DocketData docketData, boolean addNamespace) { Element processElm = new Element("process"); final Document doc = new Document(processElm); processElm.setAttribute("processID", String.valueOf(docketData.getProcessId())); Namespace xmlns = Namespace.getNamespace(NAMESPACE); processElm.setNamespace(xmlns); // namespace declaration if (addNamespace) { Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); processElm.addNamespaceDeclaration(xsi); Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi); processElm.setAttribute(attSchema); } // process information ArrayList<Element> processElements = new ArrayList<>(); Element processTitle = new Element("title", xmlns); processTitle.setText(docketData.getProcessName()); processElements.add(processTitle); Element project = new Element("project", xmlns); project.setText(docketData.getProjectName()); processElements.add(project); Element date = new Element("time", xmlns); date.setAttribute("type", "creation date"); date.setText(String.valueOf(docketData.getCreationDate())); processElements.add(date); Element ruleset = new Element("ruleset", xmlns); ruleset.setText(docketData.getRulesetName()); processElements.add(ruleset); Element comment = new Element("comment", xmlns); comment.setText(docketData.getComment()); processElements.add(comment); List<Element> processProperties = prepareProperties(docketData.getProcessProperties(), xmlns); if (!processProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(processProperties); processElements.add(properties); } // template information ArrayList<Element> templateElements = new ArrayList<>(); Element template = new Element("original", xmlns); ArrayList<Element> templateProperties = new ArrayList<>(); if (docketData.getTemplateProperties() != null) { for (Property prop : docketData.getTemplateProperties()) { Element property = new Element(PROPERTY, xmlns); property.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle()); if (prop.getValue() != null) { property.setAttribute(VALUE, replacer(prop.getValue())); } else { property.setAttribute(VALUE, ""); } Element label = new Element(LABEL, xmlns); label.setText(prop.getTitle()); property.addContent(label); templateProperties.add(property); if (prop.getTitle().equals("Signatur")) { Element secondProperty = new Element(PROPERTY, xmlns); secondProperty.setAttribute(PROPERTY_IDENTIFIER, prop.getTitle() + "Encoded"); if (prop.getValue() != null) { secondProperty.setAttribute(VALUE, "vorl:" + replacer(prop.getValue())); Element secondLabel = new Element(LABEL, xmlns); secondLabel.setText(prop.getTitle()); secondProperty.addContent(secondLabel); templateProperties.add(secondProperty); } } } } if (!templateProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(templateProperties); template.addContent(properties); } templateElements.add(template); Element templates = new Element("originals", xmlns); templates.addContent(templateElements); processElements.add(templates); // digital document information ArrayList<Element> docElements = new ArrayList<>(); Element dd = new Element("digitalDocument", xmlns); List<Element> docProperties = prepareProperties(docketData.getWorkpieceProperties(), xmlns); if (!docProperties.isEmpty()) { Element properties = new Element(PROPERTIES, xmlns); properties.addContent(docProperties); dd.addContent(properties); } docElements.add(dd); Element digdoc = new Element("digitalDocuments", xmlns); digdoc.addContent(docElements); processElements.add(digdoc); processElm.setContent(processElements); return doc; }
From source file:org.mycore.common.xml.MCRNodeBuilder.java
License:Open Source License
private Attribute buildAttribute(Namespace ns, String name, String value, Element parent) { Attribute attribute = new Attribute(name, value == null ? "" : value, ns); if (LOGGER.isDebugEnabled()) LOGGER.debug("building new attribute " + attribute.getName()); if (parent != null) parent.setAttribute(attribute);// www . java 2 s .co m return attribute; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Document buildDocumentModel(Model model, String destNamespaceURI, String destNamespacePrefix) { this.xmiElem = new Element("XMI"); this.xmiElem.setNamespace(xmiNs); Document document = new Document(this.xmiElem); this.xmiElem.setAttribute(new Attribute("version", this.xmiVersion, this.xmiNs)); // FIXME - use FUML config for this, i.e which version? this.xmiElem.addNamespaceDeclaration(umlNs); this.xmiElem.addNamespaceDeclaration(xmiNs); this.xmiElem.addNamespaceDeclaration(plasmaNs); if (this.platformNs != null) this.xmiElem.addNamespaceDeclaration(platformNs); if (this.xsiNs != null) { this.xmiElem.addNamespaceDeclaration(xsiNs); this.xmiElem.setAttribute(new Attribute("schemaLocation", this.xsiSchemaLocation, this.xsiNs)); }//from w w w .java 2 s. c o m if (this.derivePackageNamesFromURIs) this.modelElem = this.buildModelFromURITokens(model); else this.modelElem = this.buildModelFromPackageNames(model); Element profileApplicationElem = buildProfileApplication(); if (profileApplicationElem != null) this.modelElem.addContent(profileApplicationElem); collectPackages(model); collectClasses(model); collectEnumerations(model); for (Class clss : this.classMap.values()) { Package pkg = this.classPackageMap.get(clss); Element clssElem = buildClass(clss); elementMap.put(clss.getId(), clssElem); // build properties w/o any associations for (Property property : clss.getProperties()) { Element ownedAttribute = buildProperty(pkg, clss, property, clssElem); elementMap.put(property.getId(), ownedAttribute); } } // create associations for (Class clss : this.classMap.values()) { for (Property prop : clss.getProperties()) { if (prop.getType() instanceof DataTypeRef) continue; if (associationElementMap.get(prop.getId()) != null) continue; // we created it String associationUUID = UUID.randomUUID().toString(); // link assoc to both properties Element leftOwnedAttribute = elementMap.get(prop.getId()); leftOwnedAttribute.setAttribute(new Attribute("association", associationUUID)); Property targetProp = getOppositeProperty(clss, prop); if (targetProp != null) { Element rightOwnedAttribute = elementMap.get(targetProp.getId()); rightOwnedAttribute.setAttribute(new Attribute("association", associationUUID)); Element association = buildAssociation(prop, targetProp, this.modelElem, associationUUID); // map it to both props so we can know not to create it again associationElementMap.put(prop.getId(), association); associationElementMap.put(targetProp.getId(), association); } else { Class targetClass = getOppositeClass(clss, prop); Element association = buildAssociation(prop, targetClass, this.modelElem, associationUUID); // map it to both props so we can know not to create it again associationElementMap.put(prop.getId(), association); } } } return document; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildModelFromPackageNames(Model model) { Element modelElem = new Element("Model"); modelElem.setNamespace(umlNs);//from ww w .j a v a2s .com this.xmiElem.addContent(modelElem); modelElem.setAttribute(new Attribute("id", model.getId(), xmiNs)); modelElem.setAttribute(new Attribute("name", model.getName())); modelElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(model.getId(), modelElem); if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(modelElem, model.getId(), doc.getBody().getValue()); } // Only a root (model) package // tag the model w/a SDO namespace streotype, else tag the // last package descendant below if (model.getPackages().size() == 0) { Element modelStereotype = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(modelStereotype); modelStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); modelStereotype.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, model.getId())); modelStereotype.setAttribute(new Attribute(SDONamespace.URI, model.getUri())); if (model.getAlias() != null) addAlias(model.getAlias(), model.getId()); } for (Package pkg : model.getPackages()) { Element pkgElem = new Element("packagedElement"); modelElem.addContent(pkgElem); // add package child pkgElem.setAttribute(new Attribute("type", "uml:Package", xmiNs)); pkgElem.setAttribute(new Attribute("id", pkg.getId(), xmiNs)); pkgElem.setAttribute(new Attribute("name", pkg.getName())); pkgElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(pkg.getId(), pkgElem); if (pkg.getAlias() != null) addAlias(pkg.getAlias(), pkg.getId()); Element pkgStereotypeElem = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(pkgStereotypeElem); pkgStereotypeElem.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, pkg.getId())); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.URI, pkg.getUri())); if (pkg.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(pkgElem, pkg.getId(), doc.getBody().getValue()); } } return modelElem; }