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

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

Write out a frameID metadata value to an item's corresponding archives doc.xml file.

File size: 3.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 ArchiveFileReader afr = new ArchiveFileReader(_collectionItem.getDocXML());
30
31 for(Item item : items){
32
33 if(item instanceof Text){
34 if(item.isAnnotation()){
35 //TODO: Deal with annotation items correctly.
36
37 }else{
38
39 Text text = (Text)item;
40
41 if(text.getData() != null)
42 if(text.getData().size() > 0){
43 String elemText = afr.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 }
57 }else if(item instanceof Picture){
58 //TODO: Deal with picture items correctly.
59 }
60 }
61
62 noChange = writeFrameID(afr,noChange);
63
64 //addNotes();
65
66 if(!noChange)
67 _archiveFileEditor.write();
68 }
69
70 /**
71 * Method for adding/editing the framID metadata value
72 * @param afr
73 * @param noChange
74 */
75 private boolean writeFrameID(ArchiveFileReader afr, boolean noChange){
76
77 //Write code to write frame number.
78 String frameID = afr.obtainElementText("frameID");
79 String currentFrameID = Integer.toString(_collectionItem.getFrame().getNumber());
80 Text frameIDtext = null;
81
82 if(frameID == null){
83 //create a new frameID element
84 frameIDtext = new Text(currentFrameID);
85 frameIDtext.setData("frameID");
86
87 }else{
88 //check if frameID is the same as the current frame name/number.
89 if(!frameID.equals(currentFrameID)){
90
91 frameIDtext = new Text(currentFrameID);
92 frameIDtext.setData("frameID");
93
94 }
95
96 }
97
98 if(frameIDtext != null){
99 _archiveFileEditor.editArchiveDocFile(frameIDtext);
100 noChange = false;
101 }
102
103 return noChange;
104 }
105
106 /**
107 * Method to output any notes associated with an item to the
108 * doc.xml file.
109 */
110 private void addNotes() {
111 //Add notes to docXML file.
112 NoteLayer noteLayer = _collectionItem.getNoteLayer();
113
114 if(noteLayer != null){
115 StringBuffer notesStringBuffer = new StringBuffer("");
116
117 notesStringBuffer.append("<table attr=\"norect\" cellpadding=\"0\" width=\"100%\">");
118 notesStringBuffer.append("<tbody attr=\"norect\">");
119
120 for(Text t : noteLayer.getFrame().getTextItems()){
121 notesStringBuffer.append("<tr attr=\"norect\">");
122 notesStringBuffer.append("<td attr=\"norect\">");
123
124 notesStringBuffer.append(t.getText() + "<br/>");
125
126 notesStringBuffer.append("</td>");
127 notesStringBuffer.append("</tr>");
128 }
129
130 notesStringBuffer.append("</table>");
131
132 if(!notesStringBuffer.toString().equals(""))
133 {
134 //Write a "Notes" metadata element to the doc.xml file.
135 Text notesText = new Text(notesStringBuffer.toString());
136 notesText.setData("Notes");
137 _archiveFileEditor.editArchiveDocFile(notesText);
138 }
139 }
140 }
141
142}
Note: See TracBrowser for help on using the repository browser.