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;
011:
012: import java.util.HashMap;
013:
014: import org.eclipse.pde.internal.core.util.PDETextHelper;
015:
016: public class DocumentTextNode extends DocumentXMLNode implements
017: IDocumentTextNode {
018:
019: private static final long serialVersionUID = 1L;
020:
021: protected static final HashMap SUBSTITUTE_CHARS = new HashMap(5);
022:
023: static {
024: SUBSTITUTE_CHARS.put(new Character('&'), "&"); //$NON-NLS-1$
025: SUBSTITUTE_CHARS.put(new Character('<'), "<"); //$NON-NLS-1$
026: SUBSTITUTE_CHARS.put(new Character('>'), ">"); //$NON-NLS-1$
027: SUBSTITUTE_CHARS.put(new Character('\''), "'"); //$NON-NLS-1$
028: SUBSTITUTE_CHARS.put(new Character('\"'), """); //$NON-NLS-1$
029: }
030:
031: private transient int fOffset;
032: private transient int fLength;
033: private transient IDocumentElementNode fEnclosingElement;
034:
035: private String fText;
036:
037: /**
038: *
039: */
040: public DocumentTextNode() {
041: fOffset = -1;
042: fLength = 0;
043: fEnclosingElement = null;
044: }
045:
046: /* (non-Javadoc)
047: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#setEnclosingElement(org.eclipse.pde.internal.ui.model.IDocumentNode)
048: */
049: public void setEnclosingElement(IDocumentElementNode node) {
050: fEnclosingElement = node;
051: }
052:
053: /* (non-Javadoc)
054: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#getEnclosingElement()
055: */
056: public IDocumentElementNode getEnclosingElement() {
057: return fEnclosingElement;
058: }
059:
060: /* (non-Javadoc)
061: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#setText(java.lang.String)
062: */
063: public void setText(String text) {
064: fText = text;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#getText()
069: */
070: public String getText() {
071: return fText == null ? "" : fText; //$NON-NLS-1$
072: }
073:
074: /* (non-Javadoc)
075: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#setOffset(int)
076: */
077: public void setOffset(int offset) {
078: fOffset = offset;
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#getOffset()
083: */
084: public int getOffset() {
085: return fOffset;
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#getLength()
090: */
091: public int getLength() {
092: return fLength;
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.pde.internal.ui.model.IDocumentTextNode#setLength(int)
097: */
098: public void setLength(int length) {
099: fLength = length;
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.pde.internal.core.text.IDocumentTextNode#reconnectText(org.eclipse.pde.internal.core.text.IDocumentElementNode)
104: */
105: public void reconnect(IDocumentElementNode parent) {
106: // Transient field: Enclosing Element
107: // Essentially the parent (an element)
108: fEnclosingElement = parent;
109: // Transient field: Length
110: fLength = -1;
111: // Transient field: Offset
112: fOffset = -1;
113: }
114:
115: /* (non-Javadoc)
116: * @see org.eclipse.pde.internal.core.text.IDocumentTextNode#write()
117: */
118: public String write() {
119: String content = getText().trim();
120: return PDETextHelper.translateWriteText(content,
121: SUBSTITUTE_CHARS);
122: }
123:
124: /* (non-Javadoc)
125: * @see org.eclipse.pde.internal.core.text.IDocumentXMLNode#getXMLType()
126: */
127: public int getXMLType() {
128: return F_TYPE_TEXT;
129: }
130:
131: }
|