package org.honours.greenstone; import java.util.List; import org.apache.log4j.Logger; import org.expeditee.items.Item; import org.expeditee.items.Picture; import org.expeditee.items.Text; import org.honours.collection.CollectionItem; import org.honours.collection.NoteLayer; public class CollectionContentEditor { static Logger logger = Logger.getLogger(org.honours.greenstone.CollectionContentEditor.class.getName()); private CollectionItem _collectionItem; private ArchiveFileEditor _archiveFileEditor; //private HtmlForDocXML _htmlForDocXML; public CollectionContentEditor(CollectionItem currCI, String _collectionPath) { _collectionItem = currCI; _archiveFileEditor = new ArchiveFileEditor(_collectionItem.getDocXML()); } public void editCollectionItems() { List items = _collectionItem.getFrame().getItems(); boolean noChange = true; for(Item item : items){ if(item instanceof Text){ if(item.isAnnotation()){ //TODO: Deal with annotation items correctly. }else{ Text text = (Text)item; ArchiveFileReader afe = new ArchiveFileReader(_collectionItem.getDocXML()); if(text.getData() != null) if(text.getData().size() > 0){ String elemText = afe.obtainElementText(text.getData().get(0)); if(!elemText.equals(null)){ if(elemText.equals(text.getText())) continue; else noChange = false; } } if(!noChange) _archiveFileEditor.editArchiveDocFile(text); } }else if(item instanceof Picture){ //TODO: Deal with picture items correctly. } } //addNotes(); if(!noChange) _archiveFileEditor.write(); } private void addNotes() { //Add notes to docXML file. NoteLayer noteLayer = _collectionItem.getNoteLayer(); if(noteLayer != null){ StringBuffer notesStringBuffer = new StringBuffer(""); notesStringBuffer.append(""); notesStringBuffer.append(""); for(Text t : noteLayer.getFrame().getTextItems()){ notesStringBuffer.append(""); notesStringBuffer.append(""); notesStringBuffer.append(""); } notesStringBuffer.append("
"); notesStringBuffer.append(t.getText() + "
"); notesStringBuffer.append("
"); if(!notesStringBuffer.toString().equals("")) { //Write a "Notes" metadata element to the doc.xml file. Text notesText = new Text(notesStringBuffer.toString()); notesText.setData("Notes"); _archiveFileEditor.editArchiveDocFile(notesText); } } } }