1 11 12 package org.eclipse.pde.internal.core.cheatsheet.simple; 13 14 import java.io.IOException ; 15 import java.io.PrintWriter ; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 19 import org.eclipse.pde.internal.core.PDECoreMessages; 20 import org.eclipse.pde.internal.core.XMLPrintHandler; 21 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSDescription; 22 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSIntro; 23 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModel; 24 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSModelFactory; 25 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject; 26 import org.eclipse.pde.internal.core.util.PDETextHelper; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 31 35 public class SimpleCSIntro extends SimpleCSObject implements ISimpleCSIntro { 36 37 40 private ISimpleCSDescription fDescription; 41 42 45 private String fContextId; 46 47 50 private String fHref; 51 52 55 private static final long serialVersionUID = 1L; 56 57 61 public SimpleCSIntro(ISimpleCSModel model, ISimpleCSObject parent) { 62 super(model, parent); 63 reset(); 64 } 65 66 69 public String getContextId() { 70 return fContextId; 71 } 72 73 76 public ISimpleCSDescription getDescription() { 77 return fDescription; 78 } 79 80 83 public String getHref() { 84 return fHref; 85 } 86 87 90 public void setContextId(String contextId) { 91 String old = fContextId; 92 fContextId = contextId; 93 if (isEditable()) { 94 firePropertyChanged(ATTRIBUTE_CONTEXTID, old, fContextId); 95 } 96 } 97 98 101 public void setDescription(ISimpleCSDescription description) { 102 ISimpleCSObject old = fDescription; 103 fDescription = description; 104 105 if (isEditable()) { 106 fireStructureChanged(description, old); 107 } 108 } 109 110 113 public void setHref(String href) { 114 String old = fHref; 115 fHref = href; 116 if (isEditable()) { 117 firePropertyChanged(ATTRIBUTE_HREF, old, fHref); 118 } 119 } 120 121 124 public void parse(Element element) { 125 fContextId = element.getAttribute(ATTRIBUTE_CONTEXTID).trim(); 127 fHref = element.getAttribute(ATTRIBUTE_HREF).trim(); 129 NodeList children = element.getChildNodes(); 131 ISimpleCSModelFactory factory = getModel().getFactory(); 132 for (int i = 0; i < children.getLength(); i++) { 133 Node child = children.item(i); 134 if (child.getNodeType() == Node.ELEMENT_NODE) { 135 Element childElement = (Element )child; 136 String name = child.getNodeName(); 137 if (name.equals(ELEMENT_DESCRIPTION)) { 138 fDescription = factory.createSimpleCSDescription(this); 139 fDescription.parse(childElement); 140 } 141 } 142 } 143 } 144 145 public void write(String indent, PrintWriter writer) { 146 147 StringBuffer buffer = new StringBuffer (); 148 String newIndent = indent + XMLPrintHandler.XML_INDENT; 149 150 try { 151 buffer.append(ELEMENT_INTRO); if ((fContextId != null) && 156 (fContextId.length() > 0)) { 157 buffer.append(XMLPrintHandler.wrapAttribute( 158 ATTRIBUTE_CONTEXTID, 159 PDETextHelper.translateWriteText( 160 fContextId.trim(), SUBSTITUTE_CHARS))); 161 } else if ((fHref != null) && 162 (fHref.length() > 0)) { 163 buffer.append(XMLPrintHandler.wrapAttribute( 164 ATTRIBUTE_HREF, 165 PDETextHelper.translateWriteText( 166 fHref.trim(), SUBSTITUTE_CHARS))); 167 } 168 XMLPrintHandler.printBeginElement(writer, buffer.toString(), 170 indent, false); 171 if (fDescription != null) { 173 fDescription.write(newIndent, writer); 174 } 175 XMLPrintHandler.printEndElement(writer, ELEMENT_INTRO, indent); 177 178 } catch (IOException e) { 179 } 182 } 183 184 187 public void reset() { 188 fDescription = null; 189 fContextId = null; 190 fHref = null; 191 } 192 193 196 public int getType() { 197 return TYPE_INTRO; 198 } 199 200 203 public String getName() { 204 return PDECoreMessages.SimpleCSIntro_0; 205 } 206 207 210 public List getChildren() { 211 return new ArrayList (); 212 } 213 214 } 215 | Popular Tags |