/** * 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.text.DateFormat; import java.util.Date; import java.util.Locale; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.pegadi.storysketch.XMLUtil; public class AppointmentCell extends StorySketchCell { public AppointmentCell() { this(new Appointment()); } public AppointmentCell(Object userObject) { super(userObject); } public String getClassDescription() { return "Avtaler"; } public String toHTML() { Appointment a = (Appointment) userObject; StringBuffer html = new StringBuffer(); html.append("<html><body>"); html.append("<b>Avtale "); if(a.getWho().length() > 0) { html.append("med ").append(a.getWho()); } html.append("</b><br>"); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); html.append(df.format(a.getWhen())).append("<br>"); html.append("<table>"); if(a.getWhere().length() > 0) { html.append("<tr><td><b>Hvor:</b></td><td>").append(a.getWhere()).append("</td></tr>"); } if(a.getHowLong().length() > 0) { html.append("<tr><td><b>Varighet:</b></td><td>").append(a.getHowLong()).append("</td></tr>"); } if(a.getNotes().length() > 0) { html.append("<tr><td valign=\"top\"><b>Hva skjer:</b></td><td>").append(toBR(a.getNotes())).append("</td></tr>"); } html.append("</table></body></html>"); return html.toString(); } public Element getCellElement(Document doc) { Element element = doc.createElement("appointmentcell"); Appointment a = (Appointment) userObject; Element ae = doc.createElement("appointment"); Element who = doc.createElement("who"); who.appendChild(doc.createTextNode(a.getWho())); ae.appendChild(who); Element where = doc.createElement("where"); where.appendChild(doc.createTextNode(a.getWhere())); ae.appendChild(where); Element howLong = doc.createElement("howlong"); howLong.appendChild(doc.createTextNode(a.getHowLong())); ae.appendChild(howLong); Element when = doc.createElement("when"); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US); when.appendChild(doc.createTextNode(df.format(a.getWhen()))); ae.appendChild(when); ae.appendChild(XMLUtil.createParagraphElement("interviewbefore", a.getInterviewBefore(), doc)); ae.appendChild(XMLUtil.createParagraphElement("interviewafter", a.getInterviewAfter(), doc)); ae.appendChild(XMLUtil.createParagraphElement("notes", a.getNotes(), doc)); ae.setAttribute("type", Integer.toString(a.getType())); ae.setAttribute("status", a.getStatus()); element.appendChild(ae); return element; } public void setCellElement(Element e) { Appointment a = new Appointment(); Element appointment = (Element)e.getElementsByTagName("appointment").item(0); a.setWho(XMLUtil.extractValue(appointment,"who")); a.setWhere(XMLUtil.extractValue(appointment,"where")); a.setHowLong(XMLUtil.extractValue(appointment,"howlong")); Element ib = (Element)appointment.getElementsByTagName("interviewbefore").item(0); a.setInterviewBefore(XMLUtil.getStringFromParagraphElement(ib)); Element ia = (Element)appointment.getElementsByTagName("interviewafter").item(0); a.setInterviewAfter(XMLUtil.getStringFromParagraphElement(ia)); Element n = (Element)appointment.getElementsByTagName("notes").item(0); a.setNotes(XMLUtil.getStringFromParagraphElement(n)); a.setType(Integer.parseInt(appointment.getAttribute("type"))); a.setStatus(appointment.getAttribute("status")); String when = XMLUtil.extractValue(appointment,"when"); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US); try { a.setWhen(df.parse(when)); } catch (Exception ex) { ex.printStackTrace(); } userObject = a; } }