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
.OutputStream
;
16 import java
.io
.OutputStreamWriter
;
17 import java
.io
.Writer
;
18 import java
.util
.HashMap
;
19 import java
.util
.HashSet
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
25 import javax
.xml
.bind
.Marshaller
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.apache
.xerces
.dom
.DocumentImpl
;
29 import org
.apache
.xerces
.dom
.ElementImpl
;
30 import org
.apache
.xerces
.impl
.xpath
.regex
.ParseException
;
31 import org
.apache
.xml
.serialize
.DOMSerializer
;
32 import org
.apache
.xml
.serialize
.OutputFormat
;
33 import org
.apache
.xml
.serialize
.XMLSerializer
;
34 import org
.joda
.time
.DateTime
;
35 import org
.joda
.time
.format
.DateTimeFormatter
;
36 import org
.joda
.time
.format
.ISODateTimeFormat
;
37 import org
.springframework
.util
.ResourceUtils
;
38 import org
.xml
.sax
.SAXException
;
40 import eu
.etaxonomy
.cdm
.io
.jaxb
.CdmMarshallerListener
;
41 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
44 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
45 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
46 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
47 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
48 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
49 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
50 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
51 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
52 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
53 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
54 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
55 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
56 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
57 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
58 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
59 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
60 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
61 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
62 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
63 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
64 import eu
.etaxonomy
.cdm
.model
.description
.State
;
65 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
66 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
67 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
68 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
69 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
70 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
71 import eu
.etaxonomy
.cdm
.model
.media
.IdentifiableMediaEntity
;
72 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
73 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
74 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
75 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
76 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
77 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
78 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
79 import eu
.etaxonomy
.cdm
.model
.reference
.IDatabase
;
80 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
81 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
82 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
83 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
84 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
85 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
88 * Writes the SDD XML file.
95 public class SDDDocumentBuilder
{
97 private final DocumentImpl document
;
98 private XMLSerializer xmlserializer
;
99 private Writer writer
;
100 private DOMSerializer domi
;
101 private SDDDataSet cdmSource
;
103 private final Map
<Person
, String
> agents
= new HashMap
<Person
, String
>();
104 private final Map
<TaxonNameBase
<?
,?
>, String
> taxonNames
= new HashMap
<TaxonNameBase
<?
,?
>, String
>();
105 private final Map
<Feature
, String
> characters
= new HashMap
<Feature
, String
>();
106 private final Map
<FeatureNode
, String
> featureNodes
= new HashMap
<FeatureNode
, String
>();
107 private final Map
<Feature
, String
> descriptiveConcepts
= new HashMap
<Feature
, String
>();
108 private final Map
<TaxonDescription
, String
> codedDescriptions
= new HashMap
<TaxonDescription
, String
>();
109 private final Map
<Media
, String
> medias
= new HashMap
<Media
, String
>();
110 private final Map
<State
, String
> states
= new HashMap
<State
, String
>();
111 private final Map
<Reference
<?
>, String
> articles
= new HashMap
<Reference
<?
>, String
>();
112 private final Map
<VersionableEntity
, String
> featuretrees
= new HashMap
<VersionableEntity
, String
>();
113 private final Map
<DefinedTerm
, String
> modifiers
= new HashMap
<DefinedTerm
, String
>();
114 private final Map
<TaxonNode
, String
> taxonNodes
= new HashMap
<TaxonNode
, String
>();
115 private final Map
<NamedArea
, String
> namedAreas
= new HashMap
<NamedArea
, String
>();
116 private final Map
<DerivedUnit
, String
> specimens
= new HashMap
<DerivedUnit
, String
>();
118 private final Map
<VersionableEntity
, String
> features
= new HashMap
<VersionableEntity
, String
>();
119 private int agentsCount
= 0;
120 private int articlesCount
= 0;
121 private int codedDescriptionsCount
= 0;
122 private int taxonNamesCount
= 0;
123 private int charactersCount
= 0;
124 private int textcharactersCount
= 0;
125 private int mediasCount
= 0;
126 private int statesCount
= 0;
127 private final int featureNodesCount
= 0;
128 private int chartreeCount
= 0;
129 private int charnodeCount
= 0;
130 private int taxonNodesCount
= 0;
131 private int namedAreasCount
= 0;
132 private int specimenCount
= 0;
133 private int descriptiveConceptCount
= 0;
134 private int modifiersCount
= 0;
136 private final String AGENT
= "Agent";
137 private final String AGENTS
= "Agents";
138 private final String CATEGORICAL
= "Categorical";
139 private final String CATEGORICAL_CHARACTER
= "CategoricalCharacter";
140 private final String CHARACTER
= "Character";
141 private final String CHARACTERS
= "Characters";
142 private final String CHARACTER_TREE
= "CharacterTree";
143 private final String CHARACTER_TREES
= "CharacterTrees";
144 private final String CHAR_NODE
= "CharNode";
145 private final String CITATION
= "Citation";
146 private final String CODED_DESCRIPTION
= "CodedDescription";
147 private final String CODED_DESCRIPTIONS
= "CodedDescriptions";
148 private final String CONTENT
= "Content";
149 private final String CREATORS
= "Creators";
150 private final String DATASET
= "Dataset";
151 private final String DATASETS
= "Datasets";
152 private final String DATE_CREATED
= "DateCreated";
153 private final String DATE_MODIFIED
= "DateModified";
154 private final String DEPENDENCY_RULES
= "DependencyRules";
155 private final String DESCRIPTIVE_CONCEPT
= "DescriptiveConcept";
156 private final String DESCRIPTIVE_CONCEPTS
= "DescriptiveConcepts";
157 private final String DETAIL
= "Detail";
158 private final String GENERATOR
= "Generator";
159 private final String ID
= "id";
160 private final String IMAGE
= "Image";
161 private final String INAPPLICABLE_IF
= "InapplicableIf";
162 private final String IPR_STATEMENT
= "IPRStatement";
163 private final String IPR_STATEMENTS
= "IPRStatements";
164 private final String LABEL
= "Label";
165 private final String MEASURE
= "Measure";
166 private final String MEDIA_OBJECT
= "MediaObject";
167 private final String MEDIA_OBJECTS
= "MediaObjects";
168 private final String NODE
= "Node";
169 private final String NODES
= "Nodes";
170 private final String NOTE
= "Note";
171 private final String PARENT
= "Parent";
172 private final String PUBLICATIONS
= "Publications";
173 private final String QUANTITATIVE
= "Quantitative";
174 private final String QUANTITATIVE_CHARACTER
= "QuantitativeCharacter";
175 private final String REF
= "ref";
176 private final String REPRESENTATION
= "Representation";
177 private final String REVISION_DATA
= "RevisionData";
178 private final String ROLE
= "role";
179 private final String SCOPE
= "Scope";
180 private final String SHOULD_CONTAIN_ALL_CHARACTERS
= "ShouldContainAllCharacters";
181 private final String SOURCE
= "Source";
182 private final String STATE
= "State";
183 private final String STATE_DEFINITION
= "StateDefinition";
184 private final String STATES
= "States";
185 private final String STATUS
= "Status";
186 private final String SUMMARY_DATA
= "SummaryData";
187 private final String TAXON_NAME
= "TaxonName";
188 private final String TAXON_NAMES
= "TaxonNames";
189 private final String TECHNICAL_METADATA
= "TechnicalMetadata";
190 private final String TEXT
= "text";
191 private final String TEXT_CHAR
= "TextChar";
192 private final String TEXT_CHARACTER
= "TextCharacter";
193 private final String TYPE
= "Type";
194 private final String URI
= "uri";
196 private final Language defaultLanguage
= Language
.DEFAULT();
198 private static final Logger logger
= Logger
199 .getLogger(SDDDocumentBuilder
.class);
201 private final String NEWLINE
= System
.getProperty("line.separator");
203 public SDDDocumentBuilder() throws SAXException
, IOException
{
205 document
= new DocumentImpl();
209 public void marshal(SDDDataSet cdmSource
, File sddDestination
)
212 this.cdmSource
= cdmSource
;
213 Marshaller marshaller
;
214 CdmMarshallerListener marshallerListener
= new CdmMarshallerListener();
215 logger
.info("Start marshalling");
216 writeCDMtoSDD(sddDestination
);
220 public void marshal(SDDDataSet cdmSource
, String sddDestinationFileName
)
223 this.cdmSource
= cdmSource
;
224 Marshaller marshaller
;
225 CdmMarshallerListener marshallerListener
= new CdmMarshallerListener();
226 logger
.info("Start marshalling");
227 writeCDMtoSDD(ResourceUtils
.getFile(sddDestinationFileName
));
231 public void marshal(SDDDataSet dataSet
, OutputStream stream
) throws IOException
{
232 this.cdmSource
= dataSet
;
233 logger
.info("Start marshalling");
236 } catch (ParseException e
) {
240 OutputFormat format
= new OutputFormat(document
, "UTF-8", true);
242 writer
= new OutputStreamWriter(stream
, "UTF-8");
244 xmlserializer
= new XMLSerializer(writer
, format
);
245 domi
= xmlserializer
.asDOMSerializer(); // As a DOM Serializer
247 domi
.serialize(document
.getDocumentElement());
252 * Write the DOM document.
255 * @throws IOException
257 public void writeCDMtoSDD(File sddDestination
) throws IOException
{
261 } catch (ParseException e
) {
265 OutputFormat format
= new OutputFormat(document
, "UTF-8", true);
267 FileOutputStream fos
= new FileOutputStream(sddDestination
);
269 writer
= new OutputStreamWriter(fos
, "UTF-8");
271 xmlserializer
= new XMLSerializer(writer
, format
);
272 domi
= xmlserializer
.asDOMSerializer(); // As a DOM Serializer
274 domi
.serialize(document
.getDocumentElement());
284 * Builds the whole document.
288 * @throws ParseException
290 public void buildDocument() throws ParseException
{
292 // create <Datasets> = root node
293 ElementImpl baselement
= new ElementImpl(document
, DATASETS
);
294 baselement
.setAttribute("xmlns:xsi",
295 "http://www.w3.org/2001/XMLSchema-instance");
296 baselement
.setAttribute("xmlns", "http://rs.tdwg.org/UBIF/2006/");
298 .setAttribute("xsi:schemaLocation",
299 "http://rs.tdwg.org/UBIF/2006 http://rs.tdwg.org/UBIF/2006/Schema/1.1/SDD.xsd");
301 buildTechnicalMetadata(baselement
);
303 List
<Reference
> references
= cdmSource
.getReferences();
304 Iterator
<Reference
> iterator
= references
.iterator();
305 IDatabase d
= ReferenceFactory
.newDatabase();
306 while (iterator
.hasNext()) {
307 Reference
<?
> reference
= iterator
.next();
308 if (reference
.getType().equals(ReferenceType
.Database
)) {
309 buildDataset(baselement
, reference
);
312 document
.appendChild(baselement
);
320 * Builds TechnicalMetadata associated with the SDD file
322 public void buildTechnicalMetadata(ElementImpl baselement
)
323 throws ParseException
{
324 // create TechnicalMetadata
325 ElementImpl technicalMetadata
= new ElementImpl(document
,
327 // select different databases associated to different descriptions TODO
328 List
<Reference
> references
= cdmSource
.getReferences();
329 Iterator
<Reference
> iterator
= references
.iterator();
330 boolean database
= false;
331 IDatabase d
= ReferenceFactory
.newDatabase();
332 while ((iterator
.hasNext()) && (!database
)) {
333 Reference
<?
> reference
= iterator
.next();
334 if (reference
.getType().equals(ReferenceType
.Database
)) {
338 DateTime dt
= d
.getCreated();
339 String date
= dt
.toString().substring(0, 19);
340 technicalMetadata
.setAttribute("created", date
);
342 ElementImpl generator
= new ElementImpl(document
, GENERATOR
);
343 generator
.setAttribute("name", "EDIT CDM");
344 generator
.setAttribute("version", "v1");
348 "This SDD file has been generated by the SDD export functionality of the EDIT platform for Cybertaxonomy - Copyright (c) 2008");
349 technicalMetadata
.appendChild(generator
);
351 baselement
.appendChild(technicalMetadata
);
354 // Builds the information associated with a dataset
355 public void buildDataset(ElementImpl baselement
, IDatabase reference
)
356 throws ParseException
{
357 // create Dataset and language
358 ElementImpl dataset
= new ElementImpl(document
, DATASET
);
359 // no default language associated with a dataset in the CDM
360 dataset
.setAttribute("xml:lang", Language
.DEFAULT().getIso639_1());
361 baselement
.appendChild(dataset
);
362 buildRepresentation(dataset
, reference
);
363 buildRevisionData(dataset
, reference
);
364 buildIPRStatements(dataset
, reference
);
365 buildTaxonNames(dataset
);
366 buildDescriptiveConcepts(dataset
);
367 buildCharacters(dataset
);
368 buildCodedDescriptions(dataset
);
369 buildAgents(dataset
);
370 buildPublications(dataset
);
371 buildMediaObjects(dataset
);
372 buildCharacterTrees(dataset
);
373 buildClassifications(dataset
);
374 buildGeographicAreas(dataset
);
375 buildSpecimens(dataset
);
379 * Builds a Representation element using a Reference
381 public void buildRepresentation(ElementImpl element
, IDatabase reference
)
382 throws ParseException
{
384 // create <Representation> element
385 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
386 element
.appendChild(representation
);
387 buildLabel(representation
, reference
.getTitleCache());
389 Set
<Annotation
> annotations
= ((Reference
) reference
).getAnnotations();
390 Iterator
<Annotation
> iterator
= annotations
.iterator();
391 String detailText
= null;
392 if (iterator
.hasNext()) {
393 Annotation annotation
= iterator
.next();
394 detailText
= annotation
.getText();
397 if (detailText
!= null && !detailText
.equals("")) {
398 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
399 detail
.appendChild(document
.createTextNode(detailText
));
400 representation
.appendChild(detail
);
403 Set
<Media
> rm
= ((Reference
) reference
).getMedia();
405 if (rm
!= null && rm
.size() > 0) {
406 ElementImpl mediaObject
;
408 for (int i
= 0; i
< rm
.size(); i
++) {
409 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
410 mediasCount
= buildReference((Media
) rm
.toArray()[i
], medias
,
411 REF
, mediaObject
, "m", mediasCount
);
412 representation
.appendChild(mediaObject
);
419 * Builds a Representation element using a Feature
421 public void buildRepresentation(ElementImpl element
, TermBase tb
)
422 throws ParseException
{
424 // create <Representation> element
425 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
426 element
.appendChild(representation
);
428 Set
<Representation
> representations
= tb
.getRepresentations();
429 if (representations
!= null) {
430 if (!representations
.isEmpty()) {
431 String label
= ((Representation
) representations
.toArray()[0])
433 buildLabel(representation
, label
);
434 String detailText
= tb
.getDescription();
436 if (detailText
!= null && !detailText
.equals("")) {
437 if (!detailText
.equals(label
)) {
438 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
439 detail
.appendChild(document
.createTextNode(detailText
));
440 representation
.appendChild(detail
);
447 if (tb
instanceof DefinedTermBase
) {
448 DefinedTermBase dtb
= (DefinedTermBase
) tb
;
449 Set
<Media
> rm
= dtb
.getMedia();
451 if (rm
!= null && rm
.size() > 0) {
452 ElementImpl mediaObject
;
454 for (int i
= 0; i
< rm
.size(); i
++) {
455 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
456 mediasCount
= buildReference((Media
) rm
.toArray()[i
],
457 medias
, REF
, mediaObject
, "m", mediasCount
);
458 representation
.appendChild(mediaObject
);
465 * Builds a Representation element using an IdentifiableEntity
467 public void buildRepresentation(ElementImpl element
, IdentifiableEntity ie
)
468 throws ParseException
{
470 // create <Representation> element
471 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
472 element
.appendChild(representation
);
473 buildLabel(representation
, ie
.getTitleCache());
475 Set
<Annotation
> annotations
= ie
.getAnnotations();
476 Iterator iterator
= annotations
.iterator();
477 String detailText
= null;
478 if (iterator
.hasNext()) {
479 Annotation annotation
= (Annotation
) iterator
.next();
480 detailText
= annotation
.getText();
483 if (detailText
!= null && !detailText
.equals("")) {
484 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
485 detail
.appendChild(document
.createTextNode(detailText
));
486 representation
.appendChild(detail
);
489 if (ie
instanceof DefinedTermBase
) {
490 DefinedTermBase dtb
= (DefinedTermBase
) ie
;
491 Set
<Media
> rm
= dtb
.getMedia();
493 if (rm
!= null && rm
.size() > 0) {
494 ElementImpl mediaObject
;
496 for (int i
= 0; i
< rm
.size(); i
++) {
497 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
498 mediasCount
= buildReference((Media
) rm
.toArray()[i
],
499 medias
, REF
, mediaObject
, "m", mediasCount
);
500 representation
.appendChild(mediaObject
);
504 if (ie
instanceof IdentifiableMediaEntity
) {
505 IdentifiableMediaEntity ime
= (IdentifiableMediaEntity
) ie
;
506 Set
<Media
> medias
= ime
.getMedia();
507 if (medias
!= null) {
508 ElementImpl elLinks
= new ElementImpl(document
, "Links");
509 for (Iterator
<Media
> m
= medias
.iterator(); m
.hasNext();) {
510 Media media
= m
.next();
511 Set
<MediaRepresentation
> smr
= media
.getRepresentations();
512 for (Iterator
<MediaRepresentation
> mr
= smr
.iterator(); mr
514 MediaRepresentation mediarep
= mr
.next();
515 List
<MediaRepresentationPart
> lmrp
= mediarep
517 for (Iterator
<MediaRepresentationPart
> mrp
= lmrp
518 .iterator(); mrp
.hasNext();) {
519 MediaRepresentationPart mediareppart
= mrp
.next();
520 ElementImpl elLink
= new ElementImpl(document
,
522 elLink
.setAttribute("href", mediareppart
.getUri()
524 elLinks
.appendChild(elLink
);
528 element
.appendChild(elLinks
);
535 * Builds RevisionData associated with the Dataset
537 public void buildRevisionData(ElementImpl dataset
, IDatabase database
)
538 throws ParseException
{
542 // <Agent role="aut" ref="a1"/>
543 // <Agent role="aut" ref="a2"/>
544 // <Agent role="edt" ref="a3"/>
546 // <DateModified>2006-04-08T00:00:00</DateModified>
549 ElementImpl revisionData
= new ElementImpl(document
, REVISION_DATA
);
552 TeamOrPersonBase authors
= database
.getAuthorship();
553 // TeamOrPersonBase editors = database.getUpdatedBy();
555 if ((authors
!= null)) { // || (editors != null)) {
556 ElementImpl creators
= new ElementImpl(document
, CREATORS
);
557 if (authors
!= null) {
558 buildRefAgent(creators
, authors
, "aut");
560 // if (editors != null) {
561 // buildRefAgent(creators, editors, "edt");
563 revisionData
.appendChild(creators
);
566 buildDateModified(revisionData
, database
);
568 dataset
.appendChild(revisionData
);
572 * Builds ModifiedDate associated with RevisionData
574 public void buildDateModified(ElementImpl revisionData
, IDatabase database
)
575 throws ParseException
{
577 // <DateModified>2006-04-08T00:00:00</DateModified>
579 if (((Reference
) database
).getUpdated() != null) {
580 ElementImpl dateModified
= new ElementImpl(document
, DATE_MODIFIED
);
582 DateTime c
= ((Reference
) database
).getUpdated();
583 DateTimeFormatter fmt
= ISODateTimeFormat
.dateTime();
585 String date
= fmt
.print(c
);
586 dateModified
.appendChild(document
.createTextNode(date
));
588 revisionData
.appendChild(dateModified
);
594 * Builds IPRStatements associated with the Dataset
596 public void buildIPRStatements(ElementImpl dataset
, IDatabase database
)
597 throws ParseException
{
600 // <IPRStatement role="Copyright">
601 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional
606 if (database
.getRights() != null) {
607 // create IPRStatements
608 ElementImpl iprStatements
= new ElementImpl(document
,
610 dataset
.appendChild(iprStatements
);
612 // mapping between IPRStatement Copyright (SDD) and first Right in
613 // the list of Rights
614 ElementImpl iprStatement
= new ElementImpl(document
, IPR_STATEMENT
);
615 iprStatement
.setAttribute("role", "Copyright");
616 iprStatements
.appendChild(iprStatement
);
617 if (!database
.getRights().isEmpty()) {
618 buildLabel(iprStatement
, ((Rights
) database
.getRights()
619 .toArray()[0]).getText());
626 * Creates a Label element
631 public void buildLabel(ElementImpl element
, String text
) {
632 ElementImpl label
= new ElementImpl(document
, LABEL
);
633 label
.appendChild(document
.createTextNode(text
));
634 element
.appendChild(label
);
638 // # GENERIC BRICKS #
642 * Builds TaxonNames associated with the Dataset
644 public void buildTaxonNames(ElementImpl dataset
) throws ParseException
{
647 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
649 // <Label xml:lang="la">Viola hederacea Labill.</Label>
654 if (cdmSource
.getTaxonomicNames() != null) {
655 ElementImpl elTaxonNames
= new ElementImpl(document
, TAXON_NAMES
);
657 for (int i
= 0; i
< cdmSource
.getTaxonomicNames().size(); i
++) {
658 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
659 TaxonNameBase tnb
= cdmSource
.getTaxonomicNames().get(i
);
661 taxonNamesCount
= buildReference(tnb
, taxonNames
, ID
,
662 elTaxonName
, "t", taxonNamesCount
);
664 buildRepresentation(elTaxonName
, tnb
);
666 elTaxonNames
.appendChild(elTaxonName
);
669 dataset
.appendChild(elTaxonNames
);
674 public void buildDescriptiveConcepts(ElementImpl dataset
)
675 throws ParseException
{
677 if (cdmSource
.getFeatureData() != null) {
678 ElementImpl elFeatures
= new ElementImpl(document
,
679 DESCRIPTIVE_CONCEPTS
);
680 int f
= cdmSource
.getTerms().size();
681 for (int i
= 0; i
< f
; i
++) {
682 DefinedTermBase dtb
= cdmSource
.getTerms().get(i
);
683 if (dtb
instanceof Feature
) {
684 ElementImpl elFeat
= new ElementImpl(document
,
685 DESCRIPTIVE_CONCEPT
);
686 Feature feature
= (Feature
) dtb
;
687 if (feature
.getMarkers() != null) {
688 Set
<Marker
> markers
= feature
.getMarkers();
689 for (Iterator
<Marker
> m
= markers
.iterator(); m
691 Marker marker
= m
.next();
692 if (marker
.getMarkerType().getLabel()
693 .equals("DescriptiveConcept")) {
694 descriptiveConceptCount
= buildReference(dtb
,
695 descriptiveConcepts
, ID
, elFeat
, "dc",
696 descriptiveConceptCount
);
697 buildRepresentation(elFeat
, feature
);
699 .getRecommendedModifierEnumeration()
701 ElementImpl elModifiers
= new ElementImpl(
702 document
, "Modifiers");
703 for (Iterator
<TermVocabulary
<DefinedTerm
>> menum
= feature
704 .getRecommendedModifierEnumeration()
705 .iterator(); menum
.hasNext();) {
706 TermVocabulary
<DefinedTerm
> termVoc
= menum
.next();
707 Set
<DefinedTerm
> sm
= termVoc
.getTerms();
708 for (Iterator
<DefinedTerm
> modif
= sm
.iterator(); modif
.hasNext();) {
709 DefinedTerm modifier
= modif
.next();
710 ElementImpl elModifier
= new ElementImpl(
711 document
, "Modifier");
712 modifiersCount
= buildReference(
713 modifier
, modifiers
, ID
,
716 buildRepresentation(elModifier
,
718 elModifiers
.appendChild(elModifier
);
721 elFeat
.appendChild(elModifiers
);
723 elFeatures
.appendChild(elFeat
);
729 dataset
.appendChild(elFeatures
);
734 * Builds Characters associated with the Dataset
736 public void buildCharacters(ElementImpl dataset
) throws ParseException
{
738 if (cdmSource
.getTerms() != null) {
739 ElementImpl elCharacters
= new ElementImpl(document
, CHARACTERS
);
741 int f
= cdmSource
.getTerms().size();
742 for (int i
= 0; i
< f
; i
++) {
743 if (cdmSource
.getTerms().get(i
) instanceof Feature
) {
744 Feature character
= (Feature
) cdmSource
.getTerms().get(i
);
745 if (character
.isSupportsQuantitativeData()) {
746 ElementImpl elQuantitativeCharacter
= new ElementImpl(
747 document
, QUANTITATIVE_CHARACTER
);
748 charactersCount
= buildReference(character
, characters
,
749 ID
, elQuantitativeCharacter
, "c",
751 buildRepresentation(elQuantitativeCharacter
, character
);
752 elCharacters
.appendChild(elQuantitativeCharacter
);
755 if (character
.isSupportsCategoricalData()) {
756 ElementImpl elCategoricalCharacter
= new ElementImpl(
757 document
, CATEGORICAL_CHARACTER
);
758 charactersCount
= buildReference(character
, characters
,
759 ID
, elCategoricalCharacter
, "c",
761 buildRepresentation(elCategoricalCharacter
, character
);
763 Set
<TermVocabulary
<State
>> enumerations
= character
764 .getSupportedCategoricalEnumerations();
765 if (enumerations
!= null) {
766 if (enumerations
.size() > 0) {
767 ElementImpl elStates
= new ElementImpl(
769 TermVocabulary tv
= (TermVocabulary
) enumerations
771 Set
<State
> stateList
= tv
.getTerms();
772 for (int j
= 0; j
< stateList
.size(); j
++) {
773 ElementImpl elStateDefinition
= new ElementImpl(
774 document
, STATE_DEFINITION
);
775 State state
= (State
) stateList
.toArray()[j
];
776 statesCount
= buildReference(state
, states
,
777 ID
, elStateDefinition
, "s",
779 buildRepresentation(elStateDefinition
,
781 elStates
.appendChild(elStateDefinition
);
783 elCategoricalCharacter
.appendChild(elStates
);
785 .appendChild(elCategoricalCharacter
);
789 if (character
.isSupportsTextData()) {
790 ElementImpl elTextCharacter
= new ElementImpl(document
,
792 textcharactersCount
= buildReference(character
,
793 characters
, ID
, elTextCharacter
, TEXT
,
794 textcharactersCount
);
795 buildRepresentation(elTextCharacter
, character
);
796 elCharacters
.appendChild(elTextCharacter
);
801 dataset
.appendChild(elCharacters
);
806 public void buildCodedDescriptions(ElementImpl dataset
)
807 throws ParseException
{
809 if (cdmSource
.getTaxa() != null) {
810 ElementImpl elCodedDescriptions
= new ElementImpl(document
,
813 for (Iterator
<?
extends TaxonBase
> tb
= cdmSource
.getTaxa()
814 .iterator(); tb
.hasNext();) {
815 Taxon taxon
= (Taxon
) tb
.next();
816 Set
<TaxonDescription
> descriptions
= taxon
.getDescriptions();
817 for (Iterator
<TaxonDescription
> td
= descriptions
.iterator(); td
819 TaxonDescription taxonDescription
= td
.next();
820 ElementImpl elCodedDescription
= new ElementImpl(document
,
822 codedDescriptionsCount
= buildReference(taxonDescription
,
823 codedDescriptions
, ID
, elCodedDescription
, "D",
824 codedDescriptionsCount
);
825 buildRepresentation(elCodedDescription
, taxonDescription
);
826 buildScope(elCodedDescription
, taxonDescription
);
827 buildSummaryData(elCodedDescription
, taxonDescription
);
828 elCodedDescriptions
.appendChild(elCodedDescription
);
832 dataset
.appendChild(elCodedDescriptions
);
838 * Builds Scope associated with a CodedDescription
840 public void buildScope(ElementImpl element
,
841 TaxonDescription taxonDescription
) throws ParseException
{
844 // <TaxonName ref="t1"/>
845 // <Citation ref="p1" location="p. 30"/>
848 ElementImpl scope
= new ElementImpl(document
, SCOPE
);
850 Taxon taxon
= taxonDescription
.getTaxon();
852 TaxonNameBase taxonNameBase
= taxon
.getName();
853 if (taxonNameBase
!= null) {
854 String ref
= taxonNames
.get(taxonNameBase
);
855 if (!ref
.equals("")) {
856 ElementImpl taxonName
= new ElementImpl(document
,
858 taxonName
.setAttribute(REF
, ref
);
859 scope
.appendChild(taxonName
);
864 Set
<Reference
> descriptionSources
= new HashSet
<Reference
>();
865 for (IdentifiableSource source
: taxonDescription
.getSources()){
866 descriptionSources
.add(source
.getCitation());
868 for (Iterator
<Reference
> rb
= descriptionSources
.iterator(); rb
.hasNext();) {
869 Reference descriptionSource
= rb
.next();
870 if (descriptionSource
.getType().equals(ReferenceType
.Article
)) {
872 ElementImpl citation
= new ElementImpl(document
, CITATION
);
873 articlesCount
= buildReference(descriptionSource
, articles
,
874 REF
, citation
, "p", articlesCount
);
876 Set
<Annotation
> annotations
= descriptionSource
.getAnnotations();
877 for (Iterator
<Annotation
> a
= annotations
.iterator(); a
.hasNext();) {
878 Annotation annotation
= a
.next();
879 AnnotationType annotationType
= annotation
.getAnnotationType();
880 if (annotationType
!= null) {
881 String type
= annotationType
.getLabel();
882 if (type
.equals("location")) {
883 citation
.setAttribute("location",annotation
.getText());
888 scope
.appendChild(citation
);
892 element
.appendChild(scope
);
896 * Builds SummaryData associated with a CodedDescription
898 public void buildSummaryData(ElementImpl element
,
899 TaxonDescription taxonDescription
) throws ParseException
{
902 // <Categorical ref="c4">
907 ElementImpl summaryData
= new ElementImpl(document
, SUMMARY_DATA
);
908 Set
<DescriptionElementBase
> elements
= taxonDescription
.getElements();
909 for (Iterator
<DescriptionElementBase
> deb
= elements
.iterator(); deb
911 DescriptionElementBase descriptionElement
= deb
.next();
912 if (descriptionElement
instanceof CategoricalData
) {
913 CategoricalData categoricalData
= (CategoricalData
) descriptionElement
;
914 buildCategorical(summaryData
, categoricalData
);
916 if (descriptionElement
instanceof QuantitativeData
) {
917 QuantitativeData quantitativeData
= (QuantitativeData
) descriptionElement
;
918 buildQuantitative(summaryData
, quantitativeData
);
920 if (descriptionElement
instanceof TextData
) {
921 TextData textData
= (TextData
) descriptionElement
;
922 buildTextChar(summaryData
, textData
);
925 element
.appendChild(summaryData
);
929 * Builds Categorical associated with a SummaryData
931 public void buildCategorical(ElementImpl element
,
932 CategoricalData categoricalData
) throws ParseException
{
935 // <Categorical ref="c4">
940 ElementImpl categorical
= new ElementImpl(document
, CATEGORICAL
);
941 Feature feature
= categoricalData
.getFeature();
942 buildReference(feature
, characters
, REF
, categorical
, "c",
944 List
<StateData
> states
= categoricalData
.getStateData();
945 for (Iterator
<StateData
> sd
= states
.iterator(); sd
.hasNext();) {
946 StateData stateData
= sd
.next();
947 State s
= stateData
.getState();
948 buildState(categorical
, s
);
950 element
.appendChild(categorical
);
954 * Builds State associated with a Categorical
956 public void buildState(ElementImpl element
, State s
) throws ParseException
{
959 // <Categorical ref="c4">
964 ElementImpl state
= new ElementImpl(document
, STATE
);
965 buildReference(s
, states
, REF
, state
, "s", statesCount
);
966 element
.appendChild(state
);
970 * Builds Quantitative associated with a SummaryData
972 public void buildQuantitative(ElementImpl element
,
973 QuantitativeData quantitativeData
) throws ParseException
{
975 // <Quantitative ref="c2">
976 // <Measure type="Min" value="2.3"></Measure>
977 // <Measure type="Mean" value="5.1"/>
978 // <Measure type="Max" value="7.9"/>
979 // <Measure type="SD" value="1.3"/>
980 // <Measure type="N" value="20"/>
983 ElementImpl quantitative
= new ElementImpl(document
, QUANTITATIVE
);
984 Feature feature
= quantitativeData
.getFeature();
985 buildReference(feature
, characters
, REF
, quantitative
, "c",
987 Set
<StatisticalMeasurementValue
> statisticalValues
= quantitativeData
988 .getStatisticalValues();
989 for (Iterator
<StatisticalMeasurementValue
> smv
= statisticalValues
990 .iterator(); smv
.hasNext();) {
991 StatisticalMeasurementValue statisticalValue
= smv
.next();
992 buildMeasure(quantitative
, statisticalValue
);
994 element
.appendChild(quantitative
);
998 * Builds Measure associated with a Quantitative
1000 public void buildMeasure(ElementImpl element
,
1001 StatisticalMeasurementValue statisticalValue
) throws ParseException
{
1003 // <Quantitative ref="c2">
1004 // <Measure type="Min" value="2.3"></Measure>
1005 // <Measure type="Mean" value="5.1"/>
1006 // <Measure type="Max" value="7.9"/>
1007 // <Measure type="SD" value="1.3"/>
1008 // <Measure type="N" value="20"/>
1011 ElementImpl measure
= new ElementImpl(document
, MEASURE
);
1012 StatisticalMeasure type
= statisticalValue
.getType();
1013 String label
= type
.getLabel();
1014 if (label
.equals("Average")) {
1015 measure
.setAttribute("type", "Mean");
1016 } else if (label
.equals("StandardDeviation")) {
1017 measure
.setAttribute("type", "SD");
1018 } else if (label
.equals("SampleSize")) {
1019 measure
.setAttribute("type", "N");
1021 measure
.setAttribute("type", label
);
1023 float value
= statisticalValue
.getValue();
1024 measure
.setAttribute("value", String
.valueOf(value
));
1025 element
.appendChild(measure
);
1029 * Builds TextChar associated with a SummaryData
1031 public void buildTextChar(ElementImpl element
, TextData textData
)
1032 throws ParseException
{
1034 // <TextChar ref="c3">
1035 // <Content>Free form text</Content>
1038 ElementImpl textChar
= new ElementImpl(document
, TEXT_CHAR
);
1039 Feature feature
= textData
.getFeature();
1040 buildReference(feature
, characters
, REF
, textChar
, "c", charactersCount
);
1041 Map
<Language
, LanguageString
> multilanguageText
= textData
1042 .getMultilanguageText();
1043 for (Language language
: multilanguageText
.keySet()) {
1044 LanguageString languageString
= multilanguageText
.get(language
);
1045 buildContent(textChar
, languageString
);
1047 element
.appendChild(textChar
);
1051 * Builds Content associated with a TextChar
1053 public void buildContent(ElementImpl element
, LanguageString languageString
)
1054 throws ParseException
{
1056 // <TextChar ref="c3">
1057 // <Content>Free form text</Content>
1060 ElementImpl content
= new ElementImpl(document
, CONTENT
);
1061 Language language
= languageString
.getLanguage();
1062 String text
= languageString
.getText();
1063 if (!language
.getIso639_1().equals(defaultLanguage
.getIso639_1())) {
1064 content
.setAttribute("xml:lang", language
.getIso639_1());
1066 content
.setTextContent(text
);
1067 element
.appendChild(content
);
1071 * Builds an element Agent referring to Agent defined later in the SDD file
1073 public void buildRefAgent(ElementImpl element
, TeamOrPersonBase ag
,
1074 String role
) throws ParseException
{
1075 if (ag
instanceof Person
) {
1076 Person p
= (Person
) ag
;
1077 ElementImpl agent
= new ElementImpl(document
, AGENT
);
1078 if (ag
.getMarkers() != null) {
1079 Set
<Marker
> markers
= ag
.getMarkers();
1080 for (Iterator
<Marker
> m
= markers
.iterator(); m
.hasNext();) {
1081 Marker marker
= m
.next();
1082 if (marker
.getMarkerType().getLabel().equals("editor")) {
1083 agent
.setAttribute(ROLE
, "edt");
1087 agent
.setAttribute(ROLE
, role
);
1089 agentsCount
= buildReference(p
, agents
, REF
, agent
, "a",
1091 element
.appendChild(agent
);
1094 if (ag
instanceof Team
) {
1095 Team team
= (Team
) ag
;
1096 for (int i
= 0; i
< team
.getTeamMembers().size(); i
++) {
1097 Person author
= team
.getTeamMembers().get(i
);
1098 ElementImpl agent
= new ElementImpl(document
, AGENT
);
1099 if (author
.getMarkers() != null) {
1100 Set
<Marker
> markers
= author
.getMarkers();
1101 if (!markers
.isEmpty()) {
1102 for (Iterator
<Marker
> m
= markers
.iterator(); m
1104 Marker marker
= m
.next();
1105 if (marker
.getMarkerType().getLabel()
1106 .equals("editor")) {
1107 agent
.setAttribute(ROLE
, "edt");
1111 agent
.setAttribute(ROLE
, role
);
1114 agent
.setAttribute(ROLE
, role
);
1116 if (author
.getSources() != null) {
1117 IdentifiableSource os
= (IdentifiableSource
) author
1118 .getSources().toArray()[0];
1119 String id
= os
.getIdInSource();
1121 if (!id
.equals("")) {
1122 if (!agents
.containsValue(id
)) {
1123 agent
.setAttribute(REF
, id
);
1124 } else if (!agents
.containsValue("a"
1125 + (agentsCount
+ 1))) {
1126 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1129 agent
.setAttribute(REF
, id
+ (agentsCount
+ 1));
1133 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1137 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1141 agent
.setAttribute(REF
, "a" + (agentsCount
+ 1));
1144 agents
.put(author
, agent
.getAttribute(REF
));
1145 element
.appendChild(agent
);
1151 * Builds Agents associated with the Dataset
1153 public void buildAgents(ElementImpl dataset
) throws ParseException
{
1155 if (cdmSource
.getAgents() != null) {
1156 ElementImpl elAgents
= new ElementImpl(document
, AGENTS
);
1158 for (int i
= 0; i
< cdmSource
.getAgents().size(); i
++) {
1159 ElementImpl elAgent
= new ElementImpl(document
, AGENT
);
1160 AgentBase personagent
= cdmSource
.getAgents().get(i
);
1161 if (personagent
instanceof Person
) {
1162 if (personagent
.getMarkers() != null) {
1163 Set
<Marker
> markers
= personagent
.getMarkers();
1164 for (Iterator
<Marker
> m
= markers
.iterator(); m
1166 Marker marker
= m
.next();
1167 if (marker
.getMarkerType().getLabel()
1168 .equals("editor")) {
1169 agentsCount
= buildReference(personagent
,
1170 agents
, ID
, elAgent
, "a", agentsCount
);
1174 agentsCount
= buildReference(personagent
, agents
, ID
,
1175 elAgent
, "a", agentsCount
);
1176 buildRepresentation(elAgent
, personagent
);
1177 elAgents
.appendChild(elAgent
);
1181 dataset
.appendChild(elAgents
);
1185 public void buildCharacterTrees(ElementImpl dataset
) throws ParseException
{
1187 if (cdmSource
.getFeatureData() != null) {
1188 ElementImpl elChartrees
= new ElementImpl(document
, CHARACTER_TREES
);
1190 for (int i
= 0; i
< cdmSource
.getFeatureData().size(); i
++) {
1191 VersionableEntity featu
= cdmSource
.getFeatureData().get(i
);
1192 if (featu
instanceof FeatureTree
) {
1193 FeatureTree ft
= (FeatureTree
) featu
;
1194 ElementImpl elChartree
= new ElementImpl(document
,
1196 chartreeCount
= buildReference(featu
, featuretrees
, ID
,
1197 elChartree
, "ct", chartreeCount
);
1198 buildRepresentation(elChartree
, ft
);
1199 elChartrees
.appendChild(elChartree
);
1200 ElementImpl elNodes
= new ElementImpl(document
, NODES
);
1201 elChartree
.appendChild(elNodes
);
1202 List
<FeatureNode
> roots
= ft
.getRootChildren();
1203 for (Iterator
<FeatureNode
> fn
= roots
.iterator(); fn
1205 FeatureNode featureNode
= fn
.next();
1206 buildBranches(featureNode
, elNodes
, true);
1210 dataset
.appendChild(elChartrees
);
1214 public void buildClassifications(ElementImpl dataset
) throws ParseException
{
1216 if (cdmSource
.getTaxa() != null) {
1217 ElementImpl elTaxonHierarchies
= new ElementImpl(document
,
1218 "TaxonHierarchies");
1219 ElementImpl elTaxonHierarchy
= new ElementImpl(document
,
1221 for (Iterator
<?
extends TaxonBase
> tb
= cdmSource
.getTaxa()
1222 .iterator(); tb
.hasNext();) {
1223 Taxon taxon
= (Taxon
) tb
.next();
1224 if (taxon
.getTaxonNodes() != null) {
1225 for (Iterator
<TaxonNode
> tn
= taxon
.getTaxonNodes()
1226 .iterator(); tn
.hasNext();) {
1227 TaxonNode taxonnode
= tn
.next();
1228 if (taxonnode
.isTopmostNode()) {
1229 ElementImpl elNode
= new ElementImpl(document
, "Node");
1230 taxonNodesCount
= buildReference(taxonnode
,
1231 taxonNodes
, ID
, elNode
, "tn", taxonNodesCount
);
1232 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
1233 taxonNamesCount
= buildReference(taxonnode
.getTaxon().getName(),
1234 taxonNames
, REF
, elTaxonName
, "t", taxonNamesCount
);
1235 elNode
.appendChild(elTaxonName
);
1236 elTaxonHierarchy
.appendChild(elNode
);
1237 if (taxonnode
.hasChildNodes()) {buildTaxonBranches(
1238 taxonnode
.getChildNodes(), taxonnode
, elTaxonHierarchy
);
1244 elTaxonHierarchies
.appendChild(elTaxonHierarchy
);
1245 dataset
.appendChild(elTaxonHierarchies
);
1249 private void buildTaxonBranches(List
<TaxonNode
> children
, TaxonNode parent
,
1250 ElementImpl elTaxonHierarchy
) {
1251 if (children
!= null) {
1252 for (Iterator
<TaxonNode
> tn
= children
.iterator(); tn
.hasNext();) {
1253 TaxonNode taxonnode
= tn
.next();
1254 ElementImpl elNode
= new ElementImpl(document
, "Node");
1255 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1256 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
1257 if (taxonnode
.hasChildNodes()) {
1258 buildTaxonBranches(taxonnode
.getChildNodes(), taxonnode
,
1261 taxonNodesCount
= buildReference(taxonnode
, taxonNodes
, ID
,
1262 elNode
, "tn", taxonNodesCount
);
1263 taxonNodesCount
= buildReference(parent
, taxonNodes
, REF
,
1264 elParent
, "tn", taxonNodesCount
);
1265 taxonNamesCount
= buildReference(
1266 taxonnode
.getTaxon().getName(), taxonNames
, REF
,
1267 elTaxonName
, "t", taxonNamesCount
);
1268 elNode
.appendChild(elParent
);
1269 elNode
.appendChild(elTaxonName
);
1270 elTaxonHierarchy
.appendChild(elNode
);
1275 public void buildBranches(FeatureNode parent
, ElementImpl element
,
1277 List
<FeatureNode
> children
= parent
.getChildNodes();
1278 if (!parent
.isLeaf()) {
1279 ElementImpl elCharNode
= new ElementImpl(document
, NODE
);
1280 charnodeCount
= buildReference(parent
, featuretrees
, ID
,
1281 elCharNode
, "cn", charnodeCount
);
1282 FeatureNode grandparent
= parent
.getParent();
1283 if ((grandparent
!= null) && (!isRoot
)) {
1284 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1285 charnodeCount
= buildReference(grandparent
, featuretrees
, REF
,
1286 elParent
, "cn", charnodeCount
);
1287 elCharNode
.appendChild(elParent
);
1289 ElementImpl elDescriptiveConcept
= new ElementImpl(document
,
1290 DESCRIPTIVE_CONCEPT
);
1291 Feature fref
= parent
.getFeature();
1292 descriptiveConceptCount
= buildReference(fref
, descriptiveConcepts
,
1293 REF
, elDescriptiveConcept
, "dc", descriptiveConceptCount
);
1294 elCharNode
.appendChild(elDescriptiveConcept
);
1295 element
.appendChild(elCharNode
);
1296 for (Iterator
<FeatureNode
> ifn
= children
.iterator(); ifn
.hasNext();) {
1297 FeatureNode fn
= ifn
.next();
1298 buildBranches(fn
, element
, false);
1301 ElementImpl elCharNode
= new ElementImpl(document
, CHAR_NODE
);
1302 ElementImpl elParent
= new ElementImpl(document
, PARENT
);
1303 FeatureNode grandparent
= parent
.getParent();
1304 charnodeCount
= buildReference(grandparent
, featuretrees
, REF
,
1305 elParent
, "cn", charnodeCount
);
1306 charnodeCount
= buildReference(parent
, featuretrees
, ID
,
1307 elCharNode
, "cn", charnodeCount
);
1308 ElementImpl elCharacter
= new ElementImpl(document
, CHARACTER
);
1309 Feature fref
= parent
.getFeature();
1310 boolean dependencies
= false;
1311 ElementImpl elDependecyRules
= new ElementImpl(document
,
1313 if (parent
.getInapplicableIf() != null) {
1314 Set
<State
> innaplicableIf
= parent
.getInapplicableIf();
1315 ElementImpl elInnaplicableIf
= new ElementImpl(document
,
1317 for (State state
: innaplicableIf
) {
1318 ElementImpl elState
= new ElementImpl(document
, STATE
);
1319 buildReference(state
, states
, REF
, elState
, "State",
1321 elInnaplicableIf
.appendChild(elState
);
1323 elDependecyRules
.appendChild(elInnaplicableIf
);
1324 dependencies
= true;
1326 if (parent
.getOnlyApplicableIf() != null) {
1327 Set
<State
> onlyApplicableIf
= parent
.getOnlyApplicableIf();
1328 ElementImpl elOnlyApplicableIf
= new ElementImpl(document
,
1329 "OnlyApplicableIf");
1330 for (State state
: onlyApplicableIf
) {
1331 ElementImpl elState
= new ElementImpl(document
, STATE
);
1332 buildReference(state
, states
, REF
, elState
, "State",
1334 elOnlyApplicableIf
.appendChild(elState
);
1336 elDependecyRules
.appendChild(elOnlyApplicableIf
);
1337 dependencies
= true;
1339 if (dependencies
== true) {
1340 elCharNode
.appendChild(elDependecyRules
);
1342 charactersCount
= buildReference(fref
, characters
, REF
,
1343 elCharacter
, "c", charactersCount
);
1344 elCharNode
.appendChild(elCharacter
);
1345 elCharNode
.appendChild(elParent
);
1346 element
.appendChild(elCharNode
);
1350 public void buildMediaObjects(ElementImpl dataset
) throws ParseException
{
1352 if (cdmSource
.getMedia() != null) {
1353 ElementImpl elMediaObjects
= new ElementImpl(document
,
1356 for (int i
= 0; i
< cdmSource
.getMedia().size(); i
++) {
1357 ElementImpl elMediaObject
= new ElementImpl(document
,
1359 Media mediobj
= (Media
) cdmSource
.getMedia().get(i
);
1360 mediasCount
= buildReference(mediobj
, medias
, ID
,
1361 elMediaObject
, "t", mediasCount
);
1362 buildRepresentation(elMediaObject
, mediobj
);
1363 Set
<MediaRepresentation
> smr
= mediobj
.getRepresentations();
1364 for (Iterator
<MediaRepresentation
> mr
= smr
.iterator(); mr
1366 MediaRepresentation mediarep
= mr
.next();
1367 ElementImpl elType
= new ElementImpl(document
, "Type");
1368 elType
.appendChild(document
.createTextNode(mediarep
1370 elMediaObject
.appendChild(elType
);
1371 List
<MediaRepresentationPart
> lmrp
= mediarep
.getParts();
1372 for (Iterator
<MediaRepresentationPart
> mrp
= lmrp
1373 .iterator(); mrp
.hasNext();) {
1374 MediaRepresentationPart mediareppart
= mrp
.next();
1375 ElementImpl elSource
= new ElementImpl(document
,
1377 elSource
.setAttribute("href", mediareppart
.getUri()
1379 elMediaObject
.appendChild(elSource
);
1382 elMediaObjects
.appendChild(elMediaObject
);
1384 dataset
.appendChild(elMediaObjects
);
1388 public void buildPublications(ElementImpl dataset
) throws ParseException
{
1390 if (cdmSource
.getReferences() != null) {
1391 ElementImpl elPublications
= new ElementImpl(document
, PUBLICATIONS
);
1392 boolean editorial
= false;
1393 for (int i
= 0; i
< cdmSource
.getReferences().size(); i
++) {
1394 ElementImpl elPublication
= new ElementImpl(document
,
1396 Reference
<?
> publication
= cdmSource
.getReferences().get(i
);
1397 Set
<Annotation
> annotations
= publication
.getAnnotations();
1398 for (Iterator
<Annotation
> a
= annotations
.iterator(); a
1400 Annotation annotation
= a
.next();
1401 AnnotationType annotationType
= annotation
1402 .getAnnotationType();
1403 if (annotationType
!= null && annotationType
.equals(AnnotationType
.EDITORIAL())) {
1410 articlesCount
= buildReference(publication
, articles
, ID
,
1411 elPublication
, "p", articlesCount
);
1412 buildRepresentation(elPublication
, (IDatabase
) publication
);
1413 elPublications
.appendChild(elPublication
);
1416 dataset
.appendChild(elPublications
);
1420 public int buildReference(VersionableEntity ve
, Map references
,
1421 String refOrId
, ElementImpl element
, String prefix
, int count
)
1422 throws ParseException
{
1423 if (references
.containsKey(ve
)) {
1424 element
.setAttribute(refOrId
, (String
) references
.get(ve
));
1426 if (ve
instanceof IdentifiableEntity
) {
1427 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
1428 if (ie
.getSources().size() > 0) {
1429 IdentifiableSource os
= (IdentifiableSource
) ie
1430 .getSources().toArray()[0];
1431 String id
= os
.getIdInSource();
1432 String uri
= os
.getCitationMicroReference();
1434 element
.setAttribute(URI
, uri
);
1437 if (!id
.equals("")) {
1438 if (!references
.containsValue(id
)) {
1439 element
.setAttribute(refOrId
, id
);
1441 while (element
.getAttribute(refOrId
).equals("")) {
1442 if (!references
.containsValue(prefix
1444 element
.setAttribute(refOrId
, prefix
1451 while (element
.getAttribute(refOrId
).equals("")) {
1452 if (!references
.containsValue(prefix
1454 element
.setAttribute(refOrId
, prefix
1461 while (element
.getAttribute(refOrId
).equals("")) {
1462 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1463 element
.setAttribute(refOrId
, prefix
1470 while (element
.getAttribute(refOrId
).equals("")) {
1471 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1472 element
.setAttribute(refOrId
, prefix
+ (count
+ 1));
1478 while (element
.getAttribute(refOrId
).equals("")) {
1479 if (!references
.containsValue(prefix
+ (count
+ 1))) {
1480 element
.setAttribute(refOrId
, prefix
+ (count
+ 1));
1485 references
.put(ve
, element
.getAttribute(refOrId
));
1490 public void buildGeographicAreas(ElementImpl dataset
) {
1491 if (cdmSource
.getTerms() != null) {
1492 ElementImpl elGeographicAreas
= new ElementImpl(document
,
1495 int f
= cdmSource
.getTerms().size();
1496 for (int i
= 0; i
< f
; i
++) {
1497 if (cdmSource
.getTerms().get(i
) instanceof NamedArea
) {
1498 NamedArea na
= (NamedArea
) cdmSource
.getTerms().get(i
);
1499 for (Iterator
<Marker
> mark
= na
.getMarkers().iterator(); mark
1501 Marker marker
= mark
.next();
1502 if (marker
.getMarkerType().getLabel()
1503 .equals("SDDGeographicArea")) {
1504 ElementImpl elGeographicArea
= new ElementImpl(
1505 document
, "GeographicArea");
1506 namedAreasCount
= buildReference(na
, namedAreas
,
1507 ID
, elGeographicArea
, "a", namedAreasCount
);
1508 buildRepresentation(elGeographicArea
, na
);
1509 elGeographicAreas
.appendChild(elGeographicArea
);
1515 dataset
.appendChild(elGeographicAreas
);
1519 public void buildSpecimens(ElementImpl dataset
) throws ParseException
{
1521 if (cdmSource
.getOccurrences() != null) {
1522 ElementImpl elSpecimens
= new ElementImpl(document
, "Specimens");
1524 for (int i
= 0; i
< cdmSource
.getOccurrences().size(); i
++) {
1525 ElementImpl elSpecimen
= new ElementImpl(document
, "Specimen");
1526 SpecimenOrObservationBase
<?
> sob
= cdmSource
.getOccurrences().get(i
);
1527 if (sob
.getRecordBasis().isPreservedSpecimen()) {
1528 specimenCount
= buildReference(sob
, specimens
, ID
, elSpecimen
, "s", specimenCount
);
1529 buildRepresentation(elSpecimen
, sob
);
1530 elSpecimens
.appendChild(elSpecimen
);
1533 dataset
.appendChild(elSpecimens
);