Commit d269a30a1595fe7f6fa40988ce053f7a7c264866

Authored by Lyncode
1 parent b10be85130
Exists in DSpace52++

Line endings normalization (rebased)

Showing 37 changed files with 10975 additions and 10961 deletions   Show diff stats
.gitattributes
... ... @@ -0,0 +1,14 @@
  1 +# Auto detect text files and perform LF normalization
  2 +* text=auto
  3 +
  4 +# Standard to msysgit
  5 +*.doc diff=astextplain
  6 +*.DOC diff=astextplain
  7 +*.docx diff=astextplain
  8 +*.DOCX diff=astextplain
  9 +*.dot diff=astextplain
  10 +*.DOT diff=astextplain
  11 +*.pdf diff=astextplain
  12 +*.PDF diff=astextplain
  13 +*.rtf diff=astextplain
  14 +*.RTF diff=astextplain
... ...
dspace-api/src/main/java/org/dspace/app/bulkedit/BulkEditChange.java
1   -/**
2   - * The contents of this file are subject to the license and copyright
3   - * detailed in the LICENSE and NOTICE files at the root of the source
4   - * tree and available online at
5   - *
6   - * http://www.dspace.org/license/
7   - */
8   -package org.dspace.app.bulkedit;
9   -
10   -import org.dspace.content.Item;
11   -import org.dspace.content.DCValue;
12   -import org.dspace.content.Collection;
13   -
14   -import java.util.ArrayList;
15   -import java.util.List;
16   -
17   -/**
18   - * Utility class to store changes to item that may occur during a batch edit.
19   - *
20   - * @author Stuart Lewis
21   - */
22   -public class BulkEditChange
23   -{
24   - /** The item these changes relate to */
25   - private Item item;
26   -
27   - /** The List of hashtables with the new elements */
28   - private List<DCValue> adds;
29   -
30   - /** The List of hashtables with the removed elements */
31   - private List<DCValue> removes;
32   -
33   - /** The List of hashtables with the unchanged elements */
34   - private List<DCValue> constant;
35   -
36   - /** The List of the complete set of new values (constant + adds) */
37   - private List<DCValue> complete;
38   -
39   - /** The list of old collections the item used to be mapped to */
40   - private List<Collection> oldMappedCollections;
41   -
42   - /** The list of new collections the item has been mapped into */
43   - private List<Collection> newMappedCollections;
44   -
45   - /** The old owning collection */
46   - private Collection oldOwningCollection;
47   -
48   - /** The new owning collection */
49   - private Collection newOwningCollection;
50   -
51   - /** Is this a new item */
52   - private boolean newItem;
53   -
54   - /** Has this item been deleted? */
55   - private boolean deleted;
56   -
57   - /** Has this item been withdrawn? */
58   - private boolean withdrawn;
59   -
60   - /** Has this item been reinstated? */
61   - private boolean reinstated;
62   -
63   - /** Have any changes actually been made? */
64   - private boolean empty;
65   -
66   -
67   - /**
68   - * Initialise a change holder for a new item
69   - */
70   - public BulkEditChange()
71   - {
72   - // Set the item to be null
73   - item = null;
74   - newItem = true;
75   - empty = true;
76   - oldOwningCollection = null;
77   - newOwningCollection = null;
78   -
79   - // Initialise the arrays
80   - adds = new ArrayList<DCValue>();
81   - removes = new ArrayList<DCValue>();
82   - constant = new ArrayList<DCValue>();
83   - complete = new ArrayList<DCValue>();
84   - oldMappedCollections = new ArrayList<Collection>();
85   - newMappedCollections = new ArrayList<Collection>();
86   - }
87   -
88   - /**
89   - * Initialise a new change holder for an existing item
90   - *
91   - * @param i The Item to store
92   - */
93   - public BulkEditChange(Item i)
94   - {
95   - // Store the item
96   - item = i;
97   - newItem = false;
98   - empty = true;
99   -
100   - // Initialise the arrays
101   - adds = new ArrayList<DCValue>();
102   - removes = new ArrayList<DCValue>();
103   - constant = new ArrayList<DCValue>();
104   - complete = new ArrayList<DCValue>();
105   - oldMappedCollections = new ArrayList<Collection>();
106   - newMappedCollections = new ArrayList<Collection>();
107   - }
108   -
109   - /**
110   - * Store the item - used when a new item is created
111   - *
112   - * @param i The item
113   - */
114   - public void setItem(Item i)
115   - {
116   - // Store the item
117   - item = i;
118   - }
119   -
120   - /**
121   - * Add an added metadata value
122   - *
123   - * @param dcv The value to add
124   - */
125   - public void registerAdd(DCValue dcv)
126   - {
127   - // Add the added value
128   - adds.add(dcv);
129   - complete.add(dcv);
130   - empty = false;
131   - }
132   -
133   - /**
134   - * Add a removed metadata value
135   - *
136   - * @param dcv The value to remove
137   - */
138   - public void registerRemove(DCValue dcv)
139   - {
140   - // Add the removed value
141   - removes.add(dcv);
142   - empty = false;
143   - }
144   -
145   - /**
146   - * Add an unchanged metadata value
147   - *
148   - * @param dcv The value to keep unchanged
149   - */
150   - public void registerConstant(DCValue dcv)
151   - {
152   - // Add the removed value
153   - constant.add(dcv);
154   - complete.add(dcv);
155   - }
156   -
157   - /**
158   - * Add a new mapped Collection
159   - *
160   - * @param c The new mapped Collection
161   - */
162   - public void registerNewMappedCollection(Collection c)
163   - {
164   - // Add the new owning Collection
165   - newMappedCollections.add(c);
166   - empty = false;
167   - }
168   -
169   - /**
170   - * Add an old mapped Collection
171   - *
172   - * @param c The old mapped Collection
173   - */
174   - public void registerOldMappedCollection(Collection c)
175   - {
176   - // Add the old owning Collection (if it isn't there already, or is an old collection)
177   - boolean found = false;
178   -
179   - if ((this.getOldOwningCollection() != null) &&
180   - (this.getOldOwningCollection().getHandle().equals(c.getHandle())))
181   - {
182   - found = true;
183   - }
184   -
185   - for (Collection collection : oldMappedCollections)
186   - {
187   - if (collection.getHandle().equals(c.getHandle()))
188   - {
189   - found = true;
190   - }
191   - }
192   -
193   - if (!found)
194   - {
195   - oldMappedCollections.add(c);
196   - empty = false;
197   - }
198   - }
199   -
200   - /**
201   - * Register a change to the owning collection
202   - *
203   - * @param oldC The old owning collection
204   - * @param newC The new owning collection
205   - */
206   - public void changeOwningCollection(Collection oldC, Collection newC)
207   - {
208   - // Store the old owning collection
209   - oldOwningCollection = oldC;
210   -
211   - // Store the new owning collection
212   - newOwningCollection = newC;
213   - empty = false;
214   - }
215   -
216   - /**
217   - * Set the owning collection of an item
218   - *
219   - * @param newC The new owning collection
220   - */
221   - public void setOwningCollection(Collection newC)
222   - {
223   - // Store the new owning collection
224   - newOwningCollection = newC;
225   - //empty = false;
226   - }
227   -
228   - /**
229   - * Get the DSpace Item that these changes are applicable to.
230   - *
231   - * @return The item
232   - */
233   - public Item getItem()
234   - {
235   - // Return the item
236   - return item;
237   - }
238   -
239   - /**
240   - * Get the list of elements and their values that have been added.
241   - *
242   - * @return the list of elements and their values that have been added.
243   - */
244   - public List<DCValue> getAdds()
245   - {
246   - // Return the array
247   - return adds;
248   - }
249   -
250   - /**
251   - * Get the list of elements and their values that have been removed.
252   - *
253   - * @return the list of elements and their values that have been removed.
254   - */
255   - public List<DCValue> getRemoves()
256   - {
257   - // Return the array
258   - return removes;
259   - }
260   -
261   - /**
262   - * Get the list of unchanged values
263   - *
264   - * @return the list of unchanged values
265   - */
266   - public List<DCValue> getConstant()
267   - {
268   - // Return the array
269   - return constant;
270   - }
271   -
272   - /**
273   - * Get the list of all values
274   - *
275   - * @return the list of all values
276   - */
277   - public List<DCValue> getComplete()
278   - {
279   - // Return the array
280   - return complete;
281   - }
282   -
283   - /**
284   - * Get the list of new mapped Collections
285   - *
286   - * @return the list of new mapped collections
287   - */
288   - public List<Collection> getNewMappedCollections()
289   - {
290   - // Return the array
291   - return newMappedCollections;
292   - }
293   -
294   - /**
295   - * Get the list of old mapped Collections
296   - *
297   - * @return the list of old mapped collections
298   - */
299   - public List<Collection> getOldMappedCollections()
300   - {
301   - // Return the array
302   - return oldMappedCollections;
303   - }
304   -
305   - /**
306   - * Get the old owning collection
307   - *
308   - * @return the old owning collection
309   - */
310   - public Collection getOldOwningCollection()
311   - {
312   - // Return the old owning collection
313   - return oldOwningCollection;
314   - }
315   -
316   - /**
317   - * Get the new owning collection
318   - *
319   - * @return the new owning collection
320   - */
321   - public Collection getNewOwningCollection()
322   - {
323   - // Return the new owning collection
324   - return newOwningCollection;
325   - }
326   -
327   - /**
328   - * Does this change object represent a new item?
329   - *
330   - * @return Whether or not this is for a new item
331   - */
332   - public boolean isNewItem()
333   - {
334   - // Return the new item status
335   - return newItem;
336   - }
337   -
338   - /**
339   - * Does this change object represent a deleted item?
340   - *
341   - * @return Whether or not this is for a deleted item
342   - */
343   - public boolean isDeleted()
344   - {
345   - // Return the new item status
346   - return deleted;
347   - }
348   -
349   - /**
350   - * Set that this item has been deleted
351   - */
352   - public void setDeleted() {
353   - // Store the setting
354   - deleted = true;
355   - empty = false;
356   - }
357   -
358   - /**
359   - * Does this change object represent a withdrawn item?
360   - *
361   - * @return Whether or not this is for a withdrawn item
362   - */
363   - public boolean isWithdrawn()
364   - {
365   - // Return the new item status
366   - return withdrawn;
367   - }
368   -
369   - /**
370   - * Set that this item has been withdrawn
371   - */
372   - public void setWithdrawn() {
373   - // Store the setting
374   - withdrawn = true;
375   - empty = false;
376   - }
377   -
378   - /**
379   - * Does this change object represent a reinstated item?
380   - *
381   - * @return Whether or not this is for a reinstated item
382   - */
383   - public boolean isReinstated()
384   - {
385   - // Return the new item status
386   - return reinstated;
387   - }
388   -
389   - /**
390   - * Set that this item has been deleted
391   - */
392   - public void setReinstated() {
393   - // Store the setting
394   - reinstated = true;
395   - empty = false;
396   - }
397   -
398   - /**
399   - * Have any changes actually been recorded, or is this empty?
400   - *
401   - * @return Whether or not changes have been made
402   - */
403   - public boolean hasChanges()
404   - {
405   - return !empty;
406   - }
  1 +/**
  2 + * The contents of this file are subject to the license and copyright
  3 + * detailed in the LICENSE and NOTICE files at the root of the source
  4 + * tree and available online at
  5 + *
  6 + * http://www.dspace.org/license/
  7 + */
  8 +package org.dspace.app.bulkedit;
  9 +
  10 +import org.dspace.content.Item;
  11 +import org.dspace.content.DCValue;
  12 +import org.dspace.content.Collection;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * Utility class to store changes to item that may occur during a batch edit.
  19 + *
  20 + * @author Stuart Lewis
  21 + */
  22 +public class BulkEditChange
  23 +{
  24 + /** The item these changes relate to */
  25 + private Item item;
  26 +
  27 + /** The List of hashtables with the new elements */
  28 + private List<DCValue> adds;
  29 +
  30 + /** The List of hashtables with the removed elements */
  31 + private List<DCValue> removes;
  32 +
  33 + /** The List of hashtables with the unchanged elements */
  34 + private List<DCValue> constant;
  35 +
  36 + /** The List of the complete set of new values (constant + adds) */
  37 + private List<DCValue> complete;
  38 +
  39 + /** The list of old collections the item used to be mapped to */
  40 + private List<Collection> oldMappedCollections;
  41 +
  42 + /** The list of new collections the item has been mapped into */
  43 + private List<Collection> newMappedCollections;
  44 +
  45 + /** The old owning collection */
  46 + private Collection oldOwningCollection;
  47 +
  48 + /** The new owning collection */
  49 + private Collection newOwningCollection;
  50 +
  51 + /** Is this a new item */
  52 + private boolean newItem;
  53 +
  54 + /** Has this item been deleted? */
  55 + private boolean deleted;
  56 +
  57 + /** Has this item been withdrawn? */
  58 + private boolean withdrawn;
  59 +
  60 + /** Has this item been reinstated? */
  61 + private boolean reinstated;
  62 +
  63 + /** Have any changes actually been made? */
  64 + private boolean empty;
  65 +
  66 +
  67 + /**
  68 + * Initialise a change holder for a new item
  69 + */
  70 + public BulkEditChange()
  71 + {
  72 + // Set the item to be null
  73 + item = null;
  74 + newItem = true;
  75 + empty = true;
  76 + oldOwningCollection = null;
  77 + newOwningCollection = null;
  78 +
  79 + // Initialise the arrays
  80 + adds = new ArrayList<DCValue>();
  81 + removes = new ArrayList<DCValue>();
  82 + constant = new ArrayList<DCValue>();
  83 + complete = new ArrayList<DCValue>();
  84 + oldMappedCollections = new ArrayList<Collection>();
  85 + newMappedCollections = new ArrayList<Collection>();
  86 + }
  87 +
  88 + /**
  89 + * Initialise a new change holder for an existing item
  90 + *
  91 + * @param i The Item to store
  92 + */
  93 + public BulkEditChange(Item i)
  94 + {
  95 + // Store the item
  96 + item = i;
  97 + newItem = false;
  98 + empty = true;
  99 +
  100 + // Initialise the arrays
  101 + adds = new ArrayList<DCValue>();
  102 + removes = new ArrayList<DCValue>();
  103 + constant = new ArrayList<DCValue>();
  104 + complete = new ArrayList<DCValue>();
  105 + oldMappedCollections = new ArrayList<Collection>();
  106 + newMappedCollections = new ArrayList<Collection>();
  107 + }
  108 +
  109 + /**
  110 + * Store the item - used when a new item is created
  111 + *
  112 + * @param i The item
  113 + */
  114 + public void setItem(Item i)
  115 + {
  116 + // Store the item
  117 + item = i;
  118 + }
  119 +
  120 + /**
  121 + * Add an added metadata value
  122 + *
  123 + * @param dcv The value to add
  124 + */
  125 + public void registerAdd(DCValue dcv)
  126 + {
  127 + // Add the added value
  128 + adds.add(dcv);
  129 + complete.add(dcv);
  130 + empty = false;
  131 + }
  132 +
  133 + /**
  134 + * Add a removed metadata value
  135 + *
  136 + * @param dcv The value to remove
  137 + */
  138 + public void registerRemove(DCValue dcv)
  139 + {
  140 + // Add the removed value
  141 + removes.add(dcv);
  142 + empty = false;
  143 + }
  144 +
  145 + /**
  146 + * Add an unchanged metadata value
  147 + *
  148 + * @param dcv The value to keep unchanged
  149 + */
  150 + public void registerConstant(DCValue dcv)
  151 + {
  152 + // Add the removed value
  153 + constant.add(dcv);
  154 + complete.add(dcv);
  155 + }
  156 +
  157 + /**
  158 + * Add a new mapped Collection
  159 + *
  160 + * @param c The new mapped Collection
  161 + */
  162 + public void registerNewMappedCollection(Collection c)
  163 + {
  164 + // Add the new owning Collection
  165 + newMappedCollections.add(c);
  166 + empty = false;
  167 + }
  168 +
  169 + /**
  170 + * Add an old mapped Collection
  171 + *
  172 + * @param c The old mapped Collection
  173 + */
  174 + public void registerOldMappedCollection(Collection c)
  175 + {
  176 + // Add the old owning Collection (if it isn't there already, or is an old collection)
  177 + boolean found = false;
  178 +
  179 + if ((this.getOldOwningCollection() != null) &&
  180 + (this.getOldOwningCollection().getHandle().equals(c.getHandle())))
  181 + {
  182 + found = true;
  183 + }
  184 +
  185 + for (Collection collection : oldMappedCollections)
  186 + {
  187 + if (collection.getHandle().equals(c.getHandle()))
  188 + {
  189 + found = true;
  190 + }
  191 + }
  192 +
  193 + if (!found)
  194 + {
  195 + oldMappedCollections.add(c);
  196 + empty = false;
  197 + }
  198 + }
  199 +
  200 + /**
  201 + * Register a change to the owning collection
  202 + *
  203 + * @param oldC The old owning collection
  204 + * @param newC The new owning collection
  205 + */
  206 + public void changeOwningCollection(Collection oldC, Collection newC)
  207 + {
  208 + // Store the old owning collection
  209 + oldOwningCollection = oldC;
  210 +
  211 + // Store the new owning collection
  212 + newOwningCollection = newC;
  213 + empty = false;
  214 + }
  215 +
  216 + /**
  217 + * Set the owning collection of an item
  218 + *
  219 + * @param newC The new owning collection
  220 + */
  221 + public void setOwningCollection(Collection newC)
  222 + {
  223 + // Store the new owning collection
  224 + newOwningCollection = newC;
  225 + //empty = false;
  226 + }
  227 +
  228 + /**
  229 + * Get the DSpace Item that these changes are applicable to.
  230 + *
  231 + * @return The item
  232 + */
  233 + public Item getItem()
  234 + {
  235 + // Return the item
  236 + return item;
  237 + }
  238 +
  239 + /**
  240 + * Get the list of elements and their values that have been added.
  241 + *
  242 + * @return the list of elements and their values that have been added.
  243 + */
  244 + public List<DCValue> getAdds()
  245 + {
  246 + // Return the array
  247 + return adds;
  248 + }
  249 +
  250 + /**
  251 + * Get the list of elements and their values that have been removed.
  252 + *
  253 + * @return the list of elements and their values that have been removed.
  254 + */
  255 + public List<DCValue> getRemoves()
  256 + {
  257 + // Return the array
  258 + return removes;
  259 + }
  260 +
  261 + /**
  262 + * Get the list of unchanged values
  263 + *
  264 + * @return the list of unchanged values
  265 + */
  266 + public List<DCValue> getConstant()
  267 + {
  268 + // Return the array
  269 + return constant;
  270 + }
  271 +
  272 + /**
  273 + * Get the list of all values
  274 + *
  275 + * @return the list of all values
  276 + */
  277 + public List<DCValue> getComplete()
  278 + {
  279 + // Return the array
  280 + return complete;
  281 + }
  282 +
  283 + /**
  284 + * Get the list of new mapped Collections
  285 + *
  286 + * @return the list of new mapped collections
  287 + */
  288 + public List<Collection> getNewMappedCollections()
  289 + {
  290 + // Return the array
  291 + return newMappedCollections;
  292 + }
  293 +
  294 + /**
  295 + * Get the list of old mapped Collections
  296 + *
  297 + * @return the list of old mapped collections
  298 + */
  299 + public List<Collection> getOldMappedCollections()
  300 + {
  301 + // Return the array
  302 + return oldMappedCollections;
  303 + }
  304 +
  305 + /**
  306 + * Get the old owning collection
  307 + *
  308 + * @return the old owning collection
  309 + */
  310 + public Collection getOldOwningCollection()
  311 + {
  312 + // Return the old owning collection
  313 + return oldOwningCollection;
  314 + }
  315 +
  316 + /**
  317 + * Get the new owning collection
  318 + *
  319 + * @return the new owning collection
  320 + */
  321 + public Collection getNewOwningCollection()
  322 + {
  323 + // Return the new owning collection
  324 + return newOwningCollection;
  325 + }
  326 +
  327 + /**
  328 + * Does this change object represent a new item?
  329 + *
  330 + * @return Whether or not this is for a new item
  331 + */
  332 + public boolean isNewItem()
  333 + {
  334 + // Return the new item status
  335 + return newItem;
  336 + }
  337 +
  338 + /**
  339 + * Does this change object represent a deleted item?
  340 + *
  341 + * @return Whether or not this is for a deleted item
  342 + */
  343 + public boolean isDeleted()
  344 + {
  345 + // Return the new item status
  346 + return deleted;
  347 + }
  348 +
  349 + /**
  350 + * Set that this item has been deleted
  351 + */
  352 + public void setDeleted() {
  353 + // Store the setting
  354 + deleted = true;
  355 + empty = false;
  356 + }
  357 +
  358 + /**
  359 + * Does this change object represent a withdrawn item?
  360 + *
  361 + * @return Whether or not this is for a withdrawn item
  362 + */
  363 + public boolean isWithdrawn()
  364 + {
  365 + // Return the new item status
  366 + return withdrawn;
  367 + }
  368 +
  369 + /**
  370 + * Set that this item has been withdrawn
  371 + */
  372 + public void setWithdrawn() {
  373 + // Store the setting
  374 + withdrawn = true;
  375 + empty = false;
  376 + }
  377 +
  378 + /**
  379 + * Does this change object represent a reinstated item?
  380 + *
  381 + * @return Whether or not this is for a reinstated item
  382 + */
  383 + public boolean isReinstated()
  384 + {
  385 + // Return the new item status
  386 + return reinstated;
  387 + }
  388 +
  389 + /**
  390 + * Set that this item has been deleted
  391 + */
  392 + public void setReinstated() {
  393 + // Store the setting
  394 + reinstated = true;
  395 + empty = false;
  396 + }
  397 +
  398 + /**
  399 + * Have any changes actually been recorded, or is this empty?
  400 + *
  401 + * @return Whether or not changes have been made
  402 + */
  403 + public boolean hasChanges()
  404 + {
  405 + return !empty;
  406 + }
407 407 }
408 408 \ No newline at end of file
... ...
dspace-api/src/main/java/org/dspace/app/bulkedit/DSpaceCSV.java
1   -/**
2   - * The contents of this file are subject to the license and copyright
3   - * detailed in the LICENSE and NOTICE files at the root of the source
4   - * tree and available online at
5   - *
6   - * http://www.dspace.org/license/
7   - */
8   -package org.dspace.app.bulkedit;
9   -
10   -import org.dspace.content.*;
11   -import org.dspace.content.Collection;
12   -import org.dspace.core.ConfigurationManager;
13   -import org.dspace.core.Context;
14   -
15   -import java.util.*;
16   -import java.util.regex.Pattern;
17   -import java.util.regex.Matcher;
18   -import java.io.*;
19   -
20   -/**
21   - * Utility class to read and write CSV files
22   - *
23   - * **************
24   - * Important Note
25   - * **************
26   - *
27   - * This class has been made serializable, as it is stored in a Session.
28   - * Is it wise to:
29   - * a) be putting this into a user's session?
30   - * b) holding an entire CSV upload in memory?
31   - *
32   - * @author Stuart Lewis
33   - */
34   -public class DSpaceCSV implements Serializable
35   -{
36   - /** The headings of the CSV file */
37   - private List<String> headings;
38   -
39   - /** An array list of CSV lines */
40   - private List<DSpaceCSVLine> lines;
41   -
42   - /** A counter of how many CSV lines this object holds */
43   - private int counter;
44   -
45   - /** The value separator (defaults to double pipe '||') */
46   - protected static String valueSeparator;
47   -
48   - /** The value separator in an escaped form for using in regexs */
49   - protected static String escapedValueSeparator;
50   -
51   - /** The field separator (defaults to comma) */
52   - protected static String fieldSeparator;
53   -
54   - /** The field separator in an escaped form for using in regexs */
55   - protected static String escapedFieldSeparator;
56   -
57   - /** The authority separator (defaults to dobule colon '::') */
58   - protected static String authoritySeparator;
59   -
60   - /** The authority separator in an escaped form for using in regexs */
61   - protected static String escapedAuthoritySeparator;
62   -
63   -
64   - /** Whether to export all metadata such as handles and provenance information */
65   - private boolean exportAll;
66   -
67   - /** A list of metadata elements to ignore */
68   - private Map<String, String> ignore;
69   -
70   -
71   - /**
72   - * Create a new instance of a CSV line holder
73   - *
74   - * @param exportAll Whether to export all metadata such as handles and provenance information
75   - */
76   - public DSpaceCSV(boolean exportAll)
77   - {
78   - // Initialise the class
79   - init();
80   -
81   - // Store the exportAll setting
82   - this.exportAll = exportAll;
83   - }
84   -
85   - /**
86   - * Create a new instance, reading the lines in from file
87   - *
88   - * @param f The file to read from
89   - * @param c The DSpace Context
90   - *
91   - * @throws Exception thrown if there is an error reading or processing the file
92   - */
93   - public DSpaceCSV(File f, Context c) throws Exception
94   - {
95   - // Initialise the class
96   - init();
97   -
98   - // Open the CSV file
99   - BufferedReader input = null;
100   - try
101   - {
102   - input = new BufferedReader(new InputStreamReader(new FileInputStream(f),"UTF-8"));
103   -
104   - // Read the heading line
105   - String head = input.readLine();
106   - String[] headingElements = head.split(escapedFieldSeparator);
107   - int columnCounter = 0;
108   - for (String element : headingElements)
109   - {
110   - columnCounter++;
111   -
112   - // Remove surrounding quotes if there are any
113   - if ((element.startsWith("\"")) && (element.endsWith("\"")))
114   - {
115   - element = element.substring(1, element.length() - 1);
116   - }
117   -
118   - // Store the heading
119   - if ("collection".equals(element))
120   - {
121   - // Store the heading
122   - headings.add(element);
123   - }
124   - // Store the action
125   - else if ("action".equals(element))
126   - {
127   - // Store the heading
128   - headings.add(element);
129   - }
130   - else if (!"id".equals(element))
131   - {
132   - // Verify that the heading is valid in the metadata registry
133   - String[] clean = element.split("\\[");
134   - String[] parts = clean[0].split("\\.");
135   -
136   - if (parts.length < 2) {
137   - throw new MetadataImportInvalidHeadingException(element,
138   - MetadataImportInvalidHeadingException.ENTRY,
139   - columnCounter);
140   - }
141   -
142   - String metadataSchema = parts[0];
143   - String metadataElement = parts[1];
144   - String metadataQualifier = null;
145   - if (parts.length > 2) {
146   - metadataQualifier = parts[2];
147   - }
148   -
149   - // Check that the scheme exists
150   - MetadataSchema foundSchema = MetadataSchema.find(c, metadataSchema);
151   - if (foundSchema == null) {
152   - throw new MetadataImportInvalidHeadingException(clean[0],
153   - MetadataImportInvalidHeadingException.SCHEMA,
154   - columnCounter);
155   - }
156   -
157   - // Check that the metadata element exists in the schema
158   - int schemaID = foundSchema.getSchemaID();
159   - MetadataField foundField = MetadataField.findByElement(c, schemaID, metadataElement, metadataQualifier);
160   - if (foundField == null) {
161   - throw new MetadataImportInvalidHeadingException(clean[0],
162   - MetadataImportInvalidHeadingException.ELEMENT,
163   - columnCounter);
164   - }
165   -
166   - // Store the heading
167   - headings.add(element);
168   - }
169   - }
170   -
171   - // Read each subsequent line
172   - StringBuilder lineBuilder = new StringBuilder();
173   - String lineRead;
174   -
175   - while ((lineRead = input.readLine()) != null)
176   - {
177   - if (lineBuilder.length() > 0) {
178   - // Already have a previously read value - add this line
179   - lineBuilder.append("\n").append(lineRead);
180   -
181   - // Count the number of quotes in the buffer
182   - int quoteCount = 0;
183   - for (int pos = 0; pos < lineBuilder.length(); pos++) {
184   - if (lineBuilder.charAt(pos) == '"') {
185   - quoteCount++;
186   - }
187   - }
188   -
189   - if (quoteCount % 2 == 0) {
190   - // Number of quotes is a multiple of 2, add the item
191   - addItem(lineBuilder.toString());
192   - lineBuilder = new StringBuilder();
193   - }
194   - } else if (lineRead.indexOf('"') > -1) {
195   - // Get the number of quotes in the line
196   - int quoteCount = 0;
197   - for (int pos = 0; pos < lineRead.length(); pos++) {
198   - if (lineRead.charAt(pos) == '"') {
199   - quoteCount++;
200   - }
201   - }
202   -
203   - if (quoteCount % 2 == 0) {
204   - // Number of quotes is a multiple of 2, add the item
205   - addItem(lineRead);
206   - } else {
207