1 11 package org.eclipse.pde.internal.core.product; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.pde.internal.core.iproduct.IAboutInfo; 16 import org.eclipse.pde.internal.core.iproduct.IProductModel; 17 import org.w3c.dom.Element ; 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 import org.w3c.dom.Text ; 21 22 23 public class AboutInfo extends ProductObject implements IAboutInfo { 24 25 private static final long serialVersionUID = 1L; 26 private String fImagePath; 27 private String fAboutText; 28 29 public AboutInfo(IProductModel model) { 30 super(model); 31 } 32 33 36 public void setText(String text) { 37 String old = fAboutText; 38 fAboutText = text; 39 if (isEditable()) 40 firePropertyChanged(P_TEXT, old, fAboutText); 41 } 42 43 46 public String getText() { 47 return fAboutText; 48 } 49 50 53 public void setImagePath(String path) { 54 String old = fImagePath; 55 fImagePath = path; 56 if (isEditable()) 57 firePropertyChanged(P_IMAGE, old, fImagePath); 58 } 59 60 63 public String getImagePath() { 64 return fImagePath; 65 } 66 67 70 public void write(String indent, PrintWriter writer) { 71 if (isAboutImageDefined() || isAboutTextDefined()) { 72 writer.println(indent + "<aboutInfo>"); if (isAboutImageDefined()) 74 writer.println(indent + " <image path=\"" + getWritableString(fImagePath.trim()) + "\"/>"); if (isAboutTextDefined()) { 76 writer.println(indent + " <text>"); writer.println(indent + " " + getWritableString(fAboutText.trim())); writer.println(indent + " </text>"); } 80 writer.println(indent + "</aboutInfo>"); } 82 } 83 84 private boolean isAboutTextDefined() { 85 return fAboutText != null && fAboutText.length() > 0; 86 } 87 88 private boolean isAboutImageDefined() { 89 return fImagePath != null && fImagePath.length() > 0; 90 } 91 92 95 public void parse(Node node) { 96 NodeList children = node.getChildNodes(); 97 for (int i = 0; i < children.getLength(); i++) { 98 Node child = children.item(i); 99 if (child.getNodeType() == Node.ELEMENT_NODE) { 100 if (child.getNodeName().equals("image")) { fImagePath = ((Element )child).getAttribute("path"); } else if (child.getNodeName().equals("text")) { child.normalize(); 104 if (child.getChildNodes().getLength() > 0) { 105 Node text = child.getFirstChild(); 106 if (text.getNodeType() == Node.TEXT_NODE) 107 fAboutText = ((Text )text).getData().trim(); 108 } 109 } 110 } 111 } 112 } 113 114 } 115 | Popular Tags |