001: /*******************************************************************************
002: * Copyright (c) 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.product;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.pde.internal.core.iproduct.IAboutInfo;
015: import org.eclipse.pde.internal.core.iproduct.IProductModel;
016: import org.w3c.dom.Element;
017: import org.w3c.dom.Node;
018: import org.w3c.dom.NodeList;
019: import org.w3c.dom.Text;
020:
021: public class AboutInfo extends ProductObject implements IAboutInfo {
022:
023: private static final long serialVersionUID = 1L;
024: private String fImagePath;
025: private String fAboutText;
026:
027: public AboutInfo(IProductModel model) {
028: super (model);
029: }
030:
031: /* (non-Javadoc)
032: * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#setText(java.lang.String)
033: */
034: public void setText(String text) {
035: String old = fAboutText;
036: fAboutText = text;
037: if (isEditable())
038: firePropertyChanged(P_TEXT, old, fAboutText);
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#getText()
043: */
044: public String getText() {
045: return fAboutText;
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#setImagePath(java.lang.String)
050: */
051: public void setImagePath(String path) {
052: String old = fImagePath;
053: fImagePath = path;
054: if (isEditable())
055: firePropertyChanged(P_IMAGE, old, fImagePath);
056: }
057:
058: /* (non-Javadoc)
059: * @see org.eclipse.pde.internal.core.iproduct.IAboutInfo#getImagePath()
060: */
061: public String getImagePath() {
062: return fImagePath;
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.pde.internal.core.product.ProductObject#write(java.lang.String, java.io.PrintWriter)
067: */
068: public void write(String indent, PrintWriter writer) {
069: if (isAboutImageDefined() || isAboutTextDefined()) {
070: writer.println(indent + "<aboutInfo>"); //$NON-NLS-1$
071: if (isAboutImageDefined())
072: writer
073: .println(indent
074: + " <image path=\"" + getWritableString(fImagePath.trim()) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
075: if (isAboutTextDefined()) {
076: writer.println(indent + " <text>"); //$NON-NLS-1$
077: writer
078: .println(indent
079: + " " + getWritableString(fAboutText.trim())); //$NON-NLS-1$
080: writer.println(indent + " </text>"); //$NON-NLS-1$
081: }
082: writer.println(indent + "</aboutInfo>"); //$NON-NLS-1$
083: }
084: }
085:
086: private boolean isAboutTextDefined() {
087: return fAboutText != null && fAboutText.length() > 0;
088: }
089:
090: private boolean isAboutImageDefined() {
091: return fImagePath != null && fImagePath.length() > 0;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.eclipse.pde.internal.core.iproduct.IProductObject#parse(org.w3c.dom.Node)
096: */
097: public void parse(Node node) {
098: NodeList children = node.getChildNodes();
099: for (int i = 0; i < children.getLength(); i++) {
100: Node child = children.item(i);
101: if (child.getNodeType() == Node.ELEMENT_NODE) {
102: if (child.getNodeName().equals("image")) { //$NON-NLS-1$
103: fImagePath = ((Element) child).getAttribute("path"); //$NON-NLS-1$
104: } else if (child.getNodeName().equals("text")) { //$NON-NLS-1$
105: child.normalize();
106: if (child.getChildNodes().getLength() > 0) {
107: Node text = child.getFirstChild();
108: if (text.getNodeType() == Node.TEXT_NODE)
109: fAboutText = ((Text) text).getData().trim();
110: }
111: }
112: }
113: }
114: }
115:
116: }
|