2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.sdd
.out
;
13 import java
.io
.FileOutputStream
;
14 import java
.io
.IOException
;
15 import java
.io
.OutputStreamWriter
;
16 import java
.io
.Writer
;
17 import java
.util
.HashMap
;
18 import java
.util
.HashSet
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
24 import javax
.xml
.bind
.Marshaller
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.apache
.xerces
.dom
.DocumentImpl
;
28 import org
.apache
.xerces
.dom
.ElementImpl
;
29 import org
.apache
.xerces
.impl
.xpath
.regex
.ParseException
;
30 import org
.apache
.xml
.serialize
.DOMSerializer
;
31 import org
.apache
.xml
.serialize
.OutputFormat
;
32 import org
.apache
.xml
.serialize
.XMLSerializer
;
33 import org
.joda
.time
.DateTime
;
34 import org
.joda
.time
.format
.DateTimeFormatter
;
35 import org
.joda
.time
.format
.ISODateTimeFormat
;
36 import org
.springframework
.util
.ResourceUtils
;
37 import org
.xml
.sax
.SAXException
;
39 import eu
.etaxonomy
.cdm
.io
.jaxb
.CdmMarshallerListener
;
40 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
44 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
45 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
46 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
47 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
48 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
49 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
50 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
51 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
53 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
54 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
55 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
56 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
57 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
58 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
59 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
60 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
61 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
62 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
63 import eu
.etaxonomy
.cdm
.model
.description
.State
;
64 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
65 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
66 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
67 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
68 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
69 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
70 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
71 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
72 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
74 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
75 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
76 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
77 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
78 import eu
.etaxonomy
.cdm
.model
.reference
.IDatabase
;
79 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
80 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
81 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
82 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
83 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
84 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
87 * Writes the SDD XML file.
94 public class SDDDocumentBuilder
{
96 private final DocumentImpl document
;
97 private XMLSerializer xmlserializer
;
98 private Writer writer
;
99 private DOMSerializer domi
;
100 private SDDDataSet cdmSource
;
102 private final Map
<Person
, String
> agents
= new HashMap
<Person
, String
>();
103 private final Map
<TaxonNameBase
<?
,?
>, String
> taxonNames
= new HashMap
<TaxonNameBase
<?
,?
>, String
>();
104 private final Map
<Feature
, String
> characters
= new HashMap
<Feature
, String
>();
105 private final Map
<FeatureNode
, String
> featureNodes
= new HashMap
<FeatureNode
, String
>();
106 private final Map
<Feature
, String
> descriptiveConcepts
= new HashMap
<Feature
, String
>();
107 private final Map
<TaxonDescription
, String
> codedDescriptions
= new HashMap
<TaxonDescription
, String
>();
108 private final Map
<Media
, String
> medias
= new HashMap
<Media
, String
>();
109 private final Map
<State
, String
> states
= new HashMap
<State
, String
>();
110 private final Map
<Reference
<?
>, String
> articles
= new HashMap
<Reference
<?
>, String
>();
111 private final Map
<VersionableEntity
, String
> featuretrees
= new HashMap
<VersionableEntity
, String
>();
112 private final Map
<DefinedTerm
, String
> modifiers
= new HashMap
<DefinedTerm
, String
>();
113 private final Map
<TaxonNode
, String
> taxonNodes
= new HashMap
<TaxonNode
, String
>();
114 private final Map
<NamedArea
, String
> namedAreas
= new HashMap
<NamedArea
, String
>();
115 private final Map
<DerivedUnit
, String
> specimens
= new HashMap
<DerivedUnit
, String
>();
117 private final Map
<VersionableEntity
, String
> features
= new HashMap
<VersionableEntity
, String
>();
118 private int agentsCount
= 0;
119 private int articlesCount
= 0;
120 private int codedDescriptionsCount
= 0;
121 private int taxonNamesCount
= 0;
122 private int charactersCount
= 0;
123 private int textcharactersCount
= 0;
124 private int mediasCount
= 0;
125 private int statesCount
= 0;
126 private final int featureNodesCount
= 0;
127 private int chartreeCount
= 0;
128 private int charnodeCount
= 0;
129 private int taxonNodesCount
= 0;
130 private int namedAreasCount
= 0;
131 private int specimenCount
= 0;
132 private int descriptiveConceptCount
= 0;
133 private int modifiersCount
= 0;
135 private final String AGENT
= "Agent";
136 private final String AGENTS
= "Agents";
137 private final String CATEGORICAL
= "Categorical";
138 private final String CATEGORICAL_CHARACTER
= "CategoricalCharacter";
139 private final String CHARACTER
= "Character";
140 private final String CHARACTERS
= "Characters";
141 private final String CHARACTER_TREE
= "CharacterTree";
142 private final String CHARACTER_TREES
= "CharacterTrees";
143 private final String CHAR_NODE
= "CharNode";
144 private final String CITATION
= "Citation";
145 private final String CODED_DESCRIPTION
= "CodedDescription";
146 private final String CODED_DESCRIPTIONS
= "CodedDescriptions";
147 private final String CONTENT
= "Content";
148 private final String CREATORS
= "Creators";
149 private final String DATASET
= "Dataset";
150 private final String DATASETS
= "Datasets";
151 private final String DATE_CREATED
= "DateCreated";
152 private final String DATE_MODIFIED
= "DateModified";
153 private final String DEPENDENCY_RULES
= "DependencyRules";
154 private final String DESCRIPTIVE_CONCEPT
= "DescriptiveConcept";
155 private final String DESCRIPTIVE_CONCEPTS
= "DescriptiveConcepts";
156 private final String DETAIL
= "Detail";
157 private final String GENERATOR
= "Generator";
158 private final String ID
= "id";
159 private final String IMAGE
= "Image";
160 private final String INAPPLICABLE_IF
= "InapplicableIf";
161 private final String IPR_STATEMENT
= "IPRStatement";
162 private final String IPR_STATEMENTS
= "IPRStatements";
163 private final String LABEL
= "Label";
164 private final String MEASURE
= "Measure";
165 private final String MEDIA_OBJECT
= "MediaObject";
166 private final String MEDIA_OBJECTS
= "MediaObjects";
167 private final String NODE
= "Node";
168 private final String NODES
= "Nodes";
169 private final String NOTE
= "Note";
170 private final String PARENT
= "Parent";
171 private final String PUBLICATIONS
= "Publications";
172 private final String QUANTITATIVE
= "Quantitative";
173 private final String QUANTITATIVE_CHARACTER
= "QuantitativeCharacter";
174 private final String REF
= "ref";
175 private final String REPRESENTATION
= "Representation";
176 private final String REVISION_DATA
= "RevisionData";
177 private final String ROLE
= "role";
178 private final String SCOPE
= "Scope";
179 private final String SHOULD_CONTAIN_ALL_CHARACTERS
= "ShouldContainAllCharacters";
180 private final String SOURCE
= "Source";
181 private final String STATE
= "State";
182 private final String STATE_DEFINITION
= "StateDefinition";
183 private final String STATES
= "States";
184 private final String STATUS
= "Status";
185 private final String SUMMARY_DATA
= "SummaryData";
186 private final String TAXON_NAME
= "TaxonName";
187 private final String TAXON_NAMES
= "TaxonNames";
188 private final String TECHNICAL_METADATA
= "TechnicalMetadata";
189 private final String TEXT
= "text";
190 private final String TEXT_CHAR
= "TextChar";
191 private final String TEXT_CHARACTER
= "TextCharacter";
192 private final String TYPE
= "Type";
193 private final String URI
= "uri";
195 private final Language defaultLanguage
= Language
.DEFAULT();
197 private static final Logger logger
= Logger
198 .getLogger(SDDDocumentBuilder
.class);
200 private final String NEWLINE
= System
.getProperty("line.separator");
202 public SDDDocumentBuilder() throws SAXException
, IOException
{
204 document
= new DocumentImpl();
208 public void marshal(SDDDataSet cdmSource
, File sddDestination
)
211 this.cdmSource
= cdmSource
;
212 Marshaller marshaller
;
213 CdmMarshallerListener marshallerListener
= new CdmMarshallerListener();
214 logger
.info("Start marshalling");
215 writeCDMtoSDD(sddDestination
);
219 public void marshal(SDDDataSet cdmSource
, String sddDestinationFileName
)
222 this.cdmSource
= cdmSource
;
223 Marshaller marshaller
;
224 CdmMarshallerListener marshallerListener
= new CdmMarshallerListener();
225 logger
.info("Start marshalling");
226 writeCDMtoSDD(ResourceUtils
.getFile(sddDestinationFileName
));
231 * Write the DOM document.
234 * @throws IOException
236 public void writeCDMtoSDD(File sddDestination
) throws IOException
{
240 } catch (ParseException e
) {
244 OutputFormat format
= new OutputFormat(document
, "UTF-8", true);
246 FileOutputStream fos
= new FileOutputStream(sddDestination
);
248 writer
= new OutputStreamWriter(fos
, "UTF-8");
250 xmlserializer
= new XMLSerializer(writer
, format
);
251 domi
= xmlserializer
.asDOMSerializer(); // As a DOM Serializer
253 domi
.serialize(document
.getDocumentElement());
263 * Builds the whole document.
267 * @throws ParseException
269 public void buildDocument() throws ParseException
{
271 // create <Datasets> = root node
272 ElementImpl baselement
= new ElementImpl(document
, DATASETS
);
273 baselement
.setAttribute("xmlns:xsi",
274 "http://www.w3.org/2001/XMLSchema-instance");
275 baselement
.setAttribute("xmlns", "http://rs.tdwg.org/UBIF/2006/");
277 .setAttribute("xsi:schemaLocation",
278 "http://rs.tdwg.org/UBIF/2006 http://rs.tdwg.org/UBIF/2006/Schema/1.1/SDD.xsd");
280 buildTechnicalMetadata(baselement
);
282 List
<Reference
> references
= cdmSource
.getReferences();
283 Iterator
<Reference
> iterator
= references
.iterator();
284 IDatabase d
= ReferenceFactory
.newDatabase();
285 while (iterator
.hasNext()) {
286 Reference
<?
> reference
= iterator
.next();
287 if (reference
.getType().equals(ReferenceType
.Database
)) {
288 buildDataset(baselement
, reference
);
291 document
.appendChild(baselement
);
299 * Builds TechnicalMetadata associated with the SDD file
301 public void buildTechnicalMetadata(ElementImpl baselement
)
302 throws ParseException
{
303 // create TechnicalMetadata
304 ElementImpl technicalMetadata
= new ElementImpl(document
,
306 // select different databases associated to different descriptions TODO
307 List
<Reference
> references
= cdmSource
.getReferences();
308 Iterator
<Reference
> iterator
= references
.iterator();
309 boolean database
= false;
310 IDatabase d
= ReferenceFactory
.newDatabase();
311 while ((iterator
.hasNext()) && (!database
)) {
312 Reference
<?
> reference
= iterator
.next();
313 if (reference
.getType().equals(ReferenceType
.Database
)) {
317 DateTime dt
= d
.getCreated();
318 String date
= dt
.toString().substring(0, 19);
319 technicalMetadata
.setAttribute("created", date
);
321 ElementImpl generator
= new ElementImpl(document
, GENERATOR
);
322 generator
.setAttribute("name", "EDIT CDM");
323 generator
.setAttribute("version", "v1");
327 "This SDD file has been generated by the SDD export functionality of the EDIT platform for Cybertaxonomy - Copyright (c) 2008");
328 technicalMetadata
.appendChild(generator
);
330 baselement
.appendChild(technicalMetadata
);
333 // Builds the information associated with a dataset
334 public void buildDataset(ElementImpl baselement
, IDatabase reference
)
335 throws ParseException
{
336 // create Dataset and language
337 ElementImpl dataset
= new ElementImpl(document
, DATASET
);
338 // no default language associated with a dataset in the CDM
339 dataset
.setAttribute("xml:lang", Language
.DEFAULT().getIso639_1());
340 baselement
.appendChild(dataset
);
341 buildRepresentation(dataset
, reference
);
342 buildRevisionData(dataset
, reference
);
343 buildIPRStatements(dataset
, reference
);
344 buildTaxonNames(dataset
);
345 buildDescriptiveConcepts(dataset
);
346 buildCharacters(dataset
);
347 buildCodedDescriptions(dataset
);
348 buildAgents(dataset
);
349 buildPublications(dataset
);
350 buildMediaObjects(dataset
);
351 buildCharacterTrees(dataset
);
352 buildClassifications(dataset
);
353 buildGeographicAreas(dataset
);
354 buildSpecimens(dataset
);
358 * Builds a Representation element using a Reference
360 public void buildRepresentation(ElementImpl element
, IDatabase reference
)
361 throws ParseException
{
363 // create <Representation> element
364 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
365 element
.appendChild(representation
);
366 buildLabel(representation
, reference
.getTitleCache());
368 Set
<Annotation
> annotations
= ((Reference
) reference
).getAnnotations();
369 Iterator
<Annotation
> iterator
= annotations
.iterator();
370 String detailText
= null;
371 if (iterator
.hasNext()) {
372 Annotation annotation
= (Annotation
) iterator
.next();
373 detailText
= annotation
.getText();
376 if (detailText
!= null && !detailText
.equals("")) {
377 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
378 detail
.appendChild(document
.createTextNode(detailText
));
379 representation
.appendChild(detail
);
382 Set
<Media
> rm
= ((Reference
) reference
).getMedia();
384 if (rm
!= null && rm
.size() > 0) {
385 ElementImpl mediaObject
;
387 for (int i
= 0; i
< rm
.size(); i
++) {
388 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
389 mediasCount
= buildReference((Media
) rm
.toArray()[i
], medias
,
390 REF
, mediaObject
, "m", mediasCount
);
391 representation
.appendChild(mediaObject
);
398 * Builds a Representation element using a Feature
400 public void buildRepresentation(ElementImpl element
, TermBase tb
)
401 throws ParseException
{
403 // create <Representation> element
404 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
405 element
.appendChild(representation
);
407 Set
<Representation
> representations
= tb
.getRepresentations();
408 if (representations
!= null) {
409 if (!representations
.isEmpty()) {
410 String label
= ((Representation
) representations
.toArray()[0])
412 buildLabel(representation
, label
);
413 String detailText
= tb
.getDescription();
415 if (detailText
!= null && !detailText
.equals("")) {
416 if (!detailText
.equals(label
)) {
417 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
418 detail
.appendChild(document
.createTextNode(detailText
));
419 representation
.appendChild(detail
);
426 if (tb
instanceof DefinedTermBase
) {
427 DefinedTermBase dtb
= (DefinedTermBase
) tb
;
428 Set
<Media
> rm
= dtb
.getMedia();
430 if (rm
!= null && rm
.size() > 0) {
431 ElementImpl mediaObject
;
433 for (int i
= 0; i
< rm
.size(); i
++) {
434 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
435 mediasCount
= buildReference((Media
) rm
.toArray()[i
],
436 medias
, REF
, mediaObject
, "m", mediasCount
);
437 representation
.appendChild(mediaObject
);
444 * Builds a Representation element using an IdentifiableEntity
446 public void buildRepresentation(ElementImpl element
, IdentifiableEntity ie
)
447 throws ParseException
{
449 // create <Representation> element
450 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
451 element
.appendChild(representation
);
452 buildLabel(representation
, ie
.getTitleCache());
454 Set
<Annotation
> annotations
= ie
.getAnnotations();
455 Iterator iterator
= annotations
.iterator();
456 String detailText
= null;
457 if (iterator
.hasNext()) {
458 Annotation annotation
= (Annotation
) iterator
.next();
459 detailText
= annotation
.getText();
462 if (detailText
!= null && !detailText
.equals("")) {
463 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
464 detail
.appendChild(document
.createTextNode(detailText
));
465 representation
.appendChild(detail
);
468 if (ie
instanceof DefinedTermBase
) {
469 DefinedTermBase dtb
= (DefinedTermBase
) ie
;
470 Set
<Media
> rm
= dtb
.getMedia();
472 if (rm
!= null && rm
.size() > 0) {
473 ElementImpl mediaObject
;
475 for (int i
= 0; i
< rm
.size(); i
++) {
476 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
477 mediasCount
= buildReference((Media
) rm
.toArray()[i
],
478 medias
, REF
, mediaObject
, "m", mediasCount
);
479 representation
.appendChild(mediaObject
);
483 if (ie
instanceof IdentifiableMediaEntity
) {
484 IdentifiableMediaEntity ime
= (IdentifiableMediaEntity
) ie
;
485 Set
<Media
> medias
= ime
.getMedia();
486 if (medias
!= null) {
487 ElementImpl elLinks
= new ElementImpl(document
, "Links");
488 for (Iterator
<Media
> m
= medias
.iterator(); m
.hasNext();) {
489 Media media
= m
.next();
490 Set
<MediaRepresentation
> smr
= media
.getRepresentations();
491 for (Iterator
<MediaRepresentation
> mr
= smr
.iterator(); mr
493 MediaRepresentation mediarep
= mr
.next();
494 List
<MediaRepresentationPart
> lmrp
= mediarep
496 for (Iterator
<MediaRepresentationPart
> mrp
= lmrp
497 .iterator(); mrp
.hasNext();) {
498 MediaRepresentationPart mediareppart
= mrp
.next();
499 ElementImpl elLink
= new ElementImpl(document
,
501 elLink
.setAttribute("href", mediareppart
.getUri()
503 elLinks
.appendChild(elLink
);
507 element
.appendChild(elLinks
);
514 * Builds RevisionData associated with the Dataset
516 public void buildRevisionData(ElementImpl dataset
, IDatabase database
)
517 throws ParseException
{
521 // <Agent role="aut" ref="a1"/>
522 // <Agent role="aut" ref="a2"/>
523 // <Agent role="edt" ref="a3"/>
525 // <DateModified>2006-04-08T00:00:00</DateModified>
528 ElementImpl revisionData
= new ElementImpl(document
, REVISION_DATA
);
531 TeamOrPersonBase authors
= database
.getAuthorTeam();
532 // TeamOrPersonBase editors = database.getUpdatedBy();
534 if ((authors
!= null)) { // || (editors != null)) {
535 ElementImpl creators
= new ElementImpl(document
, CREATORS
);
536 if (authors
!= null) {
537 buildRefAgent(creators
, authors
, "aut");
539 // if (editors != null) {
540 // buildRefAgent(creators, editors, "edt");
542 revisionData
.appendChild(creators
);
545 buildDateModified(revisionData
, database
);
547 dataset
.appendChild(revisionData
);
551 * Builds ModifiedDate associated with RevisionData
553 public void buildDateModified(ElementImpl revisionData
, IDatabase database
)
554 throws ParseException
{
556 // <DateModified>2006-04-08T00:00:00</DateModified>
558 if (((Reference
) database
).getUpdated() != null) {
559 ElementImpl dateModified
= new ElementImpl(document
, DATE_MODIFIED
);
561 DateTime c
= ((Reference
) database
).getUpdated();
562 DateTimeFormatter fmt
= ISODateTimeFormat
.dateTime();
564 String date
= fmt
.print(c
);
565 dateModified
.appendChild(document
.createTextNode(date
));
567 revisionData
.appendChild(dateModified
);
573 * Builds IPRStatements associated with the Dataset
575 public void buildIPRStatements(ElementImpl dataset
, IDatabase database
)
576 throws ParseException
{
579 // <IPRStatement role="Copyright">
580 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional
585 if (database
.getRights() != null) {
586 // create IPRStatements
587 ElementImpl iprStatements
= new ElementImpl(document
,
589 dataset
.appendChild(iprStatements
);
591 // mapping between IPRStatement Copyright (SDD) and first Right in
592 // the list of Rights
593 ElementImpl iprStatement
= new ElementImpl(document
, IPR_STATEMENT
);
594 iprStatement
.setAttribute("role", "Copyright");
595 iprStatements
.appendChild(iprStatement
);
596 if (!database
.getRights().isEmpty()) {
597 buildLabel(iprStatement
, ((Rights
) database
.getRights()
598 .toArray()[0]).getText());
605 * Creates a Label element
610 public void buildLabel(ElementImpl element
, String text
) {
611 ElementImpl label
= new ElementImpl(document
, LABEL
);
612 label
.appendChild(document
.createTextNode(text
));
613 element
.appendChild(label
);
617 // # GENERIC BRICKS #
621 * Builds TaxonNames associated with the Dataset
623 public void buildTaxonNames(ElementImpl dataset
) throws ParseException
{
626 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
628 // <Label xml:lang="la">Viola hederacea Labill.</Label>
633 if (cdmSource
.getTaxonomicNames() != null) {
634 ElementImpl elTaxonNames
= new ElementImpl(document
, TAXON_NAMES
);
636 for (int i
= 0; i
< cdmSource
.getTaxonomicNames().size(); i
++) {
637 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
638 TaxonNameBase tnb
= cdmSource
.getTaxonomicNames().get(i
);
640 taxonNamesCount
= buildReference(tnb
, taxonNames
, ID
,
641 elTaxonName
, "t", taxonNamesCount
);
643 buildRepresentation(elTaxonName
, tnb
);
645 elTaxonNames
.appendChild(elTaxonName
);
648 dataset
.appendChild(elTaxonNames
);
653 public void buildDescriptiveConcepts(ElementImpl dataset
)
654 throws ParseException
{
656 if (cdmSource
.getFeatureData() != null) {
657 ElementImpl elFeatures
= new ElementImpl(document
,
658 DESCRIPTIVE_CONCEPTS
);
659 int f
= cdmSource
.getTerms().size();
660 for (int i
= 0; i
< f
; i
++) {
661 DefinedTermBase dtb
= cdmSource
.getTerms().get(i
);
662 if (dtb
instanceof Feature
) {
663 ElementImpl elFeat
= new ElementImpl(document
,
664 DESCRIPTIVE_CONCEPT
);
665 Feature feature
= (Feature
) dtb
;
666 if (feature
.getMarkers() != null) {
667 Set
<Marker
> markers
= feature
.getMarkers();
668 for (Iterator
<Marker
> m
= markers
.iterator(); m
670 Marker marker
= m
.next();
671 if (marker
.getMarkerType().getLabel()
672 .equals("DescriptiveConcept")) {
673 descriptiveConceptCount
= buildReference(dtb
,
674 descriptiveConcepts
, ID
, elFeat
, "dc",
675 descriptiveConceptCount
);
676 buildRepresentation(elFeat
, feature
);
678 .getRecommendedModifierEnumeration()
680 ElementImpl elModifiers
= new ElementImpl(
681 document
, "Modifiers");
682 for (Iterator
<TermVocabulary
<DefinedTerm
>> menum
= feature
683 .getRecommendedModifierEnumeration()
684 .iterator(); menum
.hasNext();) {
685 TermVocabulary
<DefinedTerm
> termVoc
= menum
.next();
686 Set
<DefinedTerm
> sm
= termVoc
.getTerms();
687 for (Iterator
<DefinedTerm
> modif
= sm
.iterator(); modif
.hasNext();) {
688 DefinedTerm modifier
= modif
.next();
689 ElementImpl elModifier
= new ElementImpl(
690 document
, "Modifier");
691 modifiersCount
= buildReference(
692 modifier
, modifiers
, ID
,
695 buildRepresentation(elModifier
,
697 elModifiers
.appendChild(elModifier
);
700 elFeat
.appendChild(elModifiers
);
702 elFeatures
.appendChild(elFeat
);
708 dataset
.appendChild(elFeatures
);
713 * Builds Characters associated with the Dataset
715 public void buildCharacters(ElementImpl dataset
) throws ParseException
{
717 if (cdmSource
.getTerms() != null) {
718 ElementImpl elCharacters
= new ElementImpl(document
, CHARACTERS
);
720 int f
= cdmSource
.getTerms().size();
721 for (int i
= 0; i
< f
; i
++) {
722 if (cdmSource
.getTerms().get(i
) instanceof Feature
) {
723 Feature character
= (Feature
) cdmSource
.getTerms().get(i
);
724 if (character
.isSupportsQuantitativeData()) {
725 ElementImpl elQuantitativeCharacter
= new ElementImpl(
726 document
, QUANTITATIVE_CHARACTER
);
727 charactersCount
= buildReference(character
, characters
,
728 ID
, elQuantitativeCharacter
, "c",
730 buildRepresentation(elQuantitativeCharacter
, character
);
731 elCharacters
.appendChild(elQuantitativeCharacter
);
734 if (character
.isSupportsCategoricalData()) {
735 ElementImpl elCategoricalCharacter
= new ElementImpl(
736 document
, CATEGORICAL_CHARACTER
);
737 charactersCount
= buildReference(character
, characters
,
738 ID
, elCategoricalCharacter
, "c",
740 buildRepresentation(elCategoricalCharacter
, character
);
742 Set
<TermVocabulary
<State
>> enumerations
= character
743 .getSupportedCategoricalEnumerations();
744 if (enumerations
!= null) {
745 if (enumerations
.size() > 0) {
746 ElementImpl elStates
= new ElementImpl(
748 TermVocabulary tv
= (TermVocabulary
) enumerations
750 Set
<State
> stateList
= tv
.getTerms();
751 for (int j
= 0; j
< stateList
.size(); j
++) {
752 ElementImpl elStateDefinition
= new ElementImpl(
753 document
, STATE_DEFINITION
);
754 State state
= (State
) stateList
.toArray()[j
];
755 statesCount
= buildReference(state
, states
,
756 ID
, elStateDefinition
, "s",
758 buildRepresentation(elStateDefinition
,
760 elStates
.appendChild(elStateDefinition
);
762 elCategoricalCharacter
.appendChild(elStates
);
764 .appendChild(elCategoricalCharacter
);
768 if (character
.isSupportsTextData()) {
769 ElementImpl elTextCharacter
= new ElementImpl(document
,
771 textcharactersCount
= buildReference(character
,
772 characters
, ID
, elTextCharacter
, TEXT
,
773 textcharactersCount
);
774 buildRepresentation(elTextCharacter
, character
);
775 elCharacters
.appendChild(elTextCharacter
);
780 dataset
.appendChild(elCharacters
);
785 public void buildCodedDescriptions(ElementImpl dataset
)
786 throws ParseException
{
788 if (cdmSource
.getTaxa() != null) {
789 ElementImpl elCodedDescriptions
= new ElementImpl(document
,
792 for (Iterator
<?
extends TaxonBase
> tb
= cdmSource
.getTaxa()
793 .iterator(); tb
.hasNext();) {
794 Taxon taxon
= (Taxon
) tb
.next();
795 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
796 for (Iterator
<TaxonDescription
> td
= descriptions
.iterator(); td
798 TaxonDescription taxonDescription
= td
.next();
799 ElementImpl elCodedDescription
= new ElementImpl(document
,
801 codedDescriptionsCount
= buildReference(taxonDescription
,
802 codedDescriptions
, ID
, elCodedDescription
, "D",
803 codedDescriptionsCount
);
804 buildRepresentation(elCodedDescription
, taxonDescription
);
805 buildScope(elCodedDescription
, taxonDescription
);
806 buildSummaryData(elCodedDescription
, taxonDescription
);
807 elCodedDescriptions
.appendChild(elCodedDescription
);
811 dataset
.appendChild(elCodedDescriptions
);
817 * Builds Scope associated with a CodedDescription
819 public void buildScope(ElementImpl element
,
820 TaxonDescription taxonDescription
) throws ParseException
{
823 // <TaxonName ref="t1"/>
824 // <Citation ref="p1" location="p. 30"/>
827 ElementImpl scope
= new ElementImpl(document
, SCOPE
);
829 Taxon taxon
= taxonDescription
.getTaxon();
831 TaxonNameBase taxonNameBase
= taxon
.getName();
832 if (taxonNameBase
!= null) {
833 String ref
= taxonNames
.get(taxonNameBase
);
834 if (!ref
.equals("")) {
835 ElementImpl taxonName
= new ElementImpl(document
,
837 taxonName
.setAttribute(REF
, ref
);
838 scope
.appendChild(taxonName
);
843 Set
<Reference
> descriptionSources
= new HashSet
<Reference
>();
844 for (IdentifiableSource source
: taxonDescription
.getSources()){
845 descriptionSources
.add(source
.getCitation());
847 for (Iterator
<Reference
> rb
= descriptionSources
.iterator(); rb
.hasNext();) {
848 Reference descriptionSource
= rb
.next();
849 if (descriptionSource
.getType().equals(ReferenceType
.Article
)) {
851 ElementImpl citation
= new ElementImpl(document
, CITATION
);
852 articlesCount
= buildReference(descriptionSource
, articles
,
853 REF
, citation
, "p", articlesCount
);
855 Set
<Annotation
> annotations
= descriptionSource
.getAnnotations();
856 for (Iterator
<Annotation
> a
= annotations
.iterator(); a
.hasNext();) {
857 Annotation annotation
= a
.next();
858 AnnotationType annotationType
= annotation
.getAnnotationType();
859 if (annotationType
!= null) {
860 String type
= annotationType
.getLabel();
861 if (type
.equals("location")) {
862 citation
.setAttribute("location",annotation
.getText());
867 scope
.appendChild(citation
);
871 element
.appendChild(scope
);
875 * Builds SummaryData associated with a CodedDescription
877 public void buildSummaryData(ElementImpl element
,
878 TaxonDescription taxonDescription
) throws ParseException
{
881 // <Categorical ref="c4">
886 ElementImpl summaryData
= new ElementImpl(document
, SUMMARY_DATA
);
887 Set
<DescriptionElementBase
> elements
= taxonDescription
.getElements();
888 for (Iterator
<DescriptionElementBase
> deb
= elements
.iterator(); deb
890 DescriptionElementBase descriptionElement
= deb
.next();
891 if (descriptionElement
instanceof CategoricalData
) {
892 CategoricalData categoricalData
= (CategoricalData
) descriptionElement
;
893 buildCategorical(summaryData
, categoricalData
);
895 if (descriptionElement
instanceof QuantitativeData
) {
896 QuantitativeData quantitativeData
= (QuantitativeData
) descriptionElement
;
897 buildQuantitative(summaryData
, quantitativeData
);
899 if (descriptionElement
instanceof TextData
) {
900 TextData textData
= (TextData
) descriptionElement
;
901 buildTextChar(summaryData
, textData
);
904 element
.appendChild(summaryData
);
908 * Builds Categorical associated with a SummaryData
910 public void buildCategorical(ElementImpl element
,
911 CategoricalData categoricalData
) throws ParseException
{
914 // <Categorical ref="c4">
919 ElementImpl categorical
= new ElementImpl(document
, CATEGORICAL
);
920 Feature feature
= categoricalData
.getFeature();
921 buildReference(feature
, characters
, REF
, categorical
, "c",
923 List
<StateData
> states
= categoricalData
.getStateData();
924 for (Iterator
<StateData
> sd
= states
.iterator(); sd
.hasNext();) {
925 StateData stateData
= sd
.next();
926 State s
= stateData
.getState();
927 buildState(categorical
, s
);
929 element
.appendChild(categorical
);
933 * Builds State associated with a Categorical
935 public void buildState(ElementImpl element
, State s
) throws ParseException
{
938 // <Categorical ref="c4">
943 ElementImpl state
= new ElementImpl(document
, STATE
);
944 buildReference(s
, states
, REF
, state
, "s", statesCount
);
945 element
.appendChild(state
);
949 * Builds Quantitative associated with a SummaryData
951 public void buildQuantitative(ElementImpl element
,
952 QuantitativeData quantitativeData
) throws ParseException
{
954 // <Quantitative ref="c2">
955 // <Measure type="Min" value="2.3"></Measure>
956 // <Measure type="Mean" value="5.1"/>
957 // <Measure type="Max" value="7.9"/>
958 // <Measure type="SD" value="1.3"/>
959 // <Measure type="N" value="20"/>
962 ElementImpl quantitative
= new ElementImpl(document
, QUANTITATIVE
);
963 Feature feature
= quantitativeData
.getFeature();
964 buildReference(feature
, characters
, REF
, quantitative
, "c",
966 Set
<StatisticalMeasurementValue
> statisticalValues
= quantitativeData
967 .getStatisticalValues();
968 for (Iterator
<StatisticalMeasurementValue
> smv
= statisticalValues
969 .iterator(); smv
.hasNext();) {
970 StatisticalMeasurementValue statisticalValue
= smv
.next();
971 buildMeasure(quantitative
, statisticalValue
);
973 element
.appendChild(quantitative
);
977 * Builds Measure associated with a Quantitative
979 public void buildMeasure(ElementImpl element
,
980 StatisticalMeasurementValue statisticalValue
) throws ParseException
{
982 // <Quantitative ref="c2">
983 // <Measure type="Min" value="2.3"></Measure>
984 // <Measure type="Mean" value="5.1"/>
985 // <Measure type="Max" value="7.9"/>
986 // <Measure type="SD" value="1.3"/>
987 // <Measure type="N" value="20"/>
990 ElementImpl measure
= new ElementImpl(document
, MEASURE
);
991 StatisticalMeasure type
= statisticalValue
.getType();
992 String label
= type
.getLabel();
993 if (label
.equals("Average")) {
994 measure
.setAttribute("type", "Mean");
995 } else if (label
.equals("StandardDeviation")) {
996 measure
.setAttribute("type", "SD");
997 } else if (label
.equals("SampleSize")) {
998 measure
.setAttribute("type", "N");
1000 measure
.setAttribute("type", label
);
1002 float value
= statisticalValue
.getValue();
1003 measure
.setAttribute("value", String
.valueOf(value
));
1004 element
.appendChild(measure
);
1008 * Builds TextChar associated with a SummaryData
1010 public void buildTextChar(ElementImpl element
, TextData textData
)
1011 throws ParseException
{
1013 // <TextChar ref="c3">
1014 // <Content>Free form text</Content>
1017 ElementImpl textChar
= new ElementImpl(document
, TEXT_CHAR
);
1018 Feature feature
= textData
.getFeature();
1019 buildReference(feature
, characters
, REF
, textChar
, "c", charactersCount
);
1020 Map
<Language
, LanguageString
> multilanguageText
= textData
1021 .getMultilanguageText();
1022 for (Language language
: multilanguageText
.keySet()) {
1023 LanguageString languageString
= multilanguageText
.get(language
);
1024 buildContent(textChar
, languageString
);
1026 element
.appendChild(textChar
);
1030 * Builds Content associated with a TextChar
1032 public void buildContent(ElementImpl element
, LanguageString languageString
)
1033 throws ParseException
{
1035 // <TextChar ref="c3">
1036 // <Content>Free form text</Content>
1039 ElementImpl content
= new ElementImpl(document
, CONTENT
);
1040 Language language
= languageString
.getLanguage();
1041 String text
= languageString
.getText();
1042 if (!language
.getIso639_1().equals(defaultLanguage
.getIso639_1())) {
1043 content
.setAttribute("xml:lang", language
.getIso639_1());
1045 content
.setTextContent(text
);
1046 element
.appendChild(content
);
1050 * Builds an element Agent referring to Agent defined later in the SDD file
1052 public void buildRefAgent(ElementImpl element
, TeamOrPersonBase ag
,
1053 String role
) throws ParseException
{
1054 if (ag
instanceof Person
) {
1055 Person p
= (Person
) ag
;
1056 ElementImpl agent
= new ElementImpl(document
, AGENT
);
1057 if (ag
.getMarkers() != null) {
1058 Set
<Marker
> markers
= ag
.getMarkers();
1059 for (Iterator
<Marker
> m
= markers
.iterator(); m
.hasNext();) {
1060 Marker marker
= m
.next();
1061 if (marker
.getMarkerType().getLabel().equals("editor")) {
1062 agent
.setAttribute(ROLE
, "edt");
1066 agent
.setAttribute(ROLE
, role
);
1068 agentsCount
= buildReference(p
, agents
, REF
, agent
, "a",
1070 element
.appendChild(agent
);
1073 if (ag
instanceof Team
) {
1074 Team team
= (Team
) ag
;
1075 for (int i
= 0; i
< team
.getTeamMembers().size(); i
++) {
1076 Person author
= team
.getTeamMembers().get(i
);
1077 ElementImpl agent
= new ElementImpl(document
, AGENT
);
1078 if (author
.getMarkers() != null) {
1079 Set
<Marker
> markers
= author
.getMarkers();
1080 if (!markers
.isEmpty()) {
1081 for (Iterator
<Marker
> m
= markers
.iterator(); m
1083 Marker marker
= m
.next();
1084 if (marker
.getMarkerType().getLabel()
1085 .equals("editor")) {
1086 agent
.setAttribute(ROLE
, "edt");
1090 agent
.setAttribute(ROLE
, role
);
1093 agent
.setAttribute(ROLE
, role
);
1095 if (author
.getSources() != null) {
1096 IdentifiableSource os
= (IdentifiableSource
) author
1097 .getSources().toArray()[0];
1098 String id
= os
.getIdInSource();
1100 if (!id
.equals("")) {
1101 if (!agents
.containsValue(id
)) {
1102 agent
.setAttribute(REF
, id
);
1103 } else if (!agents
.containsValue("a"
1104 + (agentsCount
+ 1))) {
1105 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1108 agent
.setAttribute(REF
, id
+ (agentsCount
+ 1));
1112 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1116 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1120 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1123 agents
.put(author
, agent
.getAttribute(REF
));
1124 element
.appendChild(agent
);
1130 * Builds Agents associated with the Dataset
1132 public void buildAgents(ElementImpl dataset
) throws ParseException
{
1134 if (cdmSource
.getAgents() != null) {
1135 ElementImpl elAgents
= new ElementImpl(document
, AGENTS
);
1137 for (int i
= 0; i
< cdmSource
.getAgents().size(); i
++) {
1138 ElementImpl elAgent
= new ElementImpl(document
, AGENT
);
1139 AgentBase personagent
= cdmSource
.getAgents().get(i
);
1140 if (personagent
instanceof Person
) {
1141 if (personagent
.getMarkers() != null) {
1142 Set
<Marker
> markers
= personagent
.getMarkers();
1143 for (Iterator
<Marker
> m
= markers
.iterator(); m
1145 Marker marker
= m
.next();
1146 if (marker
.getMarkerType().getLabel()
1147 .equals("editor")) {
1148 agentsCount
= buildReference(personagent
,
1149 agents
, ID
, elAgent
, "a", agentsCount
);
1153 agentsCount
= buildReference(personagent
, agents
, ID
,
1154 elAgent
, "a", agentsCount
);
1155 buildRepresentation(elAgent
, personagent
);
1156 elAgents
.appendChild(elAgent
);
1160 dataset
.appendChild(elAgents
);
1164 public void buildCharacterTrees(ElementImpl dataset
) throws ParseException
{
1166 if (cdmSource
.getFeatureData() != null) {
1167 ElementImpl elChartrees
= new ElementImpl(document
, CHARACTER_TREES
);
1169 for (int i
= 0; i
< cdmSource
.getFeatureData().size(); i
++) {
1170 VersionableEntity featu
= cdmSource
.getFeatureData().get(i
);
1171 if (featu
instanceof FeatureTree
) {
1172 FeatureTree ft
= (FeatureTree
) featu
;
1173 ElementImpl elChartree
= new ElementImpl(document
,
1175 chartreeCount
= buildReference(featu
, featuretrees
, ID
,
1176 elChartree
, "ct", chartreeCount
);
1177 buildRepresentation(elChartree
, ft
);
1178 elChartrees
.appendChild(elChartree
);
1179 ElementImpl elNodes
= new ElementImpl(document
, NODES
);
1180 elChartree
.appendChild(elNodes
);
1181 List
<FeatureNode
> roots
= ft
.getRootChildren();
1182 for (Iterator
<FeatureNode
> fn
= roots
.iterator(); fn
1184 FeatureNode featureNode
= fn
.next();
1185 buildBranches(featureNode
, elNodes
, true);
1189 dataset
.appendChild(elChartrees
);
1193 public void buildClassifications(ElementImpl dataset
) throws ParseException
{
1195 if (cdmSource
.getTaxa() != null) {
1196 ElementImpl elTaxonHierarchies
= new ElementImpl(document
,
1197 "TaxonHierarchies");
1198 ElementImpl elTaxonHierarchy
= new ElementImpl(document
,
1200 for (Iterator
<?
extends TaxonBase
> tb
= cdmSource
.getTaxa()
1201 .iterator(); tb
.hasNext();) {
1202 Taxon taxon
= (Taxon
) tb
.next();
1203 if (taxon
.getTaxonNodes() != null) {
1204 for (Iterator
<TaxonNode
> tn
= taxon
.getTaxonNodes()
1205 .iterator(); tn
.hasNext();) {
1206 TaxonNode taxonnode
= tn
.next();
1207 if (taxonnode
.isTopmostNode()) {
1208 ElementImpl elNode
= new ElementImpl(document
, "Node");
1209 taxonNodesCount
= buildReference(taxonnode
,
1210 taxonNodes
, ID
, elNode
, "tn", taxonNodesCount
);
1211 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
1212 taxonNamesCount
= buildReference(taxonnode
.getTaxon().getName(),
1213 taxonNames
, REF
, elTaxonName
, "t", taxonNamesCount
);
1214 elNode
.appendChild(elTaxonName
);
1215 elTaxonHierarchy
.appendChild(elNode
);
1216 if (taxonnode
.hasChildNodes()) {buildTaxonBranches(
1217 taxonnode
.getChildNodes(), taxonnode
, elTaxonHierarchy
);
1223 elTaxonHierarchies
.appendChild(elTaxonHierarchy
);
1224 dataset
.appendChild(elTaxonHierarchies
);
1228 private void buildTaxonBranches(List
<TaxonNode
> children
, TaxonNode parent
,
1229 ElementImpl elTaxonHierarchy
) {
1230 if (children
!= null) {
1231 for (Iterator
<TaxonNode
> tn
= children
.iterator(); tn
.hasNext();) {
1232 TaxonNode taxonnode
= tn
.next();
1233 ElementImpl elNode
= new ElementImpl(document
, "Node");
1234 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1235 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
1236 if (taxonnode
.hasChildNodes()) {
1237 buildTaxonBranches(taxonnode
.getChildNodes(), taxonnode
,
1240 taxonNodesCount
= buildReference(taxonnode
, taxonNodes
, ID
,
1241 elNode
, "tn", taxonNodesCount
);
1242 taxonNodesCount
= buildReference(parent
, taxonNodes
, REF
,
1243 elParent
, "tn", taxonNodesCount
);
1244 taxonNamesCount
= buildReference(
1245 taxonnode
.getTaxon().getName(), taxonNames
, REF
,
1246 elTaxonName
, "t", taxonNamesCount
);
1247 elNode
.appendChild(elParent
);
1248 elNode
.appendChild(elTaxonName
);
1249 elTaxonHierarchy
.appendChild(elNode
);
1254 public void buildBranches(FeatureNode parent
, ElementImpl element
,
1256 List
<FeatureNode
> children
= parent
.getChildNodes();
1257 if (!parent
.isLeaf()) {
1258 ElementImpl elCharNode
= new ElementImpl(document
, NODE
);
1259 charnodeCount
= buildReference(parent
, featuretrees
, ID
,
1260 elCharNode
, "cn", charnodeCount
);
1261 FeatureNode grandparent
= parent
.getParent();
1262 if ((grandparent
!= null) && (!isRoot
)) {
1263 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1264 charnodeCount
= buildReference(grandparent
, featuretrees
, REF
,
1265 elParent
, "cn", charnodeCount
);
1266 elCharNode
.appendChild(elParent
);
1268 ElementImpl elDescriptiveConcept
= new ElementImpl(document
,
1269 DESCRIPTIVE_CONCEPT
);
1270 Feature fref
= parent
.getFeature();
1271 descriptiveConceptCount
= buildReference(fref
, descriptiveConcepts
,
1272 REF
, elDescriptiveConcept
, "dc", descriptiveConceptCount
);
1273 elCharNode
.appendChild(elDescriptiveConcept
);
1274 element
.appendChild(elCharNode
);
1275 for (Iterator
<FeatureNode
> ifn
= children
.iterator(); ifn
.hasNext();) {
1276 FeatureNode fn
= ifn
.next();
1277 buildBranches(fn
, element
, false);
1280 ElementImpl elCharNode
= new ElementImpl(document
, CHAR_NODE
);
1281 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1282 FeatureNode grandparent
= parent
.getParent();
1283 charnodeCount
= buildReference(grandparent
, featuretrees
, REF
,
1284 elParent
, "cn", charnodeCount
);
1285 charnodeCount
= buildReference(parent
, featuretrees
, ID
,
1286 elCharNode
, "cn", charnodeCount
);
1287 ElementImpl elCharacter
= new ElementImpl(document
, CHARACTER
);
1288 Feature fref
= parent
.getFeature();
1289 boolean dependencies
= false;
1290 ElementImpl elDependecyRules
= new ElementImpl(document
,
1292 if (parent
.getInapplicableIf() != null) {
1293 Set
<State
> innaplicableIf
= parent
.getInapplicableIf();
1294 ElementImpl elInnaplicableIf
= new ElementImpl(document
,
1296 for (State state
: innaplicableIf
) {
1297 ElementImpl elState
= new ElementImpl(document
, STATE
);
1298 buildReference(state
, states
, REF
, elState
, "State",
1300 elInnaplicableIf
.appendChild(elState
);
1302 elDependecyRules
.appendChild(elInnaplicableIf
);
1303 dependencies
= true;
1305 if (parent
.getOnlyApplicableIf() != null) {
1306 Set
<State
> onlyApplicableIf
= parent
.getOnlyApplicableIf();
1307 ElementImpl elOnlyApplicableIf
= new ElementImpl(document
,
1308 "OnlyApplicableIf");
1309 for (State state
: onlyApplicableIf
) {
1310 ElementImpl elState
= new ElementImpl(document
, STATE
);
1311 buildReference(state
, states
, REF
, elState
, "State",
1313 elOnlyApplicableIf
.appendChild(elState
);
1315 elDependecyRules
.appendChild(elOnlyApplicableIf
);
1316 dependencies
= true;
1318 if (dependencies
== true)
1319 elCharNode
.appendChild(elDependecyRules
);
1320 charactersCount
= buildReference(fref
, characters
, REF
,
1321 elCharacter
, "c", charactersCount
);
1322 elCharNode
.appendChild(elCharacter
);
1323 elCharNode
.appendChild(elParent
);
1324 element
.appendChild(elCharNode
);
1328 public void buildMediaObjects(ElementImpl dataset
) throws ParseException
{
1330 if (cdmSource
.getMedia() != null) {
1331 ElementImpl elMediaObjects
= new ElementImpl(document
,
1334 for (int i
= 0; i
< cdmSource
.getMedia().size(); i
++) {
1335 ElementImpl elMediaObject
= new ElementImpl(document
,
1337 Media mediobj
= (Media
) cdmSource
.getMedia().get(i
);
1338 mediasCount
= buildReference(mediobj
, medias
, ID
,
1339 elMediaObject
, "t", mediasCount
);
1340 buildRepresentation(elMediaObject
, mediobj
);
1341 Set
<MediaRepresentation
> smr
= mediobj
.getRepresentations();
1342 for (Iterator
<MediaRepresentation
> mr
= smr
.iterator(); mr
1344 MediaRepresentation mediarep
= mr
.next();
1345 ElementImpl elType
= new ElementImpl(document
, "Type");
1346 elType
.appendChild(document
.createTextNode(mediarep
1348 elMediaObject
.appendChild(elType
);
1349 List
<MediaRepresentationPart
> lmrp
= mediarep
.getParts();
1350 for (Iterator
<MediaRepresentationPart
> mrp
= lmrp
1351 .iterator(); mrp
.hasNext();) {
1352 MediaRepresentationPart mediareppart
= mrp
.next();
1353 ElementImpl elSource
= new ElementImpl(document
,
1355 elSource
.setAttribute("href", mediareppart
.getUri()
1357 elMediaObject
.appendChild(elSource
);
1360 elMediaObjects
.appendChild(elMediaObject
);
1362 dataset
.appendChild(elMediaObjects
);
1366 public void buildPublications(ElementImpl dataset
) throws ParseException
{
1368 if (cdmSource
.getReferences() != null) {
1369 ElementImpl elPublications
= new ElementImpl(document
, PUBLICATIONS
);
1370 boolean editorial
= false;
1371 for (int i
= 0; i
< cdmSource
.getReferences().size(); i
++) {
1372 ElementImpl elPublication
= new ElementImpl(document
,
1374 Reference
<?
> publication
= cdmSource
.getReferences().get(i
);
1375 Set
<Annotation
> annotations
= publication
.getAnnotations();
1376 for (Iterator
<Annotation
> a
= annotations
.iterator(); a
1378 Annotation annotation
= a
.next();
1379 AnnotationType annotationType
= annotation
1380 .getAnnotationType();
1381 if (annotationType
!= null && annotationType
.equals(AnnotationType
.EDITORIAL())) {
1388 articlesCount
= buildReference(publication
, articles
, ID
,
1389 elPublication
, "p", articlesCount
);
1390 buildRepresentation(elPublication
, (IDatabase
) publication
);
1391 elPublications
.appendChild(elPublication
);
1394 dataset
.appendChild(elPublications
);
1398 public int buildReference(VersionableEntity ve
, Map references
,
1399 String refOrId
, ElementImpl element
, String prefix
, int count
)
1400 throws ParseException
{
1401 if (references
.containsKey(ve
)) {
1402 element
.setAttribute(refOrId
, (String
) references
.get(ve
));
1404 if (ve
instanceof IdentifiableEntity
) {
1405 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
1406 if (ie
.getSources().size() > 0) {
1407 IdentifiableSource os
= (IdentifiableSource
) ie
1408 .getSources().toArray()[0];
1409 String id
= os
.getIdInSource();
1410 String uri
= os
.getCitationMicroReference();
1412 element
.setAttribute(URI
, uri
);
1415 if (!id
.equals("")) {
1416 if (!references
.containsValue(id
)) {
1417 element
.setAttribute(refOrId
, id
);
1419 while (element
.getAttribute(refOrId
).equals("")) {
1420 if (!references
.containsValue(prefix
1422 element
.setAttribute(refOrId
, prefix
1428 while (element
.getAttribute(refOrId
).equals("")) {
1429 if (!references
.containsValue(prefix
1431 element
.setAttribute(refOrId
, prefix
1437 while (element
.getAttribute(refOrId
).equals("")) {
1438 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1439 element
.setAttribute(refOrId
, prefix
1445 while (element
.getAttribute(refOrId
).equals("")) {
1446 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1447 element
.setAttribute(refOrId
, prefix
+ (count
+ 1));
1452 while (element
.getAttribute(refOrId
).equals("")) {
1453 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1454 element
.setAttribute(refOrId
, prefix
+ (count
+ 1));
1458 references
.put(ve
, element
.getAttribute(refOrId
));
1463 public void buildGeographicAreas(ElementImpl dataset
) {
1464 if (cdmSource
.getTerms() != null) {
1465 ElementImpl elGeographicAreas
= new ElementImpl(document
,
1468 int f
= cdmSource
.getTerms().size();
1469 for (int i
= 0; i
< f
; i
++) {
1470 if (cdmSource
.getTerms().get(i
) instanceof NamedArea
) {
1471 NamedArea na
= (NamedArea
) cdmSource
.getTerms().get(i
);
1472 for (Iterator
<Marker
> mark
= na
.getMarkers().iterator(); mark
1474 Marker marker
= mark
.next();
1475 if (marker
.getMarkerType().getLabel()
1476 .equals("SDDGeographicArea")) {
1477 ElementImpl elGeographicArea
= new ElementImpl(
1478 document
, "GeographicArea");
1479 namedAreasCount
= buildReference(na
, namedAreas
,
1480 ID
, elGeographicArea
, "a", namedAreasCount
);
1481 buildRepresentation(elGeographicArea
, na
);
1482 elGeographicAreas
.appendChild(elGeographicArea
);
1488 dataset
.appendChild(elGeographicAreas
);
1492 public void buildSpecimens(ElementImpl dataset
) throws ParseException
{
1494 if (cdmSource
.getOccurrences() != null) {
1495 ElementImpl elSpecimens
= new ElementImpl(document
, "Specimens");
1497 for (int i
= 0; i
< cdmSource
.getOccurrences().size(); i
++) {
1498 ElementImpl elSpecimen
= new ElementImpl(document
, "Specimen");
1499 SpecimenOrObservationBase
<?
> sob
= cdmSource
.getOccurrences().get(i
);
1500 if (sob
.getRecordBasis().isPreservedSpecimen()) {
1501 specimenCount
= buildReference(sob
, specimens
, ID
, elSpecimen
, "s", specimenCount
);
1502 buildRepresentation(elSpecimen
, sob
);
1503 elSpecimens
.appendChild(elSpecimen
);
1506 dataset
.appendChild(elSpecimens
);