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
;
13 import java
.io
.FileOutputStream
;
14 import java
.io
.IOException
;
15 import java
.io
.OutputStreamWriter
;
16 import java
.io
.Writer
;
17 import java
.text
.SimpleDateFormat
;
18 import java
.util
.Date
;
19 import java
.util
.HashMap
;
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
.joda
.time
.DateTime
;
29 import org
.xml
.sax
.SAXException
;
31 import org
.apache
.xerces
.dom
.DocumentImpl
;
32 //import com.sun.org.apache.xerces.internal.dom.ElementImpl;
33 import com
.sun
.org
.apache
.xerces
.internal
.impl
.xpath
.regex
.ParseException
;
34 import com
.sun
.org
.apache
.xml
.internal
.serialize
.DOMSerializer
;
35 import com
.sun
.org
.apache
.xml
.internal
.serialize
.OutputFormat
;
36 import com
.sun
.org
.apache
.xml
.internal
.serialize
.XMLSerializer
;
38 import org
.apache
.xerces
.dom
.ElementImpl
;
41 import eu
.etaxonomy
.cdm
.io
.jaxb
.CdmMarshallerListener
;
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
.DefinedTermBase
;
47 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
48 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSource
;
49 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
50 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
51 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
52 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
53 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
54 import eu
.etaxonomy
.cdm
.model
.description
.State
;
55 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
56 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
57 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
58 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
59 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
62 * Writes the SDD XML file.
69 public class SDDDocumentBuilder
{
71 private DocumentImpl document
;
72 private XMLSerializer xmlserializer
;
73 private Writer writer
;
74 private DOMSerializer domi
;
75 private SDDDataSet cdmSource
;
77 private Map
<Person
,String
> agents
= new HashMap
<Person
,String
>();
78 private Map
<TaxonNameBase
,String
> taxonNames
= new HashMap
<TaxonNameBase
,String
>();
79 private Map
<Feature
,String
> characters
= new HashMap
<Feature
,String
>();
80 private Map
<Media
,String
> medias
= new HashMap
<Media
,String
>();
81 private Map
<State
,String
> states
= new HashMap
<State
,String
>();
82 private int agentsCount
= 0;
83 private int taxonNamesCount
= 0;
84 private int charactersCount
= 0;
85 private int mediasCount
= 0;
86 private int statesCount
= 0;
88 private String AGENT
= "Agent";
89 private String AGENTS
= "Agents";
90 private String CATEGORICAL
= "Categorical";
91 private String CATEGORICAL_CHARACTER
= "CategoricalCharacter";
92 private String CHARACTER
= "Character";
93 private String CHARACTERS
= "Characters";
94 private String CHARACTER_TREE
= "CharacterTree";
95 private String CHARACTER_TREES
= "CharacterTrees";
96 private String CHAR_NODE
= "CharNode";
97 private String CODED_DESCRIPTION
= "CodedDescription";
98 private String CODED_DESCRIPTIONS
= "CodedDescriptions";
99 private String CREATORS
= "Creators";
100 private String DATASET
= "Dataset";
101 private String DATASETS
= "Datasets";
102 private String DATE_CREATED
= "DateCreated";
103 private String DATE_MODIFIED
= "DateModified";
104 private String DEPENDENCY_RULES
= "DependencyRules";
105 private String DESCRIPTIVE_CONCEPT
= "DescriptiveConcept";
106 private String DESCRIPTIVE_CONCEPTS
= "DescriptiveConcepts";
107 private String DETAIL
= "Detail";
108 private String GENERATOR
= "Generator";
109 private String ID
= "id";
110 private String IMAGE
= "Image";
111 private String INAPPLICABLE_IF
= "InapplicableIf";
112 private String IPR_STATEMENT
= "IPRStatement";
113 private String IPR_STATEMENTS
= "IPRStatements";
114 private String LABEL
= "Label";
115 private String MEDIA_OBJECT
= "MediaObject";
116 private String MEDIA_OBJECTS
= "MediaObjects";
117 private String NODE
= "Node";
118 private String NODES
= "Nodes";
119 private String NOTE
= "Note";
120 private String PARENT
= "Parent";
121 private String QUANTITATIVE_CHARACTER
= "QuantitativeCharacter";
122 private String REF
= "ref";
123 private String REPRESENTATION
= "Representation";
124 private String REVISION_DATA
= "RevisionData";
125 private String ROLE
= "role";
126 private String SHOULD_CONTAIN_ALL_CHARACTERS
= "ShouldContainAllCharacters";
127 private String SOURCE
= "Source";
128 private String STATE
= "State";
129 private String STATE_DEFINITION
= "StateDefinition";
130 private String STATES
= "States";
131 private String STATUS
= "Status";
132 private String SUMMARY_DATA
= "SummaryData";
133 private String TAXON_NAME
= "TaxonName";
134 private String TAXON_NAMES
= "TaxonNames";
135 private String TECHNICAL_METADATA
= "TechnicalMetadata";
136 private String TEXT
= "Text";
137 private String TEXT_CHARACTER
= "TextCharacter";
138 private String TYPE
= "Type";
139 private String URI
= "uri";
141 private static final Logger logger
= Logger
.getLogger(SDDDocumentBuilder
.class);
143 // private SDDContext sddContext;
145 public SDDDocumentBuilder() throws SAXException
, IOException
{
147 document
= new DocumentImpl();
149 // sddContext = SDDContext.newInstance(new Class[] {SDDDataSet.class});
150 // logger.debug(sddContext.toString());
154 public void marshal(SDDDataSet cdmSource
, File sddDestination
) throws IOException
{
156 this.cdmSource
= cdmSource
;
157 Marshaller marshaller
;
158 CdmMarshallerListener marshallerListener
= new CdmMarshallerListener();
159 logger
.info("Start marshalling");
160 writeCDMtoSDD(sddDestination
);
164 /**Write the DOM document.
166 * @throws IOException
168 public void writeCDMtoSDD(File sddDestination
) throws IOException
{
172 } catch (ParseException e
) {
173 System
.out
.println("Problem with SDD export located in the buildDocument() method ...");
177 OutputFormat format
= new OutputFormat(document
, "UTF-8", true);
179 FileOutputStream fos
= new FileOutputStream(sddDestination
);
181 writer
= new OutputStreamWriter(fos
, "UTF-8");
183 xmlserializer
= new XMLSerializer(writer
, format
);
184 domi
= xmlserializer
.asDOMSerializer(); // As a DOM Serializer
186 domi
.serialize(document
.getDocumentElement());
196 * Builds the whole document.
197 * @param base the Base
198 * @throws ParseException
200 public void buildDocument() throws ParseException
{
202 //create <Datasets> = root node
203 ElementImpl baselement
= new ElementImpl(document
, DATASETS
);
205 baselement
.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
206 baselement
.setAttribute("xmlns", "http://rs.tdwg.org/UBIF/2006/");
207 baselement
.setAttribute("xsi:schemaLocation", "http://rs.tdwg.org/UBIF/2006 http://rs.tdwg.org/UBIF/2006/Schema/1.1/SDD.xsd");
209 buildTechnicalMetadata(baselement
);
211 List
<ReferenceBase
> references
= cdmSource
.getReferences();
212 Iterator
<ReferenceBase
> iterator
= references
.iterator();
213 Database d
= Database
.NewInstance();
214 while (iterator
.hasNext()) {
215 ReferenceBase reference
= (ReferenceBase
) iterator
.next();
216 if (reference
instanceof Database
) {
217 buildDataset(baselement
, (Database
) reference
);
221 // for datasets with no Database ReferenceBase
222 // buildDataset(baselement, cdmSource, null);
224 //append the root element to the DOM document
225 document
.appendChild(baselement
);
233 * Builds TechnicalMetadata associated with the SDD file
235 public void buildTechnicalMetadata(ElementImpl baselement
) throws ParseException
{
236 //create TechnicalMetadata
237 ElementImpl technicalMetadata
= new ElementImpl(document
, TECHNICAL_METADATA
);
238 //select different databases associated to different descriptions TODO
239 List
<ReferenceBase
> references
= cdmSource
.getReferences();
240 Iterator
<ReferenceBase
> iterator
= references
.iterator();
241 boolean database
= false;
242 Database d
= Database
.NewInstance();
243 while ((iterator
.hasNext()) && (!database
)) {
244 ReferenceBase reference
= (ReferenceBase
) iterator
.next();
245 if (reference
instanceof Database
) {
246 d
= (Database
) reference
;
249 DateTime dt
= d
.getCreated();
250 String date
= dt
.toString().substring(0, 19);
251 technicalMetadata
.setAttribute("created", date
);
253 ElementImpl generator
= new ElementImpl(document
, GENERATOR
);
254 generator
.setAttribute("name", "EDIT CDM");
255 generator
.setAttribute("version", "v1");
256 generator
.setAttribute("notes","This SDD file has been generated by the SDD export functionality of the EDIT platform for Cybertaxonomy - Copyright (c) 2008");
257 technicalMetadata
.appendChild(generator
);
259 baselement
.appendChild(technicalMetadata
);
262 // Builds the information associated with a dataset
263 public void buildDataset(ElementImpl baselement
, Database reference
) throws ParseException
{
264 // create Dataset and language
265 ElementImpl dataset
= new ElementImpl(document
, DATASET
);
266 // no default language associated with a dataset in the CDM
267 // dataset.setAttribute("xml:lang", datasetLanguage);
268 baselement
.appendChild(dataset
);
269 buildRepresentation(dataset
, reference
);
270 buildRevisionData(dataset
, reference
);
271 buildIPRStatements(dataset
, reference
);
272 buildTaxonNames(dataset
);
273 buildCharacters(dataset
);
278 * Builds a Representation element using a ReferenceBase
280 public void buildRepresentation(ElementImpl element
, ReferenceBase reference
) throws ParseException
{
282 // create <Representation> element
283 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
284 element
.appendChild(representation
);
285 buildLabel(representation
, reference
.getTitleCache());
287 Set
<Annotation
> annotations
= reference
.getAnnotations();
288 Iterator iterator
= annotations
.iterator();
289 String detailText
= null;
290 if (iterator
.hasNext()) {
291 Annotation annotation
= (Annotation
) iterator
.next();
292 detailText
= annotation
.getText();
295 if (detailText
!= null && !detailText
.equals("")) {
296 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
297 detail
.appendChild(document
.createTextNode(detailText
));
298 representation
.appendChild(detail
);
301 Set
<Media
> rm
= reference
.getMedia();
303 if (rm
!= null && rm
.size() > 0) {
304 ElementImpl mediaObject
;
306 for (int i
= 0; i
< rm
.size(); i
++) {
307 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
308 //mediaObject = org.apache.xerces.dom.ElementImpl(document, MEDIA_OBJECT);
309 mediasCount
= buildReference((Media
) rm
.toArray()[i
], medias
, REF
, mediaObject
, "m", mediasCount
);
310 representation
.appendChild(mediaObject
);
317 // # GENERIC BRICKS #
321 * Creates a Label element
325 public void buildLabel(ElementImpl element
, String text
) {
326 // create <Label> element
327 ElementImpl label
= new ElementImpl(document
, LABEL
);
329 // if language different from language dataset, indicate it TODO, but need to deal with a database language
330 label
.appendChild(document
.createTextNode(text
));
331 element
.appendChild(label
);
336 * Builds TaxonNames associated with the Dataset
338 public void buildTaxonNames(ElementImpl dataset
) throws ParseException
{
341 // <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
343 // <Label xml:lang="la">Viola hederacea Labill.</Label>
348 if (cdmSource
.getTaxonomicNames() != null) {
349 ElementImpl elTaxonNames
= new ElementImpl(document
, TAXON_NAMES
);
351 for (int i
= 0; i
< cdmSource
.getTaxonomicNames().size(); i
++) {
352 ElementImpl elTaxonName
= new ElementImpl(document
, TAXON_NAME
);
353 TaxonNameBase tnb
= cdmSource
.getTaxonomicNames().get(i
);
355 taxonNamesCount
= buildReference(tnb
, taxonNames
, REF
, elTaxonName
, "t", taxonNamesCount
);
357 buildRepresentation(elTaxonName
, tnb
);
359 elTaxonNames
.appendChild(elTaxonName
);
362 dataset
.appendChild(elTaxonNames
);
368 * Builds an element Agent referring to Agent defined later in the SDD file
370 public void buildRefAgent(ElementImpl element
, TeamOrPersonBase ag
, String role
) throws ParseException
{
371 if (ag
instanceof Person
) {
372 Person p
= (Person
) ag
;
373 ElementImpl agent
= new ElementImpl(document
, AGENT
);
374 agent
.setAttribute(ROLE
, role
);
375 agentsCount
= buildReference(p
, agents
, REF
, agent
, "a", agentsCount
);
376 element
.appendChild(agent
);
379 if (ag
instanceof Team
) {
380 Team team
= (Team
) ag
;
381 for (int i
= 0; i
< team
.getTeamMembers().size(); i
++) {
382 ElementImpl agent
= new ElementImpl(document
, AGENT
);
383 agent
.setAttribute(ROLE
, role
);
384 Person author
= team
.getTeamMembers().get(i
);
385 if (author
.getSources() != null) {
386 OriginalSource os
= (OriginalSource
) author
.getSources().toArray()[0];
387 String id
= os
.getIdInSource();
389 if (!id
.equals("")) {
390 if (!agents
.containsValue(id
)) {
391 agent
.setAttribute(REF
, id
);
392 } else if (!agents
.containsValue("a" + (agentsCount
+1))) {
393 agent
.setAttribute(REF
, "a" + (agentsCount
+1));
396 agent
.setAttribute(REF
, id
+ (agentsCount
+1));
400 agent
.setAttribute(REF
, "a" + (agentsCount
+1));
404 agent
.setAttribute(REF
, "a" + (agentsCount
+1));
408 agent
.setAttribute(REF
, "a" + (agentsCount
+1));
411 agents
.put(author
, agent
.getAttribute(REF
));
412 element
.appendChild(agent
);
418 * Builds ModifiedDate associated with RevisionData
420 public void buildDateModified(ElementImpl revisionData
, Database database
) throws ParseException
{
422 // <DateModified>2006-04-08T00:00:00</DateModified>
424 if (database
.getUpdated() != null) {
425 ElementImpl dateModified
= new ElementImpl(document
, DATE_MODIFIED
);
427 java
.util
.Calendar c
= database
.getUpdated();
428 Date d
= c
.getTime();
429 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
430 String date
= sdf
.format(d
);
431 dateModified
.appendChild(document
.createTextNode(date
));
433 revisionData
.appendChild(dateModified
);
439 * Builds IPRStatements associated with the Dataset
441 public void buildIPRStatements(ElementImpl dataset
, Database database
) throws ParseException
{
444 // <IPRStatement role="Copyright">
445 // <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
449 if (database
.getRights() != null) {
450 // create IPRStatements
451 ElementImpl iprStatements
= new ElementImpl(document
, IPR_STATEMENTS
);
452 dataset
.appendChild(iprStatements
);
454 //mapping between IPRStatement Copyright (SDD) and first Right in the list of Rights
455 ElementImpl iprStatement
= new ElementImpl(document
, IPR_STATEMENT
);
456 iprStatement
.setAttribute("role", "Copyright");
457 iprStatements
.appendChild(iprStatement
);
458 buildLabel(iprStatement
, ((Rights
) database
.getRights().toArray()[0]).getText());
464 * Builds RevisionData associated with the Dataset
466 public void buildRevisionData(ElementImpl dataset
, Database database
) throws ParseException
{
470 // <Agent role="aut" ref="a1"/>
471 // <Agent role="aut" ref="a2"/>
472 // <Agent role="edt" ref="a3"/>
474 // <DateModified>2006-04-08T00:00:00</DateModified>
477 ElementImpl revisionData
= new ElementImpl(document
, REVISION_DATA
);
480 TeamOrPersonBase authors
= database
.getAuthorTeam();
481 TeamOrPersonBase editors
= database
.getUpdatedBy();
483 if ((authors
!= null) || (editors
!= null)) {
484 ElementImpl creators
= new ElementImpl(document
, CREATORS
);
485 if (authors
!= null) {
486 buildRefAgent(creators
, authors
, "aut");
488 if (editors
!= null) {
489 buildRefAgent(creators
, editors
, "edt");
491 revisionData
.appendChild(creators
);
494 buildDateModified(revisionData
, database
);
496 dataset
.appendChild(revisionData
);
500 * Builds a Representation element using an IdentifiableEntity
502 public void buildRepresentation(ElementImpl element
, IdentifiableEntity ie
) throws ParseException
{
504 // create <Representation> element
505 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
506 element
.appendChild(representation
);
507 buildLabel(representation
, ie
.getTitleCache());
509 Set
<Annotation
> annotations
= ie
.getAnnotations();
510 Iterator iterator
= annotations
.iterator();
511 String detailText
= null;
512 if (iterator
.hasNext()) {
513 Annotation annotation
= (Annotation
) iterator
.next();
514 detailText
= annotation
.getText();
517 if (detailText
!= null && !detailText
.equals("")) {
518 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
519 detail
.appendChild(document
.createTextNode(detailText
));
520 representation
.appendChild(detail
);
526 * Builds Characters associated with the Dataset
528 public void buildCharacters(ElementImpl dataset
) throws ParseException
{
530 if (cdmSource
.getTerms() != null) {
531 ElementImpl elCharacters
= new ElementImpl(document
, CHARACTERS
);
533 //TODO Boucle infinie
534 int f
= cdmSource
.getTerms().size();
535 for (int i
= 0; i
< f
; i
++) {
536 if (cdmSource
.getTerms().get(i
) instanceof Feature
) {
537 Feature character
= (Feature
) cdmSource
.getTerms().get(i
);
538 if (character
.supportsQuantitativeData()) {
539 ElementImpl elQuantitativeCharacter
= new ElementImpl(document
, QUANTITATIVE_CHARACTER
);
540 charactersCount
= buildReference(character
, characters
, ID
, elQuantitativeCharacter
, "c", charactersCount
);
541 // TODO if the character also supports text, add to the label a short tag to distinguish
542 // it as the quantitative version and create a unique label
543 buildRepresentation(elQuantitativeCharacter
, character
);
544 // TODO <MeasurementUnit> and <Default>
545 elCharacters
.appendChild(elQuantitativeCharacter
);
547 if (character
.supportsTextData()) {
548 Set
<TermVocabulary
<State
>> enumerations
= character
.getSupportedCategoricalEnumerations();
549 if (enumerations
!= null) {
550 if (enumerations
.size()>0) {
551 ElementImpl elCategoricalCharacter
= new ElementImpl(document
, CATEGORICAL_CHARACTER
);
552 charactersCount
= buildReference(character
, characters
, ID
, elCategoricalCharacter
, "c", charactersCount
);
553 buildRepresentation(elCategoricalCharacter
, character
);
554 ElementImpl elStates
= new ElementImpl(document
, STATES
);
555 TermVocabulary tv
= (TermVocabulary
) enumerations
.toArray()[0];
556 Set
<State
> stateList
= tv
.getTerms();
557 for (int j
= 0; j
< stateList
.size(); j
++) {
558 ElementImpl elStateDefinition
= new ElementImpl(document
, STATE_DEFINITION
);
559 State state
= (State
) stateList
.toArray()[j
];
560 statesCount
= buildReference(state
, states
, ID
, elStateDefinition
, "s", statesCount
);
561 buildRepresentation(elStateDefinition
, state
);
562 elStates
.appendChild(elStateDefinition
);
564 elCategoricalCharacter
.appendChild(elStates
);
565 elCharacters
.appendChild(elCategoricalCharacter
);
568 if ((enumerations
== null) || (enumerations
.size() <= 0)) {
569 ElementImpl elTextCharacter
= new ElementImpl(document
, TEXT_CHARACTER
);
570 charactersCount
= buildReference(character
, characters
, ID
, elTextCharacter
, "c", charactersCount
);
571 buildRepresentation(elTextCharacter
, character
);
572 // TODO <MeasurementUnit> and <Default>
573 elCharacters
.appendChild(elTextCharacter
);
579 dataset
.appendChild(elCharacters
);
585 * Builds an element Agent referring to Agent defined later in the SDD file
587 public int buildReference(VersionableEntity ve
, Map references
, String refOrId
, ElementImpl element
, String prefix
, int count
) throws ParseException
{
588 if (ve
instanceof IdentifiableEntity
) {
589 IdentifiableEntity ie
= (IdentifiableEntity
) ve
;
590 if (ie
.getSources() != null) {
591 OriginalSource os
= (OriginalSource
) ie
.getSources().toArray()[0];
592 String id
= os
.getIdInSource();
594 if (!id
.equals("")) {
595 if (!references
.containsValue(id
)) {
596 element
.setAttribute(refOrId
, id
);
597 } else while (element
.getAttribute(refOrId
).equals("")) {
598 if (!references
.containsValue(prefix
+ (count
+1))) {
599 element
.setAttribute(refOrId
, prefix
+ (count
+1));
603 } else while (element
.getAttribute(refOrId
).equals("")) {
604 if (!references
.containsValue(prefix
+ (count
+1))) {
605 element
.setAttribute(refOrId
, prefix
+ (count
+1));
609 } else while (element
.getAttribute(refOrId
).equals("")) {
610 if (!references
.containsValue(prefix
+ (count
+1))) {
611 element
.setAttribute(refOrId
, prefix
+ (count
+1));
615 } else while (element
.getAttribute(refOrId
).equals("")) {
616 if (!references
.containsValue(prefix
+ (count
+1))) {
617 element
.setAttribute(refOrId
, prefix
+ (count
+1));
621 } else while (element
.getAttribute(refOrId
).equals("")) {
622 if (!references
.containsValue(prefix
+ (count
+1))) {
623 element
.setAttribute(refOrId
, prefix
+ (count
+1));
627 references
.put(ve
, element
.getAttribute(refOrId
));
632 * Builds a Representation element using a Feature
634 public void buildRepresentation(ElementImpl element
, TermBase tb
) throws ParseException
{
636 // create <Representation> element
637 ElementImpl representation
= new ElementImpl(document
, REPRESENTATION
);
638 element
.appendChild(representation
);
639 String label
= ((Representation
) tb
.getRepresentations().toArray()[0]).getLabel();
640 buildLabel(representation
, label
);
642 String detailText
= tb
.getDescription();
644 if (detailText
!= null && !detailText
.equals("")) {
645 if (!detailText
.equals(label
)) {
646 ElementImpl detail
= new ElementImpl(document
, DETAIL
);
647 detail
.appendChild(document
.createTextNode(detailText
));
648 representation
.appendChild(detail
);
652 if (tb
instanceof DefinedTermBase
) {
653 DefinedTermBase dtb
= (DefinedTermBase
) tb
;
654 Set
<Media
> rm
= dtb
.getMedia();
656 if (rm
!= null && rm
.size() > 0) {
657 ElementImpl mediaObject
;
659 for (int i
= 0; i
< rm
.size(); i
++) {
660 mediaObject
= new ElementImpl(document
, MEDIA_OBJECT
);
661 mediasCount
= buildReference((Media
) rm
.toArray()[i
], medias
, REF
, mediaObject
, "m", mediasCount
);
662 representation
.appendChild(mediaObject
);
671 // * Build Hashtables with the references for the different elements that build the dataset,
672 // * and that are then used in the different building elements methods
675 // public void buildReferences() {
677 // // <TaxonNames> references
678 // for (int i = 0; i < cdmSource.getTaxonomicNames().size(); i++) {
679 // OriginalSource os = (OriginalSource) cdmSource.getAgents().get(i).getSources().toArray()[i];
680 // String id = os.getIdNamespace();
682 // if (!id.equals("")) {
683 // if (!references.containsValue(id)) {
684 // references.put(cdmSource.getAgents().get(i), id);
685 // } else if (!references.containsValue("a" + (i+1))) {
686 // references.put(cdmSource.getAgents().get(i), "a" + (i+1));
688 // references.put(cdmSource.getAgents().get(i), id + (i+1));
691 // references.put(cdmSource.getAgents().get(i), "a" + (i+1));
694 // references.put(cdmSource.getAgents().get(i), "a" + (i+1));
698 // // <Character> references
699 // for (int i = 0; i < cdmSource.getFeatureData().size(); i++) {
700 // references.put(cdmSource.getFeatureData().get(i), "c" + (i+1));
703 // /* no groups so far in CDM TODO
704 // // <DescriptiveConcept> and <Node> references
705 // for (int i = 0; i < base.getNbGroups(); i++) {
706 // references.put(base.getGroupAt(i), "dc" + (i+1));
710 // // <State> references
712 // for (int i = 0; i < cdmSource.get(); i++) {
713 // variable = base.getVariableAt(i);
714 // for (int j = 0; j < variable.getNbModes(); j++) {
715 // references.put(variable.getModeAt(j), "s" + statesCounter);
720 // // <CodedDescription> references
721 // for (int i = 0; i < base.getNbIndividuals(); i++) {
722 // references.put(base.getIndividualAt(i), "D" + (i+1));
725 // // <MediaObject> references
727 // ArrayList al = base.getAllResources();
728 // for (int i = 0; i < al.size(); i++) {
729 // BaseObjectResource bor = (BaseObjectResource) al.get(i);
731 // if (!referencesMediaObjects.containsKey(bor)) {
732 // referencesMediaObjects.put(bor, "m" + mediaObjectsCounter);
733 // mediaObjectsCounter++;
738 // // BaseObjectResource bor = base.getResource();
740 // //bor.getDescription();
741 // //bor.getFullFilename();
743 // if (!referencesMediaObjects.containsKey(bor)) {
744 // referencesMediaObjects.put(bor, "m" + mediaObjectsCounter);
745 // mediaObjectsCounter++;
750 // for (int i = 0; i < base.getNbGroups(); i++) {
751 // Object[] tab = ((Group) base.getGroupAt(i)).getAllResources();
753 // for (int j = 0; j < tab.length; j++) {
754 // bor = (BaseObjectResource) tab[j];
756 // if (!referencesMediaObjects.containsKey(bor)) {
757 // referencesMediaObjects.put(bor, "m" + mediaObjectsCounter);
758 // mediaObjectsCounter++;
763 // int nbGroups = base.getNbGroups();
764 // ArrayList mObjArrayList;
765 // if (nbGroups > 0) {
766 // for (int i = 0; i < nbGroups; i++) {
767 // mObjArrayList = ((Group) base.getGroupAt(i)).getImages();
768 // for (int j = 0; j < mObjArrayList.size(); j++) {
769 // String temp = (String) mObjArrayList.get(j);
770 // if (!referencesMediaObjects.containsKey(temp)) {
771 // referencesMediaObjects.put(temp, "m" + mediaObjectsCounter);
772 // mediaObjectsCounter++;
778 // // individual.images
779 // for (int i = 0; i < base.getNbIndividuals(); i++) {
780 // Object[] tab = ((Individual) base.getIndividualAt(i)).getAllResources();
782 // for (int j = 0; j < tab.length; j++) {
783 // bor = (BaseObjectResource) tab[j];
785 // if (!referencesMediaObjects.containsKey(bor)) {
786 // referencesMediaObjects.put(bor, "m" + mediaObjectsCounter);
787 // mediaObjectsCounter++;
792 // int nbIndividuals = base.getNbIndividuals();
793 // if (nbIndividuals > 0) {
794 // for (int i = 0; i < nbIndividuals; i++) {
795 // mObjArrayList = ((Individual) base.getIndividualAt(i)).getImages();
796 // for (int j = 0; j < mObjArrayList.size(); j++) {
797 // String temp = (String) mObjArrayList.get(j);
798 // if (!referencesMediaObjects.containsKey(temp)) {
799 // referencesMediaObjects.put(temp, "m" + mediaObjectsCounter);
800 // mediaObjectsCounter++;
806 // // variable.images
808 // int nbVariables = base.getNbVariables();
809 // if (nbVariables > 0) {
810 // for (int i = 0; i < nbVariables; i++) {
811 // mObjArrayList = ((Variable) base.getVariableAt(i)).getImages();
812 // for (int j = 0; j < mObjArrayList.size(); j++) {
813 // String temp = (String) mObjArrayList.get(j);
814 // if (!referencesMediaObjects.containsKey(temp)) {
815 // referencesMediaObjects.put(temp, "m" + mediaObjectsCounter);
816 // mediaObjectsCounter++;
824 // int nbModesTotal = base.getNbModes();
826 // if (nbModesTotal > 0) {
827 // for (int i = 0; i < nbVariables; i++) {
828 // variable = (Variable) base.getVariableAt(i);
829 // nbModes = variable.getNbModes();
830 // for (int j = 0; j < nbModes; j++) {
831 // mObjArrayList = variable.getModeAt(j).getImages();
832 // for (int k = 0; k < mObjArrayList.size(); k++) {
833 // String temp = (String) mObjArrayList.get(k);
834 // if (!referencesMediaObjects.containsKey(temp)) {
835 // referencesMediaObjects.put(temp, "m" + mediaObjectsCounter);
836 // mediaObjectsCounter++;
843 // for (int i = 0; i < base.getLinks().size(); i++) {
844 // referencesLinks.put(base.getLinkAt(i), "m" + mediaObjectsCounter);
845 // mediaObjectsCounter++;