source: other-projects/GlamED/trunk/src/org/honours/greenstone/CollectionContentEditor.java@ 26588

Last change on this file since 26588 was 26588, checked in by davidb, 11 years ago

Initial import of Korii's 520 project for managing digital cultural collections from Greenstone in Expeditee.

File size: 2.7 KB
Line 
1package org.honours.greenstone;
2
3import java.util.List;
4
5import org.apache.log4j.Logger;
6import org.expeditee.items.Item;
7import org.expeditee.items.Picture;
8import org.expeditee.items.Text;
9import org.honours.collection.CollectionItem;
10import org.honours.collection.NoteLayer;
11
12public class CollectionContentEditor {
13
14 static Logger logger = Logger.getLogger(org.honours.greenstone.CollectionContentEditor.class.getName());
15
16 private CollectionItem _collectionItem;
17 private ArchiveFileEditor _archiveFileEditor;
18 //private HtmlForDocXML _htmlForDocXML;
19
20 public CollectionContentEditor(CollectionItem currCI, String _collectionPath) {
21 _collectionItem = currCI;
22 _archiveFileEditor = new ArchiveFileEditor(_collectionItem.getDocXML());
23 }
24
25 public void editCollectionItems() {
26
27 List<Item> items = _collectionItem.getFrame().getItems();
28 boolean noChange = true;
29
30 for(Item item : items){
31
32 if(item instanceof Text){
33 if(item.isAnnotation()){
34 //TODO: Deal with annotation items correctly.
35 }else{
36
37 Text text = (Text)item;
38
39 ArchiveFileReader afe = new ArchiveFileReader(_collectionItem.getDocXML());
40
41 if(text.getData() != null)
42 if(text.getData().size() > 0){
43 String elemText = afe.obtainElementText(text.getData().get(0));
44
45 if(!elemText.equals(null)){
46 if(elemText.equals(text.getText()))
47 continue;
48 else
49 noChange = false;
50 }
51 }
52
53 if(!noChange)
54 _archiveFileEditor.editArchiveDocFile(text);
55 }
56 }else if(item instanceof Picture){
57 //TODO: Deal with picture items correctly.
58 }
59 }
60
61 //addNotes();
62
63 if(!noChange)
64 _archiveFileEditor.write();
65 }
66
67 private void addNotes() {
68 //Add notes to docXML file.
69 NoteLayer noteLayer = _collectionItem.getNoteLayer();
70
71 if(noteLayer != null){
72 StringBuffer notesStringBuffer = new StringBuffer("");
73
74 notesStringBuffer.append("<table attr=\"norect\" cellpadding=\"0\" width=\"100%\">");
75 notesStringBuffer.append("<tbody attr=\"norect\">");
76
77 for(Text t : noteLayer.getFrame().getTextItems()){
78 notesStringBuffer.append("<tr attr=\"norect\">");
79 notesStringBuffer.append("<td attr=\"norect\">");
80
81 notesStringBuffer.append(t.getText() + "<br/>");
82
83 notesStringBuffer.append("</td>");
84 notesStringBuffer.append("</tr>");
85 }
86
87 notesStringBuffer.append("</table>");
88
89 if(!notesStringBuffer.toString().equals(""))
90 {
91 //Write a "Notes" metadata element to the doc.xml file.
92 Text notesText = new Text(notesStringBuffer.toString());
93 notesText.setData("Notes");
94 _archiveFileEditor.editArchiveDocFile(notesText);
95 }
96 }
97 }
98
99}
Note: See TracBrowser for help on using the repository browser.