001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 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.cheatsheet.comp;
011:
012: import java.io.PrintWriter;
013: import java.util.ArrayList;
014: import java.util.List;
015:
016: import org.eclipse.pde.internal.core.XMLPrintHandler;
017: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModel;
018: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
019: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam;
020: import org.eclipse.pde.internal.core.util.PDETextHelper;
021: import org.w3c.dom.Element;
022: import org.w3c.dom.Text;
023:
024: /**
025: * CompCSParam
026: *
027: */
028: public class CompCSParam extends CompCSObject implements ICompCSParam {
029:
030: private String fFieldName;
031:
032: private String fFieldValue;
033:
034: /**
035: *
036: */
037: private static final long serialVersionUID = 1L;
038:
039: /**
040: * @param model
041: * @param parent
042: */
043: public CompCSParam(ICompCSModel model, ICompCSObject parent) {
044: super (model, parent);
045: reset();
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getChildren()
050: */
051: public List getChildren() {
052: return new ArrayList();
053: }
054:
055: /* (non-Javadoc)
056: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getElement()
057: */
058: public String getElement() {
059: return ELEMENT_PARAM;
060: }
061:
062: /* (non-Javadoc)
063: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getName()
064: */
065: public String getName() {
066: return fFieldName;
067: }
068:
069: /* (non-Javadoc)
070: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#getType()
071: */
072: public int getType() {
073: return TYPE_PARAM;
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseAttributes(org.w3c.dom.Element)
078: */
079: protected void parseAttributes(Element element) {
080: // Process name attribute
081: // Trim leading and trailing whitespace
082: fFieldName = element.getAttribute(ATTRIBUTE_NAME).trim();
083: // Process value attribute
084: // Trim leading and trailing whitespace
085: fFieldValue = element.getAttribute(ATTRIBUTE_VALUE).trim();
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseElement(org.w3c.dom.Element)
090: */
091: protected void parseElement(Element element) {
092: // NO-OP
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#reset()
097: */
098: public void reset() {
099: fFieldName = null;
100: fFieldValue = null;
101: }
102:
103: /* (non-Javadoc)
104: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeAttributes(java.lang.StringBuffer)
105: */
106: protected void writeAttributes(StringBuffer buffer) {
107: // Print name attribute
108: if ((fFieldName != null) && (fFieldName.length() > 0)) {
109: // No trim required
110: // No encode required
111: buffer.append(XMLPrintHandler.wrapAttribute(ATTRIBUTE_NAME,
112: fFieldName));
113: }
114: // Print value attribute
115: if ((fFieldValue != null) && (fFieldValue.length() > 0)) {
116: // Trim leading and trailing whitespace
117: // Encode characters
118: buffer.append(XMLPrintHandler.wrapAttribute(
119: ATTRIBUTE_VALUE, PDETextHelper.translateWriteText(
120: fFieldValue.trim(),
121: DEFAULT_SUBSTITUTE_CHARS)));
122: }
123: }
124:
125: /* (non-Javadoc)
126: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#writeElements(java.lang.String, java.io.PrintWriter)
127: */
128: protected void writeElements(String indent, PrintWriter writer) {
129: // NO-OP
130: }
131:
132: /* (non-Javadoc)
133: * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#getFieldName()
134: */
135: public String getFieldName() {
136: return fFieldName;
137: }
138:
139: /* (non-Javadoc)
140: * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#getFieldValue()
141: */
142: public String getFieldValue() {
143: return fFieldValue;
144: }
145:
146: /* (non-Javadoc)
147: * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#setFieldName(java.lang.String)
148: */
149: public void setFieldName(String name) {
150: String old = fFieldName;
151: fFieldName = name;
152: if (isEditable()) {
153: firePropertyChanged(ATTRIBUTE_NAME, old, fFieldName);
154: }
155: }
156:
157: /* (non-Javadoc)
158: * @see org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSParam#setFieldValue(java.lang.String)
159: */
160: public void setFieldValue(String value) {
161: String old = fFieldValue;
162: fFieldValue = value;
163: if (isEditable()) {
164: firePropertyChanged(ATTRIBUTE_VALUE, old, fFieldValue);
165: }
166: }
167:
168: /* (non-Javadoc)
169: * @see org.eclipse.pde.internal.core.cheatsheet.comp.CompCSObject#parseText(org.w3c.dom.Text)
170: */
171: protected void parseText(Text text) {
172: // NO-OP
173: }
174:
175: }
|