cleanup
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / dwca / out / DwcaMetaDataRecord.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.cdm.io.dwca.out;
10
11 import java.net.URI;
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.apache.log4j.Logger;
16
17 /**
18 * @author a.mueller
19 * @since 20.04.2011
20 */
21 public class DwcaMetaDataRecord {
22 @SuppressWarnings("unused")
23 private static final Logger logger = Logger.getLogger(DwcaMetaDataRecord.class);
24
25 private String fileLocation;
26 private String rowType;
27
28 private boolean isCore;
29 private int currentIndex = 0;
30 private boolean isMetaData = false; //is this record about meta data (should be true for MetaData and EML)
31
32 private int count = 0;
33
34 private List<FieldEntry> fieldEntryList = new ArrayList<>();
35 protected List<String> fieldList = new ArrayList<>();
36
37 public DwcaMetaDataRecord(boolean isCore, String fileLocation, String rowType){
38 FieldEntry idEntry = new FieldEntry();
39 idEntry.index = currentIndex++;
40 idEntry.elementName = isCore ? "id" : "coreid";
41 fieldEntryList.add(idEntry);
42 this.isCore = isCore;
43 this.fileLocation = fileLocation;
44 this.setRowType(rowType);
45 }
46
47 protected class FieldEntry{
48 int index;
49 URI term = null;
50 String defaultValue = null;
51 String elementName = "field";
52 }
53
54 public void addFieldEntry(URI term, String defaultValue){
55 FieldEntry fieldEntry = new FieldEntry();
56 fieldEntry.index = currentIndex++;
57 fieldEntry.term = term;
58 fieldEntry.defaultValue = defaultValue;
59 this.fieldEntryList.add(fieldEntry);
60 }
61
62 //TODO needed?
63 // public abstract List<String> getHeaderList();
64
65 // public List<URI> getTermList(){
66 // List<URI> result = new ArrayList<URI>();
67 // for (String key : fieldList){
68 // URI uri = knownFields.get(key);
69 // if (uri != null){
70 // result.add(uri);
71 // }else{
72 // String message = "Unknown 'known field key' " + key;
73 // logger.warn(message);
74 // }
75 // }
76 // return result;
77 // }
78
79 public boolean hasEntries(){
80 return fieldEntryList.size() > 1;
81 }
82
83 public List<FieldEntry> getEntries(){
84 return fieldEntryList;
85 }
86
87
88 public String getFileLocation() {
89 return fileLocation;
90 }
91
92 public void setFileLocation(String fileLocation) {
93 this.fileLocation = fileLocation;
94 }
95
96 public boolean isCore() {
97 return isCore;
98 }
99
100 public void setCore(boolean isCore) {
101 this.isCore = isCore;
102 }
103
104 public void setRowType(String rowType) {
105 this.rowType = rowType;
106 }
107
108 public String getRowType() {
109 return rowType;
110 }
111
112 public int inc(){
113 return ++count;
114 }
115
116 public void setMetaData(boolean isMetaData) {
117 this.isMetaData = isMetaData;
118 }
119
120 public boolean isMetaData() {
121 return isMetaData;
122 }
123
124
125 @Override
126 public String toString() {
127 return this.fileLocation;
128 }
129 }