/** * 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 org.w3c.dom.Document; import org.w3c.dom.Element; import org.pegadi.storysketch.XMLUtil; public class PersonCell extends StorySketchCell { public PersonCell() { this(new Person()); } public PersonCell(Object userObject) { super(userObject); } public String getClassDescription() { return "Personer"; } public String toHTML() { Person p = (Person) userObject; StringBuffer html = new StringBuffer(); html.append("<html><body>"); if(p.getName().length() > 0) { html.append("<b>").append(p.getName()).append("</b>"); } else { html.append("<b>Person (uten navn) </b><br><i>Tips: </i>Du kan søke eller skrive inn informasjon ved å dobbeltklikke på personen"); } html.append("<table>"); if(p.getPhone().length() > 0) { html.append("<tr><td><b>Telefon:</b></td><td>").append(p.getPhone()).append("</td></tr>"); } if(p.getEmail().length() > 0) { String address = p.getEmail(); if(p.getName().length() > 1) { address = p.getName() +" <" +address +">"; } html.append("<tr><td><b>Epost:</b></td><td><a href=\"mailto:").append(address).append("\">").append(p.getEmail()).append("</a></td></tr>"); } if(p.getOrganization().length() > 0) { html.append("<tr><td valign=\"top\"><b>Org.:</b></td><td>").append(p.getOrganization()).append("</td></tr>"); } if(p.getPosition().length() > 0) { html.append("<tr><td valign=\"top\"><b>Stilling:</b></td><td>").append(p.getPosition()).append("</td></tr>"); } if(p.getAddress().length() > 0) { html.append("<tr><td><b>Adresse:</b></td><td>").append(p.getAddress()).append("</td></tr>"); } html.append("</table></body></html>"); return html.toString(); } public Object clone() { Person p = (Person) userObject; return new PersonCell(p.clone()); } public Element getCellElement(Document doc) { Element element = doc.createElement("personcell"); Person person = (Person)userObject; Element personElement = doc.createElement("person"); Element name = doc.createElement("name"); name.appendChild(doc.createTextNode(person.getName())); personElement.appendChild(name); personElement.appendChild(XMLUtil.createParagraphElement("organization", person.getOrganization(), doc)); Element position = doc.createElement("position"); position.appendChild(doc.createTextNode(person.getPosition())); personElement.appendChild(position); Element phone = doc.createElement("phone"); phone.appendChild(doc.createTextNode(person.getPhone())); personElement.appendChild(phone); Element email = doc.createElement("email"); email.appendChild(doc.createTextNode(person.getEmail())); personElement.appendChild(email); personElement.appendChild(XMLUtil.createParagraphElement("address", person.getAddress(), doc)); personElement.setAttribute("mood", Integer.toString(person.getMood())); personElement.setAttribute("anonymous",Boolean.toString(person.isAnonymous())); element.appendChild(personElement); return element; } public void setCellElement(Element e) { Person p = new Person(); Element person = (Element)e.getElementsByTagName("person").item(0); p.setName(XMLUtil.extractValue(person,"name")); Element o = (Element)person.getElementsByTagName("organization").item(0); p.setOrganization(XMLUtil.getStringFromParagraphElement(o)); p.setPosition(XMLUtil.extractValue(person,"position")); p.setPhone(XMLUtil.extractValue(person,"phone")); p.setEmail(XMLUtil.extractValue(person,"email")); Element a = (Element)person.getElementsByTagName("address").item(0); p.setAddress(XMLUtil.getStringFromParagraphElement(a)); p.setMood(Integer.parseInt(person.getAttribute("mood"))); p.setAnonymous(Boolean.valueOf(person.getAttribute("anonymous"))); userObject = p; } }