001: /*******************************************************************************
002: * Copyright (c) 2000, 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.text.plugin;
011:
012: import java.io.PrintWriter;
013:
014: import org.eclipse.core.runtime.CoreException;
015: import org.eclipse.pde.core.plugin.IPluginAttribute;
016: import org.eclipse.pde.internal.core.text.DocumentAttributeNode;
017: import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
018: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
019:
020: public class PluginAttribute extends PluginObjectNode implements
021: IPluginAttribute, IDocumentAttributeNode {
022:
023: private static final long serialVersionUID = 1L;
024:
025: // The plugin attribute interface requires this class to extend PluginObjectNode
026: // However, by doing that this class also extends the document
027: // element node class - which is wrong when implementing
028: // the document attribute node interface
029: // To work around this issue, we use an adaptor.
030: private DocumentAttributeNode fAttribute;
031:
032: private String fValue;
033:
034: /**
035: *
036: */
037: public PluginAttribute() {
038: super ();
039: fAttribute = new DocumentAttributeNode();
040: fValue = null;
041: }
042:
043: /* (non-Javadoc)
044: * @see org.eclipse.pde.core.plugin.IPluginAttribute#getValue()
045: */
046: public String getValue() {
047: return fValue;
048: }
049:
050: /* (non-Javadoc)
051: * @see org.eclipse.pde.core.plugin.IPluginAttribute#setValue(java.lang.String)
052: */
053: public void setValue(String value) throws CoreException {
054: fValue = value;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setEnclosingElement(org.eclipse.pde.internal.ui.model.IDocumentNode)
059: */
060: public void setEnclosingElement(IDocumentElementNode node) {
061: fAttribute.setEnclosingElement(node);
062: }
063:
064: /* (non-Javadoc)
065: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getEnclosingElement()
066: */
067: public IDocumentElementNode getEnclosingElement() {
068: return fAttribute.getEnclosingElement();
069: }
070:
071: /* (non-Javadoc)
072: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setNameOffset(int)
073: */
074: public void setNameOffset(int offset) {
075: fAttribute.setNameOffset(offset);
076: }
077:
078: /* (non-Javadoc)
079: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getNameOffset()
080: */
081: public int getNameOffset() {
082: return fAttribute.getNameOffset();
083: }
084:
085: /* (non-Javadoc)
086: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setNameLength(int)
087: */
088: public void setNameLength(int length) {
089: fAttribute.setNameLength(length);
090: }
091:
092: /* (non-Javadoc)
093: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getNameLength()
094: */
095: public int getNameLength() {
096: return fAttribute.getNameLength();
097: }
098:
099: /* (non-Javadoc)
100: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setValueOffset(int)
101: */
102: public void setValueOffset(int offset) {
103: fAttribute.setValueOffset(offset);
104: }
105:
106: /* (non-Javadoc)
107: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getValueOffset()
108: */
109: public int getValueOffset() {
110: return fAttribute.getValueOffset();
111: }
112:
113: /* (non-Javadoc)
114: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#setValueLength(int)
115: */
116: public void setValueLength(int length) {
117: fAttribute.setValueLength(length);
118: }
119:
120: /* (non-Javadoc)
121: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getValueLength()
122: */
123: public int getValueLength() {
124: return fAttribute.getValueLength();
125: }
126:
127: /* (non-Javadoc)
128: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getAttributeName()
129: */
130: public String getAttributeName() {
131: return getName();
132: }
133:
134: /* (non-Javadoc)
135: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#getAttributeValue()
136: */
137: public String getAttributeValue() {
138: return getValue();
139: }
140:
141: /* (non-Javadoc)
142: * @see org.eclipse.pde.internal.ui.model.IDocumentAttribute#write()
143: */
144: public String write() {
145: return getName() + "=\"" + getWritableString(getValue()) + "\""; //$NON-NLS-1$ //$NON-NLS-2$
146: }
147:
148: /* (non-Javadoc)
149: * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#getWritableString(java.lang.String)
150: */
151: public String getWritableString(String source) {
152: return super .getWritableString(source).replaceAll(
153: "\\r", "
") //$NON-NLS-1$ //$NON-NLS-2$
154: .replaceAll("\\n", "
"); //$NON-NLS-1$ //$NON-NLS-2$
155: }
156:
157: /* (non-Javadoc)
158: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setAttributeName(java.lang.String)
159: */
160: public void setAttributeName(String name) throws CoreException {
161: setName(name);
162: }
163:
164: /* (non-Javadoc)
165: * @see org.eclipse.pde.internal.core.text.IDocumentAttributeNode#setAttributeValue(java.lang.String)
166: */
167: public void setAttributeValue(String value) throws CoreException {
168: setValue(value);
169: }
170:
171: /* (non-Javadoc)
172: * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#reconnect(org.eclipse.pde.core.plugin.ISharedPluginModel, org.eclipse.pde.internal.core.ischema.ISchema, org.eclipse.pde.internal.core.text.IDocumentElementNode)
173: */
174: public void reconnect(IDocumentElementNode parent) {
175: // Inconsistency in model
176: // A document attribute node should not extend plugin object because plugin object extends
177: // document element node
178: super .reconnect(parent, getModel());
179: fAttribute.reconnect(parent);
180: }
181:
182: /* (non-Javadoc)
183: * @see org.eclipse.pde.internal.core.text.plugin.PluginObjectNode#write(java.lang.String, java.io.PrintWriter)
184: */
185: public void write(String indent, PrintWriter writer) {
186: // Used for text transfers for copy, cut, paste operations
187: // Although attributes cannot be copied directly
188: writer.write(write());
189: }
190:
191: }
|