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

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

Debugging setting of frame number metadata.

File size: 4.0 KB
RevLine 
[26588]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;
[26698]29 ArchiveFileReader afr = new ArchiveFileReader(_collectionItem.getDocXML());
[26588]30
31 for(Item item : items){
32
33 if(item instanceof Text){
34 if(item.isAnnotation()){
35 //TODO: Deal with annotation items correctly.
[26698]36
[26588]37 }else{
38
39 Text text = (Text)item;
[26698]40
[26588]41 if(text.getData() != null)
42 if(text.getData().size() > 0){
[26698]43 String elemText = afr.obtainElementText(text.getData().get(0));
[26588]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);
[26698]55
[26588]56 }
57 }else if(item instanceof Picture){
58 //TODO: Deal with picture items correctly.
59 }
60 }
61
[26698]62 noChange = writeFrameID(afr,noChange);
[26741]63 noChange = addNotes();
[26588]64 //addNotes();
65
66 if(!noChange)
67 _archiveFileEditor.write();
68 }
69
[26698]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){
[26755]99 System.err.println("Setting frame metadata... " + frameIDtext.getText());
[26698]100 _archiveFileEditor.editArchiveDocFile(frameIDtext);
101 noChange = false;
102 }
103
104 return noChange;
105 }
106
107 /**
108 * Method to output any notes associated with an item to the
109 * doc.xml file.
110 */
[26741]111 private boolean addNotes() {
[26588]112 //Add notes to docXML file.
113 NoteLayer noteLayer = _collectionItem.getNoteLayer();
114
115 if(noteLayer != null){
116 StringBuffer notesStringBuffer = new StringBuffer("");
117
118 notesStringBuffer.append("<table attr=\"norect\" cellpadding=\"0\" width=\"100%\">");
119 notesStringBuffer.append("<tbody attr=\"norect\">");
120
121 for(Text t : noteLayer.getFrame().getTextItems()){
122 notesStringBuffer.append("<tr attr=\"norect\">");
123 notesStringBuffer.append("<td attr=\"norect\">");
124
125 notesStringBuffer.append(t.getText() + "<br/>");
126
127 notesStringBuffer.append("</td>");
128 notesStringBuffer.append("</tr>");
129 }
130
[26741]131 notesStringBuffer.append("</tbody>");
[26588]132 notesStringBuffer.append("</table>");
133
134 if(!notesStringBuffer.toString().equals(""))
135 {
136 //Write a "Notes" metadata element to the doc.xml file.
137 Text notesText = new Text(notesStringBuffer.toString());
138 notesText.setData("Notes");
139 _archiveFileEditor.editArchiveDocFile(notesText);
140 }
[26741]141
142 System.err.println("Writing out notes...");
143 return false; //false equates to a change.
[26588]144 }
[26741]145
146 return true; //true equates to "no change"
[26588]147 }
148
149}
Note: See TracBrowser for help on using the repository browser.