/**
* Copyright 1999-2009 The Pegadi Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pegadi.storysketch.cells;
import java.util.ArrayList;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.pegadi.storysketch.views.RDFItem;
public class ArchiveCell extends StorySketchCell {
public ArchiveCell() {
this(new Archive());
}
public ArchiveCell(Object userObject) {
super(userObject);
}
public String getClassDescription() {
return "Arkivsaker";
}
public String toHTML() {
Archive a = (Archive) userObject;
StringBuffer html = new StringBuffer();
html.append("<html><body><b>Arkivsaker</b><br>");
RDFItem[] items = a.getRDFItems();
if(items.length > 0) {
for (RDFItem item : items) {
html.append("\u2022 <a href=\"").append(item.getID()).append("\">").append(item.getTitle()).append("</a><br>");
}
html.append("</ul>");
} else {
html.append("<br><i>Tips: </i>Dobbelklikk på arkivikonet for å finne og legge til arkivsaker");
}
html.append("</body></html>");
return html.toString();
}
public Element getCellElement(Document doc) {
Element element = doc.createElement("archivecell");
Archive a = (Archive) getUserObject();
RDFItem[] items = a.getRDFItems();
Element archive = doc.createElement("archive");
for (RDFItem item : items) {
archive.appendChild(item.createElement(doc));
}
element.appendChild(archive);
return element;
}
public void setCellElement(Element e) {
Archive a = new Archive();
ArrayList items = new ArrayList();
NodeList nl = e.getElementsByTagName("item");
for(int i = 0; i < nl.getLength(); i++) {
Element item = (Element) nl.item(i);
items.add(new RDFItem(item));
}
a.setRDFItems((RDFItem[]) items.toArray(new RDFItem[items.size()]));
userObject = a;
}
}