Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document')
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/AttrImpl.java780
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CDATASectionImpl.java148
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CMNodeUtil.java42
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharOperation.java91
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterDataImpl.java356
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterStringPool.java100
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CommentImpl.java204
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.java43
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.properties17
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMModelImpl.java981
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentFragmentImpl.java81
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentImpl.java1208
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapter.java51
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapterImpl.java119
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeImpl.java228
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ElementImpl.java1552
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityImpl.java247
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityReferenceImpl.java95
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/InvalidCharacterException.java67
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/JSPTag.java34
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ModelParserAdapter.java57
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeContainer.java534
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeImpl.java1171
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeIteratorImpl.java257
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeListImpl.java157
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NotationImpl.java144
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ProcessingInstructionImpl.java233
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/RangeImpl.java630
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java343
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/SourceValidator.java388
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionChecker.java143
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionContainer.java435
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionManagementException.java33
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionProxy.java369
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionUtil.java178
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TagAdapter.java35
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TextImpl.java1192
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/UserData.java56
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLGeneratorImpl.java735
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelContext.java237
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifier.java139
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifierImpl.java496
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelParser.java2422
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelUpdater.java1704
44 files changed, 0 insertions, 18532 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/AttrImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/AttrImpl.java
deleted file mode 100644
index 7c0af3399b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/AttrImpl.java
+++ /dev/null
@@ -1,780 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- *
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLCharEntity;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLNamespace;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * AttrImpl class
- */
-public class AttrImpl extends NodeImpl implements IDOMAttr {
-
- private ITextRegion equalRegion = null;
-
- private char[] fName = null;
- private ITextRegion nameRegion = null;
- private ElementImpl ownerElement = null;
- private ITextRegion fValueRegion = null;
- private char[] fValueSource = null;
- private char[] fNamespaceURI = null;
-
- /**
- * AttrImpl constructor
- */
- protected AttrImpl() {
- super();
- }
-
- /**
- * AttrImpl constructor
- *
- * @param that
- * AttrImpl
- */
- protected AttrImpl(AttrImpl that) {
- super(that);
-
- if (that != null) {
- this.fName = that.fName;
- String valueSource = that.getValueSource();
- if (valueSource != null)
- this.fValueSource = valueSource.toCharArray();
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- */
- public Node cloneNode(boolean deep) {
- AttrImpl cloned = new AttrImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- */
- protected CMAttributeDeclaration getDeclaration() {
- ElementImpl element = (ElementImpl) getOwnerElement();
- if (element == null)
- return null;
- CMElementDeclaration elementDecl = element.getDeclaration();
- if (elementDecl == null)
- return null;
-
- List nodes = ModelQueryUtil.getModelQuery(getOwnerDocument()).getAvailableContent(getOwnerElement(), elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
- String name = getName();
- for (int k = 0; k < nodes.size(); k++) {
- CMNode cmnode = (CMNode) nodes.get(k);
- if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION && name.equals(cmnode.getNodeName())) {
- return (CMAttributeDeclaration) cmnode;
- }
- }
- return null;
- }
-
- /**
- * getEndOffset method
- *
- * @return int
- */
- public int getEndOffset() {
- if (this.ownerElement == null)
- return 0;
- int offset = this.ownerElement.getStartOffset();
- if (this.fValueRegion != null) {
- return (offset + this.fValueRegion.getEnd());
- }
- if (this.equalRegion != null) {
- return (offset + this.equalRegion.getEnd());
- }
- if (this.nameRegion != null) {
- return (offset + this.nameRegion.getEnd());
- }
- return 0;
- }
-
-
- public ITextRegion getEqualRegion() {
- return this.equalRegion;
- }
-
- public String getLocalName() {
- if (this.fName == null)
- return null;
- int index = CharOperation.indexOf(this.fName, ':');
- if (index < 0)
- return new String(this.fName);
- return new String(this.fName, index + 1, this.fName.length - index - 1);
- }
-
- /**
- * getName method
- *
- * @return java.lang.String
- */
- public String getName() {
- if (this.fName == null)
- return NodeImpl.EMPTY_STRING;
- return new String(this.fName);
- }
-
-
- public ITextRegion getNameRegion() {
- return this.nameRegion;
- }
-
- public int getNameRegionEndOffset() {
- if (this.ownerElement == null)
- return 0;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // attributes
- IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return 0;
- return flatNode.getEndOffset(this.nameRegion);
- }
-
- public int getNameRegionStartOffset() {
- if (this.ownerElement == null)
- return 0;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // attributes
- IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return 0;
- return flatNode.getStartOffset(this.nameRegion);
- }
-
- public String getNameRegionText() {
- if (this.ownerElement == null)
- return null;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // attributes
- IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return null;
- return flatNode.getText(this.nameRegion);
- }
-
- public int getNameRegionTextEndOffset() {
- if (this.ownerElement == null)
- return 0;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // attributes
- IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return 0;
- return flatNode.getTextEndOffset(this.nameRegion);
- }
-
- public String getNamespaceURI() {
- String nsAttrName = null;
- String prefix = getPrefix();
- if (prefix != null && prefix.length() > 0) {
- if (prefix.equals(IXMLNamespace.XMLNS)) {
- // fixed URI
- return IXMLNamespace.XMLNS_URI;
- }
- else if (prefix.equals(IXMLNamespace.XML)) {
- // fixed URI
- return IXMLNamespace.XML_URI;
- }
-
- nsAttrName = IXMLNamespace.XMLNS_PREFIX + prefix;
- }
- else {
- String name = getName();
- if (name != null && name.equals(IXMLNamespace.XMLNS)) {
- // fixed URI
- return IXMLNamespace.XMLNS_URI;
- }
- // does not inherit namespace from owner element
- // if (this.ownerElement != null) return
- // this.ownerElement.getNamespaceURI();
- if (this.fNamespaceURI == null)
- return null;
- return new String(this.fNamespaceURI);
- }
-
- for (Node node = this.ownerElement; node != null; node = node.getParentNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- break;
- Element element = (Element) node;
- Attr attr = element.getAttributeNode(nsAttrName);
- if (attr != null)
- return attr.getValue();
- }
-
- if (this.fNamespaceURI == null)
- return null;
- return new String(this.fNamespaceURI);
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return getName();
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return ATTRIBUTE_NODE;
- }
-
- /**
- * getNodeValue method
- *
- * @return java.lang.String
- */
- public String getNodeValue() {
- return getValue();
- }
-
- /**
- * getOwnerElement method
- *
- * @return org.w3c.dom.Element
- */
- public Element getOwnerElement() {
- return this.ownerElement;
- }
-
- /**
- */
- public String getPrefix() {
- if (this.fName == null)
- return null;
- int index = CharOperation.indexOf(this.fName, ':');
- if (index <= 0)
- return null;
- // exclude JSP tag in name
- if (this.fName[0] == '<')
- return null;
- return new String(this.fName, 0, index);
- }
-
- /**
- * getSpecified method
- *
- * @return boolean
- */
- public boolean getSpecified() {
- // if there is no underlying document region,
- // then this attributes value has not really be specified
- // yet in the document, and any returned values, such as
- // an empty string or a default value are being supplied
- // as per spec, not per what's in the users document.
- return this.fValueRegion != null;
- }
-
- /**
- * getStartOffset method
- *
- * @return int
- */
- public int getStartOffset() {
- if (this.ownerElement == null)
- return 0;
- int offset = this.ownerElement.getStartOffset();
- if (this.nameRegion != null) {
- return (offset + this.nameRegion.getStart());
- }
- if (this.equalRegion != null) {
- return (offset + this.equalRegion.getStart());
- }
- if (this.fValueRegion != null) {
- return (offset + this.fValueRegion.getStart());
- }
- return 0;
- }
-
- /**
- * getValue method
- *
- * @return java.lang.String
- */
- public String getValue() {
- return getValue(getValueSource());
- }
-
- /**
- * Returns value for the source
- */
- private String getValue(String source) {
- if (source == null)
- return NodeImpl.EMPTY_STRING;
- if (source.length() == 0)
- return source;
- StringBuffer buffer = null;
- int offset = 0;
- int length = source.length();
- int ref = source.indexOf('&');
- while (ref >= 0) {
- int end = source.indexOf(';', ref + 1);
- if (end > ref + 1) {
- String name = source.substring(ref + 1, end);
- String value = getCharValue(name);
- if (value != null) {
- if (buffer == null)
- buffer = new StringBuffer(length);
- if (ref > offset)
- buffer.append(source.substring(offset, ref));
- buffer.append(value);
- offset = end + 1;
- ref = end;
- }
- }
- ref = source.indexOf('&', ref + 1);
- }
- if (buffer == null)
- return source;
- if (length > offset)
- buffer.append(source.substring(offset));
- return buffer.toString();
- }
-
- public ITextRegion getValueRegion() {
- return this.fValueRegion;
- }
-
- /**
- * ISSUE: what should behavior be if this.value == null? It's an "error"
- * to be in that state, but seems to occur relatively easily ... probably
- * due to threading bugs ... but this just shows its needs to be spec'd.
- *
- */
- public int getValueRegionStartOffset() {
- if (this.ownerElement == null)
- return 0;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // the valueRegion -- should make smarter?
- IStructuredDocumentRegion structuredDocumentRegion = this.ownerElement.getFirstStructuredDocumentRegion();
- if (structuredDocumentRegion == null)
- return 0;
- // ensure we never pass null to getStartOffset.
- if (this.fValueRegion == null) {
- return 0;
- }
- return structuredDocumentRegion.getStartOffset(this.fValueRegion);
- }
-
- public String getValueRegionText() {
- if (this.ownerElement == null)
- return null;
- // assuming the firstStructuredDocumentRegion is the one that contains
- // attributes
- IStructuredDocumentRegion flatNode = this.ownerElement.getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return null;
- if (this.fValueRegion == null)
- return null;
- return flatNode.getText(this.fValueRegion);
- }
-
- /**
- */
- public String getValueSource() {
- if (this.fValueSource != null)
- return new String(this.fValueSource);
- // DW: 4/16/2003 due to change in structuredDocument ... we need a
- // flatnode to
- // get at region values. For now I'll assume this is always the first
- // flatnode .. may need to make smarter later (e.g. to search for
- // the flatnode that this.valueRegion belongs to.
- // DW: 4/30/2003 For some reason, this method is getting called a lot
- // Not sure if its a threading problem, or a fundamental error
- // elsewhere.
- // It needs more investigation, but in the use cases I've seen,
- // doesn't
- // seem to hurt to simply return null in those cases. I saw this null
- // case,
- // when trying go format an XML file.
- if (this.ownerElement == null)
- return null;
- //attribute values will always be in the start region
- IStructuredDocumentRegion ownerRegion = this.ownerElement.getStartStructuredDocumentRegion();
- if (ownerRegion == null)
- return null;
- if (this.fValueRegion != null)
- return StructuredDocumentRegionUtil.getAttrValue(ownerRegion, this.fValueRegion);
- return NodeImpl.EMPTY_STRING;
- }
-
- private String getValueSource(ElementImpl ownerElement) {
- if (this.fValueSource != null)
- return new String(this.fValueSource);
- // DW: 4/16/2003 due to change in structuredDocument ... we need a
- // flatnode to
- // get at region values. For now I'll assume this is always the first
- // flatnode .. may need to make smarter later (e.g. to search for
- // the flatnode that this.valueRegion belongs to.
- if (this.fValueRegion != null)
- return StructuredDocumentRegionUtil.getAttrValue(ownerElement.getStructuredDocumentRegion(), this.fValueRegion);
- return NodeImpl.EMPTY_STRING;
- }
-
- /**
- */
- private String getValueSource(String value) {
- if (value == null)
- return null;
- if (value.length() == 0)
- return value;
- StringBuffer buffer = null;
- int offset = 0;
- int length = value.length();
- int amp = value.indexOf('&');
- while (amp >= 0) {
- if (buffer == null)
- buffer = new StringBuffer(length + 4);
- if (amp > offset)
- buffer.append(value.substring(offset, amp));
- buffer.append(IXMLCharEntity.AMP_REF);
- offset = amp + 1;
- amp = value.indexOf('&', offset);
- }
- if (buffer == null)
- return value;
- if (length > offset)
- buffer.append(value.substring(offset));
- return buffer.toString();
- }
-
- /**
- * Check if Attr has JSP in value
- */
- public boolean hasNestedValue() {
- if (this.fValueRegion == null)
- return false;
- if (!(this.fValueRegion instanceof ITextRegionContainer))
- return false;
- ITextRegionList regions = ((ITextRegionContainer) this.fValueRegion).getRegions();
- if (regions == null)
- return false;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- if (region == null)
- continue;
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_OPEN || isNestedLanguageOpening(regionType))
- return true;
- }
- return false;
- }
-
- /**
- * Check if Attr has only name but not equal sign nor value
- */
- public boolean hasNameOnly() {
- return (this.nameRegion != null && this.equalRegion == null && this.fValueRegion == null);
- }
-
- /**
- */
- protected final boolean hasPrefix() {
- if (this.fName == null || this.fName.length == 0)
- return false;
- return CharOperation.indexOf(this.fName, ':') > 0 && this.fName[0] != '<';
- }
-
- /**
- */
- protected final boolean ignoreCase() {
- if (this.ownerElement != null) {
- if (this.ownerElement.ignoreCase()) {
- return !hasPrefix();
- }
- }
- else {
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document != null && document.ignoreCase()) {
- // even in case insensitive document, if having prefix, it's
- // case sensitive
- return !hasPrefix();
- }
- }
- return false;
- }
-
- /**
- */
- public boolean isGlobalAttr() {
- if (hasPrefix())
- return false;
- if (this.ownerElement == null)
- return false;
- return this.ownerElement.isGlobalTag();
- }
-
- /**
- */
- public final boolean isXMLAttr() {
- if (this.ownerElement != null) {
- if (!this.ownerElement.isXMLTag()) {
- return hasPrefix();
- }
- }
- else {
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document != null && !document.isXMLType()) {
- // even in non-XML document, if having prefix, it's XML tag
- return hasPrefix();
- }
- }
- return true;
- }
-
- /**
- * matchName method
- *
- * @return boolean
- * @param name
- * java.lang.String
- */
- protected boolean matchName(String name) {
- if (name == null)
- return (this.fName == null);
- if (this.fName == null)
- return false;
- return CharOperation.equals(this.fName, name.toCharArray(), ignoreCase());
- }
-
- protected boolean matchName(char[] name) {
- if (name == null)
- return (this.fName == null);
- if (this.fName == null)
- return false;
- return CharOperation.equals(this.fName, name, ignoreCase());
- }
-
-
- /**
- * notifyValueChanged method
- */
- protected void notifyNameChanged() {
- if (this.ownerElement == null)
- return;
- DocumentImpl document = (DocumentImpl) this.ownerElement.getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.nameChanged(this);
- }
-
- /**
- * notifyValueChanged method
- */
- protected void notifyValueChanged() {
- if (this.ownerElement == null)
- return;
- DocumentImpl document = (DocumentImpl) this.ownerElement.getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.valueChanged(this);
- }
-
- /**
- * removeRegions method
- */
- void removeRegions() {
- this.nameRegion = null;
- this.fValueRegion = null;
- this.equalRegion = null;
- }
-
- /**
- */
- void resetRegions() {
- this.fValueSource = getValueSource().toCharArray();
- removeRegions();
- }
-
- /**
- */
- void resetRegions(ElementImpl ownerElement) {
- this.fValueSource = getValueSource(ownerElement).toCharArray();
- removeRegions();
- }
-
- void setEqualRegion(ITextRegion equalRegion) {
- this.equalRegion = equalRegion;
- }
-
- /**
- * setName method
- *
- * @param name
- * java.lang.String
- */
- protected void setName(String name) {
- String value = null;
- int startOffset = 0;
- if (this.ownerElement != null) {
- value = getValue();
- startOffset = this.ownerElement.getStartOffset();
- this.ownerElement.notify(REMOVE, this, value, null, startOffset);
- }
- this.fName = CharacterStringPool.getCharString(name);
- if (this.ownerElement != null) {
- this.ownerElement.notify(ADD, this, null, value, startOffset);
- }
- }
-
- void setNameRegion(ITextRegion nameRegion) {
- this.nameRegion = nameRegion;
- }
-
- protected void setNamespaceURI(String namespaceURI) {
- if (namespaceURI == null)
- this.fNamespaceURI = null;
- else
- this.fNamespaceURI = namespaceURI.toCharArray();
- }
-
- /**
- * setNodeValue method
- *
- * @param nodeValue
- * java.lang.String
- */
- public void setNodeValue(String nodeValue) throws DOMException {
- setValue(nodeValue);
- }
-
- /**
- * setOwnerElement method
- *
- * @param ownerElement
- * org.w3c.dom.Element
- */
- protected void setOwnerElement(Element ownerElement) {
- this.ownerElement = (ElementImpl) ownerElement;
- }
-
- /**
- */
- public void setPrefix(String prefix) throws DOMException {
- if (this.ownerElement != null && !this.ownerElement.isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- int prefixLength = (prefix != null ? prefix.length() : 0);
- String localName = getLocalName();
- if (prefixLength == 0) {
- setName(localName);
- return;
- }
- if (localName == null)
- localName = NodeImpl.EMPTY_STRING;
- int localLength = localName.length();
- StringBuffer buffer = new StringBuffer(prefixLength + 1 + localLength);
- buffer.append(prefix);
- buffer.append(':');
- buffer.append(localName);
- setName(buffer.toString());
-
- notifyNameChanged();
- }
-
- /**
- * setValue method
- *
- * @param value
- * java.lang.String
- */
- public void setValue(String value) {
- // Remember: as we account for "floaters" in
- // future, remember that some are created
- // in the natural process of implementing
- // DOM apis.
- // this "self notification" of about/changed,
- // is added for this case, because it known to
- // be called from properties pages. Should be a
- // added to all DOM Modifiying APIs eventually.
- try {
- getModel().aboutToChangeModel();
- setValueSource(getValueSource(value));
- }
- finally {
- getModel().changedModel();
- }
- }
-
- void setValueRegion(ITextRegion valueRegion) {
- this.fValueRegion = valueRegion;
- if (valueRegion != null)
- this.fValueSource = null;
- }
-
- public void setValueSource(String source) {
- if (this.ownerElement != null && !this.ownerElement.isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- this.fValueSource = (source != null) ? source.toCharArray() : null;
-
- notifyValueChanged();
- }
-
- /**
- * Subclasses must override
- *
- * @param regionType
- * @return
- */
- protected boolean isNestedLanguageOpening(String regionType) {
- boolean result = false;
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CDATASectionImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CDATASectionImpl.java
deleted file mode 100644
index 1a3ad5748d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CDATASectionImpl.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- *
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Iterator;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * CDATASectionImpl class
- */
-public class CDATASectionImpl extends TextImpl implements CDATASection {
-
- /**
- * CDATASectionImpl constructor
- */
- protected CDATASectionImpl() {
- super();
- }
-
- /**
- * CDATASectionImpl constructor
- *
- * @param that
- * CDATASectionImpl
- */
- protected CDATASectionImpl(CDATASectionImpl that) {
- super(that);
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- CDATASectionImpl cloned = new CDATASectionImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public String getData() throws DOMException {
- // instead of super(TextImpl).getData(), call getCharacterData()
- char[] data = getCharacterData();
- if (data == null) {
- String sdata = getData(getStructuredDocumentRegion());
- if (sdata != null)
- return sdata;
- return NodeImpl.EMPTY_STRING;
- }
- return new String(data);
- }
-
- /**
- */
- private String getData(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return null;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return null;
-
- ITextRegion contentRegion = null;
- StringBuffer buffer = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_CDATA_OPEN || regionType == DOMRegionContext.XML_CDATA_CLOSE) {
- continue;
- }
- if (contentRegion == null) { // first content
- contentRegion = region;
- } else { // multiple contents
- if (buffer == null) {
- buffer = new StringBuffer(flatNode.getText(contentRegion));
- }
- buffer.append(flatNode.getText(region));
- }
- }
-
- if (buffer != null)
- return buffer.toString();
- if (contentRegion != null)
- return flatNode.getText(contentRegion);
- return null;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return "#cdata-section";//$NON-NLS-1$
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return CDATA_SECTION_NODE;
- }
-
- /**
- */
- public boolean isClosed() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- return (regionType == DOMRegionContext.XML_CDATA_CLOSE);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CMNodeUtil.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CMNodeUtil.java
deleted file mode 100644
index ae533abf5e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CMNodeUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-
-
-/**
- */
-public class CMNodeUtil {
-
- /**
- */
- public static CMAttributeDeclaration getAttributeDeclaration(Attr attr) {
- if (attr == null)
- return null;
- return ((AttrImpl) attr).getDeclaration();
- }
-
- /**
- */
- public static CMElementDeclaration getElementDeclaration(Element element) {
- if (element == null)
- return null;
- return ((ElementImpl) element).getDeclaration();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharOperation.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharOperation.java
deleted file mode 100644
index a446bde52a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharOperation.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-class CharOperation {
-
- private CharOperation() {
- }
-
- static int indexOf(char[] array, char c) {
- return indexOf(array, c, 0);
- }
-
- static int indexOf(char[] array, char c, int start) {
- for (int i = start; i < array.length; i++) {
- if (array[i] == c)
- return i;
- }
- return -1;
- }
-
-
- /**
- * note: This method taken from org.eclipse.jdt.core.compiler.CharOperation
- *
- * Answers true if the two arrays are identical character by character, otherwise false.
- * The equality is case sensitive.
- * <br>
- * <br>
- * For example:
- * <ol>
- * <li><pre>
- * first = null
- * second = null
- * result => true
- * </pre>
- * </li>
- * <li><pre>
- * first = { }
- * second = null
- * result => false
- * </pre>
- * </li>
- * <li><pre>
- * first = { 'a' }
- * second = { 'a' }
- * result => true
- * </pre>
- * </li>
- * <li><pre>
- * first = { 'a' }
- * second = { 'A' }
- * result => false
- * </pre>
- * </li>
- * </ol>
- * @param first the first array
- * @param second the second array
- * @return true if the two arrays are identical character by character, otherwise false
- */
- public static final boolean equals(char[] first, char[] second, boolean ignoreCase) {
- if (first == second)
- return true;
- if (first == null || second == null)
- return false;
- if (first.length != second.length)
- return false;
-
- for (int i = first.length; --i >= 0;) {
- if (ignoreCase) {
- if (Character.toUpperCase(first[i]) != Character.toUpperCase(second[i])) {
- return false;
- }
- }
- else {
- if (first[i] != second[i]) {
- return false;
- }
- }
- }
- return true;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterDataImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterDataImpl.java
deleted file mode 100644
index 1eb28920bb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterDataImpl.java
+++ /dev/null
@@ -1,356 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.w3c.dom.CharacterData;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-
-
-/**
- * CharacterDataImpl class
- */
-public abstract class CharacterDataImpl extends NodeImpl implements CharacterData {
-
- private char[] data = null;
-
- /**
- * CharacterDataImpl constructor
- */
- protected CharacterDataImpl() {
- super();
- }
-
- /**
- * CharacterDataImpl constructor
- *
- * @param that
- * CharacterDataImpl
- */
- protected CharacterDataImpl(CharacterDataImpl that) {
- super(that);
-
- if (that != null) {
- this.data = that.getData().toCharArray();
- }
- }
-
- /**
- * appendData method
- *
- * @param arg
- * java.lang.String
- */
- public void appendData(String arg) throws DOMException {
- if (arg == null)
- return;
-
- String data = getData();
- if (data == null)
- data = arg;
- else
- data += arg;
- setData(data);
- }
-
- /**
- * deleteData method
- *
- * @param offset
- * int
- * @param count
- * int
- */
- public void deleteData(int offset, int count) throws DOMException {
- if (count == 0)
- return;
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (count < 0 || offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String data = getData();
- if (data == null) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int length = data.length();
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (offset == 0) {
- if (count > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (count == length)
- data = NodeImpl.EMPTY_STRING;
- else
- data = data.substring(count);
- } else {
- int end = offset + count;
- if (end > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (end == length)
- data = data.substring(0, offset);
- else
- data = data.substring(0, offset) + data.substring(end);
- }
- setData(data);
- }
-
- /**
- */
- protected final char[] getCharacterData() {
- return this.data;
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public String getData() throws DOMException {
- char[] cdata = getCharacterData();
- if (cdata != null)
- return new String(cdata);
- return null;
- }
-
- /**
- * getLength method
- *
- * @return int
- */
- public int getLength() {
- String data = getData();
- if (data == null)
- return 0;
- return data.length();
- }
-
- /**
- * getNodeValue method
- *
- * @return java.lang.String
- */
- public String getNodeValue() {
- return getData();
- }
-
- /**
- * insertData method
- *
- * @param offset
- * int
- * @param arg
- * java.lang.String
- */
- public void insertData(int offset, String arg) throws DOMException {
- if (arg == null)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String data = getData();
- if (data == null) {
- if (offset > 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- data = arg;
- } else if (offset == 0) {
- data = arg + data;
- } else {
- int length = data.length();
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (offset == length)
- data += arg;
- else
- data = data.substring(0, offset) + arg + data.substring(offset);
- }
- setData(data);
- }
-
- /**
- * isJSPContent method
- *
- * @return boolean
- */
- public boolean isJSPContent() {
- Node parent = getParentNode();
- if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE)
- return false;
- ElementImpl element = (ElementImpl) parent;
- return element.isJSPContainer();
- }
-
- /**
- * replaceData method
- *
- * @param offset
- * int
- * @param count
- * int
- * @param arg
- * java.lang.String
- */
- public void replaceData(int offset, int count, String arg) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (arg == null) {
- deleteData(offset, count);
- return;
- }
- if (count == 0) {
- insertData(offset, arg);
- return;
- }
- if (offset < 0 || count < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String data = getData();
- if (data == null) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- } else if (offset == 0) {
- int length = data.length();
- if (count > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (count == length)
- data = arg;
- else
- data = arg + data.substring(count);
- } else {
- int length = data.length();
- int end = offset + count;
- if (end > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- if (end == length)
- data = data.substring(0, offset) + arg;
- else
- data = data.substring(0, offset) + arg + data.substring(end);
- }
- setData(data);
- }
-
- /**
- */
- void resetStructuredDocumentRegions() {
- this.data = getData().toCharArray();
- setStructuredDocumentRegion(null);
- }
-
- /**
- * setData method
- *
- * @param data
- * java.lang.String
- */
- public void setData(String data) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.data = (data != null ? data.toCharArray() : null);
-
- notifyValueChanged();
- }
-
- /**
- * setNodeValue method
- *
- * @param nodeValue
- * java.lang.String
- */
- public void setNodeValue(String nodeValue) throws DOMException {
- setData(nodeValue);
- }
-
- /**
- */
- void setStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- super.setStructuredDocumentRegion(flatNode);
- if (flatNode != null)
- this.data = null;
- }
-
- /**
- * substringData method
- *
- * @return java.lang.String
- * @param offset
- * int
- * @param count
- * int
- */
- public String substringData(int offset, int count) throws DOMException {
- if (count == 0)
- return NodeImpl.EMPTY_STRING;
- if (offset < 0 || count < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String data = getData();
- if (data == null) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int length = data.length();
- if (offset == 0 && count == length)
- return data;
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int end = offset + count;
- if (end > length) {
- // no DOMException specified to be thrown
- end = length;
- }
- return data.substring(offset, end);
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(getNodeName());
- buffer.append('(');
- buffer.append(getData());
- buffer.append(')');
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode != null) {
- buffer.append('@');
- buffer.append(flatNode.toString());
- }
- return buffer.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterStringPool.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterStringPool.java
deleted file mode 100644
index 3bdb388dd2..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterStringPool.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import java.util.LinkedHashMap;
-
-/**
- * Organizes a pool of frequently used Strings as character arrays.
- *
- */
-final class CharacterStringPool {
-
- static private LinkedHashMap fPool = new LimitedHashMap();
-
- static private class LimitedHashMap extends LinkedHashMap {
- private static final long serialVersionUID = 1L;
- private static final int MAX = 500;
-
- public LimitedHashMap() {
- super(MAX / 10, .75f, true);
- }
- protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
- return size() > MAX;
- }
- }
-
- static private class CharArray {
- char[] fArray;
- /**
- * Answers a hashcode for the array. Algorithm from org.eclipse.jdt.core.compiler.CharOperation
- *
- * @param array the array for which a hashcode is required
- * @return the hashcode
- * @throws NullPointerException if array is null
- */
- public int hashCode() {
- int length = fArray.length;
- int hash = length == 0 ? 31 : fArray[0];
- if (length < 8) {
- for (int i = length; --i > 0;)
- hash = (hash * 31) + fArray[i];
- } else {
- // 8 characters is enough to compute a decent hash code, don't waste time examining every character
- for (int i = length - 1, last = i > 16 ? i - 16 : 0; i > last; i -= 2)
- hash = (hash * 31) + fArray[i];
- }
- return hash & 0x7FFFFFFF;
- }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!(obj instanceof CharArray))
- return false;
- CharArray other = (CharArray) obj;
- if (fArray.length != other.fArray.length)
- return false;
- for (int i = 0; i < fArray.length; i++) {
- if (fArray[i] != other.fArray[i])
- return false;
- }
- return true;
- }
- }
-
- private CharacterStringPool() {
- }
-
- /**
- * Returns the character array for <code>string</code>. If
- * the character array is already in the pool for character arrays,
- * the array is reused.
- *
- * @param string the string to retrieve the character array for
- * @return a pooled instance of the character array
- */
- public static char[] getCharString(String string) {
- CharArray array = new CharArray();
- array.fArray = string.toCharArray();
-
- Object obj = null;
- synchronized (fPool) {
- obj = fPool.get(array);
- if (obj == null) {
- obj = array;
- fPool.put(obj, obj);
- }
- }
- return ((CharArray) obj).fArray;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CommentImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CommentImpl.java
deleted file mode 100644
index 4a817e07b4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CommentImpl.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Iterator;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Comment;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * CommentImpl class
- */
-public class CommentImpl extends CharacterDataImpl implements Comment {
-
- private boolean isJSPTag = false;
-
- /**
- * CommentImpl constructor
- */
- protected CommentImpl() {
- super();
- }
-
- /**
- * CommentImpl constructor
- *
- * @param that
- * CommentImpl
- */
- protected CommentImpl(CommentImpl that) {
- super(that);
-
- if (that != null) {
- this.isJSPTag = that.isJSPTag;
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- CommentImpl cloned = new CommentImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public String getData() throws DOMException {
- char[] data = getCharacterData();
- if (data == null) {
- String sdata = getData(getStructuredDocumentRegion());
- if (sdata != null)
- return sdata;
- return NodeImpl.EMPTY_STRING;
- }
- return new String(data);
- }
-
- /**
- */
- private String getData(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return null;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return null;
-
- ITextRegion contentRegion = null;
- StringBuffer buffer = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_COMMENT_OPEN || regionType == DOMRegionContext.XML_COMMENT_CLOSE || isNestedCommentOpenClose(regionType)) {
- continue;
- }
- if (contentRegion == null) { // first content
- contentRegion = region;
- }
- else { // multiple contents
- if (buffer == null) {
- buffer = new StringBuffer(flatNode.getText(contentRegion));
- }
- buffer.append(flatNode.getText(region));
- }
- }
-
- if (buffer != null)
- return buffer.toString();
- if (contentRegion != null)
- return flatNode.getText(contentRegion);
- return null;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return "#comment";//$NON-NLS-1$
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return COMMENT_NODE;
- }
-
- /**
- */
- public boolean isClosed() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- return (regionType == DOMRegionContext.XML_COMMENT_CLOSE || isNestedCommentClose(regionType));
- }
-
- /**
- * Subclasses must override
- * @param regionType
- * @return
- */
- protected boolean isNestedCommentClose(String regionType) {
- boolean result = false;
- return result;
- }
- /**
- * Subclasses must override
- * @param regionType
- * @return
- */
- protected boolean isNestedCommentOpenClose(String regionType) {
- boolean result = false;
- return result;
- }
-
- public boolean isJSPTag() {
- return this.isJSPTag;
- }
-
- /**
- * setJSPTag method
- *
- * @param isJSPTag
- * boolean
- */
- public void setJSPTag(boolean isJSPTag) {
- if (isJSPTag == this.isJSPTag)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (isJSPTag) {
- if (document == null || !document.isJSPType())
- return;
- }
-
- this.isJSPTag = isJSPTag;
-
- if (getContainerDocument() != null) {
- // already in the tree, update IStructuredDocument
- setData(getData()); // calls notifyValueChanged();
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.java
deleted file mode 100644
index 5907bfda18..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import org.eclipse.osgi.util.NLS;
-
-class DOMMessages extends NLS {
- private static String BUNDLE_NAME = "org.eclipse.wst.xml.core.internal.document.DOMMessages"; //$NON-NLS-1$
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, DOMMessages.class);
- }
-
- private DOMMessages() {
- }
-
- public static String DOMSTRING_SIZE_ERR;
- public static String HIERARCHY_REQUEST_ERR;
- public static String INDEX_SIZE_ERR;
- public static String INUSE_ATTRIBUTE_ERR;
- public static String INVALID_ACCESS_ERR;
- public static String INVALID_CHARACTER_ERR;
- public static String INVALID_MODIFICATION_ERR;
- public static String INVALID_STATE_ERR;
- public static String NAMESPACE_ERR;
- public static String NO_DATA_ALLOWED_ERR;
- public static String NO_MODIFICATION_ALLOWED_ERR;
- public static String NOT_FOUND_ERR;
- public static String NOT_SUPPORTED_ERR;
- public static String SYNTAX_ERR;
- public static String TYPE_MISMATCH_ERR;
- public static String VALIDATION_ERR;
- public static String WRONG_DOCUMENT_ERR;
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.properties b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.properties
deleted file mode 100644
index 039213ef30..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMMessages.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-DOMSTRING_SIZE_ERR=DOMString Size Error
-HIERARCHY_REQUEST_ERR=Invalid Hierarchy Request
-INDEX_SIZE_ERR=Index Size Error
-INUSE_ATTRIBUTE_ERR=Attribute Node In Use Error
-INVALID_ACCESS_ERR=Invalid Access Error
-INVALID_CHARACTER_ERR=Invalid Characer Error
-INVALID_MODIFICATION_ERR=Invalid Modification Error
-INVALID_STATE_ERR=Invalid State Error
-NAMESPACE_ERR=Namespace Error
-NO_DATA_ALLOWED_ERR=No Data Allowed
-NO_MODIFICATION_ALLOWED_ERR=No Modification Allowed
-NOT_FOUND_ERR=Not Found
-NOT_SUPPORTED_ERR=Not Supported
-SYNTAX_ERR=Syntax Error
-TYPE_MISMATCH_ERR=Type Mismatch Error
-VALIDATION_ERR=Validation Error
-WRONG_DOCUMENT_ERR=Wrong Document
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMModelImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMModelImpl.java
deleted file mode 100644
index 9fc72aa9db..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMModelImpl.java
+++ /dev/null
@@ -1,981 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
-import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLNamespace;
-import org.eclipse.wst.xml.core.internal.provisional.NameValidator;
-import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-/**
- * XMLModelImpl class
- */
-public class DOMModelImpl extends AbstractStructuredModel implements IStructuredDocumentListener, IDOMModel, DOMImplementation {
- private static String TRACE_PARSER_MANAGEMENT_EXCEPTION = "parserManagement"; //$NON-NLS-1$
- private Object active = null;
- private DocumentImpl document = null;
- private ISourceGenerator generator = null;
- private XMLModelNotifier notifier = null;
- private XMLModelParser parser = null;
- private boolean refresh = false;
- private XMLModelUpdater updater = null;
-
- /**
- * XMLModelImpl constructor
- */
- public DOMModelImpl() {
- super();
- this.document = (DocumentImpl) internalCreateDocument();
- }
-
- /**
- * This API allows clients to declare that they are about to make a
- * "large" change to the model. This change might be in terms of content
- * or it might be in terms of the model id or base location.
- *
- * Note that in the case of embedded calls, notification to listeners is
- * sent only once.
- *
- * Note that the client who is making these changes has the responsibility
- * to restore the models state once finished with the changes. See
- * getMemento and restoreState.
- *
- * The method isModelStateChanging can be used by a client to determine if
- * the model is already in a change sequence.
- */
- public void aboutToChangeModel() {
- super.aboutToChangeModel();
- // technically, no need to call beginChanging so often,
- // since aboutToChangeModel can be nested.
- // but will leave as is for this release.
- // see modelChanged, and be sure stays coordinated there.
- getModelNotifier().beginChanging();
- }
-
- public void aboutToReinitializeModel() {
- XMLModelNotifier notifier = getModelNotifier();
- notifier.cancelPending();
- super.aboutToReinitializeModel();
- }
-
- /**
- * attrReplaced method
- *
- * @param element
- * org.w3c.dom.Element
- * @param newAttr
- * org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- protected void attrReplaced(Element element, Attr newAttr, Attr oldAttr) {
- if (element == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.replaceAttr(element, newAttr, oldAttr);
- setActive(null);
- }
- getModelNotifier().attrReplaced(element, newAttr, oldAttr);
- }
-
- /**
- * This API allows a client controlled way of notifying all ModelEvent
- * listners that the model has been changed. This method is a matched pair
- * to aboutToChangeModel, and must be called after aboutToChangeModel ...
- * or some listeners could be left waiting indefinitely for the changed
- * event. So, its suggested that changedModel always be in a finally
- * clause. Likewise, a client should never call changedModel without
- * calling aboutToChangeModel first.
- *
- * In the case of embedded calls, the notification is just sent once.
- *
- */
- public void changedModel() {
- // NOTE: the order of 'changedModel' and 'endChanging' is significant.
- // By calling changedModel first, this basically decrements the
- // "isChanging" counter
- // in super class and when zero all listeners to model state events
- // will be notified
- // that the model has been changed. 'endChanging' will notify all
- // deferred adapters.
- // So, the significance of order is that adapters (and methods they
- // call)
- // can count on the state of model "isChanging" to be accurate.
- // But, remember, that this means the "modelChanged" event can be
- // received before all
- // adapters have finished their processing.
- // NOTE NOTE: The above note is obsolete in fact (though still states
- // issue correctly).
- // Due to popular demand, the order of these calls were reversed and
- // behavior
- // changed on 07/22/2004.
- //
- // see also
- // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4302
- // for motivation for this 'on verge of' call.
- // this could be improved in future if notifier also used counting
- // flag to avoid nested calls. If/when changed be sure to check if
- // aboutToChangeModel needs any changes too.
- if (isModelChangeStateOnVergeOfEnding()) {
- // end lock before noticiation loop, since directly or indirectly
- // we may be "called from foriegn code" during notification.
- endLock();
- // we null out here to avoid spurious"warning" message while debug
- // tracing is enabled
- fLockObject = null;
- // the notifier is what controls adaper notification, which
- // should be sent out before the 'modelChanged' event.
- getModelNotifier().endChanging();
- }
- // changedModel handles 'nesting', so only one event sent out
- // when mulitple calls to 'aboutToChange/Changed'.
- super.changedModel();
- handleRefresh();
- }
-
- /**
- * childReplaced method
- *
- * @param parentNode
- * org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- protected void childReplaced(Node parentNode, Node newChild, Node oldChild) {
- if (parentNode == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.replaceChild(parentNode, newChild, oldChild);
- setActive(null);
- }
- getModelNotifier().childReplaced(parentNode, newChild, oldChild);
- }
-
- /**
- * Creates an XML <code>Document</code> object of the specified type
- * with its document element. HTML-only DOM implementations do not need to
- * implement this method.
- *
- * @param namespaceURIThe
- * namespace URI of the document element to create.
- * @param qualifiedNameThe
- * qualified name of the document element to be created.
- * @param doctypeThe
- * type of document to be created or <code>null</code>. When
- * <code>doctype</code> is not <code>null</code>, its
- * <code>Node.ownerDocument</code> attribute is set to the
- * document being created.
- * @return A new <code>Document</code> object.
- * @exception DOMException
- * INVALID_CHARACTER_ERR: Raised if the specified qualified
- * name contains an illegal character. <br>
- * NAMESPACE_ERR: Raised if the <code>qualifiedName</code>
- * is malformed, if the <code>qualifiedName</code> has a
- * prefix and the <code>namespaceURI</code> is
- * <code>null</code>, or if the
- * <code>qualifiedName</code> has a prefix that is "xml"
- * and the <code>namespaceURI</code> is different from "
- * http://www.w3.org/XML/1998/namespace" .<br>
- * WRONG_DOCUMENT_ERR: Raised if <code>doctype</code> has
- * already been used with a different document or was
- * created from a different implementation.
- * @see DOM Level 2
- */
- public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException {
- final DocumentImpl document = new DocumentImpl();
- if (namespaceURI == null && qualifiedName == null && doctype == null)
- return document;
-
- if (qualifiedName != null) {
-
- final int idx = qualifiedName.indexOf(':');
- if (idx > 0) {
- if (namespaceURI == null)
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
- final String prefix = qualifiedName.substring(0, idx);
- if (prefix.equals(IXMLNamespace.XML) && !namespaceURI.equals(IXMLNamespace.XML_URI))
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
-
- // Check if the qualifiedName is malformed
- if (idx == qualifiedName.length() - 1) // No local name
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
-
- String localName = qualifiedName.substring(idx + 1);
- final int length = localName.length();
- if (length == 0)
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
-
- switch (localName.charAt(0)) {
- case '-':
- case '.':
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
- }
-
- final int qualifiedLength = qualifiedName.length();
- for (int i = 0; i < qualifiedLength; i++) {
- final char c = qualifiedName.charAt(i);
- if (Character.isWhitespace(c))
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, null);
- else if (c == ':' && i != idx)
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
- }
- }
- if (!NameValidator.isValid(qualifiedName))
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, null);
- }
- else if (namespaceURI != null){
- throw new DOMException(DOMException.NAMESPACE_ERR, null);
- }
-
- final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
- if (model != null) {
- document.setModel(model);
- model.document = document;
- }
-
- if (doctype != null) {
- if (doctype.getOwnerDocument() != null)
- throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
- document.appendChild(doctype);
- }
-
- final ElementImpl root = new ElementImpl();
- document.appendChild(root);
- root.setNamespaceURI(namespaceURI);
- root.setTagName(qualifiedName);
-
- return document;
- }
-
- /**
- * Creates an empty <code>DocumentType</code> node. Entity declarations
- * and notations are not made available. Entity reference expansions and
- * default attribute additions do not occur. It is expected that a future
- * version of the DOM will provide a way for populating a
- * <code>DocumentType</code>.<br>
- * HTML-only DOM implementations do not need to implement this method.
- *
- * @param qualifiedNameThe
- * qualified name of the document type to be created.
- * @param publicIdThe
- * external subset public identifier.
- * @param systemIdThe
- * external subset system identifier.
- * @return A new <code>DocumentType</code> node with
- * <code>Node.ownerDocument</code> set to <code>null</code>.
- * @exception DOMException
- * INVALID_CHARACTER_ERR: Raised if the specified qualified
- * name contains an illegal character. <br>
- * NAMESPACE_ERR: Raised if the <code>qualifiedName</code>
- * is malformed.
- * @see DOM Level 2
- */
- public DocumentType createDocumentType(String qualifiedName, String publicId, String systemId) throws DOMException {
- DocumentTypeImpl documentType = new DocumentTypeImpl();
- documentType.setName(qualifiedName);
- documentType.setPublicId(publicId);
- documentType.setSystemId(systemId);
- return documentType;
- }
-
- /**
- */
- protected void documentTypeChanged() {
- if (this.refresh)
- return;
- // unlike 'resfresh', 'reinitialize' finishes loop
- // and flushes remaining notification que before
- // actually reinitializing.
- // ISSUE: should reinit be used instead of handlerefresh?
- // this.setReinitializeNeeded(true);
- if (this.active != null || getModelNotifier().isChanging())
- return; // defer
- handleRefresh();
- }
-
- protected void editableChanged(Node node) {
- if (node != null) {
- getModelNotifier().editableChanged(node);
- }
- }
-
- /**
- */
- protected void endTagChanged(Element element) {
- if (element == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.changeEndTag(element);
- setActive(null);
- }
- getModelNotifier().endTagChanged(element);
- }
-
- /**
- */
- private XMLModelParser getActiveParser() {
- if (this.parser == null)
- return null;
- if (this.parser != this.active)
- return null;
- return this.parser;
- }
-
- /**
- */
- private XMLModelUpdater getActiveUpdater() {
- if (this.updater == null)
- return null;
- if (this.updater != this.active)
- return null;
- return this.updater;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(Class adapter) {
- if (Document.class.equals(adapter))
- return getDocument();
- return super.getAdapter(adapter);
- }
-
- /**
- * getDocument method
- *
- * @return XMLDocument
- */
- public IDOMDocument getDocument() {
- return this.document;
- }
-
- public ISourceGenerator getGenerator() {
- if (this.generator == null) {
- this.generator = XMLGeneratorImpl.getInstance();
- }
- return this.generator;
- }
-
- /**
- * getNode method
- *
- * @param offset
- * int
- */
- public IndexedRegion getIndexedRegion(int offset) {
- if (this.document == null)
- return null;
- // search in document children
- IDOMNode parent = null;
- int length = this.document.getEndOffset();
- if (offset * 2 < length) {
- // search from the first
- IDOMNode child = (IDOMNode) this.document.getFirstChild();
- while (child != null) {
- if (child.getEndOffset() <= offset) {
- child = (IDOMNode) child.getNextSibling();
- continue;
- }
- if (child.getStartOffset() > offset) {
- break;
- }
- IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null) {
- if (startStructuredDocumentRegion.getEnd() > offset)
- return child;
- }
- IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- if (endStructuredDocumentRegion.getStart() <= offset)
- return child;
- }
- // dig more
- parent = child;
- child = (IDOMNode) parent.getFirstChild();
- }
- }
- else {
- // search from the last
- IDOMNode child = (IDOMNode) this.document.getLastChild();
- while (child != null) {
- if (child.getStartOffset() > offset) {
- child = (IDOMNode) child.getPreviousSibling();
- continue;
- }
- if (child.getEndOffset() <= offset) {
- break;
- }
- IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null) {
- if (startStructuredDocumentRegion.getEnd() > offset)
- return child;
- }
- IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- if (endStructuredDocumentRegion.getStart() <= offset)
- return child;
- }
- // dig more
- parent = child;
- child = (IDOMNode) parent.getLastChild();
- }
- }
- return parent;
- }
-
- /**
- */
- public XMLModelNotifier getModelNotifier() {
- if (this.notifier == null) {
- this.notifier = new XMLModelNotifierImpl();
- }
- return this.notifier;
- }
-
- /**
- */
- private XMLModelParser getModelParser() {
- if (this.parser == null) {
- this.parser = createModelParser();
- }
- return this.parser;
- }
-
- protected XMLModelParser createModelParser() {
- return new XMLModelParser(this);
- }
-
- /**
- */
- private XMLModelUpdater getModelUpdater() {
- if (this.updater == null) {
- this.updater = createModelUpdater();
- }
- return this.updater;
- }
-
- protected XMLModelUpdater createModelUpdater() {
- return new XMLModelUpdater(this);
- }
-
- /**
- */
- private void handleRefresh() {
- if (!this.refresh)
- return;
- XMLModelNotifier notifier = getModelNotifier();
- boolean isChanging = notifier.isChanging();
- if (!isChanging)
- notifier.beginChanging(true);
- XMLModelParser parser = getModelParser();
- setActive(parser);
- this.document.removeChildNodes();
- try {
- this.refresh = false;
- parser.replaceStructuredDocumentRegions(getStructuredDocument().getRegionList(), null);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- }
- finally {
- setActive(null);
- if (!isChanging)
- notifier.endChanging();
- }
- }
-
- /**
- * Test if the DOM implementation implements a specific feature.
- *
- * @param featureThe
- * name of the feature to test (case-insensitive). The values
- * used by DOM features are defined throughout the DOM Level 2
- * specifications and listed in the section. The name must be
- * an XML name. To avoid possible conflicts, as a convention,
- * names referring to features defined outside the DOM
- * specification should be made unique by reversing the name of
- * the Internet domain name of the person (or the organization
- * that the person belongs to) who defines the feature,
- * component by component, and using this as a prefix. For
- * instance, the W3C SVG Working Group defines the feature
- * "org.w3c.dom.svg".
- * @param versionThis
- * is the version number of the feature to test. In Level 2,
- * the string can be either "2.0" or "1.0". If the version is
- * not specified, supporting any version of the feature causes
- * the method to return <code>true</code>.
- * @return <code>true</code> if the feature is implemented in the
- * specified version, <code>false</code> otherwise.
- */
- public boolean hasFeature(String feature, String version) {
- if (feature == null)
- return false;
- if (version != null) {
- if (!version.equals("1.0") && !version.equals("2.0")) { //$NON-NLS-2$//$NON-NLS-1$
- return false;
- }
- }
- if (feature.equalsIgnoreCase("Core")) //$NON-NLS-1$
- return true; //$NON-NLS-1$
- if (feature.equalsIgnoreCase("XML")) //$NON-NLS-1$
- return true; //$NON-NLS-1$
- return false;
- }
-
- /**
- * createDocument method
- *
- * @return org.w3c.dom.Document
- */
- protected Document internalCreateDocument() {
- DocumentImpl document = new DocumentImpl();
- document.setModel(this);
- return document;
- }
-
- boolean isReparsing() {
- return (active != null);
- }
-
- /**
- * nameChanged method
- *
- * @param node
- * org.w3c.dom.Node
- */
- protected void nameChanged(Node node) {
- if (node == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.changeName(node);
- setActive(null);
- }
- // notification is already sent
- }
-
- /**
- * newModel method
- *
- */
- public void newModel(NewDocumentEvent structuredDocumentEvent) {
- if (structuredDocumentEvent == null)
- return;
- IStructuredDocument structuredDocument = structuredDocumentEvent.getStructuredDocument();
- if (structuredDocument == null)
- return;
- // this should not happen, but for the case
- if (fStructuredDocument != null && fStructuredDocument != structuredDocument)
- setStructuredDocument(structuredDocument);
-
- internalSetNewDocument(structuredDocument);
- }
-
- private void internalSetNewDocument(IStructuredDocument structuredDocument) {
- if (structuredDocument == null)
- return;
- IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
- if ((flatNodes == null) || (flatNodes.getLength() == 0)) {
- return;
- }
- if (this.document == null)
- return; // being constructed
- XMLModelUpdater updater = getActiveUpdater();
- if (updater != null) { // being updated
- try {
- updater.replaceStructuredDocumentRegions(flatNodes, null);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- }
- // // for new model, we might need to
- // // re-init, e.g. if someone calls setText
- // // on an existing model
- // checkForReinit();
- return;
- }
- XMLModelNotifier notifier = getModelNotifier();
- boolean isChanging = notifier.isChanging();
- // call even if changing to notify doing new model
- getModelNotifier().beginChanging(true);
- XMLModelParser parser = getModelParser();
- setActive(parser);
- this.document.removeChildNodes();
- try {
- parser.replaceStructuredDocumentRegions(flatNodes, null);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- // meaningless to refresh, because the result might be the same
- }
- finally {
- setActive(null);
- if (!isChanging) {
- getModelNotifier().endChanging();
- }
- // ignore refresh
- this.refresh = false;
- }
- }
-
- /**
- */
- public void noChange(NoChangeEvent event) {
- XMLModelUpdater updater = getActiveUpdater();
- if (updater != null) { // being updated
- // cleanup updater staffs
- try {
- updater.replaceStructuredDocumentRegions(null, null);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- }
- // I guess no chanage means the model could not need re-init
- // checkForReinit();
- return;
- }
- }
-
- /**
- * nodesReplaced method
- *
- */
- public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
- if (event == null)
- return;
- IStructuredDocumentRegionList oldStructuredDocumentRegions = event.getOldStructuredDocumentRegions();
- IStructuredDocumentRegionList newStructuredDocumentRegions = event.getNewStructuredDocumentRegions();
- XMLModelUpdater updater = getActiveUpdater();
- if (updater != null) { // being updated
- try {
- updater.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
- }
- catch (Exception ex) {
- if (ex.getClass().equals(StructuredDocumentRegionManagementException.class)) {
- Logger.traceException(TRACE_PARSER_MANAGEMENT_EXCEPTION, ex);
- }
- else {
- Logger.logException(ex);
- }
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- }
- // checkForReinit();
- return;
- }
- XMLModelNotifier notifier = getModelNotifier();
- boolean isChanging = notifier.isChanging();
- if (!isChanging)
- notifier.beginChanging();
- XMLModelParser parser = getModelParser();
- setActive(parser);
- try {
- parser.replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- if (!isChanging) {
- notifier.endChanging();
- handleRefresh();
- }
- }
-
- }
-
- /**
- * regionChanged method
- *
- * @param structuredDocumentEvent
- */
- public void regionChanged(RegionChangedEvent event) {
- if (event == null)
- return;
- IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
- if (flatNode == null)
- return;
- ITextRegion region = event.getRegion();
- if (region == null)
- return;
- XMLModelUpdater updater = getActiveUpdater();
- if (updater != null) { // being updated
- try {
- updater.changeRegion(event, flatNode, region);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- }
- // checkForReinit();
- return;
- }
- XMLModelNotifier notifier = getModelNotifier();
- boolean isChanging = notifier.isChanging();
- if (!isChanging)
- notifier.beginChanging();
- XMLModelParser parser = getModelParser();
- setActive(parser);
- try {
- parser.changeRegion(event, flatNode, region);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- if (!isChanging) {
- notifier.endChanging();
- handleRefresh();
- }
- }
- // checkForReinit();
- }
-
- /**
- * regionsReplaced method
- *
- * @param event
- */
- public void regionsReplaced(RegionsReplacedEvent event) {
- if (event == null)
- return;
- IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
- if (flatNode == null)
- return;
- ITextRegionList oldRegions = event.getOldRegions();
- ITextRegionList newRegions = event.getNewRegions();
- if (oldRegions == null && newRegions == null)
- return;
- XMLModelUpdater updater = getActiveUpdater();
- if (updater != null) { // being updated
- try {
- updater.replaceRegions(flatNode, newRegions, oldRegions);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- }
- // checkForReinit();
- return;
- }
- XMLModelNotifier notifier = getModelNotifier();
- boolean isChanging = notifier.isChanging();
- if (!isChanging)
- notifier.beginChanging();
- XMLModelParser parser = getModelParser();
- setActive(parser);
- try {
- parser.replaceRegions(flatNode, newRegions, oldRegions);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- this.refresh = true;
- handleRefresh();
- }
- finally {
- setActive(null);
- if (!isChanging) {
- notifier.endChanging();
- handleRefresh();
- }
- }
- // checkForReinit();
- }
-
- /**
- */
- public void releaseFromEdit() {
- if (!isShared()) {
- // this.document.releaseStyleSheets();
- // this.document.releaseDocumentType();
- }
- super.releaseFromEdit();
- }
-
- /**
- */
- public void releaseFromRead() {
- if (!isShared()) {
- // this.document.releaseStyleSheets();
- // this.document.releaseDocumentType();
- }
- super.releaseFromRead();
- }
-
- /**
- */
- private void setActive(Object active) {
- this.active = active;
- // side effect
- // when ever becomes active, besure tagNameCache is cleared
- // (and not used)
- if (active == null) {
- document.activateTagNameCache(true);
- }
- else {
- document.activateTagNameCache(false);
- }
-
- }
-
- /**
- */
- public void setGenerator(ISourceGenerator generator) {
- this.generator = generator;
- }
-
- /**
- */
- public void setModelNotifier(XMLModelNotifier notifier) {
- this.notifier = notifier;
- }
-
- /**
- */
- public void setModelParser(XMLModelParser parser) {
- this.parser = parser;
- }
-
- /**
- */
- public void setModelUpdater(XMLModelUpdater updater) {
- this.updater = updater;
- }
-
- /**
- * setStructuredDocument method
- *
- * @param structuredDocument
- */
- public void setStructuredDocument(IStructuredDocument structuredDocument) {
- IStructuredDocument oldStructuredDocument = super.getStructuredDocument();
- if (structuredDocument == oldStructuredDocument)
- return; // nothing to do
- if (oldStructuredDocument != null)
- oldStructuredDocument.removeDocumentChangingListener(this);
- super.setStructuredDocument(structuredDocument);
- if (structuredDocument != null) {
- internalSetNewDocument(structuredDocument);
- structuredDocument.addDocumentChangingListener(this);
- }
- }
-
- /**
- */
- protected void startTagChanged(Element element) {
- if (element == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.changeStartTag(element);
- setActive(null);
- }
- getModelNotifier().startTagChanged(element);
- }
-
- /**
- * valueChanged method
- *
- * @param node
- * org.w3c.dom.Node
- */
- protected void valueChanged(Node node) {
- if (node == null)
- return;
- if (getActiveParser() == null) {
- XMLModelUpdater updater = getModelUpdater();
- setActive(updater);
- updater.initialize();
- updater.changeValue(node);
- setActive(null);
- }
- getModelNotifier().valueChanged(node);
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation of DOM 3.
- */
- public Object getFeature(String feature, String version) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentFragmentImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentFragmentImpl.java
deleted file mode 100644
index cde882c636..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentFragmentImpl.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * DocumentFragmentImpl class
- */
-public class DocumentFragmentImpl extends NodeContainer implements DocumentFragment {
-
- /**
- * DocumentFragmentImpl constructor
- */
- protected DocumentFragmentImpl() {
- super();
- }
-
- /**
- * DocumentFragmentImpl constructor
- *
- * @param that
- * DocumentFragmentImpl
- */
- protected DocumentFragmentImpl(DocumentFragmentImpl that) {
- super(that);
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- DocumentFragmentImpl cloned = new DocumentFragmentImpl(this);
- if (deep)
- cloneChildNodes(cloned, deep);
-
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return "#document-fragment";//$NON-NLS-1$
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return DOCUMENT_FRAGMENT_NODE;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentImpl.java
deleted file mode 100644
index 34a3e31707..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentImpl.java
+++ /dev/null
@@ -1,1208 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- * David Carver (Intalio) - bug 273004 - add check for valid xml characters in createAttribute
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-// for org.apache.xerces 3.2.1
-// import org.apache.xerces.utils.XMLCharacterProperties;
-// DMW modified for XML4J 4.0.1
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.xerces.dom.TreeWalkerImpl;
-import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;
-import org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementRegistry;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMEntityDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLCharEntity;
-import org.eclipse.wst.xml.core.internal.provisional.NameValidator;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.DOMConfiguration;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Entity;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Notation;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-import org.w3c.dom.UserDataHandler;
-import org.w3c.dom.ranges.DocumentRange;
-import org.w3c.dom.ranges.Range;
-import org.w3c.dom.traversal.DocumentTraversal;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-import org.w3c.dom.traversal.TreeWalker;
-
-
-/**
- * DocumentImpl class
- */
-public class DocumentImpl extends NodeContainer implements IDOMDocument, DocumentRange, DocumentTraversal {
-
- private static int maxDocTypeSearch = 500;
- private static int noMaxSearch = -1;
- /**
- * Internal-use only class. This class was added to better able to handle
- * repetetive request for getElementsByTagName. The cache is cleared when
- * ever the document changes at all, so still not real efficient,
- */
- class TagNameCache {
-
- private boolean active = true;
-
- private Map cache;
-
- public TagNameCache() {
- super();
- cache = new HashMap();
- }
-
- /**
- * @param b
- */
- public void activate(boolean b) {
- active = b;
- if (!b)
- clear();
- }
-
- public void addItem(String tagname, NodeListImpl nodelist) {
- if (tagname == null || nodelist == null)
- return;
- cache.put(tagname, nodelist);
- }
-
- public void clear() {
- cache.clear();
- }
-
- public NodeListImpl getItem(String tagName) {
- NodeListImpl result = null;
- if (active) {
- result = (NodeListImpl) cache.get(tagName);
- // if (result != null) {
- // System.out.println("getElementsByTagname from cache: " +
- // tagName);
- // }
- }
- return result;
- }
-
- }
-
- private class LimitedCache extends LinkedHashMap {
- private static final long serialVersionUID = 1L;
- private static final int MAX_SIZE = 10;
- public LimitedCache() {
- super(0, 0.75f, true);
- }
-
- protected boolean removeEldestEntry(java.util.Map.Entry entry) {
- return size() > MAX_SIZE;
- }
- }
-
- // this is a constant just to give compile-time control over
- // whether or not to use the cache. If, in future, its found that
- // there are no (or few) "duplicate requests" ... then this cache
- // is not needed.
- private static final boolean usetagnamecache = true;
-
- // private DocumentTypeAdapter documentTypeAdapter = null;
-
- private DOMModelImpl model = null;
- private TagNameCache tagNameCache;
-
- private Map fCMCache;
- /**
- * DocumentImpl constructor
- */
- protected DocumentImpl() {
- super();
- if (usetagnamecache) {
- tagNameCache = new TagNameCache();
- }
- fCMCache = Collections.synchronizedMap(new LimitedCache());
- }
-
- /**
- * DocumentImpl constructor
- *
- * @param that
- * DocumentImpl
- */
- protected DocumentImpl(DocumentImpl that) {
- super(that);
- if (usetagnamecache) {
- tagNameCache = new TagNameCache();
- }
- fCMCache = Collections.synchronizedMap(new LimitedCache());
- }
-
- /**
- * @param b
- */
- void activateTagNameCache(boolean b) {
- tagNameCache.activate(b);
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * Changes the <code>ownerDocument</code> of a node, its children, as
- * well as the attached attribute nodes if there are any. If the node has
- * a parent it is first removed from its parent child list. This
- * effectively allows moving a subtree from one document to another. The
- * following list describes the specifics for each type of node.
- * <dl>
- * <dt>ATTRIBUTE_NODE</dt>
- * <dd>The <code>ownerElement</code> attribute is set to
- * <code>null</code> and the <code>specified</code> flag is set to
- * <code>true</code> on the adopted <code>Attr</code>. The
- * descendants of the source <code>Attr</code> are recursively adopted.
- * </dd>
- * <dt>DOCUMENT_FRAGMENT_NODE</dt>
- * <dd>The descendants of the source node are recursively adopted.</dd>
- * <dt>DOCUMENT_NODE</dt>
- * <dd><code>Document</code> nodes cannot be adopted.</dd>
- * <dt>DOCUMENT_TYPE_NODE</dt>
- * <dd><code>DocumentType</code> nodes cannot be adopted.</dd>
- * <dt>ELEMENT_NODE</dt>
- * <dd>Specified attribute nodes of the source element are adopted, and
- * the generated <code>Attr</code> nodes. Default attributes are
- * discarded, though if the document being adopted into defines default
- * attributes for this element name, those are assigned. The descendants
- * of the source element are recursively adopted.</dd>
- * <dt>ENTITY_NODE</dt>
- * <dd><code>Entity</code> nodes cannot be adopted.</dd>
- * <dt>ENTITY_REFERENCE_NODE</dt>
- * <dd>Only the <code>EntityReference</code> node itself is adopted,
- * the descendants are discarded, since the source and destination
- * documents might have defined the entity differently. If the document
- * being imported into provides a definition for this entity name, its
- * value is assigned.</dd>
- * <dt>NOTATION_NODE</dt>
- * <dd><code>Notation</code> nodes cannot be adopted.</dd>
- * <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE,
- * COMMENT_NODE</dt>
- * <dd>These nodes can all be adopted. No specifics.</dd>
- * Should this method simply return null when it fails? How "exceptional"
- * is failure for this method?Stick with raising exceptions only in
- * exceptional circumstances, return null on failure (F2F 19 Jun 2000).Can
- * an entity node really be adopted?No, neither can Notation nodes (Telcon
- * 13 Dec 2000).Does this affect keys and hashCode's of the adopted
- * subtree nodes?If so, what about readonly-ness of key and hashCode?if
- * not, would appendChild affect keys/hashCodes or would it generate
- * exceptions if key's are duplicate? Update: Hashcodes have been dropped.
- * Given that the key is only unique within a document an adopted node
- * needs to be given a new key, but what does it mean for the application?
- *
- * TODO: Needs to notify UserDataHandlers for the node if any
- *
- * @param source
- * The node to move into this document.
- * @return The adopted node, or <code>null</code> if this operation
- * fails, such as when the source node comes from a different
- * implementation.
- * @exception DOMException
- * NOT_SUPPORTED_ERR: Raised if the source node is of type
- * <code>DOCUMENT</code>,<code>DOCUMENT_TYPE</code>.
- * <br>
- * NO_MODIFICATION_ALLOWED_ERR: Raised when the source node
- * is readonly.
- * @see DOM Level 3
- */
- public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) throws org.w3c.dom.DOMException {
- return null;
- }
-
- /**
- * @param tagName
- */
- protected void checkTagNameValidity(String tagName) {
- if (!isValidName(tagName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, createDOMExceptionMessage(DOMException.INVALID_CHARACTER_ERR, tagName));
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- DocumentImpl cloned = new DocumentImpl(this);
- if (deep)
- cloned.importChildNodes(this, true);
- return cloned;
- }
-
- /**
- * createAttribute method
- *
- * @return org.w3c.dom.Attr
- * @param name
- * java.lang.String
- */
- public Attr createAttribute(String name) throws DOMException {
- checkTagNameValidity(name);
- AttrImpl attr = new AttrImpl();
- attr.setOwnerDocument(this);
- attr.setName(name);
- return attr;
- }
-
- /**
- */
- public Attr createAttributeNS(String uri, String name) throws DOMException {
- checkTagNameValidity(name);
- AttrImpl attr = new AttrImpl();
- attr.setOwnerDocument(this);
- attr.setName(name);
- attr.setNamespaceURI(uri);
- return attr;
- }
-
- /**
- * createCDATASection method
- *
- * @return org.w3c.dom.CDATASection
- * @param data
- * java.lang.String
- */
- public CDATASection createCDATASection(String data) throws DOMException {
- // allow CDATA section
- // if (!isXMLType()) {
- // throw new DOMException(DOMException.NOT_SUPPORTED_ERR, new
- // String());
- // }
- CDATASectionImpl cdata = new CDATASectionImpl();
- cdata.setOwnerDocument(this);
- if (data != null)
- cdata.setData(data);
- return cdata;
- }
-
- /**
- * createComment method
- *
- * @return org.w3c.dom.Comment
- * @param data
- * java.lang.String
- */
- public Comment createComment(String data) {
- CommentImpl comment = new CommentImpl();
- comment.setOwnerDocument(this);
- if (data != null)
- comment.setData(data);
- return comment;
- }
-
- public Element createCommentElement(String tagName, boolean isJSPTag) throws DOMException {
- Element result = null;
- if (!isJSPType() && isJSPTag) {
- throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, DOMMessages.INVALID_MODIFICATION_ERR);
- }
- ElementImpl element = (ElementImpl) createElement(tagName);
- element.setJSPTag(isJSPTag);
- CommentElementRegistry registry = CommentElementRegistry.getInstance();
- if (registry.setupCommentElement(element)) {
- result = element;
- }
- else {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, DOMMessages.INVALID_CHARACTER_ERR);
- }
- return result;
- }
-
- /**
- * createDoctype method
- *
- * @return org.w3c.dom.DocumentType
- * @param name
- * java.lang.String
- */
- public DocumentType createDoctype(String name) {
- DocumentTypeImpl docType = new DocumentTypeImpl();
- docType.setOwnerDocument(this);
- docType.setName(name);
- return docType;
- }
-
- /**
- * createDocumentFragment method
- *
- * @return org.w3c.dom.DocumentFragment
- */
- public DocumentFragment createDocumentFragment() {
- DocumentFragmentImpl fragment = new DocumentFragmentImpl();
- fragment.setOwnerDocument(this);
- return fragment;
- }
-
- /**
- * createElement method
- *
- * @return org.w3c.dom.Element
- * @param tagName
- * java.lang.String
- */
- public Element createElement(String tagName) throws DOMException {
- checkTagNameValidity(tagName);
-
- ElementImpl element = new ElementImpl();
- element.setOwnerDocument(this);
- element.setTagName(tagName);
- return element;
- }
-
- /**
- */
- public Element createElementNS(String uri, String tagName) throws DOMException {
- if (!isValidName(tagName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, DOMMessages.INVALID_CHARACTER_ERR);
- }
-
- ElementImpl element = (ElementImpl) createElement(tagName);
- element.setNamespaceURI(uri);
- return element;
- }
-
- /**
- * createEntity method
- *
- * @return org.w3c.dom.Entity
- * @param name
- * java.lang.String
- */
- public Entity createEntity(String name) {
- EntityImpl entity = new EntityImpl();
- entity.setOwnerDocument(this);
- entity.setName(name);
- return entity;
- }
-
- /**
- * createEntityReference method
- *
- * @return org.w3c.dom.EntityReference
- * @param name
- * java.lang.String
- */
- public EntityReference createEntityReference(String name) throws DOMException {
- if (!isXMLType()) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, DOMMessages.NOT_SUPPORTED_ERR);
- }
-
- EntityReferenceImpl ref = new EntityReferenceImpl();
- ref.setOwnerDocument(this);
- ref.setName(name);
- return ref;
- }
-
- /**
- */
- public NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) {
- if (root == null)
- root = this;
- return new NodeIteratorImpl(root, whatToShow, filter);
- }
-
- /**
- * createNotation method
- *
- * @return org.w3c.dom.Notation
- * @param name
- * java.lang.String
- */
- public Notation createNotation(String name) {
- NotationImpl notation = new NotationImpl();
- notation.setOwnerDocument(this);
- notation.setName(name);
- return notation;
- }
-
- /**
- * createProcessingInstruction method
- *
- * @return org.w3c.dom.ProcessingInstruction
- * @param target
- * java.lang.String
- * @param data
- * java.lang.String
- */
- public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException {
- ProcessingInstructionImpl pi = new ProcessingInstructionImpl();
- pi.setOwnerDocument(this);
- pi.setTarget(target);
- if (data != null)
- pi.setData(data);
- return pi;
- }
-
- /**
- */
- public Range createRange() {
- return new RangeImpl();
- }
-
- /**
- * createTextNode method
- *
- * @return org.w3c.dom.Text
- * @param data
- * java.lang.String
- */
- public Text createTextNode(String data) {
- TextImpl text = new TextImpl();
- text.setOwnerDocument(this);
- text.setData(data);
- return text;
- }
-
- /**
- * Return an instance of tree walk
- */
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.traversal.DocumentTraversal#createTreeWalker(org.w3c.dom.Node,
- * int, org.w3c.dom.traversal.NodeFilter, boolean)
- */
- public TreeWalker createTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) {
- if (root == null) {
- String msg = DOMMessages.NOT_SUPPORTED_ERR + " - Program Error: root node can not be null for TreeWalker";
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
- }
- // ISSUE: we just use Xerces implementation for now, but longer term,
- // we should make a
- // thread/job safe version (as well as not rely on Xerces "impl"
- // class.
- return new TreeWalkerImpl(root, whatToShow, filter, entityReferenceExpansion);
-
- }
-
- private DocumentType findDoctype(Node node) {
-
- int countSearch = 0;
- for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (countSearch++ > maxDocTypeSearch) {
- break;
- }
- if (child.getNodeType() == DOCUMENT_TYPE_NODE && child instanceof DocumentType) {
- return (DocumentType) child;
- }
- else if (child.getNodeType() == ELEMENT_NODE && ((IDOMElement) child).isCommentTag()) {
- // search DOCTYPE inside of generic comment element
- DocumentType docType = findDoctype(child);
- if (docType != null) {
- return docType;
- }
- }
- }
-
- return null;
- }
-
- private Element findDocumentElement(String docName, Node node, Node[] firstFound, int max) {
- int countSearch = 0;
- for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
-
- /*
- * maxDocTypeSearch limits added via bug 151929
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=151929
- * but, in other contexts,
- * if noMaxSearch is specified, then do not "break out" of long searches
- * */
- if (max != noMaxSearch && countSearch++ > max) {
- break;
- }
- if (child.getNodeType() != ELEMENT_NODE)
- continue;
- ElementImpl element = (ElementImpl) child;
- if (element.isCommentTag()) {
- Element docElement = findDocumentElement(docName, element, firstFound, max);
- if (docElement != null) {
- return docElement;
- }
- else {
- // added 'else continue' to better handle cases where
- // there is "more than one root" element
- // especially complicated by CommentElements, which are
- // sometimes treated as elements, but should
- // be treated as comments in this context.
- continue;
- }
- }
- // note: the "name" won't match in the event of a jsp tag ... but
- // incase
- // the name is null, we do not want the jsp element returned as
- // documentElement
- if (element.isJSPTag())
- continue;
- if (docName == null)
- return element;
- // use local name for namespace
- String localName = element.getLocalName();
- if (localName == null)
- continue;
- if (isXMLType()) {
- if (localName.equals(docName))
- return element;
- }
- else {
- if (localName.equalsIgnoreCase(docName))
- return element;
- }
- if (firstFound[0] == null)
- firstFound[0] = element;
- }
- return null;
- }
-
- /**
- * getCharValue method
- *
- * @return java.lang.String
- * @param name
- * java.lang.String
- */
- protected String getCharValue(String name) {
- if (name == null)
- return null;
- int length = name.length();
- if (length == 0)
- return null;
-
- if (name.charAt(0) == '#') { // character reference
- if (length == 1)
- return null;
- int radix = 10;
- String s = null;
- // now allow hexadecimal also for non XML document
- if (name.charAt(1) == 'x') { // hexadecimal
- radix = 16;
- s = name.substring(2);
- }
- else { // decimal
- s = name.substring(1);
- }
- if (s == null || s.length() == 0)
- return null;
- if (s.charAt(0) == '-')
- return null; // no minus accepted
- char c = 0;
- try {
- c = (char) Integer.parseInt(s, radix);
- }
- catch (NumberFormatException ex) {
- }
- if (c == 0)
- return null;
- return String.valueOf(c);
- }
-
- // implicit character entities for XML
- if (name.equals(IXMLCharEntity.LT_NAME))
- return IXMLCharEntity.LT_VALUE;
- if (name.equals(IXMLCharEntity.GT_NAME))
- return IXMLCharEntity.GT_VALUE;
- if (name.equals(IXMLCharEntity.AMP_NAME))
- return IXMLCharEntity.AMP_VALUE;
- if (name.equals(IXMLCharEntity.QUOT_NAME))
- return IXMLCharEntity.QUOT_VALUE;
- if (isXMLType()) {
- if (name.equals(IXMLCharEntity.APOS_NAME))
- return IXMLCharEntity.APOS_VALUE;
- }
-
- CMDocument cm = getCMDocument();
- if (cm != null) {
- CMNamedNodeMap map = cm.getEntities();
- if (map != null) {
- CMEntityDeclaration decl = (CMEntityDeclaration) map.getNamedItem(name);
- if (decl != null) {
- String value = decl.getValue();
- if (value == null)
- return null;
- int valueLength = value.length();
- if (valueLength > 1 && value.charAt(0) == '&' && value.charAt(1) == '#' && value.charAt(valueLength - 1) == ';') {
- // character reference
- return getCharValue(value.substring(1, valueLength - 1));
- }
- return value;
- }
- }
- }
-
- return null;
- }
-
- /**
- */
- protected CMDocument getCMDocument() {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
- if (modelQuery == null)
- return null;
- return modelQuery.getCorrespondingCMDocument(this);
- }
-
- /**
- * getDoctype method
- *
- * @return org.w3c.dom.DocumentType
- */
- public DocumentType getDoctype() {
- return findDoctype(this);
- }
-
- /**
- * getDocumentElement
- *
- * @return org.w3c.dom.Element From DOM 2 Spec: documentElement of type
- * Element [p.62] , readonly This is a convenience [p.119]
- * attribute that allows direct access to the child node that is
- * the root element of the document. For HTML documents, this is
- * the element with the tagName "HTML". Note: we differ from this
- * definition a little in that we don't necessarily take the first
- * child but also look to match the name. In a well formed
- * document, of course, the result is the same, but not
- * necessarily the same in an ill-formed document.
- */
- public Element getDocumentElement() {
- String name = null;
- DocumentType docType = getDocumentType();
- if (docType != null) {
- name = docType.getName();
- }
-
- Element first[] = new Element[1];
- Element docElement = findDocumentElement(name, this, first, noMaxSearch);
- if (docElement == null) {
- docElement = first[0];
- }
-
- return docElement;
- }
-
- /**
- */
- protected DocumentType getDocumentType() {
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) getAdapterFor(DocumentTypeAdapter.class);
- if (adapter == null)
- return getDoctype();
- return adapter.getDocumentType();
- }
-
-
- public String getDocumentTypeId() {
- DocumentType docType = getDocumentType();
- if (docType == null)
- return null;
- String id = docType.getPublicId();
- if (id == null)
- id = docType.getSystemId();
- return id;
- }
-
- public Element getElementById(String id) {
- if (id == null)
- return null;
- NodeIterator it = createNodeIterator(this, NodeFilter.SHOW_ALL, null, false);
- if (it == null)
- return null;
-
- for (Node node = it.nextNode(); node != null; node = it.nextNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- continue;
- ElementImpl element = (ElementImpl) node;
- if (element.hasAttribute("id") && id.equals(element.getAttribute("id"))) //$NON-NLS-1$ //$NON-NLS-2$
- return element;
- }
-
- return null;
- }
-
- public NodeList getElementsByTagName(String tagName) {
- if (tagName == null)
- return new NodeListImpl();
-
- NodeListImpl elements = null;
-
- if (usetagnamecache) {
- elements = tagNameCache.getItem(tagName);
- }
-
- if (elements == null) {
- elements = internalGetElementsByTagName(tagName);
-
- }
-
- return elements;
- }
-
- /**
- */
- public NodeList getElementsByTagNameNS(String uri, String tagName) {
- if (tagName == null)
- return new NodeListImpl();
-
- NodeIterator it = createNodeIterator(this, NodeFilter.SHOW_ALL, null, false);
- if (it == null)
- return new NodeListImpl();
- NodeListImpl elements = new NodeListImpl();
-
- if (uri != null && uri.length() == 1 && uri.charAt(0) == '*') {
- uri = null; // do not care
- }
- if (tagName.length() == 1 && tagName.charAt(0) == '*') {
- tagName = null; // do not care
- }
-
- for (Node node = it.nextNode(); node != null; node = it.nextNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- continue;
- ElementImpl element = (ElementImpl) node;
- if (tagName != null) {
- String localName = element.getLocalName();
- if (localName == null || !localName.equals(tagName))
- continue;
- }
- if (uri != null) {
- String nsURI = element.getNamespaceURI();
- if (nsURI == null || !nsURI.equals(uri))
- continue;
- }
- elements.appendNode(element);
- }
-
- return elements;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, the encoding
- * of this document. This is <code>null</code> when unspecified.
- *
- * @see DOM Level 3
- */
- public java.lang.String getEncoding() {
- return null;
- }
-
- /**
- */
- public DOMImplementation getImplementation() {
- return model;
- }
-
- /**
- * other nodes will be referring to this one to get the owning model
- */
- public IDOMModel getModel() {
- return model;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return "#document";//$NON-NLS-1$
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return DOCUMENT_NODE;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, whether this
- * document is standalone.
- *
- * @see DOM Level 3
- */
- public boolean getStandalone() {
- return false;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying whether errors checking is enforced or not.
- * When set to <code>false</code>, the implementation is free to not
- * test every possible error case normally defined on DOM operations, and
- * not raise any <code>DOMException</code>. In case of error, the
- * behavior is undefined. This attribute is <code>true</code> by
- * defaults.
- *
- * @see DOM Level 3
- */
- public boolean getStrictErrorChecking() {
- return false;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, the version
- * number of this document. This is <code>null</code> when unspecified.
- *
- * @see DOM Level 3
- */
- public String getVersion() {
- return null;
- }
-
- /**
- */
- protected boolean ignoreCase() {
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) getAdapterFor(DocumentTypeAdapter.class);
- if (adapter == null)
- return false;
- return (adapter.getTagNameCase() != DocumentTypeAdapter.STRICT_CASE);
- }
-
- /**
- */
- protected void importChildNodes(Node parent, boolean deep) {
- if (parent == null)
- return;
-
- removeChildNodes();
-
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
- Node imported = importNode(child, deep);
- if (imported == null)
- continue;
- appendChild(imported);
- }
- }
-
- /**
- */
- public Node importNode(Node node, boolean deep) throws DOMException {
- if (node == null)
- return null;
- NodeImpl imported = (NodeImpl) node.cloneNode(deep);
- if (imported == null)
- return null;
- //successful import, notify UserDataHandlers if any
- NodeImpl nodeToNotify=(NodeImpl) node;
- nodeToNotify.notifyUserDataHandlers(UserDataHandler.NODE_IMPORTED, null);
- imported.setOwnerDocument(this, deep);
- return imported;
- }
-
- private NodeListImpl internalGetElementsByTagName(String tagName) {
- // System.out.println("getElementsByTagname: " + tagName);
- NodeIterator it = createNodeIterator(this, NodeFilter.SHOW_ALL, null, false);
- if (it == null)
- return new NodeListImpl();
- NodeListImpl elements = new NodeListImpl();
-
- if (tagName.length() == 1 && tagName.charAt(0) == '*') {
- tagName = null; // do not care
- }
-
- for (Node node = it.nextNode(); node != null; node = it.nextNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- continue;
- if (tagName != null) {
- ElementImpl element = (ElementImpl) node;
- if (!element.matchTagName(tagName))
- continue;
- }
- elements.appendNode(node);
- }
- if (usetagnamecache) {
- tagNameCache.addItem(tagName, elements);
- }
- return elements;
- }
-
- /**
- */
- public boolean isJSPDocument() {
- Element element = getDocumentElement();
- if (element == null)
- return false;
- String tagName = element.getTagName();
- if (tagName == null)
- return false;
- return tagName.equals(JSPTag.JSP_ROOT);
- }
-
- /**
- */
- public boolean isJSPType() {
- if (this.model == null)
- return false;
- IModelHandler handler = this.model.getModelHandler();
- if (handler == null)
- return false;
- String id = handler.getAssociatedContentTypeId();
- if (id == null)
- return false;
- // ISSUE: -- avoid this hardcoded string
- return id.equals("org.eclipse.jst.jsp.core.jspsource"); //$NON-NLS-1$
- }
-
- /**
- */
- protected boolean isValidName(String name) {
- if (name == null || name.length() == 0)
- return false;
- // // DMW: modified for XML4J 4.0.1
- // if (XMLChar.isValidName(name)) return true;
- if (NameValidator.isValid(name))
- return true;
- // special for invalid declaration
- if (name.length() == 1 && name.charAt(0) == '!')
- return true;
- // special for JSP tag in tag name
- if (name.startsWith(JSPTag.TAG_OPEN))
- return true;
- return false;
- }
-
- /**
- */
- public boolean isXMLType() {
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) getAdapterFor(DocumentTypeAdapter.class);
- if (adapter == null)
- return true;
- return adapter.isXMLType();
- }
-
- /**
- */
- // protected void releaseDocumentType() {
- // if (this.documentTypeAdapter == null)
- // return;
- // this.documentTypeAdapter.release();
- // this.documentTypeAdapter = null;
- // }
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, the encoding
- * of this document. This is <code>null</code> when unspecified.
- *
- * @see DOM Level 3
- */
- public void setEncoding(java.lang.String encoding) {
- }
-
- /**
- * setModel method
- *
- * @param model
- * XMLModel
- */
-
- protected void setModel(IDOMModel model) {
- this.model = (DOMModelImpl) model;
- }
-
- /**
- * Provides an element's attribute declarations
- * @param element the element to retrieve the attribute map of
- * @return a <code>CMNamedNodeMap</code> of attributes if the declaration exists; null otherwise.
- */
- CMNamedNodeMap getCMAttributes(Element element) {
- CMNamedNodeMap map = (CMNamedNodeMap) fCMCache.get(element);
- if (map == null) {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
- CMElementDeclaration decl = modelQuery != null ? modelQuery.getCMElementDeclaration(element) : null;
- if (decl != null) {
- map = decl.getAttributes();
- fCMCache.put(element, map);
- }
- }
- return map;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, whether this
- * document is standalone.
- *
- * @see DOM Level 3
- */
- public void setStandalone(boolean standalone) {
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying whether errors checking is enforced or not.
- * When set to <code>false</code>, the implementation is free to not
- * test every possible error case normally defined on DOM operations, and
- * not raise any <code>DOMException</code>. In case of error, the
- * behavior is undefined. This attribute is <code>true</code> by
- * defaults.
- *
- * @see DOM Level 3
- */
- public void setStrictErrorChecking(boolean strictErrorChecking) {
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the XML declaration, the version
- * number of this document. This is <code>null</code> when unspecified.
- *
- * @see DOM Level 3
- */
- public void setVersion(java.lang.String version) {
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public String getInputEncoding() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public String getXmlEncoding() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public boolean getXmlStandalone() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setXmlStandalone(boolean xmlStandalone) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public String getXmlVersion() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setXmlVersion(String xmlVersion) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public String getDocumentURI() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setDocumentURI(String documentURI) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public DOMConfiguration getDomConfig() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void normalizeDocument() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapter.java
deleted file mode 100644
index d2167048dd..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.w3c.dom.DocumentType;
-
-
-/**
- */
-public interface DocumentTypeAdapter extends INodeAdapter {
- static final int LOWER_CASE = 2;
- static final int STRICT_CASE = 0;
- static final int UPPER_CASE = 1;
-
- /**
- */
- int getAttrNameCase();
-
- /**
- */
- DocumentType getDocumentType();
-
- /**
- */
- int getTagNameCase();
-
- /**
- */
- boolean hasFeature(String feature);
-
- /**
- */
- boolean isXMLType();
-
- /**
- */
- void release();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapterImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapterImpl.java
deleted file mode 100644
index 29c3e95c44..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeAdapterImpl.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.w3c.dom.DocumentType;
-
-
-/**
- */
-public class DocumentTypeAdapterImpl implements DocumentTypeAdapter {
-
- private IDOMDocument document = null;
- private DocumentType documentType = null;
-
- /**
- */
- protected DocumentTypeAdapterImpl() {
- super();
- }
-
- /**
- */
- protected DocumentTypeAdapterImpl(IDOMDocument document) {
- this.document = document;
- if (document != null) {
- this.documentType = document.getDoctype();
- }
- }
-
- /**
- */
- public int getAttrNameCase() {
- return STRICT_CASE;
- }
-
- /**
- */
- protected IDOMDocument getDocument() {
- return this.document;
- }
-
- /**
- */
- public DocumentType getDocumentType() {
- return this.documentType;
- }
-
- /**
- */
- public int getTagNameCase() {
- return STRICT_CASE;
- }
-
- /**
- */
- public boolean hasFeature(String feature) {
- return false;
- }
-
- /**
- */
- public boolean isAdapterForType(Object type) {
- return (type == DocumentTypeAdapter.class);
- }
-
- /**
- */
- public boolean isXMLType() {
- return true;
- }
-
- /**
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (eventType != INodeNotifier.STRUCTURE_CHANGED)
- return;
- if (notifier == null || !(notifier instanceof IDOMDocument))
- return;
- this.documentType = ((IDOMDocument) notifier).getDoctype();
- }
-
- /**
- */
- protected void notifyDocumentTypeChanged() {
- if (this.document == null)
- return;
- IDOMModel model = this.document.getModel();
- if (model == null)
- return;
- ((DOMModelImpl) model).documentTypeChanged();
- }
-
- /**
- */
- public void release() {
- // nothing to do
- }
-
- /**
- */
- protected void setDocumentType(DocumentType documentType) {
- this.documentType = documentType;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeImpl.java
deleted file mode 100644
index 5ff86bf393..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentTypeImpl.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * DocumentType class
- */
-public class DocumentTypeImpl extends NodeImpl implements IDOMDocumentType {
- private String internalSubset = null;
-
- private String name = null;
- private String publicId = null;
- private String systemId = null;
-
- /**
- * DocumentTypeImpl constructor
- */
- protected DocumentTypeImpl() {
- super();
- }
-
- /**
- * DocumentTypeImpl constructor
- *
- * @param that
- * DocumentTypeImpl
- */
- protected DocumentTypeImpl(DocumentTypeImpl that) {
- super(that);
-
- if (that != null) {
- this.name = that.name;
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- DocumentTypeImpl cloned = new DocumentTypeImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getEntities method
- *
- * @return org.w3c.dom.NamedNodeMap
- */
- public NamedNodeMap getEntities() {
- return null;
- }
-
- /**
- */
- public String getInternalSubset() {
- return this.internalSubset;
- }
-
- /**
- * getName method
- *
- * @return java.lang.String
- */
- public String getName() {
- if (this.name == null)
- return NodeImpl.EMPTY_STRING;
- return this.name;
- }
-
- /**
- * getNodeName
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return getName();
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return DOCUMENT_TYPE_NODE;
- }
-
- /**
- * getNotations method
- *
- * @return org.w3c.dom.NamedNodeMap
- */
- public NamedNodeMap getNotations() {
- return null;
- }
-
- /**
- * getPublicId method
- *
- * @return java.lang.String
- */
- public String getPublicId() {
- return this.publicId;
- }
-
- /**
- * getSystemId method
- *
- * @return java.lang.String
- */
- public String getSystemId() {
- return this.systemId;
- }
-
- /**
- */
- public boolean isClosed() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- return (regionType == DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE || regionType == DOMRegionContext.XML_DECLARATION_CLOSE);
- }
-
- /**
- */
- public void setInternalSubset(String internalSubset) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.internalSubset = internalSubset;
- }
-
- /**
- * setName method
- *
- * @param name
- * java.lang.String
- */
- protected void setName(String name) {
- this.name = name;
- }
-
- /**
- * setPublicId method
- *
- * @param publicId
- * java.lang.String
- */
- public void setPublicId(String publicId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.publicId = publicId;
-
- notifyValueChanged();
- }
-
- /**
- * setSystemId method
- *
- * @param systemId
- * java.lang.String
- */
- public void setSystemId(String systemId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.systemId = systemId;
-
- notifyValueChanged();
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(getName());
- buffer.append('(');
- buffer.append(getPublicId());
- buffer.append(')');
- buffer.append('(');
- buffer.append(getSystemId());
- buffer.append(')');
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode != null) {
- buffer.append('@');
- buffer.append(flatNode.toString());
- }
- return buffer.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ElementImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ElementImpl.java
deleted file mode 100644
index 8e5121e572..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ElementImpl.java
+++ /dev/null
@@ -1,1552 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Valentin Baciu - https://bugs.eclipse.org/bugs/show_bug.cgi?id=139552
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Iterator;
-import java.util.Stack;
-
-import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementAdapter;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLNamespace;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.UserDataHandler;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-
-
-/**
- * ElementImpl class
- */
-public class ElementImpl extends NodeContainer implements IDOMElement {
-
- private class Attributes implements NamedNodeMap {
- Attributes() {
- super();
- }
-
- public int getLength() {
- if (attrNodes == null)
- return 0;
- return attrNodes.getLength();
- }
-
- public Node getNamedItem(String name) {
- return getAttributeNode(name);
- }
-
- public Node getNamedItemNS(String uri, String name) {
- return getAttributeNodeNS(uri, name);
- }
-
- public Node item(int index) {
- if (attrNodes == null)
- return null;
- if (index >= attrNodes.getLength())
- return null;
- return attrNodes.item(index);
- }
-
- public Node removeNamedItem(String name) throws DOMException {
- return removeAttributeNode(name);
- }
-
- public Node removeNamedItemNS(String uri, String name) throws DOMException {
- return removeAttributeNodeNS(uri, name);
- }
-
- public Node setNamedItem(Node arg) throws DOMException {
- return setAttributeNode((AttrImpl) arg);
- }
-
- public Node setNamedItemNS(Node arg) throws DOMException {
- return setAttributeNodeNS((AttrImpl) arg);
- }
- }
-
-// private static final char[] XMLNS_PREFIX = IXMLNamespace.XMLNS_PREFIX.toCharArray();
- private static final byte FLAG_COMMENT = 0x1;
- private static final byte FLAG_EMPTY = 0x2;
- private static final byte FLAG_JSP = 0x4;
-
- private byte fTagFlags = 0;
-
- NodeListImpl attrNodes = null;
- private IStructuredDocumentRegion endStructuredDocumentRegion = null;
-
- private char[] fTagName = null;
-
- private char[] fNamespaceURI = null;
-
- private Stack fDefaultValueLookups = null;
-
- /**
- * ElementImpl constructor
- */
- protected ElementImpl() {
- super();
- }
-
- /**
- * ElementImpl constructor
- *
- * @param that
- * ElementImpl
- */
- protected ElementImpl(ElementImpl that) {
- super(that);
-
- if (that != null) {
- this.fTagName = that.fTagName;
- this.fTagFlags = that.fTagFlags;
-
- // clone attributes
- that.cloneAttributes(this);
- }
- }
-
- /**
- * addEndTag method
- *
- * @param end
- * org.w3c.dom.Element
- */
- protected void addEndTag(Element endTag) {
- if (endTag == null)
- return;
- if (hasEndTag())
- return;
- ElementImpl end = (ElementImpl) endTag;
-
- // move the end flat node from the end tag
- IStructuredDocumentRegion flatNode = end.getEndStructuredDocumentRegion();
- if (flatNode == null)
- return;
- end.setEndStructuredDocumentRegion(null);
- setEndStructuredDocumentRegion(flatNode);
- }
-
- /**
- * appendAttibuteNode method
- *
- * @return org.w3c.dom.Attr
- * @param newAttr
- * org.w3c.dom.Attr
- */
- public Attr appendAttributeNode(Attr newAttr) {
- if (newAttr == null)
- return null;
- AttrImpl attr = (AttrImpl) newAttr;
- if (attr.getOwnerElement() != null)
- return null;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (this.attrNodes == null)
- this.attrNodes = new NodeListImpl();
- this.attrNodes.appendNode(attr);
- attr.setOwnerElement(this);
-
- notifyAttrReplaced(attr, null);
- return attr;
- }
-
- /**
- * cloneAttributes method
- *
- * @param newOwner
- * org.w3c.dom.Element
- */
- protected void cloneAttributes(Element newOwner) {
- if (newOwner == null || newOwner == this)
- return;
-
- ElementImpl element = (ElementImpl) newOwner;
- element.removeAttributes();
-
- if (this.attrNodes == null)
- return;
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- Node node = this.attrNodes.item(i);
- if (node == null)
- continue;
- Attr cloned = (Attr) node.cloneNode(false);
- if (cloned != null)
- element.appendAttributeNode(cloned);
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- ElementImpl cloned = newInstance();
- if (deep)
- cloneChildNodes(cloned, deep);
-
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- protected ElementImpl newInstance() {
- return new ElementImpl(this);
- }
-
- /**
- * getAttribute method
- *
- * @return java.lang.String
- * @param name
- * java.lang.String
- */
- public String getAttribute(String name) {
- Attr attr = getAttributeNode(name);
- // In the absence of the attribute, get the default value
- if (attr == null) {
- final String defaultValue = getDefaultValue(name, NodeImpl.EMPTY_STRING);
- return defaultValue != null ? defaultValue : NodeImpl.EMPTY_STRING ;
- }
- return attr.getValue();
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
- */
- public Attr getAttributeNode(String name) {
- if (name == null)
- return null; // invalid parameter
- if (this.attrNodes == null)
- return null; // no attribute
-
- final Attr attr = findAttributeNode(name);
- if (attr != null)
- return attr;
-
- String implied = getDefaultValue(name, null);
- if (implied != null) {
- Attr createdAttribute = getOwnerDocument().createAttribute(name);
- createdAttribute.setNodeValue(implied);
- ((AttrImpl) createdAttribute).setOwnerElement(this);
- return createdAttribute;
- }
-
- return null; // not found
- }
-
- /**
- * Finds an attribute node in this element's attribute nodelist
- * @param name the name of the attribute to find
- * @return The {@link Attr} whose name matches <code>name</code>. Returns null if an attribute by <code>name</code>
- * could not be found.
- */
- private Attr findAttributeNode(String name) {
- if (attrNodes == null)
- return null; // no attribute
-
- int length = attrNodes.getLength();
- char[] nameChars = name.toCharArray();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) attrNodes.item(i);
- if (attr == null)
- continue;
- if (attr.matchName(nameChars))
- return attr; // found
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String)
- */
- public Attr getAttributeNodeNS(String uri, String name) {
- if (name == null)
- return null; // invalid parameter
- if (this.attrNodes == null)
- return null; // no attribute
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- String localName = attr.getLocalName();
- if (localName == null || !localName.equals(name))
- continue;
- String nsURI = attr.getNamespaceURI();
- if (uri == null) {
- if (nsURI != null)
- continue;
- }
- else {
- if (nsURI == null || !nsURI.equals(uri))
- continue;
- }
-
- // found
- return attr;
- }
-
- return null; // not found
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String)
- */
- public String getAttributeNS(String uri, String name) {
- Attr attr = getAttributeNodeNS(uri, name);
- // In the absence of the attribute, get the default value
- if (attr == null) {
- final String defaultValue = getDefaultValue(name, NodeImpl.EMPTY_STRING);
- return defaultValue != null ? defaultValue : NodeImpl.EMPTY_STRING;
- }
- return attr.getValue();
- }
-
- /**
- * getAttributes method
- *
- * @return org.w3c.dom.NamedNodeMap
- */
- public NamedNodeMap getAttributes() {
- return new Attributes();
- }
-
- /**
- */
- protected CMElementDeclaration getDeclaration() {
- Document document = getOwnerDocument();
- if (document == null)
- return null;
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
- if (modelQuery == null)
- return null;
- return modelQuery.getCMElementDeclaration(this);
- }
-
- /**
- * Get the implied default value for attribute <code>name</code>
- *
- * @param name
- * @return returns the default value for attribute <code>name</code> if it
- * is found in the content model, <code>unknownDefault</code> otherwise
- */
- private String getDefaultValue(String name, String unknownDefault) {
- if (fDefaultValueLookups != null && fDefaultValueLookups.contains(name))
- return null;
- try {
- if (fDefaultValueLookups == null)
- fDefaultValueLookups = new Stack();
- fDefaultValueLookups.push(name);
- CMNamedNodeMap map = ((DocumentImpl) getOwnerDocument()).getCMAttributes(this);
- if (map != null) {
- CMNode attribute = map.getNamedItem(name);
- if (attribute instanceof CMAttributeDeclaration)
- return ((CMAttributeDeclaration) attribute).getAttrType().getImpliedValue();
- }
- return unknownDefault;
- }
- finally {
- fDefaultValueLookups.pop();
- }
- }
-
- /**
- * getElementsByTagName method
- *
- * @return org.w3c.dom.NodeList
- * @param tagName
- * java.lang.String
- */
- public NodeList getElementsByTagName(String tagName) {
- if (tagName == null)
- return new NodeListImpl();
-
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document == null)
- return new NodeListImpl();
- NodeIterator it = document.createNodeIterator(this, NodeFilter.SHOW_ALL, null, false);
- if (it == null)
- return new NodeListImpl();
- NodeListImpl elements = new NodeListImpl();
-
- if (tagName.length() == 1 && tagName.charAt(0) == '*') {
- tagName = null; // do not care
- }
-
- it.nextNode(); // skip the first node since it is the root from createNodeIterator
- for (Node node = it.nextNode(); node != null; node = it.nextNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- continue;
- if (tagName != null) {
- ElementImpl element = (ElementImpl) node;
- if (!element.matchTagName(tagName))
- continue;
- }
- elements.appendNode(node);
- }
-
- return elements;
- }
-
- /**
- */
- public NodeList getElementsByTagNameNS(String uri, String tagName) {
- if (tagName == null)
- return new NodeListImpl();
-
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document == null)
- return new NodeListImpl();
- NodeIterator it = document.createNodeIterator(this, NodeFilter.SHOW_ALL, null, false);
- if (it == null)
- return new NodeListImpl();
- NodeListImpl elements = new NodeListImpl();
-
- if (uri != null && uri.length() == 1 && uri.charAt(0) == '*') {
- uri = null; // do not care
- }
- if (tagName.length() == 1 && tagName.charAt(0) == '*') {
- tagName = null; // do not care
- }
-
- it.nextNode(); // skip the first node since it is the root from createNodeIterator
- for (Node node = it.nextNode(); node != null; node = it.nextNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- continue;
- ElementImpl element = (ElementImpl) node;
- if (tagName != null) {
- String localName = element.getLocalName();
- if (localName == null || !localName.equals(tagName))
- continue;
- }
- if (uri != null) {
- String nsURI = element.getNamespaceURI();
- if (nsURI == null || !nsURI.equals(uri))
- continue;
- }
- elements.appendNode(element);
- }
-
- return elements;
- }
-
- /**
- * getEndOffset method
- *
- * @return int
- */
- public int getEndOffset() {
- if (this.endStructuredDocumentRegion != null)
- return this.endStructuredDocumentRegion.getEnd();
- return super.getEndOffset();
- }
-
- /**
- * getEndStartOffset method
- *
- * @return int
- */
- public int getEndStartOffset() {
- if (this.endStructuredDocumentRegion != null)
- return this.endStructuredDocumentRegion.getStart();
- return super.getEndOffset();
- }
-
- /**
- * getEndStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getEndStructuredDocumentRegion() {
- return this.endStructuredDocumentRegion;
- }
-
- public String getEndTagName() {
- if (this.endStructuredDocumentRegion == null)
- return null;
-
- ITextRegionList regions = this.endStructuredDocumentRegion.getRegions();
- if (regions == null)
- return null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedEndTag(regionType)) {
- return this.endStructuredDocumentRegion.getText(region);
- }
- }
-
- return null;
- }
-
- protected boolean isNestedEndTag(String regionType) {
- boolean result = false;
- return result;
- }
-
- /**
- * getFirstStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getFirstStructuredDocumentRegion() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode != null)
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(flatNode);
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(this.endStructuredDocumentRegion);
- }
-
- /**
- * getLastStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getLastStructuredDocumentRegion() {
- if (this.endStructuredDocumentRegion != null)
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(this.endStructuredDocumentRegion);
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(getStructuredDocumentRegion());
- }
-
- /**
- */
- public String getLocalName() {
- if (this.fTagName == null)
- return null;
- int index = CharOperation.indexOf(this.fTagName, ':');
- if (index < 0)
- return new String(this.fTagName);
- return new String(this.fTagName, index + 1, this.fTagName.length - index - 1);
- }
-
- public String getNamespaceURI() {
- if (this.fNamespaceURI != null)
- return new String(this.fNamespaceURI);
-
- String nsAttrName = null;
- String prefix = getPrefix();
- if (prefix != null && prefix.length() > 0) {
- nsAttrName = IXMLNamespace.XMLNS_PREFIX + prefix;
- }
- else {
- nsAttrName = IXMLNamespace.XMLNS;
- }
-
- for (Node node = this; node != null; node = node.getParentNode()) {
- if (node.getNodeType() != ELEMENT_NODE)
- break;
- Element element = (Element) node;
- Attr attr = element.getAttributeNode(nsAttrName);
- if (attr != null)
- return attr.getValue();
- }
-
- return null;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return getTagName();
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return ELEMENT_NODE;
- }
-
- /**
- */
- public String getPrefix() {
- if (this.fTagName == null)
- return null;
- int index = CharOperation.indexOf(this.fTagName, ':');
- if (index <= 0)
- return null;
- // exclude JSP tag in name
- if (this.fTagName[0] == '<')
- return null;
- return new String(this.fTagName, 0, index);
- }
-
- /**
- * getStartEndOffset method
- *
- * @return int
- */
- public int getStartEndOffset() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode != null)
- return flatNode.getEnd();
- return super.getStartOffset();
- }
-
- /**
- * getStartOffset method
- *
- * @return int
- */
- public int getStartOffset() {
- if (getStartStructuredDocumentRegion() == null && this.endStructuredDocumentRegion != null && !hasChildNodes()) {
- return this.endStructuredDocumentRegion.getStart();
- }
- return super.getStartOffset();
- }
-
- /**
- * getStartStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getStartStructuredDocumentRegion() {
- return getStructuredDocumentRegion();
- }
-
- /**
- * getTagName method
- *
- * @return java.lang.String
- */
- public String getTagName() {
- if (this.fTagName == null)
- return NodeImpl.EMPTY_STRING;
- return new String(fTagName);
- }
-
- /**
- */
- public boolean hasAttribute(String name) {
- return (getAttributeNode(name) != null);
- }
-
- /**
- */
- public boolean hasAttributeNS(String uri, String name) {
- return (getAttributeNodeNS(uri, name) != null);
- }
-
- /**
- */
- public boolean hasAttributes() {
- return (this.attrNodes != null && this.attrNodes.getLength() > 0);
- }
-
- /**
- * hasEndTag method
- *
- * @return boolean
- */
- public boolean hasEndTag() {
- return (this.endStructuredDocumentRegion != null);
- }
-
- /**
- */
- protected final boolean hasPrefix() {
- if (this.fTagName == null || this.fTagName.length == 0)
- return false;
- return CharOperation.indexOf(this.fTagName, ':') > 0 && this.fTagName[0] != '<';
- }
-
- /**
- * hasStartTag method
- *
- * @return boolean
- */
- public boolean hasStartTag() {
- return (getStructuredDocumentRegion() != null);
- }
-
- /**
- */
- protected final boolean ignoreCase() {
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document != null && document.ignoreCase()) {
- // even in case insensitive document, if having prefix, it's case
- // sensitive tag
- return !hasPrefix();
- }
- return false;
- }
-
- /**
- */
- protected Attr insertAttributeNode(Attr newAttr, int index) {
- if (newAttr == null)
- return null;
- AttrImpl attr = (AttrImpl) newAttr;
- if (attr.getOwnerElement() != null)
- return null;
-
- if (this.attrNodes == null)
- this.attrNodes = new NodeListImpl();
- this.attrNodes.insertNode(attr, index);
- attr.setOwnerElement(this);
-
- notifyAttrReplaced(attr, null);
- return attr;
- }
-
- /**
- * insertBefore method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param refChild
- * org.w3c.dom.Node
- */
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
- // should throw DOMException instead of return null?
- if (newChild == null)
- return null;
- if (!isContainer()) { // never be container
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
- if (newChild.getNodeType() != TEXT_NODE && newChild.getNodeType() != CDATA_SECTION_NODE) {
- if (isJSPContainer() || isCDATAContainer()) { // accepts only
- // Text
- // child
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
- }
- return super.insertBefore(newChild, refChild);
- }
-
- /**
- */
- protected boolean isCDATAContainer() {
- // use BlockMaker instead of CMElementDeclaration
- // because <style> and <script> in XHTML is not CDATA content type
- IDOMModel model = getModel();
- if (model == null)
- return false; // error
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null || fTagName == null)
- return false; // eror
- RegionParser parser = structuredDocument.getParser();
- if (parser == null || !(parser instanceof XMLSourceParser))
- return false;
- return (((XMLSourceParser) parser).getBlockMarker(new String(this.fTagName)) != null);
- /*
- * CMElementDeclaration decl = getDeclaration(); if (decl == null)
- * return false; if (decl instanceof CMNodeWrapper) { decl =
- * (CMElementDeclaration)((CMNodeWrapper)decl).getOriginNode(); if
- * (decl == null) return false; } if (decl instanceof
- * TLDElementDeclaration) { String content =
- * ((TLDElementDeclaration)decl).getBodycontent(); if (content ==
- * null) return false; return
- * content.equals(JSP11TLDNames.CONTENT_TAGDEPENDENT); } if
- * (!isGlobalTag()) return false; return (decl.getContentType() ==
- * CMElementDeclaration.CDATA);
- */
- }
-
- /**
- */
- public boolean isClosed() {
- IStructuredDocumentRegion flatNode = null;
- if (isEmptyTag() || !isContainer()) {
- flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- }
- else {
- flatNode = getEndStructuredDocumentRegion();
- if (flatNode == null)
- return false; // must be generated
- }
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- if (isCommentTag()) {
- return (isNestedClosedComment(regionType) || regionType == DOMRegionContext.XML_COMMENT_CLOSE);
- }
- if (isJSPTag()) {
- return isNestedClosed(regionType);
- }
- return (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || regionType == DOMRegionContext.XML_DECLARATION_CLOSE);
- }
-
- protected boolean isNestedClosed(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected boolean isNestedClosedComment(String regionType) {
- boolean result = false;
- return result;
- }
-
- /**
- */
- public final boolean isCommentTag() {
- return (fTagFlags & FLAG_COMMENT) != 0;
- }
-
- /**
- * isContainer method
- *
- * @return boolean
- */
- public boolean isContainer() {
- if (isCommentTag()) {
- CommentElementAdapter adapter = (CommentElementAdapter) getAdapterFor(CommentElementAdapter.class);
- if (adapter != null) {
- return (adapter.isContainer());
- }
- return (getDeclaration() == null);
- }
- if (isJSPTag()) {
- // exclude JSP directive
- return (matchTagName(JSPTag.JSP_SCRIPTLET) || matchTagName(JSPTag.JSP_DECLARATION) || matchTagName(JSPTag.JSP_EXPRESSION));
- }
- if (!isXMLTag()) { // non-XML tag
- CMElementDeclaration decl = getDeclaration();
- if (decl == null)
- return true; // undefined tag
- return (decl.getContentType() != CMElementDeclaration.EMPTY);
- }
- return true;
- }
-
- /**
- * isEmptyTag method
- *
- * @return boolean
- */
- public boolean isEmptyTag() {
- if (isJSPTag())
- return false;
- if (isCommentTag())
- return false;
- if (!isXMLTag())
- return false;
- return (fTagFlags & FLAG_EMPTY) != 0;
- }
-
- /**
- */
- public boolean isEndTag() {
- return (hasEndTag() && !hasStartTag() && !hasChildNodes());
- }
-
- /**
- */
- public boolean isGlobalTag() {
- return !hasPrefix();
- }
-
- /**
- */
- public boolean isImplicitTag() {
- if (hasStartTag() || hasEndTag())
- return false;
- // make sure this is in the document tree
- // because if not in the document tree, no tags are generated yet
- return (getContainerDocument() != null);
- }
-
- /**
- */
- public boolean isJSPContainer() {
- return (isJSPTag() && !isCommentTag() && isContainer());
- }
-
- /**
- * isJSPTag method
- *
- * @return boolean
- */
- public final boolean isJSPTag() {
- return (fTagFlags & FLAG_JSP) != 0;
- }
-
- /**
- */
- public boolean isStartTagClosed() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- if (isCommentTag()) {
- return (isNestedClosedComment(regionType) || regionType == DOMRegionContext.XML_COMMENT_CLOSE);
- }
- if (isJSPTag()) {
- if (isContainer())
- return true; // start tag always has a single region
- return isClosedNestedDirective(regionType);
- }
- return (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || regionType == DOMRegionContext.XML_DECLARATION_CLOSE);
- }
-
- protected boolean isClosedNestedDirective(String regionType) {
- boolean result = false;
- return result;
- }
-
- /**
- */
- public final boolean isXMLTag() {
- if (isJSPTag())
- return false;
- if (isCommentTag())
- return false;
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document != null && !document.isXMLType()) {
- // even in non-XML document, if having prefix, it's XML tag
- return hasPrefix();
- }
- return true;
- }
-
- /**
- */
- protected boolean matchEndTag(Element element) {
- if (element == null)
- return false;
- ElementImpl impl = (ElementImpl) element;
- if (isJSPTag() && !isCommentTag()) {
- return (impl.isJSPTag() && !impl.isCommentTag());
- }
- return matchTagName(element.getTagName());
- }
-
- /**
- * matchTagName method
- *
- * @return boolean
- * @param tagName
- * java.lang.String
- */
- public boolean matchTagName(String tagName) {
- if (tagName == null)
- return (this.fTagName == null);
- if (this.fTagName == null)
- return false;
- if (this.fTagName.length != tagName.length())
- return false;
- String stringName = new String(this.fTagName);
- if (!ignoreCase())
- return stringName.equals(tagName);
- return stringName.equalsIgnoreCase(tagName);
- }
-
- /**
- * notifyAttrReplaced method
- *
- * @param newAttr
- * org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- protected void notifyAttrReplaced(Attr newAttr, Attr oldAttr) {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.attrReplaced(this, newAttr, oldAttr);
- }
-
- /**
- * notifyValueChanged method
- */
- public void notifyEndTagChanged() {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.endTagChanged(this);
- }
-
- /**
- */
- public void notifyStartTagChanged() {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.startTagChanged(this);
- }
-
- /**
- */
- public boolean preferEmptyTag() {
- if (hasChildNodes())
- return false;
- if (isJSPTag())
- return false;
- if (isCommentTag())
- return false;
- if (!isXMLTag())
- return false;
- CMElementDeclaration decl = getDeclaration();
- if (decl == null)
- return false;
- return (decl.getContentType() == CMElementDeclaration.EMPTY);
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
- */
- public void removeAttribute(String name) throws DOMException {
- removeAttributeNode(name, false);
- }
-
- /**
- * removeAttributeNode method
- *
- * @return org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
- if (oldAttr == null)
- return null; // invalid parameter
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (this.attrNodes == null) { // no attribute
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- }
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr != oldAttr)
- continue;
-
- // found
- this.attrNodes.removeNode(i);
- attr.setOwnerElement(null);
-
- notifyAttrReplaced(null, attr);
- return attr;
- }
-
- // not found
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- }
-
- /**
- * @param name
- * @return
- */
- public Attr removeAttributeNode(String name) {
- return removeAttributeNode(name, true);
- }
-
- private Attr removeAttributeNode(String name, boolean exceptionOnNotFound) {
- if (name == null)
- return null; // invalid parameter
- if (this.attrNodes == null)
- return null; // no attribute
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- if (!attr.matchName(name))
- continue;
-
- // found
- this.attrNodes.removeNode(i);
- attr.setOwnerElement(null);
-
- notifyAttrReplaced(null, attr);
- return attr;
- }
-
- if (exceptionOnNotFound)
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- return null; // not found
- }
-
- /**
- */
- public Attr removeAttributeNodeNS(String uri, String name) {
- if (name == null)
- return null; // invalid parameter
- if (this.attrNodes == null)
- return null; // no attribute
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- String localName = attr.getLocalName();
- if (localName == null || !localName.equals(name))
- continue;
- String nsURI = attr.getNamespaceURI();
- if (uri == null) {
- if (nsURI != null)
- continue;
- }
- else {
- if (nsURI == null || !nsURI.equals(uri))
- continue;
- }
-
- // found
- this.attrNodes.removeNode(i);
- attr.setOwnerElement(null);
-
- notifyAttrReplaced(null, attr);
- return attr;
- }
-
- return null; // not found
- }
-
- /**
- */
- public void removeAttributeNS(String uri, String name) throws DOMException {
- removeAttributeNodeNS(uri, name);
- }
-
- /**
- * removeAttributes method
- */
- public void removeAttributes() {
- if (this.attrNodes == null)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr != null) {
- attr.setOwnerElement(null);
- notifyAttrReplaced(null, attr);
- }
- }
-
- this.attrNodes = null;
- }
-
- /**
- * removeEndTag method
- *
- * @return org.w3c.dom.Element
- */
- protected Element removeEndTag() {
- if (!hasEndTag())
- return null;
- NodeListImpl attrNodes = this.attrNodes;
- this.attrNodes = null; // not to copy attributes
- ElementImpl end = (ElementImpl) cloneNode(false);
- this.attrNodes = attrNodes;
- if (end == null)
- return null;
-
- // move the end flat node to the end tag
- IStructuredDocumentRegion flatNode = getEndStructuredDocumentRegion();
- if (flatNode == null)
- return null;
- setEndStructuredDocumentRegion(null);
- end.setEndStructuredDocumentRegion(flatNode);
- return end;
- }
-
- /**
- */
- protected void removeStartTag() {
- removeAttributes();
- }
-
- /**
- * Resets attribute values from IStructuredDocumentRegion.
- */
- void resetStructuredDocumentRegions() {
- if (this.attrNodes != null) {
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- attr.resetRegions();
- }
- }
-
- super.resetStructuredDocumentRegions(); // for children
-
- this.endStructuredDocumentRegion = null;
- }
-
- /**
- * setAttribute method
- *
- * @param name
- * java.lang.String
- * @param value
- * java.lang.String
- */
- public void setAttribute(String name, String value) throws DOMException {
- if (name == null)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- Attr attr = findAttributeNode(name);
- if (attr != null) {
- attr.setValue(value); // change value
- return;
- }
-
- // new attribute
- Document doc = getOwnerDocument();
- if (doc == null)
- return;
- attr = doc.createAttribute(name);
- if (attr == null)
- return;
- attr.setValue(value);
- appendAttributeNode(attr);
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
- */
- public Attr setAttributeNode(Attr newAttr) throws DOMException {
- if (newAttr == null)
- return null; // nothing to do
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- AttrImpl attr = (AttrImpl) newAttr;
- Element owner = attr.getOwnerElement();
- if (owner != null) {
- if (owner == this)
- return null; // nothing to do
- throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, DOMMessages.INUSE_ATTRIBUTE_ERR);
- }
-
- Attr oldAttr = removeAttributeNode(newAttr.getName(), false);
- appendAttributeNode(attr);
- return oldAttr;
- }
-
- /**
- */
- public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
- if (newAttr == null)
- return null; // nothing to do
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- AttrImpl attr = (AttrImpl) newAttr;
- Element owner = attr.getOwnerElement();
- if (owner != null) {
- if (owner == this)
- return null; // nothing to do
- throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, DOMMessages.INUSE_ATTRIBUTE_ERR);
- }
-
- String name = newAttr.getLocalName();
- String uri = newAttr.getNamespaceURI();
- Attr oldAttr = removeAttributeNodeNS(uri, name);
- appendAttributeNode(attr);
- return oldAttr;
- }
-
- /**
- * ISSUE: we should check for and throw NAMESPACE_ERR, according to spec.
- */
- public void setAttributeNS(String uri, String qualifiedName, String value) throws DOMException {
- if (qualifiedName == null)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=139552
- // fix provided by Valentin Baciu
- int index = qualifiedName.indexOf(':');
- String localName = index != -1 ? qualifiedName.substring(index + 1) : qualifiedName;
-
- Attr attr = getAttributeNodeNS(uri, localName);
- if (attr != null) {
- attr.setValue(value); // change value
- }
- else {
-
- // new attribute
- Document doc = getOwnerDocument();
- if (doc != null) {
- attr = doc.createAttributeNS(uri, qualifiedName);
- if (attr != null) {
- attr.setValue(value);
- appendAttributeNode(attr);
- }
- }
- }
- }
-
- /**
- */
- public void setCommentTag(boolean isCommentTag) {
- IDOMNode parent = (IDOMNode) getParentNode();
- if (parent != null && !parent.isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (isCommentTag)
- fTagFlags |= FLAG_COMMENT;
- else
- fTagFlags &= ~FLAG_COMMENT;
- }
-
- /**
- * setEmptyTag method
- *
- * @param isEmptyTag
- * boolean
- */
- public void setEmptyTag(boolean isEmptyTag) {
- IDOMNode parent = (IDOMNode) getParentNode();
- if (parent != null && !parent.isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (isEmptyTag)
- fTagFlags |= FLAG_EMPTY;
- else
- fTagFlags &= ~FLAG_EMPTY;
- }
-
- /**
- * setEndStructuredDocumentRegion method
- *
- * @param flatNode
- */
- void setEndStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- this.endStructuredDocumentRegion = flatNode;
-
- NodeContainer parent = (NodeContainer) getParentNode();
- if (parent != null) {
- parent.syncChildEditableState(this);
- }
- }
-
- /**
- * setJSPTag method
- *
- * @param isJSPTag
- * boolean
- */
- public void setJSPTag(boolean isJSPTag) {
- IDOMNode parent = (IDOMNode) getParentNode();
- if (parent != null && !parent.isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, NodeImpl.EMPTY_STRING);
- }
-
- if (isJSPTag)
- fTagFlags |= FLAG_JSP;
- else
- fTagFlags &= ~FLAG_JSP;
- }
-
- protected void setNamespaceURI(String namespaceURI) {
- if (namespaceURI == null)
- this.fNamespaceURI = null;
- else
- this.fNamespaceURI = namespaceURI.toCharArray();
- }
-
- /**
- */
- protected void setOwnerDocument(Document ownerDocument, boolean deep) {
- super.setOwnerDocument(ownerDocument, deep);
-
- if (this.attrNodes == null)
- return;
-
- int length = this.attrNodes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- attr.setOwnerDocument(ownerDocument);
- }
- }
-
- /**
- */
- public void setPrefix(String prefix) throws DOMException {
- IDOMNode parent = (IDOMNode) getParentNode();
- if (parent != null && !parent.isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, NodeImpl.EMPTY_STRING);
- }
-
- int prefixLength = (prefix != null ? prefix.length() : 0);
- String localName = getLocalName();
- if (prefixLength == 0) {
- if (localName == null || localName.length() == 0) {
- // invalid local name
- return;
- }
- setTagName(localName);
- }
- else {
- int localLength = (localName != null ? localName.length() : 0);
- StringBuffer buffer = new StringBuffer(prefixLength + 1 + localLength);
- buffer.append(prefix);
- buffer.append(':');
- if (localName != null)
- buffer.append(localName);
- setTagName(buffer.toString());
- }
-
- boolean changeEndTag = hasEndTag();
- notifyStartTagChanged();
- if (changeEndTag)
- notifyEndTagChanged();
- }
-
- /**
- * setStartStructuredDocumentRegion method
- *
- * @param flatNode
- */
- void setStartStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- setStructuredDocumentRegion(flatNode);
- }
-
- /**
- * setTagName method
- *
- * @param tagName
- * java.lang.String
- */
- protected void setTagName(String tagName) {
- this.fTagName = tagName != null ? CharacterStringPool.getCharString(tagName) : null;
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- String tagName = getTagName();
- if (hasStartTag())
- buffer.append(tagName);
- if (isEmptyTag())
- buffer.append('/');
- if (hasEndTag()) {
- buffer.append('/');
- buffer.append(tagName);
- }
- if (buffer.length() == 0)
- buffer.append(tagName);
-
- IStructuredDocumentRegion startStructuredDocumentRegion = getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null) {
- buffer.append('@');
- buffer.append(startStructuredDocumentRegion.toString());
- }
- IStructuredDocumentRegion endStructuredDocumentRegion = getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- buffer.append('@');
- buffer.append(endStructuredDocumentRegion.toString());
- }
- return buffer.toString();
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttribute(String name, boolean isId) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported in this version"); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported in this version"); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityImpl.java
deleted file mode 100644
index fae39ca20a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityImpl.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Entity;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-/**
- * EntityImpl class
- */
-public class EntityImpl extends NodeImpl implements Entity {
-
- private String name = null;
- private String notationName = null;
- private String publicId = null;
- private String systemId = null;
-
- /**
- * EntityImpl constructor
- */
- protected EntityImpl() {
- super();
- }
-
- /**
- * EntityImpl constructor
- *
- * @param that
- * EntityImpl
- */
- protected EntityImpl(EntityImpl that) {
- super(that);
-
- if (that != null) {
- this.name = that.name;
- this.publicId = that.publicId;
- this.systemId = that.systemId;
- this.notationName = that.notationName;
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- EntityImpl cloned = new EntityImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the text declaration, the encoding
- * of this entity, when it is an external parsed entity. This is
- * <code>null</code> otherwise.
- *
- * @see DOM Level 3
- */
- public java.lang.String getEncoding() {
- return null;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- if (this.name == null)
- return NodeImpl.EMPTY_STRING;
- return this.name;
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return ENTITY_NODE;
- }
-
- /**
- * getNotationName method
- *
- * @return java.lang.String
- */
- public String getNotationName() {
- return this.notationName;
- }
-
- /**
- * getPublicId method
- *
- * @return java.lang.String
- */
- public String getPublicId() {
- return this.publicId;
- }
-
- /**
- * getSystemId method
- *
- * @return java.lang.String
- */
- public String getSystemId() {
- return this.systemId;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the text declaration, the version
- * number of this entity, when it is an external parsed entity. This is
- * <code>null</code> otherwise.
- *
- * @see DOM Level 3
- */
- public java.lang.String getVersion() {
- return null;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the text declaration, the encoding
- * of this entity, when it is an external parsed entity. This is
- * <code>null</code> otherwise.
- *
- * @see DOM Level 3
- */
- public void setEncoding(java.lang.String encoding) {
- }
-
- /**
- * setName method
- *
- * @param name
- * java.lang.String
- */
- protected void setName(String name) {
- this.name = name;
- }
-
- /**
- * setNotationName method
- *
- * @param notationName
- * java.lang.String
- */
- public void setNotationName(String notationName) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.notationName = notationName;
- }
-
- /**
- * setPublicId method
- *
- * @param publicId
- * java.lang.String
- */
- public void setPublicId(String publicId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.publicId = publicId;
- }
-
- /**
- * setSystemId method
- *
- * @param systemId
- * java.lang.String
- */
- public void setSystemId(String systemId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.systemId = systemId;
- }
-
- /**
- * <p>
- * EXPERIMENTAL! Based on the <a
- * href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
- * Object Model (DOM) Level 3 Core Working Draft of 5 June 2001. </a>.
- * <p>
- * An attribute specifying, as part of the text declaration, the version
- * number of this entity, when it is an external parsed entity. This is
- * <code>null</code> otherwise.
- *
- * @see DOM Level 3
- */
- public void setVersion(java.lang.String version) {
- }
-
- public String getInputEncoding() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
- public String getXmlEncoding() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
-
- public String getXmlVersion() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version"); //$NON-NLS-1$
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityReferenceImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityReferenceImpl.java
deleted file mode 100644
index a4edb32bca..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/EntityReferenceImpl.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.Node;
-import org.w3c.dom.UserDataHandler;
-
-/**
- * EntityReference class
- */
-public class EntityReferenceImpl extends NodeImpl implements EntityReference {
-
- private String name = null;
-
- /**
- * EntityReferenceImpl constructor
- */
- protected EntityReferenceImpl() {
- super();
- }
-
- /**
- * EntityReferenceImpl constructor
- *
- * @param that
- * EntityReferenceImpl
- */
- protected EntityReferenceImpl(EntityReferenceImpl that) {
- super(that);
-
- if (that != null) {
- this.name = that.name;
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- EntityReferenceImpl cloned = new EntityReferenceImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- if (this.name == null)
- return NodeImpl.EMPTY_STRING;
- return this.name;
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return ENTITY_REFERENCE_NODE;
- }
-
- /**
- * setName method
- *
- * @param name
- * java.lang.String
- */
- protected void setName(String name) {
- this.name = name;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/InvalidCharacterException.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/InvalidCharacterException.java
deleted file mode 100644
index 1a3a079a97..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/InvalidCharacterException.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-/**
- * Thrown an invalid character is specified in : XMLNode#setSource(String)
- */
-public class InvalidCharacterException extends Exception {
-
- /**
- * Default <code>serialVersionUID</code>
- */
- private static final long serialVersionUID = 1L;
- private char invalidChar = 0;
- private int offset = -1;
-
- /**
- */
- public InvalidCharacterException() {
- super();
- }
-
- /**
- */
- public InvalidCharacterException(String s) {
- super(s);
- }
-
- /**
- */
- public InvalidCharacterException(String s, char c) {
- super(s);
- this.invalidChar = c;
- }
-
- /**
- */
- public InvalidCharacterException(String s, char c, int offset) {
- super(s);
- this.invalidChar = c;
- this.offset = offset;
- }
-
- /**
- */
- public char getInvalidChar() {
- return this.invalidChar;
- }
-
- /**
- */
- public int getOffset() {
- return this.offset;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/JSPTag.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/JSPTag.java
deleted file mode 100644
index 6f2de44010..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/JSPTag.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-/**
- * JSPTag interface
- */
-public interface JSPTag {
- static final String COMMENT_CLOSE = "--%>";//$NON-NLS-1$
- static final String COMMENT_OPEN = "<%--";//$NON-NLS-1$
- static final String DECLARATION_TOKEN = "!";//$NON-NLS-1$
- static final String DIRECTIVE_TOKEN = "@";//$NON-NLS-1$
- static final String EXPRESSION_TOKEN = "=";//$NON-NLS-1$
- static final String JSP_DECLARATION = "jsp:declaration";//$NON-NLS-1$
- static final String JSP_DIRECTIVE = "jsp:directive";//$NON-NLS-1$
- static final String JSP_EXPRESSION = "jsp:expression";//$NON-NLS-1$
- static final String JSP_ROOT = "jsp:root";//$NON-NLS-1$
-
- static final String JSP_SCRIPTLET = "jsp:scriptlet";//$NON-NLS-1$
- static final String TAG_CLOSE = "%>";//$NON-NLS-1$
- static final String TAG_OPEN = "<%";//$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ModelParserAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ModelParserAdapter.java
deleted file mode 100644
index e61907dd5d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ModelParserAdapter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-/**
- */
-public interface ModelParserAdapter extends INodeAdapter {
-
- /**
- */
- public boolean canBeImplicitTag(Element element);
-
- /**
- */
- public boolean canBeImplicitTag(Element element, Node child);
-
- /**
- */
- public boolean canContain(Element element, Node child);
-
- /**
- */
- public Element createCommentElement(Document document, String data, boolean isJSPTag);
-
- /**
- */
- public Element createImplicitElement(Document document, Node parent, Node child);
-
- /**
- */
- public String getFindRootName(String tagName);
-
- /**
- */
- public boolean isEndTag(IDOMElement element);
-
- boolean isEndTagOmissible(Element element);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeContainer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeContainer.java
deleted file mode 100644
index ac7a403352..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeContainer.java
+++ /dev/null
@@ -1,534 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-
-/**
- * NodeContainer class
- */
-public abstract class NodeContainer extends NodeImpl implements Node, NodeList {
-
- /**
- */
- private class ChildNodesCache implements NodeList {
- private Node curChild = null;
- private int curIndex = -1;
- private int length = 0;
-
- ChildNodesCache() {
- initializeCache();
- }
-
- public int getLength() {
- // atomic
- return this.length;
- }
-
- private void initializeCache() {
- // note we use the outter objects lockobject
- // (since we are using their "children".
- synchronized (lockObject) {
- for (Node child = firstChild; child != null; child = child.getNextSibling()) {
- this.length++;
- }
- }
- }
-
- public Node item(int index) {
- synchronized (lockObject) {
- if (this.length == 0)
- return null;
- if (index < 0)
- return null;
- if (index >= this.length)
- return null;
-
- if (this.curIndex < 0) { // first time
- if (index * 2 >= this.length) { // search from the last
- this.curIndex = this.length - 1;
- this.curChild = lastChild;
- } else { // search from the first
- this.curIndex = 0;
- this.curChild = firstChild;
- }
- }
-
- if (index == this.curIndex)
- return this.curChild;
-
- if (index > this.curIndex) {
- while (index > this.curIndex) {
- this.curIndex++;
- this.curChild = this.curChild.getNextSibling();
- }
- } else { // index < this.curIndex
- while (index < this.curIndex) {
- this.curIndex--;
- this.curChild = this.curChild.getPreviousSibling();
- }
- }
-
- return this.curChild;
- }
- }
- }
-
- private NodeList childNodesCache = null;
-
- private boolean fChildEditable = true;
- NodeImpl firstChild = null;
- NodeImpl lastChild = null;
-
- Object lockObject = new byte[0];
-
- /**
- * NodeContainer constructor
- */
- protected NodeContainer() {
- super();
- }
-
- /**
- * NodeContainer constructor
- *
- * @param that
- * NodeContainer
- */
- protected NodeContainer(NodeContainer that) {
- super(that);
- }
-
- /**
- * appendChild method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- */
- public Node appendChild(Node newChild) throws DOMException {
- return insertBefore(newChild, null);
- }
-
- /**
- * cloneChildNodes method
- *
- * @param container
- * org.w3c.dom.Node
- * @param deep
- * boolean
- */
- protected void cloneChildNodes(Node newParent, boolean deep) {
- if (newParent == null || newParent == this)
- return;
- if (!(newParent instanceof NodeContainer))
- return;
-
- NodeContainer container = (NodeContainer) newParent;
- container.removeChildNodes();
-
- for (Node child = getFirstChild(); child != null; child = child.getNextSibling()) {
- Node cloned = child.cloneNode(deep);
- if (cloned != null)
- container.appendChild(cloned);
- }
- }
-
- /**
- * getChildNodes method
- *
- * @return org.w3c.dom.NodeList
- */
- public NodeList getChildNodes() {
- return this;
- }
-
- /**
- * getFirstChild method
- *
- * @return org.w3c.dom.Node
- */
- public Node getFirstChild() {
- return this.firstChild;
- }
-
- /**
- * getLastChild method
- *
- * @return org.w3c.dom.Node
- */
- public Node getLastChild() {
- return this.lastChild;
- }
-
- /**
- * getLength method
- *
- * @return int
- */
- public int getLength() {
- if (this.firstChild == null)
- return 0;
- synchronized (lockObject) {
- if (this.childNodesCache == null)
- this.childNodesCache = new ChildNodesCache();
- return this.childNodesCache.getLength();
- }
- }
-
- /**
- */
- public String getSource() {
- StringBuffer buffer = new StringBuffer();
-
- IStructuredDocumentRegion startStructuredDocumentRegion = getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null) {
- String source = startStructuredDocumentRegion.getText();
- if (source != null)
- buffer.append(source);
- }
-
- for (NodeImpl child = firstChild; child != null; child = (NodeImpl) child.getNextSibling()) {
- String source = child.getSource();
- if (source != null)
- buffer.append(source);
- }
-
- IStructuredDocumentRegion endStructuredDocumentRegion = getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- String source = endStructuredDocumentRegion.getText();
- if (source != null)
- buffer.append(source);
- }
-
- return buffer.toString();
- }
-
- /**
- * hasChildNodes method
- *
- * @return boolean
- */
- public boolean hasChildNodes() {
- return (this.firstChild != null);
- }
-
- /**
- * insertBefore method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param refChild
- * org.w3c.dom.Node
- */
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
- if (newChild == null)
- return null; // nothing to do
- if (refChild != null && refChild.getParentNode() != this) {
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- }
- if (!isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- if (newChild == refChild)
- return newChild; // nothing to do
- //new child can not be a parent of this, would cause cycle
- if(isParent(newChild)) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
-
- if (newChild.getNodeType() == DOCUMENT_FRAGMENT_NODE) {
- // insert child nodes instead
- for (Node child = newChild.getFirstChild(); child != null; child = newChild.getFirstChild()) {
- newChild.removeChild(child);
- insertBefore(child, refChild);
- }
- return newChild;
- }
- // synchronized in case another thread is getting item, or length
- synchronized (lockObject) {
- this.childNodesCache = null; // invalidate child nodes cache
- }
-
- NodeImpl child = (NodeImpl) newChild;
- NodeImpl next = (NodeImpl) refChild;
- NodeImpl prev = null;
- Node oldParent = child.getParentNode();
- if (oldParent != null)
- oldParent.removeChild(child);
- if (next == null) {
- prev = this.lastChild;
- this.lastChild = child;
- } else {
- prev = (NodeImpl) next.getPreviousSibling();
- next.setPreviousSibling(child);
- }
- if (prev == null)
- this.firstChild = child;
- else
- prev.setNextSibling(child);
- child.setPreviousSibling(prev);
- child.setNextSibling(next);
- child.setParentNode(this);
- // make sure having the same owner document
- if (child.getOwnerDocument() == null) {
- if (getNodeType() == DOCUMENT_NODE) {
- child.setOwnerDocument((Document) this);
- } else {
- child.setOwnerDocument(getOwnerDocument());
- }
- }
-
- notifyChildReplaced(child, null);
-
- return child;
- }
-
- public boolean isChildEditable() {
- if (!fChildEditable) {
- DOMModelImpl model = (DOMModelImpl) getModel();
- if (model != null && model.isReparsing()) {
- return true;
- }
- }
- return fChildEditable;
- }
-
- /**
- * isContainer method
- *
- * @return boolean
- */
- public boolean isContainer() {
- return true;
- }
-
- /**
- * item method
- *
- * @return org.w3c.dom.Node
- * @param index
- * int
- */
- public Node item(int index) {
- if (this.firstChild == null)
- return null;
- synchronized (lockObject) {
- if (this.childNodesCache == null)
- this.childNodesCache = new ChildNodesCache();
- return this.childNodesCache.item(index);
- }
- }
-
- /**
- * notifyChildReplaced method
- *
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- protected void notifyChildReplaced(Node newChild, Node oldChild) {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
-
- syncChildEditableState(newChild);
-
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.childReplaced(this, newChild, oldChild);
- }
-
- /**
- * removeChild method
- *
- * @return org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- public Node removeChild(Node oldChild) throws DOMException {
- if (oldChild == null)
- return null;
- if (oldChild.getParentNode() != this) {
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- }
-
- if (!isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- // synchronized in case another thread is getting item, or length
- synchronized (lockObject) {
- this.childNodesCache = null; // invalidate child nodes cache
- }
-
- NodeImpl child = (NodeImpl) oldChild;
- NodeImpl prev = (NodeImpl) child.getPreviousSibling();
- NodeImpl next = (NodeImpl) child.getNextSibling();
-
- child.setEditable(true, true); // clear ReadOnly flags
-
- if (prev == null)
- this.firstChild = next;
- else
- prev.setNextSibling(next);
- if (next == null)
- this.lastChild = prev;
- else
- next.setPreviousSibling(prev);
- child.setPreviousSibling(null);
- child.setNextSibling(null);
- child.setParentNode(null);
-
- notifyChildReplaced(null, child);
-
- return child;
- }
-
- /**
- * removeChildNodes method
- */
- public void removeChildNodes() {
- if (!isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- Node nextChild = null;
- for (Node child = getFirstChild(); child != null; child = nextChild) {
- nextChild = child.getNextSibling();
- removeChild(child);
- }
- }
-
- /**
- * removeChildNodes method
- *
- * @return org.w3c.dom.DocumentFragment
- * @param firstChild
- * org.w3c.dom.Node
- * @param lastChild
- * org.w3c.dom.Node
- */
- public DocumentFragment removeChildNodes(Node firstChild, Node lastChild) {
- if (!hasChildNodes())
- return null;
- if (!isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- Document document = null;
- if (getNodeType() == DOCUMENT_NODE)
- document = (Document) this;
- else
- document = getOwnerDocument();
- if (document == null)
- return null;
- DocumentFragment fragment = document.createDocumentFragment();
- if (fragment == null)
- return null;
-
- if (firstChild == null)
- firstChild = getFirstChild();
- if (lastChild == null)
- lastChild = getLastChild();
- Node nextChild = null;
- for (Node child = firstChild; child != null; child = nextChild) {
- nextChild = child.getNextSibling();
- removeChild(child);
- fragment.appendChild(child);
- if (child == lastChild)
- break;
- }
-
- return fragment;
- }
-
- /**
- * replaceChild method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
- if (!isChildEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- if (oldChild == null || oldChild == newChild)
- return newChild;
- if (newChild != null)
- insertBefore(newChild, oldChild);
- return removeChild(oldChild);
- }
-
- public void setChildEditable(boolean editable) {
- if (fChildEditable == editable) {
- return;
- }
-
- ReadOnlyController roc = ReadOnlyController.getInstance();
- Node node;
- if (editable) {
- for (node = getFirstChild(); node != null; node = node.getNextSibling()) {
- roc.unlockNode((IDOMNode) node);
- }
- } else {
- for (node = getFirstChild(); node != null; node = node.getNextSibling()) {
- roc.lockNode((IDOMNode) node);
- }
- }
-
- fChildEditable = editable;
- notifyEditableChanged();
- }
-
- protected void syncChildEditableState(Node child) {
- ReadOnlyController roc = ReadOnlyController.getInstance();
- if (fChildEditable) {
- roc.unlockNode((NodeImpl) child);
- } else {
- roc.lockNode((NodeImpl) child);
- }
- }
-
- /**
- * <p>Checks to see if the given <code>Node</code> is a parent of <code>this</code> node</p>
- *
- * @param possibleParent the possible parent <code>Node</code> of <code>this</code> node
- * @return <code>true</code> if <code>possibleParent</code> is the parent of <code>this</code>,
- * <code>false</code> otherwise.
- */
- private boolean isParent(Node possibleParent) {
- Node parent = this.getParentNode();
- while(parent != null && parent != possibleParent) {
- parent = parent.getParentNode();
- }
-
- return parent == possibleParent;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeImpl.java
deleted file mode 100644
index 44e5df5140..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeImpl.java
+++ /dev/null
@@ -1,1171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- *
- * David Carver (STAR) - bug 295127 - implement isSameNode and compareDocumentPosition methods.
- * Unit Tests covered in wst.xsl XPath 2.0 tests.
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.io.Serializable;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.wst.sse.core.internal.model.FactoryRegistry;
-import org.eclipse.wst.sse.core.internal.provisional.AbstractNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.w3c.dom.TypeInfo;
-import org.w3c.dom.UserDataHandler;
-
-/**
- * NodeImpl class
- */
-public abstract class NodeImpl extends AbstractNotifier implements Node, IDOMNode {
- // define one empty nodelist, for repeated use
- private final static NodeList EMPTY_NODE_LIST = new NodeListImpl();
- // DocumentPosition
- //private final static short DOCUMENT_POSITION_DISCONNECTED = 0x01;
- private final static short DOCUMENT_POSITION_PRECEDING = 0x02;
- private final static short DOCUMENT_POSITION_FOLLOWING = 0x04;
- //private final static short DOCUMENT_POSITION_CONTAINS = 0x08;
- //private final static short DOCUMENT_POSITION_CONTAINED_BY = 0x10;
- private final static short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20;
-
-
- private boolean fDataEditable = true;
- private IStructuredDocumentRegion flatNode = null;
- private NodeImpl nextSibling = null;
-
- private DocumentImpl ownerDocument = null;
- private NodeImpl parentNode = null;
- private NodeImpl previousSibling = null;
- // define one empty String constant for repeated use
- static final String EMPTY_STRING = "";
-
- /**
- * NodeImpl constructor
- */
- protected NodeImpl() {
- super();
- }
-
- /**
- * NodeImpl constructor
- *
- * @param that
- * NodeImpl
- */
- protected NodeImpl(NodeImpl that) {
- if (that != null) {
- this.ownerDocument = that.ownerDocument;
- }
- }
-
- /**
- * appendChild method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- */
- public Node appendChild(Node newChild) throws DOMException {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
-
- /**
- * contains method
- *
- * @return boolean
- * @param offset
- * int
- */
- public boolean contains(int offset) {
- return (offset >= getStartOffset() && offset < getEndOffset());
- }
-
- /**
- * @param s
- * @param tagName
- * @return
- */
- protected String createDOMExceptionMessage(short s, String tagName) {
- String result = null;
- // TODO: Should localize these messages, and provide /u escaped
- // version of tagName
- result = lookupMessage(s) + " " + tagName; //$NON-NLS-1$
- return result;
- }
-
- /**
- * getAttributes method
- *
- * @return org.w3c.dom.NamedNodeMap
- */
- public NamedNodeMap getAttributes() {
- return null;
- }
-
- /**
- */
- protected String getCharValue(String name) {
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document == null)
- return null;
- return document.getCharValue(name);
- }
-
- /**
- * getChildNodes method
- *
- * @return org.w3c.dom.NodeList
- */
- public NodeList getChildNodes() {
- // As per DOM spec, correct behavior for getChildNodes is to return a
- // zero length NodeList, not null, when there are no children.
- // We'll use a common instance of an empty node list, just to prevent
- // creating a trival object many many times.
-
- return EMPTY_NODE_LIST;
- }
-
- /**
- * getCommonAncestor method
- *
- * @return org.w3c.dom.Node
- * @param node
- * org.w3c.dom.Node
- */
- public Node getCommonAncestor(Node node) {
- if (node == null)
- return null;
-
- for (Node na = node; na != null; na = na.getParentNode()) {
- for (Node ta = this; ta != null; ta = ta.getParentNode()) {
- if (ta == na)
- return ta;
- }
- }
-
- return null; // not found
- }
-
- /**
- * getContainerDocument method
- *
- * @return org.w3c.dom.Document
- */
- public Document getContainerDocument() {
- Node parent = null;
- for (Node node = this; node != null; node = parent) {
- if (node.getNodeType() == Node.DOCUMENT_NODE) {
- return (Document) node;
- }
- /* Break out of a bad hierarchy */
- if ((parent = node.getParentNode()) == node)
- break;
- }
- return null;
- }
-
- /**
- * getEndOffset method
- *
- * @return int
- */
- public int getEndOffset() {
- Node node = this;
- while (node != null) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) node;
- IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null)
- return endStructuredDocumentRegion.getEnd();
- }
-
- Node last = node.getLastChild();
- if (last != null) { // dig into the last
- node = last;
- continue;
- }
-
- IStructuredDocumentRegion lastStructuredDocumentRegion = ((NodeImpl) node).getStructuredDocumentRegion();
- if (lastStructuredDocumentRegion != null)
- return lastStructuredDocumentRegion.getEnd();
-
- Node prev = node.getPreviousSibling();
- if (prev != null) { // move to the previous
- node = prev;
- continue;
- }
-
- Node parent = node.getParentNode();
- node = null;
- while (parent != null) {
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) parent;
- IStructuredDocumentRegion startStructuredDocumentRegion = element.getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null)
- return startStructuredDocumentRegion.getEnd();
- }
- Node parentPrev = parent.getPreviousSibling();
- if (parentPrev != null) { // move to the previous
- node = parentPrev;
- break;
- }
- parent = parent.getParentNode();
- }
- }
- return 0;
- }
-
- public IStructuredDocumentRegion getEndStructuredDocumentRegion() {
- return null;
- }
-
- /**
- */
- public FactoryRegistry getFactoryRegistry() {
- IDOMModel model = getModel();
- if (model != null) {
- FactoryRegistry reg = model.getFactoryRegistry();
- if (reg != null)
- return reg;
- }
- return null;
- }
-
- /**
- * getFirstChild method
- *
- * @return org.w3c.dom.Node
- */
- public Node getFirstChild() {
- return null;
- }
-
- /**
- * getFirstStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getFirstStructuredDocumentRegion() {
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(this.flatNode);
- }
-
- /**
- */
- public int getIndex() {
- Node parent = getParentNode();
- if (parent == null)
- return -1; // error
- int index = 0;
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child == this)
- return index;
- index++;
- }
- return -1; // error
- }
-
- /**
- * getLastChild method
- *
- * @return org.w3c.dom.Node
- */
- public Node getLastChild() {
- return null;
- }
-
- /**
- * getLastStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getLastStructuredDocumentRegion() {
- return StructuredDocumentRegionUtil.getStructuredDocumentRegion(this.flatNode);
- }
-
- /**
- */
- public String getLocalName() {
- return null;
- }
-
- /**
- * the default implementation can just refer to the owning document
- */
- public IDOMModel getModel() {
- if (this.ownerDocument == null)
- return null;
- return this.ownerDocument.getModel();
- }
-
- /**
- * all but attr return null
- */
- public ITextRegion getNameRegion() {
- return null;
- }
-
- /**
- */
- public String getNamespaceURI() {
- return null;
- }
-
- /**
- * getNextSibling method
- *
- * @return org.w3c.dom.Node
- */
- public Node getNextSibling() {
- return this.nextSibling;
- }
-
- /**
- * getNodeAt method
- *
- * @return org.w3c.dom.Node
- * @param offset
- * int
- */
- Node getNodeAt(int offset) {
- IDOMNode parent = this;
- IDOMNode child = (IDOMNode) getFirstChild();
- while (child != null) {
- if (child.getEndOffset() <= offset) {
- child = (IDOMNode) child.getNextSibling();
- continue;
- }
- if (child.getStartOffset() > offset) {
- break;
- }
-
- IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
- if (startStructuredDocumentRegion != null) {
- if (startStructuredDocumentRegion.getEnd() > offset)
- return child;
- }
-
- // dig more
- parent = child;
- child = (IDOMNode) parent.getFirstChild();
- }
-
- return parent;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#getNodeValue()
- */
- public String getNodeValue() throws DOMException {
- return null;
- }
-
- /**
- * getOwnerDocument method
- *
- * @return org.w3c.dom.Document
- */
- public Document getOwnerDocument() {
- return this.ownerDocument;
- }
-
- /**
- * getParentNode method
- *
- * @return org.w3c.dom.Node
- */
- public Node getParentNode() {
- return this.parentNode;
- }
-
- /**
- */
- public String getPrefix() {
- return null;
- }
-
- /**
- * getPreviousSibling method
- *
- * @return org.w3c.dom.Node
- */
- public Node getPreviousSibling() {
- return this.previousSibling;
- }
-
- /**
- */
- public String getSource() {
- if (this.flatNode == null)
- return NodeImpl.EMPTY_STRING;
- return this.flatNode.getText();
- }
-
- /**
- * getStartOffset method
- *
- * @return int
- */
- public int getStartOffset() {
- if (this.flatNode != null)
- return this.flatNode.getStart();
- NodeImpl prev = (NodeImpl) getPreviousSibling();
- if (prev != null)
- return prev.getEndOffset();
- Node parent = getParentNode();
- if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) parent;
- if (element.hasStartTag())
- return element.getStartEndOffset();
- return element.getStartOffset();
- }
- // final fallback to look into first child
- NodeImpl child = (NodeImpl) getFirstChild();
- while (child != null) {
- IStructuredDocumentRegion childStructuredDocumentRegion = child.getStructuredDocumentRegion();
- if (childStructuredDocumentRegion != null)
- return childStructuredDocumentRegion.getStart();
- child = (NodeImpl) child.getFirstChild();
- }
- return 0;
- }
-
- public IStructuredDocumentRegion getStartStructuredDocumentRegion() {
- return getFirstStructuredDocumentRegion();
- }
-
- /**
- * Every node (indirectly) knows its structuredDocument
- */
- public IStructuredDocument getStructuredDocument() {
- return getModel().getStructuredDocument();
- }
-
- /**
- */
- IStructuredDocumentRegion getStructuredDocumentRegion() {
- return this.flatNode;
- }
-
- /**
- * all but attr return null
- */
- public ITextRegion getValueRegion() {
- return null;
- }
-
- /**
- */
- public String getValueSource() {
- return getNodeValue();
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#hasAttributes()
- */
- public boolean hasAttributes() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#hasChildNodes()
- */
- public boolean hasChildNodes() {
- return false;
- }
-
- /**
- * hasProperties method
- *
- * @return boolean
- */
- public boolean hasProperties() {
- return false;
- }
-
- /**
- * insertBefore method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param refChild
- * org.w3c.dom.Node
- */
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
-
- public boolean isChildEditable() {
- return false;
- }
-
- /**
- */
- public boolean isClosed() {
- return true;
- }
-
- /**
- * isContainer method
- *
- * @return boolean
- */
- public boolean isContainer() {
- return false;
- }
-
- public boolean isDataEditable() {
- if (!fDataEditable) {
- DOMModelImpl model = (DOMModelImpl) getModel();
- if (model != null && model.isReparsing()) {
- return true;
- }
- }
- return fDataEditable;
- }
-
- /**
- */
- public boolean isSupported(String feature, String version) {
- if (this.ownerDocument == null)
- return false;
- DOMImplementation impl = this.ownerDocument.getImplementation();
- if (impl == null)
- return false;
- return impl.hasFeature(feature, version);
- }
-
- /**
- * @param s
- * @return
- */
- private String lookupMessage(short s) {
- // TODO: make localized version
- String result = null;
- switch (s) {
- case DOMException.DOMSTRING_SIZE_ERR :
- result = DOMMessages.DOMSTRING_SIZE_ERR;
- break;
- case DOMException.HIERARCHY_REQUEST_ERR :
- result = DOMMessages.HIERARCHY_REQUEST_ERR;
- break;
- case DOMException.INDEX_SIZE_ERR :
- result = DOMMessages.INDEX_SIZE_ERR;
- break;
- case DOMException.INUSE_ATTRIBUTE_ERR :
- result = DOMMessages.INUSE_ATTRIBUTE_ERR;
- break;
- case DOMException.INVALID_ACCESS_ERR :
- result = DOMMessages.INVALID_ACCESS_ERR;
- break;
- case DOMException.INVALID_CHARACTER_ERR :
- result = DOMMessages.INVALID_CHARACTER_ERR;
- break;
- case DOMException.INVALID_MODIFICATION_ERR :
- result = DOMMessages.INVALID_MODIFICATION_ERR;
- break;
- case DOMException.INVALID_STATE_ERR :
- result = DOMMessages.INVALID_STATE_ERR;
- break;
- case DOMException.NAMESPACE_ERR :
- result = DOMMessages.NAMESPACE_ERR;
- break;
- case DOMException.NO_DATA_ALLOWED_ERR :
- result = DOMMessages.NO_DATA_ALLOWED_ERR;
- break;
- case DOMException.NO_MODIFICATION_ALLOWED_ERR :
- result = DOMMessages.NO_MODIFICATION_ALLOWED_ERR;
- break;
- case DOMException.NOT_FOUND_ERR :
- result = DOMMessages.NOT_FOUND_ERR;
- break;
- case DOMException.NOT_SUPPORTED_ERR :
- result = DOMMessages.NOT_SUPPORTED_ERR;
- break;
- case DOMException.SYNTAX_ERR :
- result = DOMMessages.SYNTAX_ERR;
- break;
- case 17:// DOMException.TYPE_MISMATCH_ERR :
- result = DOMMessages.TYPE_MISMATCH_ERR;
- break;
- case 16:// DOMException.VALIDATION_ERR :
- result = DOMMessages.VALIDATION_ERR;
- break;
- case DOMException.WRONG_DOCUMENT_ERR :
- result = DOMMessages.WRONG_DOCUMENT_ERR;
- break;
- default :
- result = NodeImpl.EMPTY_STRING;
- break;
- }
- return result;
- }
-
- /**
- * normalize method
- */
- public void normalize() {
- TextImpl prevText = null;
- for (Node child = getFirstChild(); child != null; child = child.getNextSibling()) {
- switch (child.getNodeType()) {
- case TEXT_NODE : {
- if (prevText == null) {
- prevText = (TextImpl) child;
- break;
- }
- Text text = (Text) child;
- removeChild(text);
- prevText.appendText(text);
- child = prevText;
- break;
- }
- case ELEMENT_NODE : {
- Element element = (Element) child;
- element.normalize();
- prevText = null;
- break;
- }
- default :
- prevText = null;
- break;
- }
- }
- }
-
- protected void notifyEditableChanged() {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.editableChanged(this);
- }
-
- /**
- * notifyValueChanged method
- */
- protected void notifyValueChanged() {
- DocumentImpl document = (DocumentImpl) getContainerDocument();
- if (document == null)
- return;
-
- syncDataEditableState();
-
- DOMModelImpl model = (DOMModelImpl) document.getModel();
- if (model == null)
- return;
- model.valueChanged(this);
- }
-
- /**
- * removeChild method
- *
- * @return org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- public Node removeChild(Node oldChild) throws DOMException {
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessages.NOT_FOUND_ERR);
- }
-
- /**
- * removeChildNodes method
- */
- public void removeChildNodes() {
- }
-
- /**
- * removeChildNodes method
- *
- * @return org.w3c.dom.DocumentFragment
- * @param firstChild
- * org.w3c.dom.Node
- * @param lastChild
- * org.w3c.dom.Node
- */
- public DocumentFragment removeChildNodes(Node firstChild, Node lastChild) {
- return null;
- }
-
- /**
- * replaceChild method
- *
- * @return org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, DOMMessages.HIERARCHY_REQUEST_ERR);
- }
-
- /**
- * Resets children values from IStructuredDocumentRegion.
- */
- void resetStructuredDocumentRegions() {
- for (NodeImpl child = (NodeImpl) getFirstChild(); child != null; child = (NodeImpl) child.getNextSibling()) {
- child.resetStructuredDocumentRegions();
- }
- this.flatNode = null;
- }
-
- public void setChildEditable(boolean editable) {
- // nop
- }
-
- public void setDataEditable(boolean editable) {
- if (fDataEditable == editable) {
- return;
- }
-
- ReadOnlyController roc = ReadOnlyController.getInstance();
- if (editable) {
- roc.unlockData(this);
- }
- else {
- roc.lockData(this);
- }
-
- fDataEditable = editable;
-
- notifyEditableChanged();
- }
-
- public void setEditable(boolean editable, boolean deep) {
- if (deep) {
- IDOMNode node = (IDOMNode) getFirstChild();
- while (node != null) {
- node.setEditable(editable, deep);
- node = (IDOMNode) node.getNextSibling();
- }
- }
- setChildEditable(editable);
- setDataEditable(editable);
- }
-
- /**
- * setNextSibling method
- *
- * @param nextSibling
- * org.w3c.dom.Node
- */
- protected void setNextSibling(Node nextSibling) {
- this.nextSibling = (NodeImpl) nextSibling;
- }
-
- /**
- * setNodeValue method
- *
- * @param nodeValue
- * java.lang.String
- */
- public void setNodeValue(String nodeValue) throws DOMException {
- }
-
- /**
- * setOwnerDocument method
- *
- * @param ownerDocument
- * org.w3c.dom.Document
- */
- protected void setOwnerDocument(Document ownerDocument) {
- this.ownerDocument = (DocumentImpl) ownerDocument;
- }
-
- /**
- */
- protected void setOwnerDocument(Document ownerDocument, boolean deep) {
- this.ownerDocument = (DocumentImpl) ownerDocument;
-
- if (deep) {
- for (NodeImpl child = (NodeImpl) getFirstChild(); child != null; child = (NodeImpl) child.getNextSibling()) {
- child.setOwnerDocument(ownerDocument, deep);
- }
- }
- }
-
- /**
- * setParentNode method
- *
- * @param parentNode
- * org.w3c.dom.Node
- */
- protected void setParentNode(Node parentNode) {
- this.parentNode = (NodeImpl) parentNode;
- }
-
- /**
- */
- public void setPrefix(String prefix) throws DOMException {
- }
-
- /**
- * setPreviousSibling method
- *
- * @param previousSibling
- * org.w3c.dom.Node
- */
- protected void setPreviousSibling(Node previousSibling) {
- this.previousSibling = (NodeImpl) previousSibling;
- }
-
- /**
- */
- public void setSource(String source) throws InvalidCharacterException {
- // not supported
- }
-
- /**
- */
- void setStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- this.flatNode = flatNode;
- }
-
- /**
- */
- public void setValueSource(String source) {
- setNodeValue(source);
- }
-
- protected void syncDataEditableState() {
- ReadOnlyController roc = ReadOnlyController.getInstance();
- if (fDataEditable) {
- roc.unlockData(this);
- }
- else {
- roc.lockData(this);
- }
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- return getNodeName();
- }
-
- public int getLength() {
- int result = -1;
- int start = getStartOffset();
- if (start >= 0) {
- int end = getEndOffset();
- if (end >= 0) {
- result = end - start;
- if (result < -1) {
- result = -1;
- }
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
- */
- public short compareDocumentPosition(Node other) throws DOMException {
- if (!(other instanceof IDOMNode))
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, DOMMessages.NOT_SUPPORTED_ERR);
-
- int nodeStart = this.getStartOffset();
- int otherStart = ((IDOMNode) other).getStartOffset();
-
- if (otherStart > nodeStart) {
- return DOCUMENT_POSITION_FOLLOWING;
- }
- else if (otherStart < nodeStart) {
- return DOCUMENT_POSITION_PRECEDING;
- }
- return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String getBaseURI() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public Object getFeature(String feature, String version) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#getTextContent()
- */
- public String getTextContent() throws DOMException {
- switch (getNodeType()) {
- case Node.DOCUMENT_NODE :
- case Node.DOCUMENT_TYPE_NODE :
- case Node.NOTATION_NODE :
- return null;
- case Node.TEXT_NODE :
- case Node.CDATA_SECTION_NODE :
- case Node.COMMENT_NODE :
- case Node.PROCESSING_INSTRUCTION_NODE :
- return getNodeValue();
- }
-
- if (hasChildNodes()) {
- final StringBuffer builder = new StringBuffer();
-
- Node child = getFirstChild();
- while (child != null) {
- short nodeType = child.getNodeType();
- if (nodeType == Node.COMMENT_NODE || nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
- child = child.getNextSibling();
- continue;
- }
-
- String text = ((IDOMNode) child).getTextContent();
- if (text != null) {
- builder.append(text);
- }
- child = child.getNextSibling();
- }
-
- return builder.toString();
- }
-
- return EMPTY_STRING;
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isDefaultNamespace(String namespaceURI) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#isEqualNode(org.w3c.dom.Node)
- */
- public boolean isEqualNode(Node arg) {
- return this.equals(arg);
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#isSameNode(org.w3c.dom.Node)
- */
- public boolean isSameNode(Node other) {
- return this == other;
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String lookupNamespaceURI(String prefix) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String lookupPrefix(String namespaceURI) {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public void setTextContent(String textContent) throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public TypeInfo getSchemaTypeInfo() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isId() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented in this version."); //$NON-NLS-1$
- }
-
- /**
- * Retrieves the object for a node associated to a key.
- *
- * @param key The key associated with the object.
- * @return object The object for this node, associated with the key passed
- * or null if there was none set.
- *
- * @since DOM Level 3
- */
- public Object getUserData(String key) {
-
- if (key==null) return null;
- Map userDataTable = UserData.getInstance().getUserDataTable(this);
- if (userDataTable!=null) {
- UserDataAndHandler userDataAndHandler = (UserDataAndHandler) userDataTable.get(key);
- if (userDataAndHandler!=null) {
- return userDataAndHandler.getData();
- }
- }
- return null;
- }
-
- /**
- * Sets the user data and handler for a key
- *
- * @param key The key associated with the object.
- * @param object The object for this node, associated with the key passed.
- * Null passed removes the existing association to the key.
- * @param handler UserDataHandler for the userdata associated with this key
- * @return Object The previous userdata object if set, null if it was none.
- *
- * @since DOM Level 3
- */
- public Object setUserData(String key, Object data, UserDataHandler handler) {
-
- UserDataAndHandler previousDataAndHandler=null;
-
- //return immediately for null keys
- if (key ==null) return null;
- Map userDataTable = UserData.getInstance().getUserDataTable(this);
- //remove association for the key if data is null
- if (data==null) {
- if (userDataTable==null) return null;
-
- //see if there is a previous value set
- previousDataAndHandler = (UserDataAndHandler) userDataTable.get(key);
- if (previousDataAndHandler!=null) {
- userDataTable.remove(key);
- return previousDataAndHandler.getData();
- }
- //there is no previous value found
- return null;
- }
-
- //if data passed is not null
- //the first data in the hashtable
- if (userDataTable==null) {
- userDataTable=new Hashtable();
- UserDataAndHandler userDataAndHandler=new UserDataAndHandler(data,handler);
- userDataTable.put(key,userDataAndHandler);
- return null;
- //there is already data in the hashtable
- } else {
- UserDataAndHandler userDataAndHandler=new UserDataAndHandler(data,handler);
- previousDataAndHandler=(UserDataAndHandler) userDataTable.put(key,userDataAndHandler);
-
- //if we replace a value
- if (previousDataAndHandler!=null)
- return previousDataAndHandler.getData();
- else {
- return null;
- }
- }
- }
-
- /**
- * Notifies the UserDataHandlers of the node.
- *
- * @param operation
- * @param destination
- */
- protected void notifyUserDataHandlers(short operation, Node destination) {
-
- if (operation!=UserDataHandler.NODE_ADOPTED
- & operation!=UserDataHandler.NODE_CLONED
- & operation!=UserDataHandler.NODE_DELETED
- & operation!=UserDataHandler.NODE_IMPORTED
- & operation!=UserDataHandler.NODE_RENAMED)
- return;
- Map userDataTable = UserData.getInstance().getUserDataTable(this);
- if (userDataTable!=null) {
- Iterator entries =userDataTable.entrySet().iterator();
- while (entries.hasNext()) {
- Map.Entry entry = (Map.Entry) entries.next();
- String key = entry.getKey().toString(); //should always be a string
- UserDataAndHandler dataAndHandler = (UserDataAndHandler) entry.getValue();
- if (dataAndHandler!=null) {
- UserDataHandler dataHandler=dataAndHandler.getHandler();
- if (dataHandler!=null) {
- dataHandler.handle(operation, key, dataAndHandler.getData(), this, destination);
- }
- }
- }
- }
- }
-
- /**
- *
- * Class for user data and UserDataHandler
- */
- protected static class UserDataAndHandler implements Serializable {
-
- /**
- * Generated Serial ID
- */
- private static final long serialVersionUID = 4860521237315444841L;
- /**
- * Generated serialization version
- */
-
- private Object data;
- private UserDataHandler handler;
-
- public UserDataAndHandler(Object data, UserDataHandler handler)
- {
- this.data=data;
- this.handler=handler;
- }
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public UserDataHandler getHandler() {
- return handler;
- }
-
- public void setHandler(UserDataHandler handler) {
- this.handler = handler;
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeIteratorImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeIteratorImpl.java
deleted file mode 100644
index c4a278b694..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeIteratorImpl.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-
-/**
- * NodeIteratorImpl class
- */
-public class NodeIteratorImpl implements NodeIterator {
- private NodeFilter filter = null;
- private Node nextNode = null;
-
- private Node rootNode = null;
- private int whatToShow = NodeFilter.SHOW_ALL;
-
- /**
- * NodeIteratorImpl constructor
- *
- * @param rootNode
- * org.w3c.dom.Node
- */
- NodeIteratorImpl(Node rootNode, int whatToShow, NodeFilter filter) {
- this.rootNode = rootNode;
- this.nextNode = rootNode;
- this.whatToShow = whatToShow;
- this.filter = filter;
- }
-
- /**
- */
- private final boolean acceptNode(Node node) {
- if (this.whatToShow != NodeFilter.SHOW_ALL) {
- if (node == null)
- return false;
- short nodeType = node.getNodeType();
- switch (this.whatToShow) {
- case NodeFilter.SHOW_ELEMENT :
- if (nodeType != Node.ELEMENT_NODE)
- return false;
- break;
- case NodeFilter.SHOW_ATTRIBUTE :
- if (nodeType != Node.ATTRIBUTE_NODE)
- return false;
- break;
- case NodeFilter.SHOW_TEXT :
- if (nodeType != Node.TEXT_NODE)
- return false;
- break;
- case NodeFilter.SHOW_CDATA_SECTION :
- if (nodeType != Node.CDATA_SECTION_NODE)
- return false;
- break;
- case NodeFilter.SHOW_ENTITY_REFERENCE :
- if (nodeType != Node.ENTITY_REFERENCE_NODE)
- return false;
- break;
- case NodeFilter.SHOW_ENTITY :
- if (nodeType != Node.ENTITY_NODE)
- return false;
- break;
- case NodeFilter.SHOW_PROCESSING_INSTRUCTION :
- if (nodeType != Node.PROCESSING_INSTRUCTION_NODE)
- return false;
- break;
- case NodeFilter.SHOW_COMMENT :
- if (nodeType != Node.COMMENT_NODE)
- return false;
- break;
- case NodeFilter.SHOW_DOCUMENT :
- if (nodeType != Node.DOCUMENT_NODE)
- return false;
- break;
- case NodeFilter.SHOW_DOCUMENT_TYPE :
- if (nodeType != Node.DOCUMENT_TYPE_NODE)
- return false;
- break;
- case NodeFilter.SHOW_DOCUMENT_FRAGMENT :
- if (nodeType != Node.DOCUMENT_FRAGMENT_NODE)
- return false;
- break;
- case NodeFilter.SHOW_NOTATION :
- if (nodeType != Node.NOTATION_NODE)
- return false;
- break;
- default :
- return false;
- }
- }
- if (this.filter != null) {
- return (this.filter.acceptNode(node) == NodeFilter.FILTER_ACCEPT);
- }
- return true;
- }
-
- /**
- * Detaches the <code>NodeIterator</code> from the set which it iterated
- * over, releasing any computational resources and placing the iterator in
- * the INVALID state. After <code>detach</code> has been invoked, calls
- * to <code>nextNode</code> or <code>previousNode</code> will raise
- * the exception INVALID_STATE_ERR.
- */
- public void detach() {
- this.rootNode = null;
- this.nextNode = null;
- this.filter = null;
- }
-
- /**
- * The value of this flag determines whether the children of entity
- * reference nodes are visible to the iterator. If false, they and their
- * descendants will be rejected. Note that this rejection takes precedence
- * over <code>whatToShow</code> and the filter. Also note that this is
- * currently the only situation where <code>NodeIterators</code> may
- * reject a complete subtree rather than skipping individual nodes. <br>
- * <br>
- * To produce a view of the document that has entity references expanded
- * and does not expose the entity reference node itself, use the
- * <code>whatToShow</code> flags to hide the entity reference node and
- * set <code>expandEntityReferences</code> to true when creating the
- * iterator. To produce a view of the document that has entity reference
- * nodes but no entity expansion, use the <code>whatToShow</code> flags
- * to show the entity reference node and set
- * <code>expandEntityReferences</code> to false.
- */
- public boolean getExpandEntityReferences() {
- // not supported
- return false;
- }
-
- /**
- * The <code>NodeFilter</code> used to screen nodes.
- */
- public NodeFilter getFilter() {
- return this.filter;
- }
-
- /**
- */
- private final Node getNextNode() {
- if (this.nextNode == null)
- return null;
- Node oldNext = this.nextNode;
- Node child = this.nextNode.getFirstChild();
- if (child != null) {
- this.nextNode = child;
- return oldNext;
- }
- for (Node node = this.nextNode; node != null && node != this.rootNode; node = node.getParentNode()) {
- Node next = node.getNextSibling();
- if (next != null) {
- this.nextNode = next;
- return oldNext;
- }
- }
- this.nextNode = null;
- return oldNext;
- }
-
- /**
- */
- private final Node getPreviousNode() {
- if (this.nextNode == this.rootNode)
- return null;
- Node prev = null;
- if (this.nextNode == null) {
- prev = this.rootNode; // never null
- } else {
- prev = this.nextNode.getPreviousSibling();
- if (prev == null) {
- this.nextNode = this.nextNode.getParentNode();
- return this.nextNode;
- }
- }
- Node last = prev.getLastChild();
- while (last != null) {
- prev = last;
- last = prev.getLastChild();
- }
- this.nextNode = prev;
- return this.nextNode;
- }
-
- /**
- * The root node of the <code>NodeIterator</code>, as specified when it
- * was created.
- */
- public Node getRoot() {
- return this.rootNode;
- }
-
- /**
- * This attribute determines which node types are presented via the
- * iterator. The available set of constants is defined in the
- * <code>NodeFilter</code> interface. Nodes not accepted by
- * <code>whatToShow</code> will be skipped, but their children may still
- * be considered. Note that this skip takes precedence over the filter, if
- * any.
- */
- public int getWhatToShow() {
- return this.whatToShow;
- }
-
- /**
- * Returns the next node in the set and advances the position of the
- * iterator in the set. After a <code>NodeIterator</code> is created,
- * the first call to <code>nextNode()</code> returns the first node in
- * the set.
- *
- * @return The next <code>Node</code> in the set being iterated over, or
- * <code>null</code> if there are no more members in that set.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if this method is called after
- * the <code>detach</code> method was invoked.
- */
- public Node nextNode() throws DOMException {
- for (Node node = getNextNode(); node != null; node = getNextNode()) {
- if (acceptNode(node))
- return node;
- }
- return null;
- }
-
- /**
- * Returns the previous node in the set and moves the position of the
- * <code>NodeIterator</code> backwards in the set.
- *
- * @return The previous <code>Node</code> in the set being iterated
- * over, or <code>null</code> if there are no more members in
- * that set.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if this method is called after
- * the <code>detach</code> method was invoked.
- */
- public Node previousNode() throws DOMException {
- for (Node node = getPreviousNode(); node != null; node = getPreviousNode()) {
- if (acceptNode(node))
- return node;
- }
- return null;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeListImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeListImpl.java
deleted file mode 100644
index a620f329ec..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeListImpl.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * An array-backed NodeList, used to keep the array size down
- */
-public class NodeListImpl implements NodeList {
-
- private Object fLockObject = new byte[0];
- private final static int growthConstant = 2;
- private Node[] fNodes = null;
- private int fNodeCount = 0;
-
- /**
- * NodeListImpl constructor
- */
- public NodeListImpl() {
- super();
- }
-
- protected NodeListImpl(NodeListImpl list) {
- super();
- fNodeCount = list.fNodeCount;
- fNodes = list.fNodes;
- }
-
- /**
- * appendNode method
- *
- * @return org.w3c.dom.Node
- * @param node
- * org.w3c.dom.Node
- */
- protected Node appendNode(Node node) {
- if (node == null)
- return null;
- synchronized (fLockObject) {
- ensureCapacity(fNodeCount + 1);
- fNodes[fNodeCount++] = node;
- }
- return node;
- }
-
- /**
- * Grow the node array to at least the given size while keeping the
- * contents the same
- *
- * @param needed
- */
- private void ensureCapacity(int needed) {
- if (fNodes == null) {
- // first time
- fNodes = new Node[needed];
- return;
- }
- int oldLength = fNodes.length;
- if (oldLength < needed) {
- Node[] oldNodes = fNodes;
- Node[] newNodes = new Node[needed + growthConstant];
- System.arraycopy(oldNodes, 0, newNodes, 0, fNodeCount);
- fNodes = newNodes;
- }
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.NodeList#getLength()
- */
- public int getLength() {
- return fNodeCount;
- }
-
- protected final Node[] getNodes() {
- return fNodes;
- }
-
- /**
- */
- protected Node insertNode(Node node, int index) {
- if (node == null)
- return null;
- synchronized (fLockObject) {
- if (fNodes == null) {
- // first time, ignore index
- fNodes = new Node[1];
- fNodes[fNodeCount++] = node;
- return node;
- }
-
- // gracefully handle out of bounds
- if (index < 0 || index > fNodeCount + 1)
- return appendNode(node);
-
- /*
- * Grow a new Node array, copying the old contents around the new
- * Node
- */
- Node[] newNodes = new Node[fNodeCount + growthConstant];
- System.arraycopy(fNodes, 0, newNodes, 0, index);
- newNodes[index] = node;
- System.arraycopy(fNodes, index, newNodes, index + 1, fNodeCount - index);
- fNodes = newNodes;
- fNodeCount++;
- }
- return node;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.NodeList#item(int)
- */
- public Node item(int index) {
- if (index < 0 || index >= fNodeCount)
- return null; // invalid parameter
- return fNodes[index];
- }
-
- /**
- * removeNode method
- *
- * @return org.w3c.dom.Node
- * @param index
- * int
- */
- protected Node removeNode(int index) {
- if (this.fNodes == null)
- return null; // no node
-
- synchronized (fLockObject) {
- if (index < 0 || index >= fNodeCount)
- return null; // invalid parameter
-
- Node removed = fNodes[index];
- Node[] newNodes = new Node[fNodeCount - 1];
- // copy around node being removed
- System.arraycopy(fNodes, 0, newNodes, 0, index);
- System.arraycopy(fNodes, index + 1, newNodes, index, fNodeCount - index - 1);
- fNodes = newNodes;
- fNodeCount--;
- return removed;
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NotationImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NotationImpl.java
deleted file mode 100644
index 186eea2e7e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NotationImpl.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-import org.w3c.dom.Notation;
-import org.w3c.dom.UserDataHandler;
-
-/**
- * NotationImpl class
- */
-public class NotationImpl extends NodeImpl implements Notation {
-
- private String name = null;
- private String publicId = null;
- private String systemId = null;
-
- /**
- * NotationImpl constructor
- */
- protected NotationImpl() {
- super();
- }
-
- /**
- * NotationImpl constructor
- *
- * @param that
- * NotationImpl
- */
- protected NotationImpl(NotationImpl that) {
- super(that);
-
- if (that != null) {
- this.name = that.name;
- this.publicId = that.publicId;
- this.systemId = that.systemId;
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- NotationImpl cloned = new NotationImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- if (this.name == null)
- return NodeImpl.EMPTY_STRING;
- return this.name;
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return NOTATION_NODE;
- }
-
- /**
- * getPublicId method
- *
- * @return java.lang.String
- */
- public String getPublicId() {
- return this.publicId;
- }
-
- /**
- * getSystemId method
- *
- * @return java.lang.String
- */
- public String getSystemId() {
- return this.systemId;
- }
-
- /**
- * setName method
- *
- * @param name
- * java.lang.String
- */
- protected void setName(String name) {
- this.name = name;
- }
-
- /**
- * setPublicId method
- *
- * @param publicId
- * java.lang.String
- */
- public void setPublicId(String publicId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- this.publicId = publicId;
- }
-
- /**
- * setSystemId method
- *
- * @param systemId
- * java.lang.String
- */
- public void setSystemId(String systemId) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- this.systemId = systemId;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ProcessingInstructionImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ProcessingInstructionImpl.java
deleted file mode 100644
index 044eb53b3b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ProcessingInstructionImpl.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Iterator;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.UserDataHandler;
-
-
-/**
- * ProcessingInstructionImpl class
- */
-public class ProcessingInstructionImpl extends NodeImpl implements ProcessingInstruction {
- private String data = null;
-
- private String target = null;
-
- /**
- * ProcessingInstructionImpl constructor
- */
- protected ProcessingInstructionImpl() {
- super();
- }
-
- /**
- * ProcessingInstructionImpl constructor
- *
- * @param that
- * ProcessingInstructionImpl
- */
- protected ProcessingInstructionImpl(ProcessingInstructionImpl that) {
- super(that);
-
- if (that != null) {
- this.target = that.target;
- this.data = that.getData();
- }
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- ProcessingInstructionImpl cloned = new ProcessingInstructionImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public String getData() {
- if (this.data != null)
- return this.data;
-
- IStructuredDocumentRegion flatNode = getFirstStructuredDocumentRegion();
- if (flatNode == null)
- return NodeImpl.EMPTY_STRING;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return NodeImpl.EMPTY_STRING;
-
- ITextRegion targetRegion = null;
- ITextRegion dataRegion = null;
- ITextRegion closeRegion = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_PI_OPEN)
- continue;
- if (regionType == DOMRegionContext.XML_PI_CLOSE) {
- closeRegion = region;
- }
- else {
- if (targetRegion == null)
- targetRegion = region;
- else if (dataRegion == null)
- dataRegion = region;
- }
- }
- if (dataRegion == null)
- return NodeImpl.EMPTY_STRING;
- int offset = dataRegion.getStart();
- int end = flatNode.getLength();
- if (closeRegion != null)
- end = closeRegion.getStart();
- String source = flatNode.getText();
- return source.substring(offset, end);
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return getTarget();
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- public short getNodeType() {
- return PROCESSING_INSTRUCTION_NODE;
- }
-
- /**
- * getNodeValue method
- *
- * @return java.lang.String
- */
- public String getNodeValue() {
- return getData();
- }
-
- /**
- * getTarget method
- *
- * @return java.lang.String
- */
- public String getTarget() {
- if (this.target == null)
- return NodeImpl.EMPTY_STRING;
- return this.target;
- }
-
- /**
- */
- public boolean isClosed() {
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return true; // will be generated
- String regionType = StructuredDocumentRegionUtil.getLastRegionType(flatNode);
- return (regionType == DOMRegionContext.XML_PI_CLOSE);
- }
-
- /**
- */
- void resetStructuredDocumentRegions() {
- this.data = getData();
- setStructuredDocumentRegion(null);
- }
-
- /**
- * setData method
- *
- * @param data
- * java.lang.String
- */
- public void setData(String data) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.data = data;
-
- notifyValueChanged();
- }
-
- /**
- * setNodeValue method
- *
- * @param nodeValue
- * java.lang.String
- */
- public void setNodeValue(String nodeValue) throws DOMException {
- setData(nodeValue);
- }
-
- /**
- */
- void setStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- super.setStructuredDocumentRegion(flatNode);
- if (flatNode != null)
- this.data = null;
- }
-
- /**
- * setTarget method
- *
- * @param target
- * java.lang.String
- */
- protected void setTarget(String target) {
- this.target = target;
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append(getTarget());
- buffer.append('(');
- buffer.append(getData());
- buffer.append(')');
- return buffer.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/RangeImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/RangeImpl.java
deleted file mode 100644
index ad30e282ec..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/RangeImpl.java
+++ /dev/null
@@ -1,630 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.w3c.dom.ranges.Range;
-import org.w3c.dom.ranges.RangeException;
-
-
-/**
- */
-public class RangeImpl implements Range {
- private Node endContainer = null;
- private int endOffset = 0;
-
- private Node startContainer = null;
- private int startOffset = 0;
-
- /**
- */
- protected RangeImpl() {
- super();
- }
-
- /**
- */
- protected RangeImpl(RangeImpl that) {
- super();
-
- if (that != null) {
- this.startContainer = that.startContainer;
- this.startOffset = that.startOffset;
- this.endContainer = that.endContainer;
- this.endOffset = that.endOffset;
- }
- }
-
- /**
- * Duplicates the contents of a Range
- *
- * @return A DocumentFragment that contains content equivalent to this
- * Range.
- * @exception DOMException
- * HIERARCHY_REQUEST_ERR: Raised if a DocumentType node
- * would be extracted into the new DocumentFragment. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public DocumentFragment cloneContents() throws DOMException {
- // not supported
- return null;
- }
-
- /**
- * Produces a new Range whose boundary-points are equal to the
- * boundary-points of the Range.
- *
- * @return The duplicated Range.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public Range cloneRange() throws DOMException {
- return new RangeImpl(this);
- }
-
- /**
- * Collapse a Range onto one of its boundary-points
- *
- * @param toStartIf
- * TRUE, collapses the Range onto its start; if FALSE,
- * collapses it onto its end.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void collapse(boolean toStart) throws DOMException {
- if (toStart) {
- this.endContainer = this.startContainer;
- this.endOffset = this.startOffset;
- } else {
- this.startContainer = this.endContainer;
- this.startOffset = this.endOffset;
- }
- }
-
- /**
- * Compare the boundary-points of two Ranges in a document.
- *
- * @param howA
- * code representing the type of comparison, as defined above.
- * @param sourceRangeThe
- * <code>Range</code> on which this current
- * <code>Range</code> is compared to.
- * @return -1, 0 or 1 depending on whether the corresponding
- * boundary-point of the Range is respectively before, equal to,
- * or after the corresponding boundary-point of
- * <code>sourceRange</code>.
- * @exception DOMException
- * WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in
- * the same Document or DocumentFragment. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public short compareBoundaryPoints(short how, Range sourceRange) throws DOMException {
- if (sourceRange == null)
- return (short) 0; // error
-
- Node container1 = null;
- int offset1 = 0;
- Node container2 = null;
- int offset2 = 0;
-
- switch (how) {
- case START_TO_START :
- container1 = this.startContainer;
- offset1 = this.startOffset;
- container2 = sourceRange.getStartContainer();
- offset2 = sourceRange.getStartOffset();
- break;
- case START_TO_END :
- container1 = this.startContainer;
- offset1 = this.startOffset;
- container2 = sourceRange.getEndContainer();
- offset2 = sourceRange.getEndOffset();
- break;
- case END_TO_END :
- container1 = this.endContainer;
- offset1 = this.endOffset;
- container2 = sourceRange.getEndContainer();
- offset2 = sourceRange.getEndOffset();
- break;
- case END_TO_START :
- container1 = this.endContainer;
- offset1 = this.endOffset;
- container2 = sourceRange.getStartContainer();
- offset2 = sourceRange.getStartOffset();
- break;
- default :
- return (short) 0; // error
- }
-
- return comparePoints(container1, offset1, container2, offset2);
- }
-
- /*
- */
- protected short comparePoints(Node container1, int offset1, Node container2, int offset2) {
- if (container1 == null || container2 == null)
- return (short) 0; // error
-
- if (container1 == container2) {
- if (offset1 > offset2)
- return (short) 1;
- if (offset1 < offset2)
- return (short) -1;
- return 0;
- }
-
- // get node offsets
- IDOMNode node1 = null;
- if (container1.hasChildNodes()) {
- Node child = container1.getFirstChild();
- for (int i = 0; i < offset1; i++) {
- Node next = child.getNextSibling();
- if (next == null)
- break;
- child = next;
- }
- node1 = (IDOMNode) child;
- offset1 = 0;
- } else {
- node1 = (IDOMNode) container1;
- }
- int nodeOffset1 = node1.getStartOffset();
- IDOMNode node2 = null;
- if (container2.hasChildNodes()) {
- Node child = container2.getFirstChild();
- for (int i = 0; i < offset2; i++) {
- Node next = child.getNextSibling();
- if (next == null)
- break;
- child = next;
- }
- node2 = (IDOMNode) child;
- offset2 = 0;
- } else {
- node2 = (IDOMNode) container2;
- }
- int nodeOffset2 = node2.getStartOffset();
-
- if (nodeOffset1 > nodeOffset2)
- return (short) 1;
- if (nodeOffset1 < nodeOffset2)
- return (short) -1;
- if (offset1 > offset2)
- return (short) 1;
- if (offset1 < offset2)
- return (short) -1;
- return (short) 0;
- }
-
- /**
- * Removes the contents of a Range from the containing document or
- * document fragment without returning a reference to the removed content.
- *
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of
- * the content of the Range is read-only or any of the
- * nodes that contain any of the content of the Range are
- * read-only. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void deleteContents() throws DOMException {
- // not supported
- }
-
- /**
- * Called to indicate that the Range is no longer in use and that the
- * implementation may relinquish any resources associated with this Range.
- * Subsequent calls to any methods or attribute getters on this Range will
- * result in a <code>DOMException</code> being thrown with an error code
- * of <code>INVALID_STATE_ERR</code>.
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void detach() throws DOMException {
- this.startContainer = null;
- this.startOffset = 0;
- this.endContainer = null;
- this.endOffset = 0;
- }
-
- /**
- * Moves the contents of a Range from the containing document or document
- * fragment to a new DocumentFragment.
- *
- * @return A DocumentFragment containing the extracted contents.
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of
- * the content of the Range is read-only or any of the
- * nodes which contain any of the content of the Range are
- * read-only. <br>
- * HIERARCHY_REQUEST_ERR: Raised if a DocumentType node
- * would be extracted into the new DocumentFragment. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public DocumentFragment extractContents() throws DOMException {
- // not supported
- return null;
- }
-
- /**
- * TRUE if the Range is collapsed
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public boolean getCollapsed() throws DOMException {
- if (this.startContainer == this.endContainer && this.startOffset == this.endOffset)
- return true;
- return false;
- }
-
- /**
- * The deepest common ancestor container of the Range's two
- * boundary-points.
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public Node getCommonAncestorContainer() throws DOMException {
- if (this.startContainer == null)
- return null;
- return ((NodeImpl) this.startContainer).getCommonAncestor(this.endContainer);
- }
-
- /**
- * Node within which the Range ends
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public Node getEndContainer() throws DOMException {
- return this.endContainer;
- }
-
- /**
- * Offset within the ending node of the Range.
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public int getEndOffset() throws DOMException {
- return this.endOffset;
- }
-
- /**
- * Node within which the Range begins
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public Node getStartContainer() throws DOMException {
- return this.startContainer;
- }
-
- /**
- * Offset within the starting node of the Range.
- *
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public int getStartOffset() throws DOMException {
- return this.startOffset;
- }
-
- /**
- * Inserts a node into the Document or DocumentFragment at the start of
- * the Range. If the container is a Text node, this will be split at the
- * start of the Range (as if the Text node's splitText method was
- * performed at the insertion point) and the insertion will occur between
- * the two resulting Text nodes. Adjacent Text nodes will not be
- * automatically merged. If the node to be inserted is a DocumentFragment
- * node, the children will be inserted rather than the DocumentFragment
- * node itself.
- *
- * @param newNodeThe
- * node to insert at the start of the Range
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor
- * container of the start of the Range is read-only. <br>
- * WRONG_DOCUMENT_ERR: Raised if <code>newNode</code> and
- * the container of the start of the Range were not created
- * from the same document. <br>
- * HIERARCHY_REQUEST_ERR: Raised if the container of the
- * start of the Range is of a type that does not allow
- * children of the type of <code>newNode</code> or if
- * <code>newNode</code> is an ancestor of the container.
- * <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if <code>newNode</code>
- * is an Attr, Entity, Notation, or Document node.
- */
- public void insertNode(Node newNode) throws RangeException, DOMException {
- // not supported
- }
-
- /**
- * Select a node and its contents
- *
- * @param refNodeThe
- * node to select.
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if an ancestor of
- * <code>refNode</code> is an Entity, Notation or
- * DocumentType node or if <code>refNode</code> is a
- * Document, DocumentFragment, Attr, Entity, or Notation
- * node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void selectNode(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- Node parent = refNode.getParentNode();
- if (parent == null)
- return;
- int index = ((NodeImpl) refNode).getIndex();
- if (index < 0)
- return;
- setStart(parent, index);
- setEnd(parent, index + 1);
- }
-
- /**
- * Select the contents within a node
- *
- * @param refNodeNode
- * to select from
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code>
- * or an ancestor of <code>refNode</code> is an Entity,
- * Notation or DocumentType node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void selectNodeContents(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- if (refNode.getNodeType() == Node.TEXT_NODE) {
- Text text = (Text) refNode;
- setStart(refNode, 0);
- setEnd(refNode, text.getLength());
- } else {
- NodeList childNodes = refNode.getChildNodes();
- int length = (childNodes != null ? childNodes.getLength() : 0);
- setStart(refNode, 0);
- setEnd(refNode, length);
- }
- }
-
- /**
- * Sets the attributes describing the end of a Range.
- *
- * @param refNodeThe
- * <code>refNode</code> value. This parameter must be
- * different from <code>null</code>.
- * @param offsetThe
- * <code>endOffset</code> value.
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code>
- * or an ancestor of <code>refNode</code> is an Entity,
- * Notation, or DocumentType node.
- * @exception DOMException
- * INDEX_SIZE_ERR: Raised if <code>offset</code> is
- * negative or greater than the number of child units in
- * <code>refNode</code>. Child units are 16-bit units if
- * <code>refNode</code> is a type of CharacterData node
- * (e.g., a Text or Comment node) or a
- * ProcessingInstruction node. Child units are Nodes in all
- * other cases. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setEnd(Node refNode, int offset) throws RangeException, DOMException {
- this.endContainer = refNode;
- this.endOffset = offset;
- }
-
- /**
- * Sets the end of a Range to be after a node
- *
- * @param refNodeRange
- * ends after <code>refNode</code>.
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if the root container of
- * <code>refNode</code> is not an Attr, Document or
- * DocumentFragment node or if <code>refNode</code> is a
- * Document, DocumentFragment, Attr, Entity, or Notation
- * node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setEndAfter(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- Node parent = refNode.getParentNode();
- if (parent == null)
- return;
- int index = ((NodeImpl) refNode).getIndex();
- if (index < 0)
- return;
- setEnd(parent, index + 1);
- }
-
- /**
- * Sets the end position to be before a node.
- *
- * @param refNodeRange
- * ends before <code>refNode</code>
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if the root container of
- * <code>refNode</code> is not an Attr, Document, or
- * DocumentFragment node or if <code>refNode</code> is a
- * Document, DocumentFragment, Attr, Entity, or Notation
- * node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setEndBefore(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- Node parent = refNode.getParentNode();
- if (parent == null)
- return;
- int index = ((NodeImpl) refNode).getIndex();
- if (index < 0)
- return;
- setEnd(parent, index);
- }
-
- /**
- * Sets the attributes describing the start of the Range.
- *
- * @param refNodeThe
- * <code>refNode</code> value. This parameter must be
- * different from <code>null</code>.
- * @param offsetThe
- * <code>startOffset</code> value.
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code>
- * or an ancestor of <code>refNode</code> is an Entity,
- * Notation, or DocumentType node.
- * @exception DOMException
- * INDEX_SIZE_ERR: Raised if <code>offset</code> is
- * negative or greater than the number of child units in
- * <code>refNode</code>. Child units are 16-bit units if
- * <code>refNode</code> is a type of CharacterData node
- * (e.g., a Text or Comment node) or a
- * ProcessingInstruction node. Child units are Nodes in all
- * other cases. <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setStart(Node refNode, int offset) throws RangeException, DOMException {
- this.startContainer = refNode;
- this.startOffset = offset;
- }
-
- /**
- * Sets the start position to be after a node
- *
- * @param refNodeRange
- * starts after <code>refNode</code>
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if the root container of
- * <code>refNode</code> is not an Attr, Document, or
- * DocumentFragment node or if <code>refNode</code> is a
- * Document, DocumentFragment, Attr, Entity, or Notation
- * node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setStartAfter(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- Node parent = refNode.getParentNode();
- if (parent == null)
- return;
- int index = ((NodeImpl) refNode).getIndex();
- if (index < 0)
- return;
- setStart(parent, index + 1);
- }
-
- /**
- * Sets the start position to be before a node
- *
- * @param refNodeRange
- * starts before <code>refNode</code>
- * @exception RangeException
- * INVALID_NODE_TYPE_ERR: Raised if the root container of
- * <code>refNode</code> is not an Attr, Document, or
- * DocumentFragment node or if <code>refNode</code> is a
- * Document, DocumentFragment, Attr, Entity, or Notation
- * node.
- * @exception DOMException
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- */
- public void setStartBefore(Node refNode) throws RangeException, DOMException {
- if (refNode == null)
- return;
- Node parent = refNode.getParentNode();
- if (parent == null)
- return;
- int index = ((NodeImpl) refNode).getIndex();
- if (index < 0)
- return;
- setStart(parent, index);
- }
-
- /**
- * Reparents the contents of the Range to the given node and inserts the
- * node at the position of the start of the Range.
- *
- * @param newParentThe
- * node to surround the contents with.
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor
- * container of either boundary-point of the Range is
- * read-only. <br>
- * WRONG_DOCUMENT_ERR: Raised if <code> newParent</code>
- * and the container of the start of the Range were not
- * created from the same document. <br>
- * HIERARCHY_REQUEST_ERR: Raised if the container of the
- * start of the Range is of a type that does not allow
- * children of the type of <code>newParent</code> or if
- * <code>newParent</code> is an ancestor of the container
- * or if <code>node</code> would end up with a child node
- * of a type not allowed by the type of <code>node</code>.
- * <br>
- * INVALID_STATE_ERR: Raised if <code>detach()</code> has
- * already been invoked on this object.
- * @exception RangeException
- * BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially
- * selects a non-text node. <br>
- * INVALID_NODE_TYPE_ERR: Raised if <code> node</code> is
- * an Attr, Entity, DocumentType, Notation, Document, or
- * DocumentFragment node.
- */
- public void surroundContents(Node newParent) throws RangeException, DOMException {
- // not supported
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java
deleted file mode 100644
index 57c2375444..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Node;
-
-
-class ReadOnlyController {
-
- class Span {
- int length;
- int offset;
-
- Span(int offset, int length) {
- this.offset = offset;
- this.length = length;
- }
- }
-
- private static ReadOnlyController fInstance;
-
- static synchronized ReadOnlyController getInstance() {
- if (fInstance == null) {
- fInstance = new ReadOnlyController();
- }
- return fInstance;
- }
-
- static private void lock(IStructuredDocument doc, int offset, int length, boolean canInsertBefore, boolean canInsertAfter) {
- if (doc == null) {
- return;
- }
- if (doc instanceof BasicStructuredDocument) {
- ((BasicStructuredDocument)doc).makeReadOnly(offset, length, canInsertBefore, canInsertAfter);
- } else {
- doc.makeReadOnly(offset, length);
- }
- }
-
- static private void lock(IStructuredDocumentRegion node, boolean canInsertBefore, boolean canInsertAfter) {
- if (node == null) {
- return;
- }
- IStructuredDocument doc = node.getParentDocument();
- if (doc == null) {
- return;
- }
- if (doc instanceof BasicStructuredDocument) {
- ((BasicStructuredDocument)doc).makeReadOnly(node.getStart(), node.getLength(), canInsertBefore, canInsertAfter);
- } else {
- doc.makeReadOnly(node.getStart(), node.getLength());
- }
- }
-
- static private void unlock(IStructuredDocumentRegion node) {
- if (node == null) {
- return;
- }
- IStructuredDocument doc = node.getParentDocument();
- if (doc == null) {
- return;
- }
- doc.clearReadOnly(node.getStart(), node.getLength());
- }
-
- private ReadOnlyController() {
- super();
- }
-
- private Span getDataSpan(IDOMNode node) {
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE :
- return getDataSpanForElement((IDOMElement) node);
- case Node.TEXT_NODE :
- return getDataSpanForText((IDOMText) node);
- default :
- return new Span(0, -1);
- }
- }
-
- private Span getDataSpanForElement(IDOMElement node) {
- IStructuredDocumentRegion docRegion = node.getStartStructuredDocumentRegion();
- if (docRegion == null) {
- return new Span(0, -1);
- }
-
- ITextRegionList regions = docRegion.getRegions();
- if (regions == null) {
- return new Span(0, -1);
- }
-
- String startType;
- String endType;
- if (node.isCommentTag()) {
- startType = DOMRegionContext.XML_COMMENT_OPEN;
- endType = DOMRegionContext.XML_COMMENT_CLOSE;
- } else {
- startType = DOMRegionContext.XML_TAG_NAME;
- endType = DOMRegionContext.XML_TAG_CLOSE;
- }
-
- int startOffset = -1;
- int endOffset = -1;
- ITextRegion prevRegion = null;
- ITextRegion region;
- for (int i = 0; i < regions.size(); i++) {
- region = regions.get(i);
- String type = region.getType();
- if (type == startType) {
- startOffset = region.getEnd();
- } else if (type == endType && prevRegion != null) {
- endOffset = prevRegion.getTextEnd();
- }
- prevRegion = region;
- }
-
- if (0 <= startOffset && 0 <= endOffset) {
- return new Span(startOffset, endOffset - startOffset);
- } else {
- return new Span(0, -1);
- }
- }
-
- private Span getDataSpanForText(IDOMText node) {
- IStructuredDocumentRegion docRegion = ((NodeImpl) node).getStructuredDocumentRegion();
- if (docRegion == null) {
- return new Span(0, -1);
- }
- return new Span(0, docRegion.getLength());
- }
-
- /**
- * This method is used from parent's setChildEditable()
- *
- * case 1:<parent><node attr="value"/> <node2></parent>
- * x####################x case 2:<parent><node attr="value"> <child>
- * </child> </node> </parent> x###################? ?#######x (? :
- * editable if node.isEditable() == true)
- */
- void lockBoth(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- IStructuredDocumentRegion flatNode;
- boolean canInsert = false;
-
- // end node (element)
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- flatNode = node.getEndStructuredDocumentRegion();
- if (flatNode != null) {
- canInsert = node.isChildEditable();
- lock(flatNode, canInsert, false);
- }
- }
- // start node
- flatNode = node.getStartStructuredDocumentRegion();
- if (flatNode != null) {
- lock(flatNode, false, canInsert);
- }
- }
-
- void lockData(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- Span span = getDataSpan(node);
- if (0 <= span.length) {
- lock(node.getModel().getStructuredDocument(), node.getStartOffset() + span.offset, span.length, false, false);
- }
- }
-
- /**
- * lock itself and all descendants
- */
- void lockDeep(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- int offset = node.getStartOffset();
- int length = node.getEndOffset() - offset;
-
- boolean canInsert = true;
- IDOMNode parent = (IDOMNode) node.getParentNode();
- if (parent != null && !parent.isChildEditable()) {
- canInsert = false;
- }
- lock(node.getStructuredDocument(), offset, length, canInsert, canInsert);
- }
-
- /**
- * This method is used from parent's setChildEditable()
- *
- * case 1:<parent><node attr="value"/> <node2></parent> x######x x##x
- * case 2:<parent><node attr="value"> <child></child> </node> </parent>
- * x######x x#? ?#######x (? : editable if node.isEditable() == true)
- */
- void lockNode(IDOMNode node) {
- if (node == null) {
- return;
- }
- if (!node.isDataEditable()) {
- lockBoth(node);
- return;
- }
-
- IStructuredDocumentRegion flatNode;
- boolean canInsert = false;
-
- // end node (element)
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- flatNode = node.getEndStructuredDocumentRegion();
- if (flatNode != null) {
- canInsert = node.isChildEditable();
- lock(flatNode, canInsert, false);
- }
- }
- // start node
- flatNode = node.getStartStructuredDocumentRegion();
- if (flatNode != null) {
- Span span = getDataSpan(node);
- if (0 <= span.length) {
- IStructuredDocument structuredDocument = flatNode.getParentDocument();
- int offset, length;
- offset = flatNode.getStart();
- length = span.offset;
- lock(structuredDocument, offset, length, false, false);
- offset = offset + span.offset + span.length;
- length = flatNode.getEnd() - offset;
- lock(structuredDocument, offset, length, false, canInsert);
- } else {
- lock(flatNode, false, canInsert);
- }
- }
- }
-
- private void unlock(IStructuredDocument doc, int offset, int length) {
- if (doc == null) {
- return;
- }
- doc.clearReadOnly(offset, length);
- }
-
- void unlockBoth(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- IStructuredDocumentRegion flatNode;
- // start node
- flatNode = node.getStartStructuredDocumentRegion();
- if (flatNode != null) {
- unlock(flatNode);
- }
- // end node
- flatNode = node.getEndStructuredDocumentRegion();
- if (flatNode != null) {
- unlock(flatNode);
- }
- }
-
- void unlockData(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- Span span = getDataSpan(node);
- if (0 <= span.length) {
- unlock(node.getModel().getStructuredDocument(), span.offset, span.length);
- }
- }
-
- void unlockDeep(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- int offset = node.getStartOffset();
- int length = node.getEndOffset() - offset;
-
- unlock(node.getStructuredDocument(), offset, length);
- }
-
- void unlockNode(IDOMNode node) {
- if (node == null) {
- return;
- }
-
- IStructuredDocumentRegion flatNode;
- // end node
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- flatNode = node.getEndStructuredDocumentRegion();
- if (flatNode != null) {
- unlock(flatNode);
- }
- }
-
- // start node
- flatNode = node.getStartStructuredDocumentRegion();
- if (flatNode != null) {
- if (node.isDataEditable()) {
- unlock(flatNode);
- } else {
- Span span = getDataSpan(node);
- if (span.length <= 0) {
- unlock(flatNode);
- } else {
- IStructuredDocument structuredDocument = flatNode.getParentDocument();
- int offset, length;
- offset = flatNode.getStart();
- length = span.offset - offset;
- unlock(structuredDocument, offset, length);
- offset = span.offset + span.length;
- length = flatNode.getEnd() - span.offset;
- unlock(structuredDocument, offset, length);
- }
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/SourceValidator.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/SourceValidator.java
deleted file mode 100644
index 2051222cfd..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/SourceValidator.java
+++ /dev/null
@@ -1,388 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.XMLCoreMessages;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLCharEntity;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Node;
-
-/**
- */
-public class SourceValidator {
-
- private NodeImpl node = null;
-
- /**
- */
- public SourceValidator(Node node) {
- super();
-
- if (node != null) {
- this.node = (NodeImpl) node;
- }
- }
-
- /**
- */
- public String convertSource(String source) {
- if (source == null)
- return null;
- if (this.node == null)
- return null; // error
-
- // setup conversion conditions
- boolean acceptTag = false;
- boolean acceptClose = false;
- boolean acceptQuote = false;
- boolean acceptAmpersand = false;
- boolean acceptEntityRef = true;
- boolean acceptJSPEnd = true;
- String endTagName = null;
- if (this.node.getNodeType() == Node.ATTRIBUTE_NODE) {
- IDOMDocument document = (IDOMDocument) this.node.getOwnerDocument();
- if (document != null && document.isJSPType())
- acceptTag = true;
- if (acceptTag) {
- Attr attr = (Attr) this.node;
- ElementImpl element = (ElementImpl) attr.getOwnerElement();
- if (element != null && element.isJSPTag())
- acceptTag = false;
- }
- // if the source does not include single quote,
- // double quote is valid
- acceptQuote = (source.indexOf('\'') < 0);
- } else if (this.node.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) this.node;
- if (text.isJSPContent()) {
- int index = source.indexOf(JSPTag.TAG_CLOSE);
- if (index < 0)
- return source;
- acceptTag = true;
- acceptClose = true;
- acceptQuote = true;
- acceptAmpersand = true;
- acceptJSPEnd = false;
- } else if (text.isCDATAContent()) {
- endTagName = text.getParentNode().getNodeName();
- if (endTagName == null)
- return null; // error
- acceptTag = true;
- acceptClose = true;
- acceptQuote = true;
- acceptAmpersand = true;
- }
- } else {
- IDOMDocument document = null;
- if (this.node.getNodeType() == Node.DOCUMENT_NODE) {
- document = (IDOMDocument) this.node;
- } else {
- document = (IDOMDocument) this.node.getOwnerDocument();
- }
- if (document != null && document.isJSPType())
- acceptTag = true;
- }
-
- StringBuffer buffer = null;
- int copiedLength = 0;
- int length = source.length();
- for (int i = 0; i < length; i++) {
- String ref = null;
- char c = source.charAt(i);
- switch (c) {
- case '<' :
- if (acceptTag) {
- if (endTagName != null) {
- if (!matchEndTag(source, i + 1, endTagName))
- continue;
- } else {
- int skip = skipTag(source, i + 1);
- if (skip >= 0) {
- i += skip;
- continue;
- }
- }
- // invalid JSP tag
- }
- ref = IXMLCharEntity.LT_REF;
- break;
- case '>' :
- if (acceptClose)
- continue;
- ref = IXMLCharEntity.GT_REF;
- break;
- case '&' :
- if (acceptAmpersand)
- continue;
- if (acceptEntityRef) {
- int skip = skipEntityRef(source, i + 1);
- if (skip >= 0) {
- i += skip;
- continue;
- }
- }
- ref = IXMLCharEntity.AMP_REF;
- break;
- case '"' :
- if (acceptQuote)
- continue;
- ref = IXMLCharEntity.QUOT_REF;
- break;
- case '%' :
- if (acceptJSPEnd)
- continue;
- if (source.charAt(i + 1) != '>')
- continue;
- i++;
- ref = IXMLCharEntity.GT_REF;
- break;
- default :
- continue;
- }
-
- if (ref != null) {
- if (buffer == null) {
- buffer = new StringBuffer(length + 8);
- }
- if (i > copiedLength) {
- buffer.append(source.substring(copiedLength, i));
- }
- buffer.append(ref);
- copiedLength = i + 1; // skip this character
- }
- }
-
- if (buffer != null) {
- if (copiedLength < length) {
- buffer.append(source.substring(copiedLength, length));
- }
- return buffer.toString();
- }
- return source;
- }
-
- /**
- */
- private final boolean matchEndTag(String source, int offset, String endTagName) {
- if (source == null || endTagName == null)
- return false;
- int length = source.length();
- if (offset < 0 || offset >= length)
- return false;
- if (source.charAt(offset) != '/')
- return false;
- offset++;
- int end = offset + endTagName.length();
- if (end > length)
- return false;
- return endTagName.equalsIgnoreCase(source.substring(offset, end));
- }
-
- /**
- */
- private final int skipEntityRef(String source, int offset) {
- if (source == null)
- return -1;
- if (offset < 0 || offset >= source.length())
- return -1;
- DocumentImpl document = (DocumentImpl) this.node.getOwnerDocument();
- if (document == null)
- return -1; // error
-
- int end = source.indexOf(';', offset);
- if (end < 0 || end == offset)
- return -1;
- String name = source.substring(offset, end);
- if (name == null || document.getCharValue(name) == null)
- return -1;
- return (end + 1 - offset);
- }
-
- /**
- */
- private final int skipTag(String source, int offset) {
- if (source == null)
- return -1;
- if (offset < 0 || offset >= source.length())
- return -1;
-
- int end = offset;
- if (source.charAt(offset) == '%') {
- // JSP tag
- int found = source.indexOf(JSPTag.TAG_CLOSE, offset + 1);
- if (found < 0)
- return -1; // invalid JSP tag
- end = found + 2;
- } else {
- // normal tag
- int found = source.lastIndexOf('>');
- if (found < offset)
- return -1; // invalid tag
- end = found + 1;
- }
- return (end - offset);
- }
-
- /**
- */
- public boolean validateSource(String source) throws InvalidCharacterException {
- if (source == null)
- return true;
- if (this.node == null)
- return false; // error
- String message = null;
-
-
- // setup validation conditions
- boolean acceptTag = false;
- boolean acceptClose = false;
- boolean acceptQuote = true;
- boolean acceptEntityRef = true;
- String endTagName = null;
- if (this.node.getNodeType() == Node.ATTRIBUTE_NODE) {
- IDOMDocument document = (IDOMDocument) this.node.getOwnerDocument();
- if (document != null && document.isJSPType())
- acceptTag = true;
- if (acceptTag) {
- Attr attr = (Attr) this.node;
- ElementImpl element = (ElementImpl) attr.getOwnerElement();
- if (element != null && element.isJSPTag())
- acceptTag = false;
- }
- // if the source does not include single quote,
- // double quote is valid
- acceptQuote = (source.indexOf('\'') < 0);
- } else if (this.node.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) this.node;
- if (text.isJSPContent()) {
- int index = source.indexOf(JSPTag.TAG_CLOSE);
- if (index < 0)
- return true;
- message = XMLCoreMessages.Invalid_character_gt_fo_ERROR_;
- throw new InvalidCharacterException(message, '>', index + 1);
- } else if (text.isCDATAContent()) {
- endTagName = text.getParentNode().getNodeName();
- if (endTagName == null)
- return false; // error
- acceptTag = true;
- acceptClose = true;
- } else if(hasNestedRegion(text)) {
- //there are cases (such as with EL) that the text is to complicated
- // to be verified by this validator
- return true;
- }
- } else {
- IDOMDocument document = null;
- if (this.node.getNodeType() == Node.DOCUMENT_NODE) {
- document = (IDOMDocument) this.node;
- } else {
- document = (IDOMDocument) this.node.getOwnerDocument();
- }
- if (document != null && document.isJSPType())
- acceptTag = true;
- }
-
- char c = 0;
- int length = source.length();
- for (int i = 0; i < length; i++) {
- c = source.charAt(i);
- switch (c) {
- case '<' :
- if (acceptTag) {
- if (endTagName != null) {
- if (!matchEndTag(source, i + 1, endTagName))
- continue;
- } else {
- int skip = skipTag(source, i + 1);
- if (skip >= 0) {
- i += skip;
- continue;
- }
- }
- // invalid tag
- }
- message = XMLCoreMessages.Invalid_character_lt_fo_ERROR_;
- break;
- case '>' :
- if (acceptClose)
- continue;
- message = XMLCoreMessages.Invalid_character_gt_fo_ERROR_;
- break;
- case '&' :
- if (acceptEntityRef) {
- if (endTagName != null)
- continue;
- int skip = skipEntityRef(source, i + 1);
- if (skip >= 0) {
- i += skip;
- continue;
- }
- // invalid entity reference
- }
- message = XMLCoreMessages.Invalid_character_amp_fo_ERROR_;
- break;
- case '"' :
- if (acceptQuote)
- continue;
- message = XMLCoreMessages.Invalid_character__f_EXC_;
- break;
- default :
- continue;
- }
-
- if (message != null) {
- throw new InvalidCharacterException(message, c, i);
- }
- }
-
- return true;
- }
-
- /**
- * True if the text has nested regions, meaning container is probably too
- * complicated (like EL regions) to validate with this validator.
- *
- * @param text
- * @return
- */
- private boolean hasNestedRegion(TextImpl text) {
- boolean done = false;
-
- IStructuredDocumentRegion currRegion = text.getFirstStructuredDocumentRegion();
- IStructuredDocumentRegion lastRegion = text.getLastStructuredDocumentRegion();
-
- while(currRegion != null && !done) {
-
- ITextRegionList regions = currRegion.getRegions();
- for(int i = 0; i < regions.size(); ++i) {
- ITextRegion container = regions.get(i);
- if ((container instanceof ITextRegionContainer)) {
- ITextRegionList regions2 = ((ITextRegionContainer) container).getRegions();
- if (regions2 != null) {
- return true;
- }
- }
- }
-
- done = currRegion == lastRegion;
- currRegion = currRegion.getNext();
- }
-
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionChecker.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionChecker.java
deleted file mode 100644
index 547c8f35c5..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionChecker.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.io.IOException;
-import java.io.Writer;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.w3c.dom.Node;
-
-
-/**
- * This class is only for debug purpose.
- */
-public class StructuredDocumentRegionChecker {
- String EOL = System.getProperty("line.separator"); //$NON-NLS-1$
-
- private int offset = 0;
- Writer testWriter = null;
-
- /**
- */
- public StructuredDocumentRegionChecker() {
- super();
- }
-
- public StructuredDocumentRegionChecker(Writer writer) {
- super();
- testWriter = writer;
- }
-
- /**
- */
- private void checkChildNodes(Node node) {
- for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
- checkNode(child);
- }
- }
-
- /**
- */
- public void checkModel(IDOMModel model) {
- checkChildNodes(model.getDocument());
- }
-
- /**
- */
- private void checkNode(Node node) {
- checkStructuredDocumentRegion(((NodeImpl) node).getStructuredDocumentRegion());
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- checkChildNodes(node);
- checkStructuredDocumentRegion(((ElementImpl) node).getEndStructuredDocumentRegion());
- }
- }
-
- /**
- */
- private void checkStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return;
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int n = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < n; i++) {
- IStructuredDocumentRegion c = container.getStructuredDocumentRegion(i);
- if (c == null) {
- reportError("null"); //$NON-NLS-1$
- continue;
- }
- checkStructuredDocumentRegion(c);
- }
- return;
- }
-
- int start = flatNode.getStart();
- if (start < this.offset)
- reportError("overwrap"); //$NON-NLS-1$
- if (start > this.offset)
- reportError("gap"); //$NON-NLS-1$
- int end = flatNode.getEnd();
- this.offset = end;
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- IStructuredDocumentRegion p = proxy.getStructuredDocumentRegion();
- if (p == null) {
- reportError("null"); //$NON-NLS-1$
- return;
- }
- int s = p.getStart();
- int e = p.getEnd();
- if (s > start || e < end)
- reportError("out"); //$NON-NLS-1$
- if (s == start && e == end)
- reportWarning("vain"); //$NON-NLS-1$
- }
- }
-
- /**
- */
- private void reportError(String message) {
- String msg = "StructuredDocumentRegionChecker : error : " + message; //$NON-NLS-1$
- if (testWriter != null) {
- try {
- testWriter.write(msg + EOL);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- System.out.println(msg);
- }
- throw new StructuredDocumentRegionManagementException();
- }
-
- /**
- */
- private void reportWarning(String message) {
- String msg = "StructuredDocumentRegionChecker : warning : " + message; //$NON-NLS-1$
- if (testWriter != null) {
- try {
- testWriter.write(msg + EOL);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else {
- System.out.println(msg);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionContainer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionContainer.java
deleted file mode 100644
index 245211d84d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionContainer.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Vector;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-
-
-class StructuredDocumentRegionContainer implements IStructuredDocumentRegion {
-
- private Vector flatNodes = new Vector(2);
-
- /**
- */
- StructuredDocumentRegionContainer() {
- super();
- }
-
-
- public void addRegion(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjust(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustLength(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustStart(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustTextLength(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- /**
- */
- void appendStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return;
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- if (container.getStructuredDocumentRegionCount() > 0) {
- this.flatNodes.addAll(container.flatNodes);
- }
- }
- else {
- this.flatNodes.addElement(flatNode);
- }
- }
-
- public boolean containsOffset(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public boolean containsOffset(ITextRegion region, int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void equatePositions(ITextRegion region) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public ITextRegion getDeepestRegionAtCharacterOffset(int offset) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public int getEnd() {
- IStructuredDocumentRegion last = getLastStructuredDocumentRegion();
- if (last == null)
- return 0;
- return last.getEnd();
- }
-
- /**
- */
- public int getEndOffset() {
- return getEnd();
- }
-
- public int getEndOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public ITextRegion getFirstRegion() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- IStructuredDocumentRegion getFirstStructuredDocumentRegion() {
- if (this.flatNodes.isEmpty())
- return null;
- return (IStructuredDocumentRegion) this.flatNodes.elementAt(0);
- }
-
- /**
- */
- public String getFullText() {
- return getText();
- }
-
- /**
- */
- public String getFullText(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public String getFullText(String context) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public ITextRegion getLastRegion() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- IStructuredDocumentRegion getLastStructuredDocumentRegion() {
- int size = this.flatNodes.size();
- if (size == 0)
- return null;
- return (IStructuredDocumentRegion) this.flatNodes.elementAt(size - 1);
- }
-
- /**
- */
- public int getLength() {
- return (getEnd() - getStart());
- }
-
- public IStructuredDocumentRegion getNext() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public int getNumberOfRegions() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public ITextRegionContainer getParent() {
- return null;
- }
-
- public IStructuredDocument getParentDocument() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public IStructuredDocumentRegion getPrevious() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public ITextRegion getRegionAtCharacterOffset(int offset) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public ITextRegionList getRegions() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public int getStart() {
- IStructuredDocumentRegion first = getFirstStructuredDocumentRegion();
- if (first == null)
- return 0;
- return first.getStart();
- }
-
- /**
- */
- public int getStartOffset() {
- return getStart();
- }
-
- public int getStartOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public IStructuredDocument getStructuredDocument() {
- IStructuredDocumentRegion first = getFirstStructuredDocumentRegion();
- if (first == null)
- return null;
- return first.getParentDocument();
- }
-
- /**
- */
- IStructuredDocumentRegion getStructuredDocumentRegion(int index) {
- if (index < 0 || index >= this.flatNodes.size())
- return null;
- return (IStructuredDocumentRegion) this.flatNodes.elementAt(index);
- }
-
- /**
- */
- int getStructuredDocumentRegionCount() {
- return this.flatNodes.size();
- }
-
- /**
- */
- public String getText() {
- int size = this.flatNodes.size();
- if (size == 0)
- return NodeImpl.EMPTY_STRING;
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < size; i++) {
- IStructuredDocumentRegion flatNode = (IStructuredDocumentRegion) this.flatNodes.elementAt(i);
- if (flatNode == null)
- continue;
- buffer.append(flatNode.getText());
- }
- return buffer.toString();
- }
-
- /**
- */
- public String getText(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public String getText(String context) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public int getTextEnd() {
- return getEnd();
- }
-
- /**
- */
- public int getTextEndOffset() {
- return getTextEnd();
- }
-
- public int getTextEndOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- * The text length is equal to length if there is no white space at the
- * end of a region. Otherwise it is smaller than length.
- */
- public int getTextLength() {
- return (getTextEnd() - getStart());
- }
-
- /**
- */
- public String getType() {
- return "StructuredDocumentRegionContainer";//$NON-NLS-1$
- }
-
- /**
- */
- void insertStructuredDocumentRegion(IStructuredDocumentRegion flatNode, int index) {
- if (flatNode == null)
- return;
- if (index < 0)
- return;
- int size = this.flatNodes.size();
- if (index > size)
- return;
- if (index == size) {
- appendStructuredDocumentRegion(flatNode);
- return;
- }
- this.flatNodes.insertElementAt(flatNode, index);
- }
-
- public boolean isEnded() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- IStructuredDocumentRegion removeStructuredDocumentRegion(int index) {
- if (index < 0 || index >= this.flatNodes.size())
- return null;
- IStructuredDocumentRegion flatNode = (IStructuredDocumentRegion) this.flatNodes.elementAt(index);
- this.flatNodes.removeElementAt(index);
- return flatNode;
- }
-
- /**
- */
- IStructuredDocumentRegion removeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (oldStructuredDocumentRegion == null)
- return null;
- int size = this.flatNodes.size();
- for (int i = 0; i < size; i++) {
- IStructuredDocumentRegion flatNode = (IStructuredDocumentRegion) this.flatNodes.elementAt(i);
- if (flatNode == oldStructuredDocumentRegion) {
- this.flatNodes.removeElementAt(i);
- return flatNode;
- }
- }
- return null; // not found
- }
-
- /**
- */
- IStructuredDocumentRegion replaceStructuredDocumentRegion(IStructuredDocumentRegion flatNode, int index) {
- if (flatNode == null)
- return removeStructuredDocumentRegion(index);
- if (index < 0 || index >= this.flatNodes.size())
- return null;
- IStructuredDocumentRegion oldStructuredDocumentRegion = (IStructuredDocumentRegion) this.flatNodes.elementAt(index);
- this.flatNodes.setElementAt(flatNode, index);
- return oldStructuredDocumentRegion;
- }
-
- public boolean sameAs(IStructuredDocumentRegion region, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public boolean sameAs(ITextRegion region, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public boolean sameAs(ITextRegion oldRegion, IStructuredDocumentRegion documentRegion, ITextRegion newRegion, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setEnded(boolean hasEnd) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setLength(int newLength) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setNext(IStructuredDocumentRegion newNext) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setParentDocument(IStructuredDocument document) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setPrevious(IStructuredDocumentRegion newPrevious) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public void setRegions(ITextRegionList embeddedRegions) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setStart(int newStart) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append('{');
- int count = getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- if (i != 0)
- buffer.append(',');
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion(i);
- if (flatNode == null)
- buffer.append("null");//$NON-NLS-1$
- else
- buffer.append(flatNode.toString());
- }
- buffer.append('}');
- return buffer.toString();
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion flatnode, String changes, int start, int end) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
-
- public boolean isDeleted() {
- // if someone "gets" these temp regions by
- // accident, we'll always return "deleted".
- return true;
- }
-
-
- public void setDeleted(boolean deleted) {
- // do nothing
-
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionManagementException.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionManagementException.java
deleted file mode 100644
index 90fecbe615..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionManagementException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-
-/**
- */
-public class StructuredDocumentRegionManagementException extends RuntimeException {
-
- /**
- * Default <code>serialVersionUID</code>
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * StructuredDocumentRegionManagementException constructor
- */
- public StructuredDocumentRegionManagementException() {
- super("IStructuredDocumentRegion management failed.");//$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionProxy.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionProxy.java
deleted file mode 100644
index 531226086a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionProxy.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-
-
-class StructuredDocumentRegionProxy implements IStructuredDocumentRegion {
- private IStructuredDocumentRegion flatNode = null;
- private int length = 0;
-
- private int offset = 0;
-
- /**
- */
- StructuredDocumentRegionProxy() {
- super();
- }
-
- /**
- */
- StructuredDocumentRegionProxy(int offset, int length) {
- super();
-
- this.offset = offset;
- this.length = length;
- }
-
- /**
- */
- StructuredDocumentRegionProxy(int offset, int length, IStructuredDocumentRegion flatNode) {
- super();
-
- this.offset = offset;
- this.length = length;
- this.flatNode = flatNode;
- if (this.flatNode != null)
- this.offset -= this.flatNode.getStart();
- }
-
- public void addRegion(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjust(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustLength(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustStart(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public void adjustTextLength(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public boolean containsOffset(int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public boolean containsOffset(ITextRegion region, int i) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void equatePositions(ITextRegion region) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
-
- }
-
- public ITextRegion getDeepestRegionAtCharacterOffset(int offset) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public int getEnd() {
- int flatNodeOffset = 0;
- if (this.flatNode != null)
- flatNodeOffset = this.flatNode.getStart();
- return flatNodeOffset + this.offset + this.length;
- }
-
- public int getEndOffset() {
- return getEnd();
- }
-
- public int getEndOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public ITextRegion getFirstRegion() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public String getFullText() {
- return getText();
- }
-
- public String getFullText(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public String getFullText(String context) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public ITextRegion getLastRegion() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public int getLength() {
- return this.length;
- }
-
- public IStructuredDocumentRegion getNext() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public int getNumberOfRegions() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- int getOffset() {
- int flatNodeOffset = 0;
- if (this.flatNode != null)
- flatNodeOffset = this.flatNode.getStart();
- return flatNodeOffset + this.offset;
- }
-
- /**
- */
- public ITextRegionContainer getParent() {
- return null;
- }
-
- public IStructuredDocument getParentDocument() {
- return null;
- // throw new Error("intentionally not implemented since should never
- // be called");
- }
-
- public IStructuredDocumentRegion getPrevious() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public ITextRegion getRegionAtCharacterOffset(int offset) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public ITextRegionList getRegions() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public int getStart() {
- int flatNodeOffset = 0;
- if (this.flatNode != null)
- flatNodeOffset = this.flatNode.getStart();
- return flatNodeOffset + this.offset;
- }
-
- /**
- */
- public int getStartOffset() {
- return getStart();
- }
-
- public int getStartOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public IStructuredDocument getStructuredDocument() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- IStructuredDocumentRegion getStructuredDocumentRegion() {
- return this.flatNode;
- }
-
- /**
- */
- public String getText() {
- if (this.flatNode == null)
- return NodeImpl.EMPTY_STRING;
- String text = this.flatNode.getText();
- if (text == null)
- return NodeImpl.EMPTY_STRING;
- int end = this.offset + this.length;
- return text.substring(this.offset, end);
- }
-
- /**
- */
- public String getText(ITextRegion aRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public String getText(String context) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public int getTextEnd() {
- return getEnd();
- }
-
- /**
- */
- public int getTextEndOffset() {
- return getTextEnd();
- }
-
- public int getTextEndOffset(ITextRegion containedRegion) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- * The text length is equal to length if there is no white space at the
- * end of a region. Otherwise it is smaller than length.
- */
- public int getTextLength() {
- return getLength();
- }
-
- /**
- */
- public String getType() {
- return "StructuredDocumentRegionProxy";//$NON-NLS-1$
- }
-
- public boolean isDeleted() {
- // I'll assume never really needed here
- return true;
- }
-
- public boolean isEnded() {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public boolean sameAs(IStructuredDocumentRegion region, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- public boolean sameAs(ITextRegion region, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public boolean sameAs(ITextRegion oldRegion, IStructuredDocumentRegion documentRegion, ITextRegion newRegion, int shift) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setDeleted(boolean deleted) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setEnded(boolean hasEnd) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- * had to make public, due to API transition.
- */
- public void setLength(int length) {
- this.length = length;
- }
-
- public void setNext(IStructuredDocumentRegion newNext) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- void setOffset(int offset) {
- this.offset = offset;
- if (this.flatNode != null)
- this.offset -= this.flatNode.getStart();
- }
-
- public void setParentDocument(IStructuredDocument document) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setPrevious(IStructuredDocumentRegion newPrevious) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setRegions(ITextRegionList embeddedRegions) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- public void setStart(int newStart) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-
- /**
- */
- void setStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (this.flatNode != null)
- this.offset += this.flatNode.getStart();
- this.flatNode = flatNode;
- if (this.flatNode != null)
- this.offset -= flatNode.getStart();
- }
-
- /**
- * toString method
- *
- * @return java.lang.String
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append('[');
- buffer.append(getStart());
- buffer.append(',');
- buffer.append(getEnd());
- buffer.append(']');
- buffer.append('(');
- if (this.flatNode != null)
- buffer.append(this.flatNode.toString());
- else
- buffer.append("null");//$NON-NLS-1$
- buffer.append(')');
- return buffer.toString();
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion flatnode, String changes, int start, int end) {
- throw new Error("intentionally not implemented since should never be called"); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionUtil.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionUtil.java
deleted file mode 100644
index 84a378bea4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/StructuredDocumentRegionUtil.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-/**
- * Provides convenient functions to handle IStructuredDocumentRegion and
- * ITextRegion.
- */
-class StructuredDocumentRegionUtil {
-
- /**
- * Extracts contents enclosed with quotes. Quotes may be double or single.
- */
- static String getAttrValue(IStructuredDocumentRegion flatNode, ITextRegion region) {
- if (region == null)
- return null;
- if (flatNode == null)
- return null;
- String value = flatNode.getText(region);
- if (value == null)
- return null;
- int length = value.length();
- if (length == 0)
- return value;
- char firstChar = value.charAt(0);
- if (firstChar == '"' || firstChar == '\'') {
- if (length == 1)
- return null;
- if (value.charAt(length - 1) == firstChar)
- length--;
- return value.substring(1, length);
- }
- return value;
- }
-
- /**
- * Extracts the name without heading '&' and tailing ';'.
- */
- static String getEntityRefName(IStructuredDocumentRegion flatNode, ITextRegion region) {
- if (region == null)
- return null;
- String ref = flatNode.getText(region);
- int length = ref.length();
- if (length == 0)
- return ref;
- int offset = 0;
- if (ref.charAt(0) == '&')
- offset = 1;
- if (ref.charAt(length - 1) == ';')
- length--;
- if (offset >= length)
- return null;
- return ref.substring(offset, length);
- }
-
- /**
- * Returns the first region.
- */
- static ITextRegion getFirstRegion(IStructuredDocumentRegion flatNode) {
- if(flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy)flatNode).getStructuredDocumentRegion();
- }
- if (flatNode == null)
- return null;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null || regions.size() == 0)
- return null;
- return regions.get(0);
- }
-
- /**
- * Returns the type of the first region.
- */
- static String getFirstRegionType(IStructuredDocumentRegion flatNode) {
- if(flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy)flatNode).getStructuredDocumentRegion();
- }
- if (flatNode == null)
- return DOMRegionContext.UNDEFINED;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null || regions.size() == 0)
- return DOMRegionContext.UNDEFINED;
- ITextRegion region = regions.get(0);
- return region.getType();
- }
-
- /**
- */
- static IStructuredDocumentRegion getFirstStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return null;
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- flatNode = ((StructuredDocumentRegionContainer) flatNode).getFirstStructuredDocumentRegion();
- }
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy) flatNode).getStructuredDocumentRegion();
- }
- return flatNode;
- }
-
- /**
- * Returns the last region.
- */
- static ITextRegion getLastRegion(IStructuredDocumentRegion flatNode) {
- if(flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy)flatNode).getStructuredDocumentRegion();
- }
- if (flatNode == null)
- return null;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null || regions.size() == 0)
- return null;
- return regions.get(regions.size() - 1);
- }
-
- /**
- * Returns the type of the first region.
- */
- static String getLastRegionType(IStructuredDocumentRegion flatNode) {
- if(flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy)flatNode).getStructuredDocumentRegion();
- }
- if (flatNode == null)
- return DOMRegionContext.UNDEFINED;
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null || regions.size() == 0)
- return DOMRegionContext.UNDEFINED;
- ITextRegion region = regions.get(regions.size() - 1);
- return region.getType();
- }
-
- /**
- */
- static IStructuredDocumentRegion getLastStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return null;
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- flatNode = ((StructuredDocumentRegionContainer) flatNode).getLastStructuredDocumentRegion();
- }
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy) flatNode).getStructuredDocumentRegion();
- }
- return flatNode;
- }
-
- /**
- */
- static IStructuredDocumentRegion getStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return null;
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- flatNode = ((StructuredDocumentRegionProxy) flatNode).getStructuredDocumentRegion();
- }
- return flatNode;
- }
-
- StructuredDocumentRegionUtil() {
- super();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TagAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TagAdapter.java
deleted file mode 100644
index f49ff7b959..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TagAdapter.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-
-/**
- */
-public interface TagAdapter extends INodeAdapter {
-
- /**
- */
- String getEndTag(IDOMElement element);
-
- /**
- */
- String getStartTag(IDOMElement element);
-
- /**
- */
- boolean isEndTag();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TextImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TextImpl.java
deleted file mode 100644
index d1d2c247d6..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TextImpl.java
+++ /dev/null
@@ -1,1192 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- * Balazs Banfai: Bug 154737 getUserData/setUserData support for Node
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=154737
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
-import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-import org.w3c.dom.UserDataHandler;
-
-/**
- * TextImpl class
- */
-public class TextImpl extends CharacterDataImpl implements IDOMText {
-
- /**
- */
- private class StringPair {
- private String fFirst = null;
- private String fSecond = null;
-
- StringPair(String first, String second) {
- this.fFirst = first;
- this.fSecond = second;
- }
-
- String getFirst() {
- return this.fFirst;
- }
-
- String getSecond() {
- return this.fSecond;
- }
- }
-
- private String fSource = null;
-
- /**
- * TextImpl constructor
- */
- protected TextImpl() {
- super();
- }
-
- /**
- * TextImpl constructor
- *
- * @param that
- * TextImpl
- */
- protected TextImpl(TextImpl that) {
- super(that);
-
- if (that != null) {
- this.fSource = that.getSource();
- }
- }
-
- /**
- * appendData method
- *
- * @param arg
- * java.lang.String
- */
- public void appendData(String arg) throws DOMException {
- if (arg == null || arg.length() == 0)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- String newSource = getSource(arg);
- if (newSource == null)
- return;
- String source = getSource();
- if (source != null)
- setTextSource(source + newSource);
- else
- setTextSource(newSource);
- }
-
- /**
- */
- IStructuredDocumentRegion appendStructuredDocumentRegion(IStructuredDocumentRegion newStructuredDocumentRegion) {
- if (newStructuredDocumentRegion == null)
- return null;
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null) {
- setStructuredDocumentRegion(newStructuredDocumentRegion);
- return newStructuredDocumentRegion;
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- container.appendStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- else {
- StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
- container.appendStructuredDocumentRegion(flatNode);
- container.appendStructuredDocumentRegion(newStructuredDocumentRegion);
- setStructuredDocumentRegion(container);
- }
-
- return newStructuredDocumentRegion;
- }
-
- /**
- * appendText method
- *
- * @param text
- * org.w3c.dom.Text
- */
- public void appendText(Text newText) {
- if (newText == null)
- return;
-
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- TextImpl text = (TextImpl) newText;
- String newSource = text.getSource();
- if (newSource == null || newSource.length() == 0)
- return;
- String source = getSource();
- if (source != null)
- setTextSource(source + newSource);
- else
- setTextSource(newSource);
- }
-
- /**
- * cloneNode method
- *
- * @return org.w3c.dom.Node
- * @param deep
- * boolean
- */
- public Node cloneNode(boolean deep) {
- TextImpl cloned = new TextImpl(this);
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * deleteData method
- *
- * @param offset
- * int
- * @param count
- * int
- */
- public void deleteData(int offset, int count) throws DOMException {
- if (count == 0)
- return;
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- if (count < 0 || offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String source = getSource();
- if (source == null || source.length() == 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- StringPair pair = substringSourceExcluded(source, offset, count);
- if (pair == null)
- return;
- source = null;
- String first = pair.getFirst();
- if (first != null)
- source = first;
- String second = pair.getSecond();
- if (second != null) {
- if (source != null)
- source += second;
- else
- source = second;
- }
- if (source == null)
- source = NodeImpl.EMPTY_STRING; // delete all
- setTextSource(source);
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public String getData() throws DOMException {
- if (this.fSource != null)
- return getData(this.fSource);
- String data = super.getData();
- if (data != null)
- return data;
- return getData(getStructuredDocumentRegion());
- }
-
- /**
- */
- private String getData(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return NodeImpl.EMPTY_STRING;
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int length = container.getLength();
- if (length < 16)
- length = 16; // default
- StringBuffer buffer = new StringBuffer(length);
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- String data = getData(content);
- if (data == null)
- continue;
- buffer.append(data);
- }
- return buffer.toString();
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- return flatNode.getText();
- }
-
- ITextRegion region = StructuredDocumentRegionUtil.getFirstRegion(flatNode);
- if (region != null) {
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_ENTITY_REFERENCE || regionType == DOMRegionContext.XML_CHAR_REFERENCE) {
- String name = StructuredDocumentRegionUtil.getEntityRefName(flatNode, region);
- if (name != null) {
- DocumentImpl document = (DocumentImpl) getOwnerDocument();
- if (document != null) {
- String value = document.getCharValue(name);
- if (value != null)
- return value;
- }
- }
- }
- }
-
- return flatNode.getText();
- }
-
- /**
- * Returns data for the source
- */
- private String getData(String source) {
- if (source == null)
- return null;
- StringBuffer buffer = null;
- int offset = 0;
- int length = source.length();
- int ref = source.indexOf('&');
- while (ref >= 0) {
- int end = source.indexOf(';', ref + 1);
- if (end > ref + 1) {
- String name = source.substring(ref + 1, end);
- String value = getCharValue(name);
- if (value != null) {
- if (buffer == null)
- buffer = new StringBuffer(length);
- if (ref > offset)
- buffer.append(source.substring(offset, ref));
- buffer.append(value);
- offset = end + 1;
- ref = end;
- }
- }
- ref = source.indexOf('&', ref + 1);
- }
- if (buffer == null)
- return source;
- if (length > offset)
- buffer.append(source.substring(offset));
- return buffer.toString();
- }
-
- /**
- * getFirstStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getFirstStructuredDocumentRegion() {
- return StructuredDocumentRegionUtil.getFirstStructuredDocumentRegion(getStructuredDocumentRegion());
- }
-
- /**
- * getLastStructuredDocumentRegion method
- *
- */
- public IStructuredDocumentRegion getLastStructuredDocumentRegion() {
- return StructuredDocumentRegionUtil.getLastStructuredDocumentRegion(getStructuredDocumentRegion());
- }
-
- /**
- * getNodeName method
- *
- * @return java.lang.String
- */
- public String getNodeName() {
- return "#text";//$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Node#getNodeType()
- */
- public short getNodeType() {
- return TEXT_NODE;
- }
-
- /**
- */
- public String getSource() {
- if (this.fSource != null)
- return this.fSource;
- String data = super.getData();
- if (data != null && data.length() > 0) {
- String source = getSource(data);
- if (source != null)
- return source;
- }
- return super.getSource();
- }
-
- /**
- * Returns source for the data
- */
- private String getSource(String data) {
- if (data == null)
- return null;
- IDOMModel model = getModel();
- if (model == null)
- return null; // error
- ISourceGenerator generator = model.getGenerator();
- if (generator == null)
- return null; // error
- return generator.generateTextData(this, data);
- }
-
- /**
- */
- String getTextSource() {
- return this.fSource;
- }
-
- /**
- */
- public String getValueSource() {
- return getSource();
- }
-
- /**
- */
- boolean hasStructuredDocumentRegion(IStructuredDocumentRegion askedStructuredDocumentRegion) {
- if (askedStructuredDocumentRegion == null)
- return false;
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return false;
-
- if (flatNode == askedStructuredDocumentRegion)
- return true;
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- if (proxy.getStructuredDocumentRegion() == askedStructuredDocumentRegion)
- return true;
- return false;
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue;
- if (content == askedStructuredDocumentRegion)
- return true;
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == askedStructuredDocumentRegion)
- return true;
- }
- }
- return false;
- }
-
- return false;
- }
-
- /**
- * insertData method
- *
- * @param offset
- * int
- * @param arg
- * java.lang.String
- */
- public void insertData(int offset, String arg) throws DOMException {
- if (arg == null || arg.length() == 0)
- return;
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- if (offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String source = getSource();
- if (source == null || source.length() == 0) {
- if (offset > 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- source = getSource(arg);
- if (source != null)
- setTextSource(source);
- return;
- }
-
- StringPair pair = substringSourceExcluded(source, offset, 0);
- if (pair == null)
- return; // error
- StringBuffer buffer = new StringBuffer(source.length() + arg.length());
- String first = pair.getFirst();
- if (first != null)
- buffer.append(first);
- source = getSource(arg);
- if (source != null)
- buffer.append(source);
- String second = pair.getSecond();
- if (second != null)
- buffer.append(second);
- setTextSource(buffer.toString());
- }
-
- /**
- */
- IStructuredDocumentRegion insertStructuredDocumentRegion(IStructuredDocumentRegion newStructuredDocumentRegion, IStructuredDocumentRegion nextStructuredDocumentRegion) {
- if (newStructuredDocumentRegion == null)
- return null;
- if (nextStructuredDocumentRegion == null)
- return appendStructuredDocumentRegion(newStructuredDocumentRegion);
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return null; // error
-
- if (flatNode == nextStructuredDocumentRegion) {
- StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
- container.appendStructuredDocumentRegion(newStructuredDocumentRegion);
- container.appendStructuredDocumentRegion(flatNode);
- setStructuredDocumentRegion(container);
- return newStructuredDocumentRegion;
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == nextStructuredDocumentRegion) {
- container.insertStructuredDocumentRegion(newStructuredDocumentRegion, i);
- return newStructuredDocumentRegion;
- }
- }
- return null; // error
- }
-
- return null; // error
- }
-
- /**
- * insertText method
- *
- * @param text
- * org.w3c.dom.Text
- * @param offset
- * int
- */
- public void insertText(Text newText, int offset) throws DOMException {
- if (newText == null)
- return;
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- TextImpl text = (TextImpl) newText;
- String newSource = text.getSource();
- if (newSource == null || newSource.length() == 0)
- return;
- if (offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String source = getSource();
- if (source == null || source.length() == 0) {
- if (offset > 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- setTextSource(newSource);
- return;
- }
-
- StringPair pair = substringSourceExcluded(source, offset, 0);
- if (pair == null)
- return; // error
- StringBuffer buffer = new StringBuffer(source.length() + newSource.length());
- String first = pair.getFirst();
- if (first != null)
- buffer.append(first);
- buffer.append(newSource);
- String second = pair.getSecond();
- if (second != null)
- buffer.append(second);
- setTextSource(buffer.toString());
- }
-
- /**
- * isCDATAContent method
- *
- * @return boolean
- */
- public boolean isCDATAContent() {
- Node parent = getParentNode();
- if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE)
- return false;
- ElementImpl element = (ElementImpl) parent;
- return element.isCDATAContainer();
- }
-
- /**
- */
- public boolean isInvalid() {
- return isInvalid(getStructuredDocumentRegion());
- }
-
- /**
- */
- private boolean isInvalid(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return false;
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (isInvalid(content))
- return true;
- }
- return false;
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- return isInvalid(proxy.getStructuredDocumentRegion());
- }
-
- String regionType = StructuredDocumentRegionUtil.getFirstRegionType(flatNode);
- if (regionType != DOMRegionContext.XML_CONTENT && isNotNestedContent(regionType) && regionType != DOMRegionContext.XML_ENTITY_REFERENCE && regionType != DOMRegionContext.XML_CHAR_REFERENCE && regionType != DOMRegionContext.BLOCK_TEXT && regionType != DOMRegionContext.WHITE_SPACE) {
- return true;
- }
-
- return false;
- }
-
- protected boolean isNotNestedContent(String regionType) {
- boolean result = true;
- return result;
- }
-
- /**
- */
- boolean isSharingStructuredDocumentRegion(IStructuredDocumentRegion sharedStructuredDocumentRegion) {
- if (sharedStructuredDocumentRegion == null)
- return false;
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return false;
-
- if (flatNode == sharedStructuredDocumentRegion)
- return false;
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- if (proxy.getStructuredDocumentRegion() == sharedStructuredDocumentRegion)
- return true;
- return false;
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue;
- if (content == sharedStructuredDocumentRegion)
- return false;
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == sharedStructuredDocumentRegion)
- return true;
- }
- }
- return false;
- }
-
- return false;
- }
-
- /**
- * Returns whether this text node contains <a
- * href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>
- * element content whitespace</a>, often abusively called "ignorable
- * whitespace". The text node is determined to contain whitespace in
- * element content during the load of the document or if validation occurs
- * while using <code>Document.normalizeDocument()</code>.
- *
- * @see DOM Level 3
- */
- public boolean isElementContentWhitespace() {
- return isWhitespace();
- }
-
- /**
- */
- public boolean isWhitespace() {
- String data = getData();
- if (data == null)
- return true;
- int length = data.length();
- for (int i = 0; i < length; i++) {
- if (!Character.isWhitespace(data.charAt(i)))
- return false;
- }
- return true;
- }
-
- /**
- */
- IStructuredDocumentRegion removeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (oldStructuredDocumentRegion == null)
- return null;
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return null; // error
-
- if (flatNode == oldStructuredDocumentRegion) {
- setStructuredDocumentRegion(null);
- return oldStructuredDocumentRegion;
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- // removed with proxy
- setStructuredDocumentRegion(null);
- return oldStructuredDocumentRegion;
- }
- return null; // error
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == oldStructuredDocumentRegion) {
- container.removeStructuredDocumentRegion(i);
- if (container.getStructuredDocumentRegionCount() == 1) {
- // get back to single IStructuredDocumentRegion
- setStructuredDocumentRegion(container.getStructuredDocumentRegion(0));
- }
- return oldStructuredDocumentRegion;
- }
-
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- // removed with proxy
- container.removeStructuredDocumentRegion(i);
- if (container.getStructuredDocumentRegionCount() == 1) {
- // get back to single IStructuredDocumentRegion
- setStructuredDocumentRegion(container.getStructuredDocumentRegion(0));
- }
- return oldStructuredDocumentRegion;
- }
- }
- }
- return null; // error
- }
-
- return null; // error
- }
-
- /**
- * replaceData method
- *
- * @param offset
- * int
- * @param count
- * int
- * @param arg
- * java.lang.String
- */
- public void replaceData(int offset, int count, String arg) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- if (arg == null || arg.length() == 0) {
- deleteData(offset, count);
- return;
- }
- if (count == 0) {
- insertData(offset, arg);
- return;
- }
- if (offset < 0 || count < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String source = getSource();
- if (source == null || source.length() == 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- StringPair pair = substringSourceExcluded(source, offset, count);
- if (pair == null)
- return; // error
- StringBuffer buffer = new StringBuffer(source.length() + arg.length());
- String first = pair.getFirst();
- if (first != null)
- buffer.append(first);
- source = getSource(arg);
- if (source != null)
- buffer.append(source);
- String second = pair.getSecond();
- if (second != null)
- buffer.append(second);
- setTextSource(buffer.toString());
- }
-
- /**
- */
- IStructuredDocumentRegion replaceStructuredDocumentRegion(IStructuredDocumentRegion newStructuredDocumentRegion, IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (oldStructuredDocumentRegion == null)
- return null;
- if (newStructuredDocumentRegion == null)
- return removeStructuredDocumentRegion(oldStructuredDocumentRegion);
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null)
- return null; // error
-
- if (flatNode == oldStructuredDocumentRegion) {
- setStructuredDocumentRegion(newStructuredDocumentRegion);
- return oldStructuredDocumentRegion;
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- if (newStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- // proxy must not be nested
- setStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- else {
- proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- return oldStructuredDocumentRegion;
- }
- return null; // error
- }
-
- if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue; // error
- if (content == oldStructuredDocumentRegion) {
- container.replaceStructuredDocumentRegion(newStructuredDocumentRegion, i);
- return oldStructuredDocumentRegion;
- }
-
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- if (newStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- // proxy must not be nested
- container.replaceStructuredDocumentRegion(newStructuredDocumentRegion, i);
- }
- else {
- proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- return oldStructuredDocumentRegion;
- }
- }
- }
- return null; // error
- }
-
- return null; // error
- }
-
- /**
- */
- void resetStructuredDocumentRegions() {
- String source = getSource();
- if (source != null && source.length() > 0)
- this.fSource = source;
- super.resetStructuredDocumentRegions();
- }
-
- /**
- * getData method
- *
- * @return java.lang.String
- */
- public void setData(String data) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.fSource = null;
- super.setData(data);
- }
-
- /**
- */
- public void setSource(String source) throws InvalidCharacterException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- SourceValidator validator = new SourceValidator(this);
- if (validator.validateSource(source))
- setTextSource(source);
- }
-
- /**
- */
- void setStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- super.setStructuredDocumentRegion(flatNode);
- if (flatNode != null)
- this.fSource = null;
- }
-
- /**
- */
- public void setTextSource(String source) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- this.fSource = source;
-
- notifyValueChanged();
- }
-
- /**
- */
- public void setValueSource(String source) {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
-
- SourceValidator validator = new SourceValidator(this);
- setTextSource(validator.convertSource(source));
- }
-
- /**
- * splitText method
- *
- * @return org.w3c.dom.Text
- * @param offset
- * int
- */
- public Text splitText(int offset) throws DOMException {
- if (!isDataEditable()) {
- throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessages.NO_MODIFICATION_ALLOWED_ERR);
- }
- if (offset < 0) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int length = getLength();
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- Document document = getOwnerDocument();
- if (document == null)
- return null;
-
- String source = null;
- if (offset < length) {
- int count = length - offset;
- source = substringSource(offset, count);
- deleteData(offset, count);
- }
- TextImpl text = (TextImpl) document.createTextNode(null);
- if (source != null)
- text.setTextSource(source);
-
- Node parent = getParentNode();
- if (parent != null)
- parent.insertBefore(text, getNextSibling());
-
- return text;
- }
-
- /**
- */
- Text splitText(IStructuredDocumentRegion nextStructuredDocumentRegion) {
- if (nextStructuredDocumentRegion == null)
- return null;
-
- IStructuredDocumentRegion flatNode = getStructuredDocumentRegion();
- if (flatNode == null || !(flatNode instanceof StructuredDocumentRegionContainer))
- return null; // error
-
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- int index = 0;
- for (; index < count; index++) {
- if (container.getStructuredDocumentRegion(index) == nextStructuredDocumentRegion)
- break;
- }
- if (index >= count) {
- // this is the case nextStructuredDocumentRegion is a new
- // IStructuredDocumentRegion
- // search gap by offset
- int offset = nextStructuredDocumentRegion.getStart();
- for (index = 0; index < count; index++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(index);
- if (content == null)
- continue; // error
- if (content.getStart() >= offset)
- break;
- }
- if (index >= count)
- return null; // error
- }
- if (index == 0)
- return this; // nothing to do
-
- Document document = getOwnerDocument();
- if (document == null)
- return null; // error
- Node parent = getParentNode();
- if (parent == null)
- return null; // error
- TextImpl nextText = (TextImpl) document.createTextNode(null);
- if (nextText == null)
- return null; // error
-
- for (; index < count; count--) {
- nextText.appendStructuredDocumentRegion(container.removeStructuredDocumentRegion(index));
- }
-
- // normalize IStructuredDocumentRegion
- if (index == 1) {
- setStructuredDocumentRegion(container.getStructuredDocumentRegion(0));
- }
-
- parent.insertBefore(nextText, getNextSibling());
- return nextText;
- }
-
- /**
- * Retruns data for the range
- */
- private String substringData(String data, int offset, int count) throws DOMException {
- // sure offset and count are non-negative
- if (count == 0)
- return NodeImpl.EMPTY_STRING;
- if (data == null) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int length = data.length();
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- int end = offset + count;
- if (end > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- return data.substring(offset, end);
- }
-
- /**
- * Returns source for the range specified by: offset: data offset count:
- * data count
- */
- private String substringSource(int offset, int count) throws DOMException {
- // sure offset and count are non-negative
- if (this.fSource != null)
- return substringSource(this.fSource, offset, count);
-
- String data = super.getData();
- if (data != null && data.length() > 0) {
- data = substringData(data, offset, count);
- if (data == null)
- return NodeImpl.EMPTY_STRING;
- String source = getSource(data);
- if (source != null)
- return source;
- }
-
- return substringSource(getSource(), offset, count);
- }
-
- /**
- * Returns source for the range specified by: offset: data offset count:
- * data count
- */
- private String substringSource(String source, int offset, int count) throws DOMException {
- // sure offset and count are non-negative
- if (count == 0)
- return NodeImpl.EMPTY_STRING;
- if (source == null) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- int length = source.length();
- int end = offset + count;
-
- // find character reference
- int ref = source.indexOf('&');
- while (ref >= 0) {
- if (ref >= end)
- break;
- int refEnd = source.indexOf(';', ref + 1);
- if (refEnd > ref + 1) {
- String name = source.substring(ref + 1, refEnd);
- if (getCharValue(name) != null) {
- // found, shift for source offsets
- int refCount = refEnd - ref;
- if (ref < offset)
- offset += refCount;
- if (ref < end)
- end += refCount;
- ref = refEnd;
- }
- }
- ref = source.indexOf('&', ref + 1);
- }
-
- if (offset > length || end > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- return source.substring(offset, end);
- }
-
- /**
- * Returns sources before and after the range specified by: offset: data
- * offset count: data count
- */
- private StringPair substringSourceExcluded(String source, int offset, int count) throws DOMException {
- // sure offset and count are non-negative
- if (source == null) {
- if (offset == 0 && count == 0)
- return new StringPair(null, null);
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- int length = source.length();
- int end = offset + count;
-
- // find character reference
- int ref = source.indexOf('&');
- while (ref >= 0) {
- if (ref >= end)
- break;
- int refEnd = source.indexOf(';', ref + 1);
- if (refEnd > ref + 1) {
- String name = source.substring(ref + 1, refEnd);
- if (getCharValue(name) != null) {
- // found, shift for source offsets
- int refCount = refEnd - ref;
- if (ref < offset)
- offset += refCount;
- if (ref < end)
- end += refCount;
- ref = refEnd;
- }
- }
- ref = source.indexOf('&', ref + 1);
- }
-
- if (offset > length) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
-
- String first = (offset > 0 ? source.substring(0, offset) : null);
- String second = (end < length ? source.substring(end, length) : null);
- return new StringPair(first, second);
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Text#getWholeText()
- */
- public String getWholeText() {
- Node current = this;
- // rewind
- while (current.getPreviousSibling() != null)
- current = current.getPreviousSibling();
- // playback
- StringBuffer buffer = new StringBuffer();
- while (current != null) {
- if (current.getNodeType() == Node.TEXT_NODE || current.getNodeType() == Node.CDATA_SECTION_NODE) {
- buffer.append(current.getNodeValue());
- }
- current = current.getNextSibling();
- }
- return buffer.toString();
- }
- /**
- * Replaces the text of the current node and all logically-adjacent text
- * nodes with the specified text. All logically-adjacent text nodes are
- * removed including the current node unless it was the recipient of the
- * replacement text. <br>
- * This method returns the node which received the replacement text. The
- * returned node is:
- * <ul>
- * <li><code>null</code>, when the replacement text is the empty
- * string; </li>
- * <li>the current node, except when the current node is read-only; </li>
- * <li> a new <code>Text</code> node of the same type (
- * <code>Text</code> or <code>CDATASection</code>) as the current
- * node inserted at the location of the replacement. </li>
- * </ul>
- * <br>
- * For instance, in the above example calling
- * <code>replaceWholeText</code> on the <code>Text</code> node that
- * contains "bar" with "yo" in argument results in the following: <br>
- * Where the nodes to be removed are read-only descendants of an
- * <code>EntityReference</code>, the <code>EntityReference</code>
- * must be removed instead of the read-only nodes. If any
- * <code>EntityReference</code> to be removed has descendants that are
- * not <code>EntityReference</code>, <code>Text</code>, or
- * <code>CDATASection</code> nodes, the <code>replaceWholeText</code>
- * method must fail before performing any modification of the document,
- * raising a <code>DOMException</code> with the code
- * <code>NO_MODIFICATION_ALLOWED_ERR</code>. <br>
- * For instance, in the example below calling
- * <code>replaceWholeText</code> on the <code>Text</code> node that
- * contains "bar" fails, because the <code>EntityReference</code> node
- * "ent" contains an <code>Element</code> node which cannot be removed.
- *
- * @param content
- * The content of the replacing <code>Text</code> node.
- * @return The <code>Text</code> node created with the specified
- * content.
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if one of the
- * <code>Text</code> nodes being replaced is readonly.
- * @see DOM Level 3
- */
- public Text replaceWholeText(String content)
- throws DOMException {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not implemented"); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/UserData.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/UserData.java
deleted file mode 100644
index 695ff71f10..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/UserData.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.w3c.dom.Node;
-
-/**
- * Collects user data associated to a Node.
- *
- */
-final class UserData {
-
- private static UserData fInstance;
-
- /**
- * Mapping of a Node to its User Data table (represented by a Map)
- */
- private Map fData;
-
- private UserData() {
- fData = new WeakHashMap(0);
- }
-
- public static synchronized UserData getInstance() {
- if (fInstance == null)
- fInstance = new UserData();
- return fInstance;
- }
-
- /**
- * Get the user data table associated with <code>node</code>.
- *
- * @param node the node
- * @return the user data table associated with the <code>node</code>
- */
- public synchronized Map getUserDataTable(Node node) {
- if (fData.containsKey(node))
- return (Map) fData.get(node);
- Map table = new HashMap();
- fData.put(node, table);
- return table;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLGeneratorImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLGeneratorImpl.java
deleted file mode 100644
index 17c7eb9e03..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLGeneratorImpl.java
+++ /dev/null
@@ -1,735 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementRegistry;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLCharEntity;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-
-/**
- */
-public class XMLGeneratorImpl implements ISourceGenerator {
- private static final String CDATA_CLOSE = "]]>";//$NON-NLS-1$
- private static final String CDATA_OPEN = "<![CDATA[";//$NON-NLS-1$
- private static final String COMMENT_CLOSE = "-->";//$NON-NLS-1$
- private static final String COMMENT_OPEN = "<!--";//$NON-NLS-1$
- private static final String DOCTYPE_OPEN = "<!DOCTYPE";//$NON-NLS-1$
- private static final String EMPTY_CLOSE = " />";//$NON-NLS-1$
- private static final String END_OPEN = "</";//$NON-NLS-1$
-
- private static XMLGeneratorImpl instance = null;
- private static final String PI_CLOSE = "?>";//$NON-NLS-1$
- private static final String PI_OPEN = "<?";//$NON-NLS-1$
- private static final String PUBLIC_ID = "PUBLIC";//$NON-NLS-1$
- private static final String SSI_PREFIX = "ssi";//$NON-NLS-1$
- //private static final String SSI_FEATURE = "SSI";//$NON-NLS-1$
- private static final String SSI_TOKEN = "#";//$NON-NLS-1$
- private static final String SYSTEM_ID = "SYSTEM";//$NON-NLS-1$
- private static final String TAG_CLOSE = ">";//$NON-NLS-1$
-
- /**
- */
- public synchronized static ISourceGenerator getInstance() {
- if (instance == null)
- instance = new XMLGeneratorImpl();
- return instance;
- }
-
- /**
- */
- //private boolean isCommentTag(XMLElement element) {
- // if (element == null) return false;
- // DocumentImpl document = (DocumentImpl)element.getOwnerDocument();
- // if (document == null) return false;
- // DocumentTypeAdapter adapter = document.getDocumentTypeAdapter();
- // if (adapter == null) return false;
- // if (!adapter.hasFeature(SSI_FEATURE)) return false;
- // String prefix = element.getPrefix();
- // return (prefix != null && prefix.equals(SSI_PREFIX));
- //}
- /**
- * Helper to modify the tag name in sub-classes
- */
- private static void setTagName(Element element, String tagName) {
- if (element == null || tagName == null)
- return;
- ((ElementImpl) element).setTagName(tagName);
- }
-
- /**
- * XMLModelGenerator constructor
- */
- private XMLGeneratorImpl() {
- super();
- }
-
- /**
- */
- public String generateAttrName(Attr attr) {
- if (attr == null)
- return null;
- String attrName = attr.getName();
- if (attrName == null)
- return null;
- if (attrName.startsWith(JSPTag.TAG_OPEN)) {
- if (!attrName.endsWith(JSPTag.TAG_CLOSE)) {
- // close JSP
- return (attrName + JSPTag.TAG_CLOSE);
- }
- }
- if (((IDOMAttr) attr).isGlobalAttr() && CMNodeUtil.getAttributeDeclaration(attr) != null) {
- switch (getAttrNameCase(attr)) {
- case DocumentTypeAdapter.UPPER_CASE :
- attrName = attrName.toUpperCase();
- break;
- case DocumentTypeAdapter.LOWER_CASE :
- attrName = attrName.toLowerCase();
- break;
- default :
- // ASIS_CASE
- break;
- }
- }
- return attrName;
- }
-
- /**
- */
- public String generateAttrValue(Attr attr) {
- return generateAttrValue(attr, (char) 0); // no quote preference
- }
-
- /**
- */
- public String generateAttrValue(Attr attr, char quote) {
- if (attr == null)
- return null;
- String name = attr.getName();
- SourceValidator validator = new SourceValidator(attr);
- String value = validator.convertSource(((IDOMNode) attr).getValueSource());
- if (value == null || value.length() == 0) {
- if (name != null && name.startsWith(JSPTag.TAG_OPEN))
- return null;
- if (isBooleanAttr(attr)) {
- if (((AttrImpl) attr).isXMLAttr()) {
- // generate the name as value
- value = attr.getName();
- } else {
- // not to generate '=' and value for HTML boolean
- return null;
- }
- }
- }
- return generateAttrValue(value, quote);
- }
-
- /**
- */
- public String generateAttrValue(String value, char quote) {
- // assume the valid is already validated not to include both quotes
- if (quote == '"') {
- if ((value != null) && (value.indexOf('"') >= 0))
- quote = '\''; // force
- } else if (quote == '\'') {
- if ((value != null) && (value.indexOf('\'') >= 0))
- quote = '"'; // force
- } else { // no preference
- if ((value != null) && (value.indexOf('"') < 0))
- quote = '"';
- else
- quote = '\'';
- }
-
- int length = (value == null ? 0 : value.length());
- StringBuffer buffer = new StringBuffer(length + 2);
- buffer.append(quote);
- if (value != null)
- buffer.append(value);
- buffer.append(quote);
- return buffer.toString();
- }
-
- /**
- * generateCDATASection method
- *
- * @return java.lang.String
- * @param comment
- * org.w3c.dom.CDATASection
- */
- public String generateCDATASection(CDATASection cdata) {
- if (cdata == null)
- return null;
-
- String data = cdata.getData();
- int length = (data != null ? data.length() : 0);
- StringBuffer buffer = new StringBuffer(length + 16);
- buffer.append(CDATA_OPEN);
- if (data != null)
- buffer.append(data);
- buffer.append(CDATA_CLOSE);
- return buffer.toString();
- }
-
- /**
- * generateChild method
- *
- * @return java.lang.String
- * @param org.w3c.dom.Node
- */
- public String generateChild(Node parentNode) {
- if (parentNode == null)
- return null;
- if (!parentNode.hasChildNodes())
- return null;
-
- StringBuffer buffer = new StringBuffer();
- for (Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
- String childSource = generateSource(child);
- if (childSource != null)
- buffer.append(childSource);
- }
- return buffer.toString();
- }
-
- /**
- */
- public String generateCloseTag(Node node) {
- if (node == null)
- return null;
-
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE : {
- ElementImpl element = (ElementImpl) node;
- if (element.isCommentTag()) {
- if (element.isJSPTag())
- return JSPTag.COMMENT_CLOSE;
- return COMMENT_CLOSE;
- }
- if (element.isJSPTag())
- return JSPTag.TAG_CLOSE;
- if (element.isEmptyTag())
- return EMPTY_CLOSE;
- return TAG_CLOSE;
- }
- case Node.COMMENT_NODE : {
- CommentImpl comment = (CommentImpl) node;
- if (comment.isJSPTag())
- return JSPTag.COMMENT_CLOSE;
- return COMMENT_CLOSE;
- }
- case Node.DOCUMENT_TYPE_NODE :
- return TAG_CLOSE;
- case Node.PROCESSING_INSTRUCTION_NODE :
- return PI_CLOSE;
- case Node.CDATA_SECTION_NODE :
- return CDATA_CLOSE;
- default :
- break;
- }
-
- return null;
- }
-
- /**
- * generateComment method
- *
- * @return java.lang.String
- * @param comment
- * org.w3c.dom.Comment
- */
- public String generateComment(Comment comment) {
- if (comment == null)
- return null;
-
- String data = comment.getData();
- int length = (data != null ? data.length() : 0);
- StringBuffer buffer = new StringBuffer(length + 8);
- CommentImpl impl = (CommentImpl) comment;
- if (!impl.isJSPTag())
- buffer.append(COMMENT_OPEN);
- else
- buffer.append(JSPTag.COMMENT_OPEN);
- if (data != null)
- buffer.append(data);
- if (!impl.isJSPTag())
- buffer.append(COMMENT_CLOSE);
- else
- buffer.append(JSPTag.COMMENT_CLOSE);
- return buffer.toString();
- }
-
- /**
- * generateDoctype method
- *
- * @return java.lang.String
- * @param docType
- * org.w3c.dom.DocumentType
- */
- public String generateDoctype(DocumentType docType) {
- if (docType == null)
- return null;
-
- String name = docType.getName();
- int length = (name != null ? name.length() : 0);
- StringBuffer buffer = new StringBuffer(length + 16);
- buffer.append(DOCTYPE_OPEN);
- buffer.append(' ');
- if (name != null)
- buffer.append(name);
- DocumentTypeImpl dt = (DocumentTypeImpl) docType;
- String publicID = dt.getPublicId();
- String systemID = dt.getSystemId();
- if (publicID != null) {
- buffer.append(' ');
- buffer.append(PUBLIC_ID);
- buffer.append(' ');
- buffer.append('"');
- buffer.append(publicID);
- buffer.append('"');
- if (systemID != null) {
- buffer.append(' ');
- buffer.append('"');
- buffer.append(systemID);
- buffer.append('"');
- }
- } else {
- if (systemID != null) {
- buffer.append(' ');
- buffer.append(SYSTEM_ID);
- buffer.append(' ');
- buffer.append('"');
- buffer.append(systemID);
- buffer.append('"');
- }
- }
- buffer.append('>');
- return buffer.toString();
- }
-
- /**
- * generateElement method
- *
- * @return java.lang.String
- * @param element
- * Element
- */
- public String generateElement(Element element) {
- if (element == null)
- return null;
-
- // if empty tag is preferrable, generate as empty tag
- ElementImpl impl = (ElementImpl) element;
- if (impl.preferEmptyTag())
- impl.setEmptyTag(true);
-
- StringBuffer buffer = new StringBuffer();
- String startTag = generateStartTag(element);
- if (startTag != null)
- buffer.append(startTag);
- String child = generateChild(element);
- if (child != null)
- buffer.append(child);
- String endTag = generateEndTag(element);
- if (endTag != null)
- buffer.append(endTag);
- return buffer.toString();
- }
-
- /**
- * generateEndTag method
- *
- * @return java.lang.String
- * @param element
- * org.w3c.dom.Element
- */
- public String generateEndTag(Element element) {
- if (element == null)
- return null;
-
- ElementImpl impl = (ElementImpl) element;
-
- // first check if tag adapter exists
- TagAdapter adapter = (TagAdapter) impl.getExistingAdapter(TagAdapter.class);
- if (adapter != null) {
- String endTag = adapter.getEndTag(impl);
- if (endTag != null)
- return endTag;
- }
-
- if (impl.isEmptyTag())
- return null;
- if (!impl.isContainer())
- return null;
- if (impl.isJSPTag())
- return JSPTag.TAG_CLOSE;
-
- String tagName = generateTagName(element);
- int length = (tagName != null ? tagName.length() : 0);
- StringBuffer buffer = new StringBuffer(length + 4);
- buffer.append(END_OPEN);
- if (tagName != null)
- buffer.append(tagName);
- buffer.append('>');
- return buffer.toString();
- }
-
- /**
- * generateEntityRef method
- *
- * @return java.lang.String
- * @param entityRef
- * org.w3c.dom.EntityReference
- */
- public String generateEntityRef(EntityReference entityRef) {
- if (entityRef == null)
- return null;
-
- String name = entityRef.getNodeName();
- int length = (name != null ? name.length() : 0);
- StringBuffer buffer = new StringBuffer(length + 4);
- buffer.append('&');
- if (name != null)
- buffer.append(name);
- buffer.append(';');
- return buffer.toString();
- }
-
- /**
- * generatePI method
- *
- * @return java.lang.String
- * @param pi
- * org.w3c.dom.ProcessingInstruction
- */
- public String generatePI(ProcessingInstruction pi) {
- if (pi == null)
- return null;
-
- String target = pi.getTarget();
- String data = pi.getData();
- int length = (target != null ? target.length() : 0);
- if (data != null)
- length += data.length();
- StringBuffer buffer = new StringBuffer(length + 8);
- buffer.append(PI_OPEN);
- if (target != null)
- buffer.append(target);
- buffer.append(' ');
- if (data != null)
- buffer.append(data);
- buffer.append(PI_CLOSE);
- return buffer.toString();
- }
-
- /**
- * generateSource method
- *
- * @return java.lang.String
- * @param node
- * org.w3c.dom.Node
- */
- public String generateSource(Node node) {
- switch (node.getNodeType()) {
- case Node.ELEMENT_NODE :
- return generateElement((Element) node);
- case Node.TEXT_NODE :
- return generateText((Text) node);
- case Node.COMMENT_NODE :
- return generateComment((Comment) node);
- case Node.DOCUMENT_TYPE_NODE :
- return generateDoctype((DocumentType) node);
- case Node.PROCESSING_INSTRUCTION_NODE :
- return generatePI((ProcessingInstruction) node);
- case Node.CDATA_SECTION_NODE :
- return generateCDATASection((CDATASection) node);
- case Node.ENTITY_REFERENCE_NODE :
- return generateEntityRef((EntityReference) node);
- default :
- // DOCUMENT
- break;
- }
- return generateChild(node);
- }
-
- /**
- * generateStartTag method
- *
- * @return java.lang.String
- * @param element
- * Element
- */
- public String generateStartTag(Element element) {
- if (element == null)
- return null;
-
- ElementImpl impl = (ElementImpl) element;
-
- if (impl.isJSPTag()) {
- // check if JSP content type and JSP Document
- IDOMDocument document = (IDOMDocument) element.getOwnerDocument();
- if (document != null && document.isJSPType()) {
- if (document.isJSPDocument() && !impl.hasChildNodes()) {
- impl.setJSPTag(false);
- }
- } else {
- impl.setJSPTag(false);
- }
- }
- if (impl.isCommentTag() && impl.getExistingAdapter(TagAdapter.class) == null) {
- CommentElementRegistry registry = CommentElementRegistry.getInstance();
- registry.setupCommentElement(impl);
- }
-
- // first check if tag adapter exists
- TagAdapter adapter = (TagAdapter) impl.getExistingAdapter(TagAdapter.class);
- if (adapter != null) {
- String startTag = adapter.getStartTag(impl);
- if (startTag != null)
- return startTag;
- }
-
- StringBuffer buffer = new StringBuffer();
-
- if (impl.isCommentTag()) {
- if (impl.isJSPTag())
- buffer.append(JSPTag.COMMENT_OPEN);
- else
- buffer.append(COMMENT_OPEN);
- String tagName = generateTagName(element);
- if (tagName != null)
- buffer.append(tagName);
- } else if (impl.isJSPTag()) {
- buffer.append(JSPTag.TAG_OPEN);
- String tagName = generateTagName(element);
- if (tagName != null)
- buffer.append(tagName);
- if (impl.isContainer())
- return buffer.toString(); // JSP container
- } else {
- buffer.append('<');
- String tagName = generateTagName(element);
- if (tagName != null)
- buffer.append(tagName);
- }
-
- NamedNodeMap attributes = element.getAttributes();
- int length = attributes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) attributes.item(i);
- if (attr == null)
- continue;
- buffer.append(' ');
- String attrName = generateAttrName(attr);
- if (attrName != null)
- buffer.append(attrName);
- String attrValue = generateAttrValue(attr);
- if (attrValue != null) {
- // attr name only for HTML boolean and JSP
- buffer.append('=');
- buffer.append(attrValue);
- }
- }
-
- String closeTag = generateCloseTag(element);
- if (closeTag != null)
- buffer.append(closeTag);
-
- return buffer.toString();
- }
-
- /**
- */
- public String generateTagName(Element element) {
- if (element == null)
- return null;
- IDOMElement xe = (IDOMElement) element;
- String tagName = element.getTagName();
- if (tagName == null)
- return null;
- if (xe.isJSPTag()) {
- if (tagName.equals(JSPTag.JSP_EXPRESSION))
- return JSPTag.EXPRESSION_TOKEN;
- if (tagName.equals(JSPTag.JSP_DECLARATION))
- return JSPTag.DECLARATION_TOKEN;
- if (tagName.equals(JSPTag.JSP_DIRECTIVE))
- return JSPTag.DIRECTIVE_TOKEN;
- if (tagName.startsWith(JSPTag.JSP_DIRECTIVE)) {
- int offset = JSPTag.JSP_DIRECTIVE.length() + 1; // after '.'
- return (JSPTag.DIRECTIVE_TOKEN + tagName.substring(offset));
- }
- return (xe.isCommentTag()) ? tagName : null;
- } else if (tagName.startsWith(JSPTag.TAG_OPEN)) {
- if (!tagName.endsWith(JSPTag.TAG_CLOSE)) {
- // close JSP
- return (tagName + JSPTag.TAG_CLOSE);
- }
- } else if (xe.isCommentTag()) {
- String prefix = element.getPrefix();
- if (prefix.equals(SSI_PREFIX)) {
- return (SSI_TOKEN + element.getLocalName());
- }
- } else {
- if (!xe.isJSPTag() && xe.isGlobalTag() && // global tag
- CMNodeUtil.getElementDeclaration(xe) != null) {
- String newName = tagName;
- switch (getTagNameCase(xe)) {
- case DocumentTypeAdapter.UPPER_CASE :
- newName = tagName.toUpperCase();
- break;
- case DocumentTypeAdapter.LOWER_CASE :
- newName = tagName.toLowerCase();
- break;
- }
- if (newName != tagName) {
- tagName = newName;
- setTagName(element, tagName);
- }
- }
- }
- return tagName;
- }
-
- /**
- * generateText method
- *
- * @return java.lang.String
- * @param text
- * org.w3c.dom.Text
- */
- public String generateText(Text text) {
- if (text == null)
- return null;
- TextImpl impl = (TextImpl) text;
- String source = impl.getTextSource();
- if (source != null)
- return source;
- return generateTextData(text, impl.getData());
- }
-
- /**
- */
- public String generateTextData(Text text, String data) {
- if (data == null)
- return null;
- if (text == null)
- return null;
- TextImpl impl = (TextImpl) text;
- if (impl.isJSPContent() || impl.isCDATAContent()) {
- return new SourceValidator(impl).convertSource(data);
- }
- String source = data;
-
- // convert special characters to character entities
- StringBuffer buffer = null;
- int offset = 0;
- int length = data.length();
- for (int i = 0; i < length; i++) {
- String name = getCharName(data.charAt(i));
- if (name == null)
- continue;
- if (buffer == null)
- buffer = new StringBuffer(length + 8);
- if (i > offset)
- buffer.append(data.substring(offset, i));
- buffer.append('&');
- buffer.append(name);
- buffer.append(';');
- offset = i + 1;
- }
- if (buffer != null) {
- if (length > offset)
- buffer.append(data.substring(offset));
- source = buffer.toString();
- }
-
- if (source == null || source.length() == 0)
- return null;
- return source;
- }
-
- /**
- */
- private int getAttrNameCase(Attr attr) {
- DocumentImpl document = (DocumentImpl) attr.getOwnerDocument();
- if (document == null)
- return DocumentTypeAdapter.STRICT_CASE;
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class);
- if (adapter == null)
- return DocumentTypeAdapter.STRICT_CASE;
- return adapter.getAttrNameCase();
- }
-
- /**
- */
- private String getCharName(char c) {
- switch (c) {
- case '<' :
- return IXMLCharEntity.LT_NAME;
- case '>' :
- return IXMLCharEntity.GT_NAME;
- case '&' :
- return IXMLCharEntity.AMP_NAME;
- case '"' :
- return IXMLCharEntity.QUOT_NAME;
- }
- return null;
- }
-
- /**
- */
- private int getTagNameCase(Element element) {
- DocumentImpl document = (DocumentImpl) element.getOwnerDocument();
- if (document == null)
- return DocumentTypeAdapter.STRICT_CASE;
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class);
- if (adapter == null)
- return DocumentTypeAdapter.STRICT_CASE;
- return adapter.getTagNameCase();
- }
-
- /**
- */
- private boolean isBooleanAttr(Attr attr) {
- if (attr == null)
- return false;
- CMAttributeDeclaration decl = CMNodeUtil.getAttributeDeclaration(attr);
- if (decl == null)
- return false;
- CMDataType type = decl.getAttrType();
- if (type == null)
- return false;
- String values[] = type.getEnumeratedValues();
- if (values == null)
- return false;
- return (values.length == 1 && values[0].equals(decl.getAttrName()));
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelContext.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelContext.java
deleted file mode 100644
index 6a799f75f4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelContext.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-/**
- * XMLModelContext class
- */
-class XMLModelContext {
- private Node nextNode = null;
- private Node parentNode = null;
-
- // private XMLModelImpl model = null;
- private Node rootNode = null;
-
- /**
- * XMLModelContext constructor
- *
- * @param rootNode
- * org.w3c.dom.Node
- */
- XMLModelContext(Node rootNode) {
- super();
-
- this.rootNode = rootNode;
- }
-
- /**
- * findEndTag method
- *
- * @return org.w3c.dom.Element
- * @param tagName
- * java.lang.String
- */
- Element findEndTag(String tagName) {
- if (tagName == null)
- return null;
- if (this.parentNode == null)
- return null;
-
- for (Node parent = this.parentNode.getParentNode(); parent != null; parent = parent.getParentNode()) {
- if (parent.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl element = (ElementImpl) parent;
- if (element.hasEndTag()) {
- if (element.matchTagName(tagName))
- return element;
- // if ancestor element has end tag stop search
- break;
- }
- if (element.getNextSibling() != null)
- break;
- }
-
- return null;
- }
-
- /**
- */
- Text findNextText() {
- Node node = this.nextNode;
- while (node != null) {
- if (node != this.nextNode && node.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) node;
- // skip empty text
- if (text.getStructuredDocumentRegion() != null)
- return text;
- }
- Node child = node.getFirstChild();
- if (child != null) {
- node = child;
- continue;
- }
- while (node != null) {
- Node next = node.getNextSibling();
- if (next != null) {
- node = next;
- break;
- }
- node = node.getParentNode();
- }
- }
- return null;
- }
-
- /**
- * findPreviousText method
- *
- * @return org.w3c.dom.Text
- */
- Text findPreviousText() {
- if (this.parentNode == null)
- return null;
- Node node = null;
- if (this.nextNode != null)
- node = this.nextNode.getPreviousSibling();
- else
- node = this.parentNode.getLastChild();
- if (node == null || node.getNodeType() != Node.TEXT_NODE)
- return null;
- return (Text) node;
- }
-
- /**
- * findStartTag method
- *
- * @return org.w3c.dom.Element
- * @param tagName
- * java.lang.String
- */
- Element findStartTag(String tagName, String rootName) {
- if (tagName == null)
- return null;
-
- // check previous for empty content element
- Node prev = null;
- if (this.nextNode != null)
- prev = this.nextNode.getPreviousSibling();
- else if (this.parentNode != null)
- prev = this.parentNode.getLastChild();
- if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) prev;
- if (!element.hasEndTag() && !element.isEmptyTag() && element.matchTagName(tagName))
- return element;
- }
-
- for (Node parent = this.parentNode; parent != null; parent = parent.getParentNode()) {
- if (parent.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl element = (ElementImpl) parent;
- if (element.matchTagName(tagName))
- return element;
- if (rootName != null && element.matchTagName(rootName))
- break;
- }
-
- return null;
- }
-
- /**
- * getNextNode method
- *
- * @return org.w3c.dom.Node
- */
- Node getNextNode() {
- return this.nextNode;
- }
-
- /**
- * getParentNode method
- *
- * @return org.w3c.dom.Node
- */
- Node getParentNode() {
- return this.parentNode;
- }
-
- /**
- * getRootNode method
- *
- * @return org.w3c.dom.Node
- */
- Node getRootNode() {
- return this.rootNode;
- }
-
- /**
- * setLast method
- */
- void setLast() {
- if (this.parentNode == null)
- return;
- if (this.nextNode != null) {
- Node prev = this.nextNode.getPreviousSibling();
- if (prev == null || prev.getNodeType() != Node.ELEMENT_NODE)
- return;
- ElementImpl element = (ElementImpl) prev;
- if (element.hasEndTag() || !element.isContainer() || element.isEmptyTag())
- return;
- setParentNode(prev);
- }
-
- // find last open parent
- Node parent = this.parentNode;
- Node last = parent.getLastChild();
- while (last != null) {
- if (last.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl element = (ElementImpl) last;
- if (element.hasEndTag() || !element.isContainer() || element.isEmptyTag())
- break;
- parent = element;
- last = parent.getLastChild();
- }
- if (parent != this.parentNode)
- setParentNode(parent);
- }
-
- /**
- * setNextNode method
- *
- * @param nextNode
- * org.w3c.dom.Node
- */
- void setNextNode(Node nextNode) {
- this.nextNode = nextNode;
- if (nextNode == null)
- return;
- this.parentNode = nextNode.getParentNode();
- }
-
- /**
- * setParentNode method
- *
- * @param parentNode
- * org.w3c.dom.Node
- */
- void setParentNode(Node parentNode) {
- this.parentNode = parentNode;
- this.nextNode = null;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifier.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifier.java
deleted file mode 100644
index 9a3e255aeb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifier.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- *
- * XMLModelNotifier manages the notification process. Clients should not use
- * extend or reference.
- *
- * ISSUE: should be internalized.
- */
-
-public interface XMLModelNotifier {
-
- /**
- * attrReplaced method
- *
- * @param element
- * org.w3c.dom.Element
- * @param newAttr
- * org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- void attrReplaced(Element element, Attr newAttr, Attr oldAttr);
-
- /**
- * Signal that changing is starting.
- *
- */
- void beginChanging();
-
- /**
- * Signal that changing is starting with a brand new model.
- *
- */
- void beginChanging(boolean newModel);
-
- /**
- * Cancel pending notifications. This is called in the context of
- * "reinitialization" so is assumed ALL notifications can be safely
- * canceled, assuming that once factories and adapters are re-initialized
- * they will be re-notified as text is set in model, if still appropriate.
- */
- void cancelPending();
-
- /**
- * childReplaced method
- *
- * @param parentNode
- * org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- void childReplaced(Node parentNode, Node newChild, Node oldChild);
-
- /**
- * Editable state changed for node.
- *
- */
- void editableChanged(Node node);
-
- /**
- * Signal changing is finished.
- *
- */
- void endChanging();
-
- /**
- * Signal end tag changed.
- *
- * @param element
- *
- */
- void endTagChanged(Element element);
-
- /**
- * Used to reflect state of model.
- *
- * @return true if model had changed.
- *
- */
- boolean hasChanged();
-
- /**
- * Used to reflect state of parsing process.
- *
- * @return true if model is currently changing.
- */
- boolean isChanging();
-
- /**
- * signal property changed
- *
- * @param node
- */
- void propertyChanged(Node node);
-
- /**
- * signal start tag changed
- *
- * @param element
- */
- void startTagChanged(Element element);
-
- /**
- * signal structured changed.
- *
- * @param node
- */
- void structureChanged(Node node);
-
- /**
- * valueChanged method
- *
- * @param node
- * org.w3c.dom.Node
- */
- void valueChanged(Node node);
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifierImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifierImpl.java
deleted file mode 100644
index 75f89a089b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelNotifierImpl.java
+++ /dev/null
@@ -1,496 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-public class XMLModelNotifierImpl implements XMLModelNotifier {
-
- private static class NotifyEvent {
- Object changedFeature;
- boolean discarded;
- Object newValue;
- // note: don't initialize instance variables, since
- // that causes double assignments, and lots of these are created.
- INodeNotifier notifier;
- Object oldValue;
- int pos;
- String reason;
- int type;
- int index;
-
- NotifyEvent(INodeNotifier notifier, int type, Object changedFeature, Object oldValue, Object newValue, int pos) {
- this.notifier = notifier;
- this.type = type;
- this.changedFeature = changedFeature;
- this.oldValue = oldValue;
- this.newValue = newValue;
- this.pos = pos;
- this.reason = ""; //$NON-NLS-1$
- }
- }
-
- private final static String ADDED_THEN_REMOVED = "Discard: Added then removed rule"; //$NON-NLS-1$
- private final static boolean fOptimizeDeferred = true;
- private final static boolean fOptimizeDeferredAccordingToParentAdded = true;
- private final static boolean fOptimizeDeferredAccordingToParentRemoved = true;
- private final static String PARENT_IS_ADDED = "Disarded: Parent has just been added"; //$NON-NLS-1$
- /* start: for debugging only */
- private final static String PARENT_IS_REMOVED_TOO = "Discard: Parent was removed too"; //$NON-NLS-1$
- private final static String PARENT_IS_REPARENTED = "Not Discard: Parent was removed so this implies reparenting"; //$NON-NLS-1$
- private Node changedRoot = null;
-
- private boolean changing = false;
- private boolean doingNewModel = false;
- private List fEvents = null;
- private boolean flushing = false;
-
- /**
- */
- public XMLModelNotifierImpl() {
- super();
- }
-
- /**
- * attrReplaced method
- *
- * @param element
- * org.w3c.dom.Element
- * @param newAttr
- * org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- public void attrReplaced(Element element, Attr newAttr, Attr oldAttr) {
- if (element == null)
- return;
- Attr attr = null;
- String oldValue = null;
- String newValue = null;
- if (oldAttr != null) {
- attr = oldAttr;
- oldValue = oldAttr.getValue();
- }
- if (newAttr != null) {
- attr = newAttr;
- newValue = newAttr.getValue();
- }
- IDOMNode notifier = (IDOMNode) element;
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, attr, oldValue, newValue, offset);
- propertyChanged(notifier);
- }
-
- /**
- */
- public void beginChanging() {
- this.changing = true;
- }
-
- /**
- */
- public void beginChanging(boolean newModel) {
- beginChanging();
- this.doingNewModel = newModel;
- }
-
- public void cancelPending() {
- // we don't want to change the size of this array, since
- // the array may be being processed, in the deferred notification
- // loop, but we can signal that all
- // should be discarded, so any remaining ones will be ignored.
- if (this.fEvents != null) {
- int size = fEvents.size();
- for (int i = 0; i < size; i++) {
- NotifyEvent event = (NotifyEvent) fEvents.get(i);
- event.discarded = true;
- }
- }
- // this cancel is presumably being called as a function of
- // "reinitiailization" so we can ignore changes to the
- // old root, and changes to the new one will be triggered during
- // reinitialization.
- changedRoot = null;
- }
-
- /**
- * childReplaced method
- *
- * @param parentNode
- * org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- public void childReplaced(Node parentNode, Node newChild, Node oldChild) {
- if (parentNode == null)
- return;
- IDOMNode notifier = (IDOMNode) parentNode;
- int type = INodeNotifier.CHANGE;
- if (newChild == null)
- type = INodeNotifier.REMOVE;
- else if (oldChild == null)
- type = INodeNotifier.ADD;
- int offset = notifier.getStartOffset();
- notify(notifier, type, oldChild, oldChild, newChild, offset);
- structureChanged(notifier);
- }
-
- public void editableChanged(Node node) {
- if (node == null)
- return;
- IDOMNode notifier = (IDOMNode) node;
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, null, null, null, offset);
- propertyChanged(notifier);
- }
-
- /**
- */
- public void endChanging() {
- this.doingNewModel = false;
- if (!this.changing)
- return; // avoid nesting calls
- notifyDeferred();
- if (this.changedRoot != null) {
- notifyStructureChanged(this.changedRoot);
- if (Debug.debugNotifyDeferred) {
- String p = this.changedRoot.getNodeName();
- System.out.println("Deferred STRUCTURE_CHANGED: " + p); //$NON-NLS-1$
- }
- this.changedRoot = null;
- }
- this.changing = false;
- }
-
- /**
- */
- public void endTagChanged(Element element) {
- if (element == null)
- return;
- IDOMNode notifier = (IDOMNode) element;
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, null, null, null, offset);
- propertyChanged(element);
- }
-
- /**
- */
- public boolean hasChanged() {
- return (this.fEvents != null);
- }
-
- /**
- */
- public boolean isChanging() {
- return this.changing;
- }
-
- /**
- */
- private void notify(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (notifier == null)
- return;
- if (this.changing && !this.flushing) {
- // defer notification
- if (this.fEvents == null)
- this.fEvents = new ArrayList();
- // we do not defer anything if we are doing a new Model,
- // except for the document event, since all others are
- // trivial and not needed at that initial point.
- // But even for that one document event, in the new model case,
- // it is still important to defer it.
- if ((!doingNewModel) || (((Node) notifier).getNodeType() == Node.DOCUMENT_NODE)) {
- this.fEvents.add(new NotifyEvent(notifier, eventType, changedFeature, oldValue, newValue, pos));
- }
- return;
- }
- try {
- // Its important to "keep going" if exception occurs, since this
- // notification
- // comes in between "about to change" and "changed" events. We do
- // log, however,
- // since would indicate a program error.
- notifier.notify(eventType, changedFeature, oldValue, newValue, pos);
- } catch (Exception e) {
- Logger.logException("A structured model client threw following exception during adapter notification (" + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " )", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- /**
- */
- private void notifyDeferred() {
- if (this.fEvents == null)
- return;
- if (this.flushing)
- return;
- this.flushing = true; // force notification
- int count = this.fEvents.size();
-
- if (!doingNewModel && fOptimizeDeferred) {
- Map notifyEvents = new HashMap();
- for (int i = 0; i < count; i++) {
- NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
- if (event == null)
- continue; // error
- event.index = i;
- if(event.type == INodeNotifier.REMOVE) {
- addToMap(event.oldValue, event, notifyEvents);
- }
- if(event.type == INodeNotifier.ADD) {
- addToMap(event.newValue, event, notifyEvents);
- }
- }
- Iterator it = notifyEvents.values().iterator();
- while (it.hasNext()) {
- NotifyEvent[] es = (NotifyEvent[]) it.next();
- for (int i = 0; i < es.length - 1; i++) {
- NotifyEvent event = es[i];
- if(es[i].discarded) continue;
- NotifyEvent next = es[i + 1];
- if(es[i].type == INodeNotifier.ADD && next.type == INodeNotifier.REMOVE) {
- // Added then removed later, discard both
- event.discarded = true;
- next.discarded = true;
- if (Debug.debugNotifyDeferred) {
- event.reason = event.reason + ADDED_THEN_REMOVED + "(see " + next.index + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- next.reason = next.reason + ADDED_THEN_REMOVED + "(see " + event.index + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
- }
- for (int i = 0; i < count; i++) {
- NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
- if (event == null)
- continue; // error
- if(event.discarded) continue;
- if (event.notifier != null && fOptimizeDeferredAccordingToParentAdded) {
- if (event.type == INodeNotifier.ADD) {
- NotifyEvent[] es = (NotifyEvent[])notifyEvents.get(event.notifier);
- if(es != null) for (int p = 0; p < es.length && es[p].index < event.index; p++) {
- NotifyEvent prev = es[p];
- if (prev.type == INodeNotifier.REMOVE && prev.oldValue == event.notifier) {
- // parent is reparented, do not discard
- if (Debug.debugNotifyDeferred) {
- event.reason = event.reason + PARENT_IS_REPARENTED + "(see " + prev.index + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- break;
- } else if (prev.type == INodeNotifier.ADD && prev.newValue == event.notifier) {
- // parent has been added, discard this
- event.discarded = true;
- if (Debug.debugNotifyDeferred) {
- event.reason = event.reason + PARENT_IS_ADDED + "(see " + prev.index + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- break;
- }
- }
- }
- }
- if(event.discarded) continue;
- if (event.notifier != null && fOptimizeDeferredAccordingToParentRemoved) {
- if (event.type == INodeNotifier.REMOVE) {
- NotifyEvent[] es = (NotifyEvent[])notifyEvents.get(event.notifier);
- if(es != null) for (int n = 0; n < es.length; n++) {
- NotifyEvent next = es[n];
- if(next.index > event.index && next.type == INodeNotifier.REMOVE) {
- if (next.oldValue == event.notifier) {
- // parent will be removed, discard this
- event.discarded = true;
- if (Debug.debugNotifyDeferred) {
- event.reason = event.reason + PARENT_IS_REMOVED_TOO + "(see " + next.index + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- break;
- }
- }
- }
- }
- }
- if(event.discarded) continue;
- }
- }
- for (int i = 0; i < count; i++) {
- NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
- if (event == null)
- continue; // error
- if(event.discarded) continue;
- notify(event.notifier, event.type, event.changedFeature, event.oldValue, event.newValue, event.pos);
- }
- if (Debug.debugNotifyDeferred) {
- for (int l = 0; l < count; l++) {
- NotifyEvent event = (NotifyEvent) this.fEvents.get(l);
- Object o = null;
- String t = null;
- if (event.type == INodeNotifier.ADD) {
- o = event.newValue;
- t = " + "; //$NON-NLS-1$
- } else if (event.type == INodeNotifier.REMOVE) {
- o = event.oldValue;
- t = " - "; //$NON-NLS-1$
- }
- if (o instanceof Element) {
- String p = ((Node) event.notifier).getNodeName();
- String c = ((Node) o).getNodeName();
- String d = (event.discarded ? "! " : " "); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println(d + p + t + c);
- }
- }
- }
- this.flushing = false;
- this.fEvents = null;
- }
-
- void addToMap(Object o, NotifyEvent event, Map map) {
- if(o == null) return;
- Object x = map.get(o);
- if(x == null) {
- map.put(o, new NotifyEvent[]{event});
- } else {
- NotifyEvent[] es = (NotifyEvent[])x;
- NotifyEvent[] es2 = new NotifyEvent[es.length + 1];
- System.arraycopy(es, 0, es2, 0, es.length);
- es2[es.length] = event;
- map.put(o, es2);
- }
- }
-
- /**
- */
- private void notifyStructureChanged(Node root) {
- if (root == null)
- return;
- INodeNotifier notifier = (INodeNotifier) root;
- try {
- // Its important to "keep going" if exception occurs, since this
- // notification
- // comes in between "about to change" and "changed" events. We do
- // log, however,
- // since would indicate a program error.
- notifier.notify(INodeNotifier.STRUCTURE_CHANGED, null, null, null, -1);
- } catch (Exception e) {
- Logger.logException("A structured model client threw following exception during adapter notification (" + INodeNotifier.EVENT_TYPE_STRINGS[INodeNotifier.STRUCTURE_CHANGED] + " )", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- }
-
- /**
- */
- public void propertyChanged(Node node) {
- }
-
- /**
- * @param node
- */
- private void setCommonRootIfNeeded(Node node) {
- // defer notification
- if (this.changedRoot == null) {
- this.changedRoot = node;
- } else {
- // tiny optimization: if previous commonAncestor (changedRoot) is
- // already 'document',
- // or if already equal to this 'node',
- // then no need to re-calculate
- if (changedRoot.getNodeType() != Node.DOCUMENT_NODE && changedRoot != node) {
- Node common = ((NodeImpl) this.changedRoot).getCommonAncestor(node);
- if (common != null)
- this.changedRoot = common;
- else
- this.changedRoot = node;
- }
- }
- }
-
- /**
- */
- public void startTagChanged(Element element) {
- if (element == null)
- return;
- IDOMNode notifier = (IDOMNode) element;
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, null, null, null, offset);
- propertyChanged(element);
- }
-
- /**
- */
- public void structureChanged(Node node) {
- if (node == null)
- return;
- if (isChanging()) {
- setCommonRootIfNeeded(node);
- if (Debug.debugNotifyDeferred) {
- String p = this.changedRoot.getNodeName();
- System.out.println("requested STRUCTURE_CHANGED: " + p); //$NON-NLS-1$
- }
- return;
- }
- if (Debug.debugNotifyDeferred) {
- String p = node.getNodeName();
- System.out.println("STRUCTURE_CHANGED: " + p); //$NON-NLS-1$
- }
- notifyStructureChanged(node);
- }
-
- /**
- * valueChanged method
- *
- * @param node
- * org.w3c.dom.Node
- */
- public void valueChanged(Node node) {
- if (node == null)
- return;
- IDOMNode notifier = null;
- if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
- Attr attr = (Attr) node;
- notifier = (IDOMNode) attr.getOwnerElement();
- // TODO_dmw: experimental: changed 06/29/2004 to send "structuure
- // changed" even for attribute value changes
- // there are pros and cons to considering attribute value
- // "structure changed". Will (re)consider
- // setCommonRootIfNeeded(notifier);
- if (notifier == null)
- return;
- String value = attr.getValue();
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, attr, null, value, offset);
- } else {
- // note: we do not send structured changed event for content
- // changed
- notifier = (IDOMNode) node;
- String value = node.getNodeValue();
- int offset = notifier.getStartOffset();
- notify(notifier, INodeNotifier.CHANGE, null, null, value, offset);
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- IDOMNode parent = (IDOMNode) node.getParentNode();
- if (parent != null) {
- notify(parent, INodeNotifier.CONTENT_CHANGED, node, null, value, offset);
- }
- }
- }
- propertyChanged(notifier);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelParser.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelParser.java
deleted file mode 100644
index 9f893bb53c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelParser.java
+++ /dev/null
@@ -1,2422 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementConfiguration;
-import org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementRegistry;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-
-/**
- * XMLModelParser
- */
-public class XMLModelParser {
- private XMLModelContext context = null;
- private DOMModelImpl model = null;
- private TextImpl lastTextNode = null;
-
- /**
- */
- protected XMLModelParser(DOMModelImpl model) {
- super();
-
- if (model != null) {
- this.model = model;
- }
- }
-
- /**
- */
- protected boolean canBeImplicitTag(Element element) {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.canBeImplicitTag(element);
- }
- return false;
- }
-
- /**
- */
- protected boolean canBeImplicitTag(Element element, Node child) {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.canBeImplicitTag(element, child);
- }
- return false;
- }
-
- /**
- */
- protected boolean canContain(Element element, Node child) {
- if (element == null || child == null)
- return false;
- ElementImpl impl = (ElementImpl) element;
- if (impl.isEndTag())
- return false; // invalid (floating) end tag
- if (!impl.isContainer())
- return false;
- if (child.getNodeType() != Node.TEXT_NODE) {
- if (impl.isJSPContainer() || impl.isCDATAContainer()) {
- // accepts only Text child
- return false;
- }
- }
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.canContain(element, child);
- }
- return true;
- }
-
- /**
- */
- private void changeAttrEqual(IStructuredDocumentRegion flatNode, ITextRegion region) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return;
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return;
- Node node = root.getNodeAt(offset);
- if (node == null)
- return;
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- // just notify the change instead of setting data
- ProcessingInstructionImpl pi = (ProcessingInstructionImpl) node;
- pi.notifyValueChanged();
- }
- return;
- }
- // actually, do nothing
- }
-
- /**
- * changeAttrName method
- *
- */
- private void changeAttrName(IStructuredDocumentRegion flatNode, ITextRegion region) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return;
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return;
- Node node = root.getNodeAt(offset);
- if (node == null)
- return;
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- // just notify the change instead of setting data
- ProcessingInstructionImpl pi = (ProcessingInstructionImpl) node;
- pi.notifyValueChanged();
- }
- return;
- }
-
- ElementImpl element = (ElementImpl) node;
- NamedNodeMap attributes = element.getAttributes();
- if (attributes == null)
- return;
- int length = attributes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) attributes.item(i);
- if (attr == null)
- continue;
- if (attr.getNameRegion() != region)
- continue;
-
- String name = flatNode.getText(region);
- attr.setName(name);
- break;
- }
- }
-
- /**
- * changeAttrValue method
- *
- */
- private void changeAttrValue(IStructuredDocumentRegion flatNode, ITextRegion region) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return;
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return;
- Node node = root.getNodeAt(offset);
- if (node == null)
- return;
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- // just notify the change instead of setting data
- ProcessingInstructionImpl pi = (ProcessingInstructionImpl) node;
- pi.notifyValueChanged();
- }
- return;
- }
-
- ElementImpl element = (ElementImpl) node;
- NamedNodeMap attributes = element.getAttributes();
- if (attributes == null)
- return;
- int length = attributes.getLength();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) attributes.item(i);
- if (attr == null)
- continue;
- if (attr.getValueRegion() != region)
- continue;
- // just notify the change instead of setting value
- attr.notifyValueChanged();
- break;
- }
- }
-
- /**
- * changeData method
- *
- */
- private void changeData(IStructuredDocumentRegion flatNode, ITextRegion region) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return;
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return;
- Node node = root.getNodeAt(offset);
- if (node == null)
- return;
- switch (node.getNodeType()) {
- case Node.TEXT_NODE : {
- TextImpl text = (TextImpl) node;
- if (text.isSharingStructuredDocumentRegion(flatNode)) {
- // has consecutive text sharing IStructuredDocumentRegion
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- this.context.setNextNode(node);
- cleanupText();
- break;
- }
- case Node.CDATA_SECTION_NODE :
- case Node.PROCESSING_INSTRUCTION_NODE :
- break;
- case Node.COMMENT_NODE :
- case Node.ELEMENT_NODE :
- // comment tag
- changeStructuredDocumentRegion(flatNode);
- return;
- default :
- return;
- }
-
- // just notify the change instead of setting data
- NodeImpl impl = (NodeImpl) node;
- impl.notifyValueChanged();
- }
-
- /**
- */
- private void changeEndTag(IStructuredDocumentRegion flatNode, ITextRegionList newRegions, ITextRegionList oldRegions) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return; // error
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return; // error
- Node node = root.getNodeAt(offset);
- if (node == null)
- return; // error
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- changeStructuredDocumentRegion(flatNode);
- return;
- }
-
- // check if change is only for close tag
- if (newRegions != null) {
- Iterator e = newRegions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_CLOSE)
- continue;
-
- // other region has changed
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- }
- if (oldRegions != null) {
- Iterator e = oldRegions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_CLOSE)
- continue;
-
- // other region has changed
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- }
-
- // change for close tag has no impact
- // do nothing
- }
-
- /**
- * changeRegion method
- *
- */
- void changeRegion(RegionChangedEvent change, IStructuredDocumentRegion flatNode, ITextRegion region) {
- if (flatNode == null || region == null)
- return;
- if (this.model.getDocument() == null)
- return;
- this.context = new XMLModelContext(this.model.getDocument());
-
- //determine if change was whitespace only change
- boolean isWhitespaceChange = false;
- if(change.getText() != null && change.getText().length() > 0) {
- isWhitespaceChange = Character.isWhitespace(change.getText().charAt(0));
- } else if(change.getDeletedText() != null && change.getDeletedText().length() > 0) {
- isWhitespaceChange = Character.isWhitespace(change.getDeletedText().charAt(0));
- }
-
- // optimize typical cases
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_CONTENT || regionType == DOMRegionContext.XML_COMMENT_TEXT || regionType == DOMRegionContext.XML_CDATA_TEXT || regionType == DOMRegionContext.BLOCK_TEXT || isNestedContent(regionType)) {
- changeData(flatNode, region);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- if (isWhitespaceChange && (change.getOffset() >= flatNode.getStartOffset() + region.getTextEnd())) {
- // change is entirely in white-space
- return;
- }
- changeAttrName(flatNode, region);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- if (isWhitespaceChange && (change.getOffset() >= flatNode.getStartOffset() + region.getTextEnd())) {
- // change is entirely in white-space
- return;
- }
- changeAttrValue(flatNode, region);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- if (isWhitespaceChange && (change.getOffset() >= flatNode.getStartOffset() + region.getTextEnd())) {
- // change is entirely in white-space
- return;
- }
- changeAttrEqual(flatNode, region);
- }
- else if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
- if (isWhitespaceChange && (change.getOffset() >= flatNode.getStartOffset() + region.getTextEnd())) {
- // change is entirely in white-space
- return;
- }
- changeTagName(flatNode, region);
- }
- else {
- changeStructuredDocumentRegion(flatNode);
- }
- }
-
-
-
- /**
- */
- private void changeStartTag(IStructuredDocumentRegion flatNode, ITextRegionList newRegions, ITextRegionList oldRegions) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return; // error
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return; // error
- Node node = root.getNodeAt(offset);
- if (node == null)
- return; // error
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- ElementImpl element = (ElementImpl) node;
-
- // check if changes are only for attributes and close tag
- boolean tagNameUnchanged = false;
- if (newRegions != null) {
- Iterator e = newRegions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
- continue;
- if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
- // change from empty tag may have impact on structure
- if (!element.isEmptyTag())
- continue;
- }
- else if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
- String oldTagName = element.getTagName();
- String newTagName = flatNode.getText(region);
- if (oldTagName != null && newTagName != null && oldTagName.equals(newTagName)) {
- // the tag name is unchanged
- tagNameUnchanged = true;
- continue;
- }
- }
-
- // other region has changed
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- }
- if (oldRegions != null) {
- Iterator e = oldRegions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS || regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
- continue;
- if (regionType == DOMRegionContext.XML_TAG_CLOSE) {
- // change from empty tag may have impact on structure
- if (!element.isEmptyTag())
- continue;
- }
- else if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
- // if new tag name is unchanged, it's OK
- if (tagNameUnchanged)
- continue;
- }
-
- // other region has changed
- changeStructuredDocumentRegion(flatNode);
- return;
- }
- }
-
- // update attributes
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return; // error
- NamedNodeMap attributes = element.getAttributes();
- if (attributes == null)
- return; // error
-
- // first remove attributes
- int regionIndex = 0;
- int attrIndex = 0;
- AttrImpl attr = null;
- while (attrIndex < attributes.getLength()) {
- attr = (AttrImpl) attributes.item(attrIndex);
- if (attr == null) { // error
- attrIndex++;
- continue;
- }
- ITextRegion nameRegion = attr.getNameRegion();
- if (nameRegion == null) { // error
- element.removeAttributeNode(attr);
- continue;
- }
- boolean found = false;
- for (int i = regionIndex; i < regions.size(); i++) {
- ITextRegion region = regions.get(i);
- if (region == nameRegion) {
- regionIndex = i + 1; // next region
- found = true;
- break;
- }
- }
- if (found) {
- attrIndex++;
- }
- else {
- element.removeAttributeNode(attr);
- }
- }
-
- // insert or update attributes
- attrIndex = 0; // reset to first
- AttrImpl newAttr = null;
- ITextRegion oldValueRegion = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- if (newAttr != null) {
- // insert deferred new attribute
- element.insertAttributeNode(newAttr, attrIndex++);
- newAttr = null;
- }
- else if (attr != null && oldValueRegion != null) {
- // notify existing attribute value removal
- attr.notifyValueChanged();
- }
-
- oldValueRegion = null;
- attr = (AttrImpl) attributes.item(attrIndex);
- if (attr != null && attr.getNameRegion() == region) {
- // existing attribute
- attrIndex++;
- // clear other regions
- oldValueRegion = attr.getValueRegion();
- attr.setEqualRegion(null);
- attr.setValueRegion(null);
- }
- else {
- String name = flatNode.getText(region);
- attr = (AttrImpl) this.model.getDocument().createAttribute(name);
- if (attr != null)
- attr.setNameRegion(region);
- // defer insertion of new attribute
- newAttr = attr;
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- if (attr != null) {
- attr.setEqualRegion(region);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- if (attr != null) {
- attr.setValueRegion(region);
- if (attr != newAttr && oldValueRegion != region) {
- // notify existing attribute value changed
- attr.notifyValueChanged();
- }
- oldValueRegion = null;
- attr = null;
- }
- }
- }
-
- if (newAttr != null) {
- // insert deferred new attribute
- element.appendAttributeNode(newAttr);
- }
- else if (attr != null && oldValueRegion != null) {
- // notify existing attribute value removal
- attr.notifyValueChanged();
- }
- }
-
- /**
- * changeStructuredDocumentRegion method
- *
- */
- private void changeStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return;
- if (this.model.getDocument() == null)
- return;
-
- setupContext(flatNode);
-
- removeStructuredDocumentRegion(flatNode);
- // make sure the parent is set to deepest level
- // when end tag has been removed
- this.context.setLast();
- insertStructuredDocumentRegion(flatNode);
-
- cleanupText();
- cleanupEndTag();
- }
-
- /**
- */
- private void changeTagName(IStructuredDocumentRegion flatNode, ITextRegion region) {
- int offset = flatNode.getStart();
- if (offset < 0)
- return; // error
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return; // error
- Node node = root.getNodeAt(offset);
- if (node == null)
- return; // error
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- changeStructuredDocumentRegion(flatNode);
- return;
- }
-
- ElementImpl element = (ElementImpl) node;
- String newTagName = flatNode.getText(region);
- if (newTagName == null || !element.matchTagName(newTagName)) {
- // the tag name is changed
- changeStructuredDocumentRegion(flatNode);
- return;
- }
-
- // the tag name is unchanged
- // this happens when typing spaces after the tag name
- // do nothing, but...
- // if it's not a change in the end tag of an element with the start
- // tag,
- // and case has been changed, set to element and notify
- if (!element.hasStartTag() || StructuredDocumentRegionUtil.getFirstRegionType(flatNode) != DOMRegionContext.XML_END_TAG_OPEN) {
- String tagName = element.getTagName();
- if (tagName == null || !tagName.equals(newTagName)) {
- element.setTagName(newTagName);
- element.notifyValueChanged();
- }
- }
- }
-
- /**
- * cleanupContext method
- */
- private void cleanupEndTag() {
- Node parent = this.context.getParentNode();
- Node next = this.context.getNextNode();
- while (parent != null) {
- while (next != null) {
- if (next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) next;
- if (element.isEndTag()) {
- // floating end tag
- String tagName = element.getTagName();
- String rootName = getFindRootName(tagName);
- ElementImpl start = (ElementImpl) this.context.findStartTag(tagName, rootName);
- if (start != null) {
- insertEndTag(start);
- // move the end tag from 'element' to 'start'
- start.addEndTag(element);
- removeNode(element);
- parent = this.context.getParentNode();
- next = this.context.getNextNode();
- continue;
- }
- }
- }
-
- Node first = next.getFirstChild();
- if (first != null) {
- parent = next;
- next = first;
- this.context.setNextNode(next);
- }
- else {
- next = next.getNextSibling();
- this.context.setNextNode(next);
- }
- }
-
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) parent;
- if (!element.hasEndTag() && element.hasStartTag() && element.getNextSibling() == null) {
- String tagName = element.getTagName();
- ElementImpl end = (ElementImpl) this.context.findEndTag(tagName);
- if (end != null) {
- // move the end tag from 'end' to 'element'
- element.addEndTag(end);
- removeEndTag(end);
- this.context.setParentNode(parent); // reset context
- continue;
- }
- }
- }
-
- next = parent.getNextSibling();
- parent = parent.getParentNode();
- if (next != null) {
- this.context.setNextNode(next);
- }
- else {
- this.context.setParentNode(parent);
- }
- }
- }
-
- /**
- */
- private void cleanupText() {
- if (lastTextNode != null) {
- lastTextNode.notifyValueChanged();
- lastTextNode = null;
- }
- Node parent = this.context.getParentNode();
- if (parent == null)
- return; // error
- Node next = this.context.getNextNode();
- Node prev = (next == null ? parent.getLastChild() : next.getPreviousSibling());
-
- TextImpl nextText = null;
- TextImpl prevText = null;
- if (next != null && next.getNodeType() == Node.TEXT_NODE) {
- nextText = (TextImpl) next;
- }
- if (prev != null && prev.getNodeType() == Node.TEXT_NODE) {
- prevText = (TextImpl) prev;
- }
- if (nextText == null && prevText == null)
- return;
- if (nextText != null && prevText != null) {
- // consecutive Text nodes created by setupContext(),
- // concat them
- IStructuredDocumentRegion flatNode = nextText.getStructuredDocumentRegion();
- if (flatNode != null)
- prevText.appendStructuredDocumentRegion(flatNode);
- Node newNext = next.getNextSibling();
- parent.removeChild(next);
- next = null;
- this.context.setNextNode(newNext);
- }
-
- TextImpl childText = (prevText != null ? prevText : nextText);
- if (childText.getNextSibling() == null && childText.getPreviousSibling() == null) {
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl parentElement = (ElementImpl) parent;
- if (!parentElement.hasStartTag() && !parentElement.hasEndTag()) {
- if (childText.isWhitespace() || childText.isInvalid()) {
- // implicit parent is not required
- Node newParent = parent.getParentNode();
- if (newParent != null) {
- Node newNext = parent.getNextSibling();
- newParent.removeChild(parent);
- parent.removeChild(childText);
- newParent.insertBefore(childText, newNext);
- if (childText == next) {
- this.context.setNextNode(childText);
- }
- else if (newNext != null) {
- this.context.setNextNode(newNext);
- }
- else {
- this.context.setParentNode(newParent);
- }
- // try again
- cleanupText();
- }
- }
- }
- }
- }
- }
-
- /**
- * This routine create an Element from comment data for comment style
- * elements, such as SSI and METADATA
- */
- protected Element createCommentElement(String data, boolean isJSPTag) {
- String trimmedData = data.trim();
- CommentElementConfiguration[] configs = CommentElementRegistry.getInstance().getConfigurations();
- for (int iConfig = 0; iConfig < configs.length; iConfig++) {
- CommentElementConfiguration config = configs[iConfig];
- if ((isJSPTag && !config.acceptJSPComment()) || (!isJSPTag && !config.acceptXMLComment())) {
- continue;
- }
- String[] prefixes = config.getPrefix();
- for (int iPrefix = 0; iPrefix < prefixes.length; iPrefix++) {
- if (trimmedData.startsWith(prefixes[iPrefix])) {
- return config.createElement(this.model.getDocument(), data, isJSPTag);
- }
- }
- }
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.createCommentElement(this.model.getDocument(), data, isJSPTag);
- }
- return null;
- }
-
- /**
- * This routine create an implicit Element for given parent and child,
- * such as HTML, BODY, HEAD, and TBODY for HTML document.
- */
- protected Element createImplicitElement(Node parent, Node child) {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.createImplicitElement(this.model.getDocument(), parent, child);
- }
- return null;
- }
-
- /**
- */
- private void demoteNodes(Node root, Node newParent, Node oldParent, Node next) {
- if (newParent.getNodeType() != Node.ELEMENT_NODE)
- return;
- ElementImpl newElement = (ElementImpl) newParent;
-
- // find next
- while (next == null) {
- if (oldParent.getNodeType() != Node.ELEMENT_NODE)
- return;
- ElementImpl oldElement = (ElementImpl) oldParent;
- if (oldElement.hasEndTag())
- return;
- oldParent = oldElement.getParentNode();
- if (oldParent == null)
- return; // error
- next = oldElement.getNextSibling();
- }
-
- while (next != null) {
- boolean done = false;
- if (next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl nextElement = (ElementImpl) next;
- if (!nextElement.hasStartTag()) {
- Node nextChild = nextElement.getFirstChild();
- if (nextChild != null) {
- // demote children
- next = nextChild;
- oldParent = nextElement;
- continue;
- }
-
- if (nextElement.hasEndTag()) {
- if (nextElement.matchEndTag(newElement)) {
- // stop at the matched invalid end tag
- next = nextElement.getNextSibling();
- oldParent.removeChild(nextElement);
- newElement.addEndTag(nextElement);
-
- if (newElement == root)
- return;
- Node p = newElement.getParentNode();
- // check if reached to top
- if (p == null || p == oldParent || p.getNodeType() != Node.ELEMENT_NODE)
- return;
- newElement = (ElementImpl) p;
- done = true;
- }
- }
- else {
- // remove implicit element
- next = nextElement.getNextSibling();
- oldParent.removeChild(nextElement);
- done = true;
- }
- }
- }
-
- if (!done) {
- if (!canContain(newElement, next)) {
- if (newElement == root)
- return;
- Node p = newElement.getParentNode();
- // check if reached to top
- if (p == null || p == oldParent || p.getNodeType() != Node.ELEMENT_NODE)
- return;
- newElement = (ElementImpl) p;
- continue;
- }
-
- Node child = next;
- next = next.getNextSibling();
- oldParent.removeChild(child);
- insertNode(newElement, child, null);
- Node childParent = child.getParentNode();
- if (childParent != newElement) {
- newElement = (ElementImpl) childParent;
- }
- }
-
- // find next parent and sibling
- while (next == null) {
- if (oldParent.getNodeType() != Node.ELEMENT_NODE)
- return;
- ElementImpl oldElement = (ElementImpl) oldParent;
-
- // dug parent must not have children at this point
- if (!oldElement.hasChildNodes() && !oldElement.hasStartTag()) {
- oldParent = oldElement.getParentNode();
- if (oldParent == null)
- return; // error
- next = oldElement;
- break;
- }
-
- if (oldElement.hasEndTag())
- return;
- oldParent = oldElement.getParentNode();
- if (oldParent == null)
- return; // error
- next = oldElement.getNextSibling();
- }
- }
- }
-
- private ModelParserAdapter getParserAdapter() {
- return (ModelParserAdapter) this.model.getDocument().getAdapterFor(ModelParserAdapter.class);
- }
-
- /**
- */
- protected String getFindRootName(String tagName) {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.getFindRootName(tagName);
- }
- return null;
- }
-
- /**
- */
- protected final IDOMModel getModel() {
- return this.model;
- }
-
- /**
- * insertCDATASection method
- *
- */
- private void insertCDATASection(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- CDATASectionImpl cdata = null;
- try {
- cdata = (CDATASectionImpl) this.model.getDocument().createCDATASection(null);
- }
- catch (DOMException ex) {
- }
- if (cdata == null) { // CDATA section might not be supported
- insertInvalidDecl(flatNode); // regard as invalid decl
- return;
- }
-
- cdata.setStructuredDocumentRegion(flatNode);
- insertNode(cdata);
- }
-
- /**
- * insertComment method
- *
- */
- private void insertComment(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- StringBuffer data = null;
- boolean isJSPTag = false;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (isNestedCommentOpen(regionType)) {
- isJSPTag = true;
- }
- else if (regionType == DOMRegionContext.XML_COMMENT_TEXT || isNestedCommentText(regionType)) {
- if (data == null) {
- data = new StringBuffer(flatNode.getText(region));
- }
- else {
- data.append(flatNode.getText(region));
- }
- }
- }
-
- if (data != null) {
- ElementImpl element = (ElementImpl) createCommentElement(data.toString(), isJSPTag);
- if (element != null) {
- if (!isEndTag(element)) {
- element.setStartStructuredDocumentRegion(flatNode);
- insertStartTag(element);
- return;
- }
-
- // end tag
- element.setEndStructuredDocumentRegion(flatNode);
-
- String tagName = element.getTagName();
- String rootName = getFindRootName(tagName);
- ElementImpl start = (ElementImpl) this.context.findStartTag(tagName, rootName);
- if (start != null) { // start tag found
- insertEndTag(start);
- start.addEndTag(element);
- return;
- }
-
- // invalid end tag
- insertNode(element);
- return;
- }
- }
-
- CommentImpl comment = (CommentImpl) this.model.getDocument().createComment(null);
- if (comment == null)
- return;
- if (isJSPTag)
- comment.setJSPTag(true);
- comment.setStructuredDocumentRegion(flatNode);
- insertNode(comment);
- }
-
- /**
- * insertDecl method
- *
- */
- private void insertDecl(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- boolean isDocType = false;
- String name = null;
- String publicId = null;
- String systemId = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_DOCTYPE_DECLARATION) {
- isDocType = true;
- }
- else if (regionType == DOMRegionContext.XML_DOCTYPE_NAME) {
- if (name == null)
- name = flatNode.getText(region);
- }
- else if (regionType == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF) {
- if (publicId == null)
- publicId = StructuredDocumentRegionUtil.getAttrValue(flatNode, region);
- }
- else if (regionType == DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF) {
- if (systemId == null)
- systemId = StructuredDocumentRegionUtil.getAttrValue(flatNode, region);
- }
- }
-
- // invalid declaration
- if (!isDocType) {
- insertInvalidDecl(flatNode);
- return;
- }
-
- DocumentTypeImpl docType = (DocumentTypeImpl) this.model.getDocument().createDoctype(name);
- if (docType == null)
- return;
- if (publicId != null)
- docType.setPublicId(publicId);
- if (systemId != null)
- docType.setSystemId(systemId);
- docType.setStructuredDocumentRegion(flatNode);
- insertNode(docType);
- }
-
- /**
- * insertEndTag method can be used by subclasses, but not overrided.
- *
- * @param element
- * org.w3c.dom.Element
- */
- protected void insertEndTag(Element element) {
- if (element == null)
- return;
-
- Node newParent = element.getParentNode();
- if (newParent == null)
- return; // error
-
- if (!((ElementImpl) element).isContainer()) {
- // just update context
- Node elementNext = element.getNextSibling();
- if (elementNext != null)
- this.context.setNextNode(elementNext);
- else
- this.context.setParentNode(newParent);
- return;
- }
-
- // promote children
- Node newNext = element.getNextSibling();
- Node oldParent = this.context.getParentNode();
- if (oldParent == null)
- return; // error
- Node oldNext = this.context.getNextNode();
- promoteNodes(element, newParent, newNext, oldParent, oldNext);
-
- // update context
- // re-check the next sibling
- newNext = element.getNextSibling();
- if (newNext != null)
- this.context.setNextNode(newNext);
- else
- this.context.setParentNode(newParent);
- }
-
- /**
- * insertEndTag method
- *
- */
- private void insertEndTag(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- String tagName = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
- if (tagName == null)
- tagName = flatNode.getText(region);
- }
- }
-
- if (tagName == null) { // invalid end tag
- insertText(flatNode); // regard as invalid text
- return;
- }
-
- String rootName = getFindRootName(tagName);
- ElementImpl start = (ElementImpl) this.context.findStartTag(tagName, rootName);
- if (start != null) { // start tag found
- insertEndTag(start);
- start.setEndStructuredDocumentRegion(flatNode);
- return;
- }
-
- // invalid end tag
- ElementImpl end = null;
- try {
- end = (ElementImpl) this.model.getDocument().createElement(tagName);
- }
- catch (DOMException ex) {
- }
- if (end == null) { // invalid end tag
- insertText(flatNode); // regard as invalid text
- return;
- }
- end.setEndStructuredDocumentRegion(flatNode);
- insertNode(end);
- }
-
- /**
- * insertEntityRef method
- *
- */
- private void insertEntityRef(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- String name = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_ENTITY_REFERENCE || regionType == DOMRegionContext.XML_CHAR_REFERENCE) {
- if (name == null)
- name = StructuredDocumentRegionUtil.getEntityRefName(flatNode, region);
- }
- }
-
- if (name == null) { // invalid entity
- insertText(flatNode);
- return;
- }
-
- // ISSUE: avoid this cast
- String value = ((DocumentImpl)this.model.getDocument()).getCharValue(name);
- if (value != null) { // character entity
- TextImpl text = (TextImpl) this.context.findPreviousText();
- if (text != null) { // existing text found
- // do not append data
- text.appendStructuredDocumentRegion(flatNode);
- // Adjacent text nodes, where changes were queued
- if (lastTextNode != null && lastTextNode != text)
- lastTextNode.notifyValueChanged();
- lastTextNode = text;
- return;
- }
-
- // new text
- text = (TextImpl) this.model.getDocument().createTextNode(null);
- if (text == null)
- return;
- text.setStructuredDocumentRegion(flatNode);
- insertNode(text);
- return;
- }
-
- // general entity reference
- EntityReferenceImpl ref = null;
- try {
- ref = (EntityReferenceImpl) this.model.getDocument().createEntityReference(name);
- }
- catch (DOMException ex) {
- }
- if (ref == null) { // entity reference might not be supported
- insertText(flatNode); // regard as invalid text
- return;
- }
-
- ref.setStructuredDocumentRegion(flatNode);
- insertNode(ref);
- }
-
- /**
- * insertInvalidDecl method
- *
- */
- private void insertInvalidDecl(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- ElementImpl element = null;
- try {
- element = (ElementImpl) this.model.getDocument().createElement("!");//$NON-NLS-1$
- }
- catch (DOMException ex) {
- }
- if (element == null) { // invalid tag
- insertText(flatNode); // regard as invalid text
- return;
- }
- element.setEmptyTag(true);
- element.setStartStructuredDocumentRegion(flatNode);
- insertNode(element);
- }
-
- /**
- * insertJSPTag method
- *
- */
- private void insertNestedTag(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- String tagName = null;
- AttrImpl attr = null;
- List attrNodes = null;
- boolean isCloseTag = false;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (isNestedTagOpen(regionType) || isNestedTagName(regionType)) {
- tagName = computeNestedTag(regionType, tagName, flatNode, region);
- }
- else if (isNestedTagClose(regionType)) {
- isCloseTag = true;
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- String name = flatNode.getText(region);
- attr = (AttrImpl) this.model.getDocument().createAttribute(name);
- if (attr != null) {
- attr.setNameRegion(region);
- if (attrNodes == null)
- attrNodes = new ArrayList();
- attrNodes.add(attr);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- if (attr != null) {
- attr.setEqualRegion(region);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- if (attr != null) {
- attr.setValueRegion(region);
- attr = null;
- }
- }
- }
-
- if (tagName == null) {
- if (isCloseTag) {
- // close JSP tag
- Node parent = this.context.getParentNode();
- if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl start = (ElementImpl) parent;
- if (start.isJSPContainer()) {
- insertEndTag(start);
- start.setEndStructuredDocumentRegion(flatNode);
- return;
- }
- }
- }
- // invalid JSP tag
- insertText(flatNode); // regard as invalid text
- return;
- }
-
- ElementImpl element = null;
- try {
- element = (ElementImpl) this.model.getDocument().createElement(tagName);
- }
- catch (DOMException ex) {
- }
- if (element == null) { // invalid tag
- insertText(flatNode); // regard as invalid text
- return;
- }
- if (attrNodes != null) {
- for (int i = 0; i < attrNodes.size(); i++) {
- element.appendAttributeNode((Attr) attrNodes.get(i));
- }
- }
- element.setJSPTag(true);
- element.setStartStructuredDocumentRegion(flatNode);
- insertStartTag(element);
- }
-
- protected boolean isNestedTagClose(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected boolean isNestedTagOpen(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected String computeNestedTag(String regionType, String tagName, IStructuredDocumentRegion structuredDocumentRegion, ITextRegion region) {
- return tagName;
- }
-
- /**
- * insertNode method
- *
- * @param child
- * org.w3c.dom.Node
- */
- private void insertNode(Node node) {
- if(node != null && this.context != null) {
- Node parent = this.context.getParentNode();
- if(parent != null) {
- Node next = this.context.getNextNode();
- // Reset parents which are closed container elements; should not be parents
- if(parent.getNodeType() == Node.ELEMENT_NODE) {
- String type = ((ElementImpl)parent).getStartStructuredDocumentRegion().getLastRegion().getType();
- if(((ElementImpl)parent).isContainer() && type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- next = parent.getNextSibling();
- parent = parent.getParentNode();
- }
- else {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- while (parent.getNodeType() == Node.ELEMENT_NODE && !adapter.canContain( (Element) parent, node) && adapter.isEndTagOmissible((Element) parent)) {
- next = parent.getNextSibling();
- parent = parent.getParentNode();
- }
- }
- }
- }
- insertNode(parent, node, next);
- next = node.getNextSibling();
- if (next != null) {
- this.context.setNextNode(next);
- } else {
- this.context.setParentNode(node.getParentNode());
- }
- }
- }
- }
-
- /**
- */
- private void insertNode(Node parent, Node node, Node next) {
- while (next != null && next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl nextElement = (ElementImpl) next;
- if (nextElement.hasStartTag())
- break;
- if (!canBeImplicitTag(nextElement, node))
- break;
- parent = nextElement;
- next = nextElement.getFirstChild();
- }
- Element implicitElement = createImplicitElement(parent, node);
- if (implicitElement != null)
- node = implicitElement;
- parent.insertBefore(node, next);
- }
-
- /**
- * insertPI method
- *
- */
- private void insertPI(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- String target = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_PI_OPEN || regionType == DOMRegionContext.XML_PI_CLOSE)
- continue;
- if (target == null)
- target = flatNode.getText(region);
- }
-
- ProcessingInstructionImpl pi = (ProcessingInstructionImpl) this.model.getDocument().createProcessingInstruction(target, null);
- if (pi == null)
- return;
- pi.setStructuredDocumentRegion(flatNode);
- insertNode(pi);
- }
-
- /**
- * insertStartTag method can be used by subclasses, but not overridden.
- *
- * @param element
- * org.w3c.dom.Element
- */
- protected void insertStartTag(Element element) {
- if (element == null)
- return;
- if (this.context == null)
- return;
-
- insertNode(element);
-
- ElementImpl newElement = (ElementImpl) element;
- if (newElement.isEmptyTag() || !newElement.isContainer())
- return;
-
- // Ignore container tags that have been closed
- String type = newElement.getStartStructuredDocumentRegion().getLastRegion().getType();
- if(newElement.isContainer() && type == DOMRegionContext.XML_EMPTY_TAG_CLOSE)
- return;
-
- // demote siblings
- Node parent = this.context.getParentNode();
- if (parent == null)
- return; // error
- Node next = this.context.getNextNode();
- demoteNodes(element, element, parent, next);
-
- // update context
- Node firstChild = element.getFirstChild();
- if (firstChild != null)
- this.context.setNextNode(firstChild);
- else
- this.context.setParentNode(element);
- }
-
- /**
- * insertStartTag method
- *
- */
- private void insertStartTag(IStructuredDocumentRegion flatNode) {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
-
- String tagName = null;
- boolean isEmptyTag = false;
- AttrImpl attr = null;
- List attrNodes = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_NAME || isNestedTagName(regionType)) {
- if (tagName == null)
- tagName = flatNode.getText(region);
- }
- else if (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- isEmptyTag = true;
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- String name = flatNode.getText(region);
- attr = (AttrImpl) this.model.getDocument().createAttribute(name);
- if (attr != null) {
- attr.setNameRegion(region);
- if (attrNodes == null)
- attrNodes = new ArrayList();
- attrNodes.add(attr);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- if (attr != null) {
- attr.setEqualRegion(region);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- if (attr != null) {
- attr.setValueRegion(region);
- attr = null;
- }
- }
- }
-
- if (tagName == null) { // invalid start tag
- insertText(flatNode); // regard as invalid text
- return;
- }
-
- ElementImpl element = null;
- try {
- element = (ElementImpl) this.model.getDocument().createElement(tagName);
- }
- catch (DOMException ex) {
- // typically invalid name
- }
- if (element == null) { // invalid tag
- insertText(flatNode); // regard as invalid text
- return;
- }
- if (attrNodes != null) {
- for (int i = 0; i < attrNodes.size(); i++) {
- element.appendAttributeNode((Attr) attrNodes.get(i));
- }
- }
- if (isEmptyTag)
- element.setEmptyTag(true);
- element.setStartStructuredDocumentRegion(flatNode);
- insertStartTag(element);
- }
-
- /**
- * insertStructuredDocumentRegion method
- *
- */
- protected void insertStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- String regionType = StructuredDocumentRegionUtil.getFirstRegionType(flatNode);
- boolean isTextNode = false;
- if (regionType == DOMRegionContext.XML_TAG_OPEN) {
- insertStartTag(flatNode);
- }
- else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
- insertEndTag(flatNode);
- }
- else if (regionType == DOMRegionContext.XML_COMMENT_OPEN || isNestedCommentOpen(regionType)) {
- insertComment(flatNode);
- }
- else if (regionType == DOMRegionContext.XML_ENTITY_REFERENCE || regionType == DOMRegionContext.XML_CHAR_REFERENCE) {
- insertEntityRef(flatNode);
- isTextNode = true;
- }
- else if (regionType == DOMRegionContext.XML_DECLARATION_OPEN) {
- insertDecl(flatNode);
- }
- else if (regionType == DOMRegionContext.XML_PI_OPEN) {
- insertPI(flatNode);
- }
- else if (regionType == DOMRegionContext.XML_CDATA_OPEN) {
- insertCDATASection(flatNode);
- }
- else if (isNestedTag(regionType)) {
- insertNestedTag(flatNode);
- }
- else {
- insertText(flatNode);
- isTextNode = true;
- }
-
- // Changes to text regions are queued up, and once the value is done changing a notification is sent
- if (!isTextNode && lastTextNode != null) {
- lastTextNode.notifyValueChanged();
- lastTextNode = null;
- }
- }
-
- protected boolean isNestedTag(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected boolean isNestedCommentText(String regionType) {
- boolean result = false;
- return result;
- }
-
-
- protected boolean isNestedCommentOpen(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected boolean isNestedTagName(String regionType) {
- boolean result = false;
- return result;
- }
-
- protected boolean isNestedContent(String regionType) {
- boolean result = false;
- return result;
- }
-
- /**
- * insertText method Can be called from subclasses, not to be overrided or
- * re-implemented.
- *
- */
- protected void insertText(IStructuredDocumentRegion flatNode) {
- TextImpl text = (TextImpl) this.context.findPreviousText();
- if (text != null) { // existing text found
- text.appendStructuredDocumentRegion(flatNode);
- // Adjacent text nodes, where changes were queued
- if (lastTextNode != null && lastTextNode != text)
- lastTextNode.notifyValueChanged();
- lastTextNode = text;
- return;
- }
-
- // new text
- text = (TextImpl) this.model.getDocument().createTextNode(null);
- if (text == null)
- return;
- text.setStructuredDocumentRegion(flatNode);
- insertNode(text);
- }
-
- /**
- */
- protected boolean isEndTag(IDOMElement element) {
- ModelParserAdapter adapter = getParserAdapter();
- if (adapter != null) {
- return adapter.isEndTag(element);
- }
- return element.isEndTag();
- }
-
- /**
- */
- private void promoteNodes(Node root, Node newParent, Node newNext, Node oldParent, Node next) {
- ElementImpl newElement = null;
- if (newParent.getNodeType() == Node.ELEMENT_NODE) {
- newElement = (ElementImpl) newParent;
- }
-
- Node rootParent = root.getParentNode();
- while (oldParent != rootParent) {
- while (next != null) {
- boolean done = false;
- boolean endTag = false;
- if (next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl nextElement = (ElementImpl) next;
- if (!nextElement.hasStartTag()) {
- Node nextChild = nextElement.getFirstChild();
- if (nextChild != null) {
- // promote children
- next = nextChild;
- oldParent = nextElement;
- continue;
- }
-
- if (nextElement.hasEndTag()) {
- if (nextElement.matchEndTag(newElement)) {
- endTag = true;
- }
- }
- else {
- // remove implicit element
- next = nextElement.getNextSibling();
- oldParent.removeChild(nextElement);
- done = true;
- }
- }
- }
-
- if (!done) {
- if (!endTag && newElement != null && !canContain(newElement, next)) {
- newParent = newElement.getParentNode();
- if (newParent == null)
- return; // error
- Node elementNext = newElement.getNextSibling();
- // promote siblings
- promoteNodes(newElement, newParent, elementNext, newElement, newNext);
- newNext = newElement.getNextSibling();
- if (newParent.getNodeType() == Node.ELEMENT_NODE) {
- newElement = (ElementImpl) newParent;
- }
- else {
- newElement = null;
- }
- continue;
- }
-
- Node child = next;
- next = next.getNextSibling();
- oldParent.removeChild(child);
- insertNode(newParent, child, newNext);
- Node childParent = child.getParentNode();
- if (childParent != newParent) {
- newParent = childParent;
- newElement = (ElementImpl) newParent;
- newNext = child.getNextSibling();
- }
- }
- }
-
- if (oldParent.getNodeType() != Node.ELEMENT_NODE)
- return;
- ElementImpl oldElement = (ElementImpl) oldParent;
- oldParent = oldElement.getParentNode();
- if (oldParent == null)
- return; // error
- next = oldElement.getNextSibling();
-
- if (oldElement.hasEndTag()) {
- Element end = null;
- if (!oldElement.hasChildNodes() && !oldElement.hasStartTag()) {
- oldParent.removeChild(oldElement);
- end = oldElement;
- }
- else {
- end = oldElement.removeEndTag();
- }
- if (end != null) {
- insertNode(newParent, end, newNext);
- Node endParent = end.getParentNode();
- if (endParent != newParent) {
- newParent = endParent;
- newElement = (ElementImpl) newParent;
- newNext = end.getNextSibling();
- }
- }
- }
- }
- }
-
- /**
- * removeEndTag method
- *
- * @param element
- * org.w3c.dom.Element
- */
- private void removeEndTag(Element element) {
- if (element == null)
- return;
- if (this.context == null)
- return;
-
- Node parent = element.getParentNode();
- if (parent == null)
- return; // error
-
- if (!((ElementImpl) element).isContainer()) {
- // just update context
- Node elementNext = element.getNextSibling();
- if (elementNext != null)
- this.context.setNextNode(elementNext);
- else
- this.context.setParentNode(parent);
- return;
- }
-
- // demote siblings
- Node next = element.getNextSibling();
- ElementImpl newElement = (ElementImpl) element;
- // find new parent
- for (Node last = newElement.getLastChild(); last != null; last = last.getLastChild()) {
- if (last.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl lastElement = (ElementImpl) last;
- if (lastElement.hasEndTag() || lastElement.isEmptyTag() || !lastElement.isContainer())
- break;
- newElement = lastElement;
- }
- Node lastChild = newElement.getLastChild();
- demoteNodes(element, newElement, parent, next);
-
- // update context
- Node newNext = null;
- if (lastChild != null)
- newNext = lastChild.getNextSibling();
- else
- newNext = newElement.getFirstChild();
- if (newNext != null)
- this.context.setNextNode(newNext);
- else
- this.context.setParentNode(newElement);
- }
-
- /**
- * Remove the specified node if it is no longer required implicit tag with
- * remaining child nodes promoted.
- */
- private Element removeImplicitElement(Node parent) {
- if (parent == null)
- return null;
- if (parent.getNodeType() != Node.ELEMENT_NODE)
- return null;
- ElementImpl element = (ElementImpl) parent;
- if (!element.isImplicitTag())
- return null;
- if (canBeImplicitTag(element))
- return null;
-
- Node elementParent = element.getParentNode();
- if (elementParent == null)
- return null; // error
- Node firstChild = element.getFirstChild();
- Node child = firstChild;
- Node elementNext = element.getNextSibling();
- while (child != null) {
- Node nextChild = child.getNextSibling();
- element.removeChild(child);
- elementParent.insertBefore(child, elementNext);
- child = nextChild;
- }
-
- // reset context
- if (this.context.getParentNode() == element) {
- Node oldNext = this.context.getNextNode();
- if (oldNext != null) {
- this.context.setNextNode(oldNext);
- }
- else {
- if (elementNext != null) {
- this.context.setNextNode(elementNext);
- }
- else {
- this.context.setParentNode(elementParent);
- }
- }
- }
- else if (this.context.getNextNode() == element) {
- if (firstChild != null) {
- this.context.setNextNode(firstChild);
- }
- else {
- if (elementNext != null) {
- this.context.setNextNode(elementNext);
- }
- else {
- this.context.setParentNode(elementParent);
- }
- }
- }
-
- removeNode(element);
- return element;
- }
-
- /**
- * removeNode method
- *
- * @param node
- * org.w3c.dom.Node
- */
- private void removeNode(Node node) {
- if (node == null)
- return;
- if (this.context == null)
- return;
-
- Node parent = node.getParentNode();
- if (parent == null)
- return;
- Node next = node.getNextSibling();
- Node prev = node.getPreviousSibling();
-
- // update context
- Node oldParent = this.context.getParentNode();
- if (node == oldParent) {
- if (next != null)
- this.context.setNextNode(next);
- else
- this.context.setParentNode(parent);
- }
- else {
- Node oldNext = this.context.getNextNode();
- if (node == oldNext) {
- this.context.setNextNode(next);
- }
- }
-
- parent.removeChild(node);
-
- if (removeImplicitElement(parent) != null)
- return;
-
- // demote sibling
- if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl newElement = (ElementImpl) prev;
- if (!newElement.hasEndTag() && !newElement.isEmptyTag() && newElement.isContainer()) {
- // find new parent
- for (Node last = newElement.getLastChild(); last != null; last = last.getLastChild()) {
- if (last.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl lastElement = (ElementImpl) last;
- if (lastElement.hasEndTag() || lastElement.isEmptyTag() || !lastElement.isContainer())
- break;
- newElement = lastElement;
- }
- Node lastChild = newElement.getLastChild();
- demoteNodes(prev, newElement, parent, next);
-
- // update context
- Node newNext = null;
- if (lastChild != null)
- newNext = lastChild.getNextSibling();
- else
- newNext = newElement.getFirstChild();
- if (newNext != null)
- this.context.setNextNode(newNext);
- else
- this.context.setParentNode(newElement);
- }
- }
- }
-
- /**
- * removeStartTag method
- *
- * @param element
- * org.w3c.dom.Element
- */
- private void removeStartTag(Element element) {
- if (element == null)
- return;
- if (this.context == null)
- return;
-
- // for implicit tag
- ElementImpl oldElement = (ElementImpl) element;
- if (canBeImplicitTag(oldElement)) {
- Node newParent = null;
- Node prev = oldElement.getPreviousSibling();
- if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl prevElement = (ElementImpl) prev;
- if (!prevElement.hasEndTag()) {
- if (prevElement.hasStartTag() || prevElement.matchTagName(oldElement.getTagName())) {
- newParent = prevElement;
- }
- }
- }
- if (newParent == null) {
- // this element should stay as implicit tag
- // just remove all attributes
- oldElement.removeStartTag();
-
- // update context
- Node child = oldElement.getFirstChild();
- if (child != null) {
- this.context.setNextNode(child);
- }
- else if (oldElement.hasEndTag()) {
- this.context.setParentNode(oldElement);
- }
- return;
- }
- }
- // for comment tag
- if (oldElement.isCommentTag())
- oldElement.removeStartTag();
-
- // promote children
- Node elementParent = element.getParentNode();
- Node parent = elementParent;
- if (parent == null)
- return;
- Node first = element.getFirstChild();
- Node firstElement = null; // for the case first is removed as end
- // tag
- if (first != null) {
- // find new parent for children
- ElementImpl newElement = null;
- for (Node last = element.getPreviousSibling(); last != null; last = last.getLastChild()) {
- if (last.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl lastElement = (ElementImpl) last;
- if (lastElement.hasEndTag() || lastElement.isEmptyTag() || !lastElement.isContainer())
- break;
- newElement = lastElement;
- }
- Node next = first;
- if (newElement != null) {
- while (next != null) {
- if (!newElement.hasEndTag() && newElement.hasStartTag() && next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl nextElement = (ElementImpl) next;
- if (!nextElement.hasStartTag() && nextElement.hasEndTag() && nextElement.matchEndTag(newElement)) {
- // stop at the matched invalid end tag
- Node elementChild = nextElement.getFirstChild();
- while (elementChild != null) {
- Node nextChild = elementChild.getNextSibling();
- nextElement.removeChild(elementChild);
- newElement.appendChild(elementChild);
- elementChild = nextChild;
- }
-
- next = nextElement.getNextSibling();
- element.removeChild(nextElement);
- newElement.addEndTag(nextElement);
- if (nextElement == first)
- firstElement = newElement;
-
- Node newParent = newElement.getParentNode();
- if (newParent == parent)
- break;
- if (newParent == null || newParent.getNodeType() != Node.ELEMENT_NODE)
- break; // error
- newElement = (ElementImpl) newParent;
- continue;
- }
- }
- if (!canContain(newElement, next)) {
- Node newParent = newElement.getParentNode();
- if (newParent == parent)
- break;
- if (newParent == null || newParent.getNodeType() != Node.ELEMENT_NODE)
- break; // error
- newElement = (ElementImpl) newParent;
- continue;
- }
- Node child = next;
- next = next.getNextSibling();
- element.removeChild(child);
- newElement.appendChild(child);
- }
- newElement = null;
- }
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- newElement = (ElementImpl) parent;
- }
- while (next != null) {
- if (newElement == null || canContain(newElement, next)) {
- Node child = next;
- next = next.getNextSibling();
- element.removeChild(child);
- parent.insertBefore(child, element);
- continue;
- }
-
- parent = newElement.getParentNode();
- if (parent == null)
- return;
-
- // promote siblings
- Node newNext = newElement.getNextSibling();
- Node child = element;
- while (child != null) {
- Node nextChild = child.getNextSibling();
- newElement.removeChild(child);
- parent.insertBefore(child, newNext);
- child = nextChild;
- }
-
- // leave the old end tag where it is
- if (newElement.hasEndTag()) {
- Element end = newElement.removeEndTag();
- if (end != null) {
- parent.insertBefore(end, newNext);
- }
- }
- if (!newElement.hasStartTag()) {
- // implicit element
- if (!newElement.hasChildNodes()) {
- parent.removeChild(newElement);
- }
- }
-
- if (parent.getNodeType() == Node.ELEMENT_NODE) {
- newElement = (ElementImpl) parent;
- }
- else {
- newElement = null;
- }
- }
- }
-
- Node newNext = element;
- Node startElement = null; // for the case element is removed as end
- // tag
- if (oldElement.hasEndTag()) {
- // find new parent for invalid end tag and siblings
- ElementImpl newElement = null;
- for (Node last = element.getPreviousSibling(); last != null; last = last.getLastChild()) {
- if (last.getNodeType() != Node.ELEMENT_NODE)
- break;
- ElementImpl lastElement = (ElementImpl) last;
- if (lastElement.hasEndTag() || lastElement.isEmptyTag() || !lastElement.isContainer())
- break;
- newElement = lastElement;
- }
- if (newElement != null) {
- // demote invalid end tag and sibling
- Node next = element;
- while (next != null) {
- if (!newElement.hasEndTag() && newElement.hasStartTag() && next.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl nextElement = (ElementImpl) next;
- if (!nextElement.hasStartTag() && nextElement.hasEndTag() && nextElement.matchEndTag(newElement)) {
- // stop at the matched invalid end tag
- Node elementChild = nextElement.getFirstChild();
- while (elementChild != null) {
- Node nextChild = elementChild.getNextSibling();
- nextElement.removeChild(elementChild);
- newElement.appendChild(elementChild);
- elementChild = nextChild;
- }
-
- next = nextElement.getNextSibling();
- parent.removeChild(nextElement);
- newElement.addEndTag(nextElement);
- if (nextElement == newNext)
- startElement = newElement;
-
- Node newParent = newElement.getParentNode();
- if (newParent == parent)
- break;
- if (newParent == null || newParent.getNodeType() != Node.ELEMENT_NODE)
- break; // error
- newElement = (ElementImpl) newParent;
- continue;
- }
- }
- if (!canContain(newElement, next)) {
- Node newParent = newElement.getParentNode();
- if (newParent == parent)
- break;
- if (newParent == null || newParent.getNodeType() != Node.ELEMENT_NODE)
- break; // error
- newElement = (ElementImpl) newParent;
- continue;
- }
- Node child = next;
- next = next.getNextSibling();
- parent.removeChild(child);
- if (child == oldElement) {
- if (!oldElement.isCommentTag()) {
- // clone (re-create) end tag
- Element end = oldElement.removeEndTag();
- if (end != null) {
- child = end;
- newNext = end;
- }
- }
- }
- newElement.appendChild(child);
- }
- }
- else {
- if (!oldElement.isCommentTag()) {
- // clone (re-create) end tag
- Element end = oldElement.removeEndTag();
- if (end != null) {
- parent.insertBefore(end, oldElement);
- parent.removeChild(oldElement);
- newNext = end;
- }
- }
- }
- }
- else {
- newNext = oldElement.getNextSibling();
- parent.removeChild(oldElement);
- }
-
- // update context
- Node oldParent = this.context.getParentNode();
- Node oldNext = this.context.getNextNode();
- if (element == oldParent) {
- if (oldNext != null) {
- this.context.setNextNode(oldNext); // reset for new parent
- }
- else if (newNext != null) {
- this.context.setNextNode(newNext);
- }
- else {
- this.context.setParentNode(parent);
- }
- }
- else if (element == oldNext) {
- if (firstElement != null) {
- this.context.setParentNode(firstElement);
- }
- else if (first != null) {
- this.context.setNextNode(first);
- }
- else if (startElement != null) {
- this.context.setParentNode(startElement);
- }
- else {
- this.context.setNextNode(newNext);
- }
- }
-
- removeImplicitElement(elementParent);
- }
-
- /**
- * removeStructuredDocumentRegion method
- *
- */
- private void removeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- NodeImpl next = (NodeImpl) this.context.getNextNode();
- if (next != null) {
- short nodeType = next.getNodeType();
- if (nodeType != Node.ELEMENT_NODE) {
- IStructuredDocumentRegion flatNode = next.getStructuredDocumentRegion();
- if (flatNode == oldStructuredDocumentRegion) {
- removeNode(next);
- return;
- }
- if (nodeType != Node.TEXT_NODE) {
- throw new StructuredDocumentRegionManagementException();
- }
- if (flatNode == null) {
- // this is the case for empty Text
- // remove and continue
- removeNode(next);
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- TextImpl text = (TextImpl) next;
- boolean isShared = text.isSharingStructuredDocumentRegion(oldStructuredDocumentRegion);
- if (isShared) {
- // make sure there is next Text node sharing this
- TextImpl nextText = (TextImpl) this.context.findNextText();
- if (nextText == null || !nextText.hasStructuredDocumentRegion(oldStructuredDocumentRegion)) {
- isShared = false;
- }
- }
- oldStructuredDocumentRegion = text.removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- if (oldStructuredDocumentRegion == null) {
- throw new StructuredDocumentRegionManagementException();
- }
- if (text.getStructuredDocumentRegion() == null) {
- // this is the case partial IStructuredDocumentRegion is
- // removed
- removeNode(text);
- }
- else {
- // notify the change
- text.notifyValueChanged();
- }
- // if shared, continue to remove IStructuredDocumentRegion
- // from them
- if (isShared)
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
-
- ElementImpl element = (ElementImpl) next;
- if (element.hasStartTag()) {
- IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
- if (flatNode != oldStructuredDocumentRegion) {
- throw new StructuredDocumentRegionManagementException();
- }
- if (element.hasEndTag() || element.hasChildNodes()) {
- element.setStartStructuredDocumentRegion(null);
- removeStartTag(element);
- }
- else {
- removeNode(element);
- }
- }
- else {
- Node child = element.getFirstChild();
- if (child != null) {
- this.context.setNextNode(child);
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
-
- if (!element.hasEndTag()) {
- // implicit element
- removeNode(element);
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
-
- IStructuredDocumentRegion flatNode = element.getEndStructuredDocumentRegion();
- if (flatNode != oldStructuredDocumentRegion) {
- throw new StructuredDocumentRegionManagementException();
- }
- removeNode(element);
- }
- return;
- }
-
- Node parent = this.context.getParentNode();
- if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE) {
- throw new StructuredDocumentRegionManagementException();
- }
-
- ElementImpl end = (ElementImpl) parent;
- if (end.hasEndTag()) {
- IStructuredDocumentRegion flatNode = end.getEndStructuredDocumentRegion();
- if (flatNode != oldStructuredDocumentRegion) {
- throw new StructuredDocumentRegionManagementException();
- }
- if (!end.hasStartTag() && !end.hasChildNodes()) {
- this.context.setNextNode(end);
- removeNode(end);
- }
- else {
- end.setEndStructuredDocumentRegion(null);
- removeEndTag(end);
- }
- return;
- }
-
- next = (NodeImpl) end.getNextSibling();
- if (next != null) {
- this.context.setNextNode(next);
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
-
- parent = end.getParentNode();
- if (parent != null) {
- this.context.setParentNode(parent);
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- }
-
- /**
- * replaceRegions method
- *
- * @param newRegions
- * java.util.Vector
- * @param oldRegions
- * java.util.Vector
- */
- void replaceRegions(IStructuredDocumentRegion flatNode, ITextRegionList newRegions, ITextRegionList oldRegions) {
- if (flatNode == null)
- return;
- if (this.model.getDocument() == null)
- return;
- this.context = new XMLModelContext(this.model.getDocument());
-
- // optimize typical cases
- String regionType = StructuredDocumentRegionUtil.getFirstRegionType(flatNode);
- if (regionType == DOMRegionContext.XML_TAG_OPEN) {
- changeStartTag(flatNode, newRegions, oldRegions);
- }
- else if (regionType == DOMRegionContext.XML_END_TAG_OPEN) {
- changeEndTag(flatNode, newRegions, oldRegions);
- }
- else {
- changeStructuredDocumentRegion(flatNode);
- }
- }
-
- /**
- * replaceStructuredDocumentRegions method
- *
- */
- void replaceStructuredDocumentRegions(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
- if (this.model.getDocument() == null)
- return;
- this.context = new XMLModelContext(this.model.getDocument());
-
- int newCount = (newStructuredDocumentRegions != null ? newStructuredDocumentRegions.getLength() : 0);
- int oldCount = (oldStructuredDocumentRegions != null ? oldStructuredDocumentRegions.getLength() : 0);
-
- if (oldCount > 0) {
- setupContext(oldStructuredDocumentRegions.item(0));
- // Node startParent = this.context.getParentNode();
-
- for (int i = 0; i < oldCount; i++) {
- IStructuredDocumentRegion documentRegion = oldStructuredDocumentRegions.item(i);
- removeStructuredDocumentRegion(documentRegion);
- }
- }
- else {
- if (newCount == 0)
- return;
- setupContext(newStructuredDocumentRegions.item(0));
- }
- // make sure the parent is set to deepest level
- // when end tag has been removed
- this.context.setLast();
-
- if (newCount > 0) {
- for (int i = 0; i < newCount; i++) {
- IStructuredDocumentRegion documentRegion = newStructuredDocumentRegions.item(i);
- insertStructuredDocumentRegion(documentRegion);
- }
- }
-
- cleanupText();
- cleanupEndTag();
- }
-
- /**
- * setupContext method
- *
- */
- private void setupContext(IStructuredDocumentRegion startStructuredDocumentRegion) {
- int offset = startStructuredDocumentRegion.getStart();
- if (offset < 0)
- return;
- NodeImpl root = (NodeImpl) this.context.getRootNode();
- if (root == null)
- return;
-
- if (offset == 0) {
- // at the beginning of document
- Node child = root.getFirstChild();
- if (child != null)
- this.context.setNextNode(child);
- else
- this.context.setParentNode(root);
- return;
- }
-
- NodeImpl node = (NodeImpl) root.getNodeAt(offset);
- if (node == null) {
- // might be at the end of document
- this.context.setParentNode(root);
- this.context.setLast();
- return;
- }
-
- if (offset == node.getStartOffset()) {
- this.context.setNextNode(node);
- return;
- }
-
- if (node.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) node;
- Text nextText = text.splitText(startStructuredDocumentRegion);
- // notify the change
- text.notifyValueChanged();
- if (nextText == null)
- return; // error
- this.context.setNextNode(nextText);
- return;
- }
-
- for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (offset >= ((NodeImpl) child).getEndOffset())
- continue;
- this.context.setNextNode(child);
- return;
- }
- this.context.setParentNode(node);
- this.context.setLast();
- }
-
- protected XMLModelContext getContext() {
- return context;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelUpdater.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelUpdater.java
deleted file mode 100644
index a92b2338ec..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/XMLModelUpdater.java
+++ /dev/null
@@ -1,1704 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver (STAR) - bug 296999 - Inefficient use of new String()
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.document;
-
-
-
-import java.util.Enumeration;
-import java.util.Iterator;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
-
-
-/**
- * XMLModelUpdater class
- */
-public class XMLModelUpdater {
- private int diff = 0;
- private int gapLength = 0;
- private int gapOffset = 0;
- private IStructuredDocumentRegion gapStructuredDocumentRegion = null;
- private ISourceGenerator generator = null;
- private DOMModelImpl model = null;
- private NodeImpl nextNode = null;
- private NodeImpl parentNode = null;
-
- protected XMLModelUpdater(DOMModelImpl model) {
- super();
-
- if (model != null) {
- this.model = model;
- this.generator = model.getGenerator();
- }
- }
-
- /**
- * changeAttrValue method
- *
- * @param attrNode
- * org.w3c.dom.Attr
- */
- private void changeAttrName(Attr attrNode) {
- if (attrNode == null)
- return;
-
- AttrImpl attr = (AttrImpl) attrNode;
- ElementImpl element = (ElementImpl) attr.getOwnerElement();
- if (element == null)
- return;
-
- if (element.isCommentTag()) {
- changeStartTag(element);
- return;
- }
-
- int offset = element.getStartOffset();
- int start = offset;
- int end = offset;
-
- String name = attr.getName();
- if (name == null)
- name = NodeImpl.EMPTY_STRING;
- ITextRegion nameRegion = attr.getNameRegion();
- if (nameRegion == null)
- return; // error
- start += nameRegion.getStart();
- // use getTextEnd() because getEnd() may include the tailing spaces
- end += nameRegion.getTextEnd();
-
- replaceSource(name, start, end);
- }
-
- /**
- * changeAttrValue method
- *
- * @param attrNode
- * org.w3c.dom.Attr
- */
- private void changeAttrValue(Attr attrNode) {
- if (attrNode == null)
- return;
-
- AttrImpl attr = (AttrImpl) attrNode;
- ElementImpl element = (ElementImpl) attr.getOwnerElement();
- if (element == null)
- return;
-
- if (element.isCommentTag()) {
- changeStartTag(element);
- return;
- }
-
- int offset = element.getStartOffset();
- int start = offset;
- int end = offset;
-
- String value = null;
- ITextRegion valueRegion = attr.getValueRegion();
- if (valueRegion != null) {
- char quote = 0; // no quote preference
- // DW: 4/16/2003 due to change in structuredDocument ... we need a
- // flatnode to
- // get at region values. For now I'll assume this is always the
- // first
- // flatnode .. may need to make smarter later (e.g. to search for
- // the flatnode that this.valueRegion belongs to.
- IStructuredDocumentRegion documentRegion = element.getFirstStructuredDocumentRegion();
- String oldValue = documentRegion.getText(valueRegion);
- if (oldValue != null && oldValue.length() > 0) {
- char firstChar = oldValue.charAt(0);
- if (firstChar == '"' || firstChar == '\'') {
- quote = firstChar;
- }
- }
-
- ITextRegion startRegion = valueRegion;
-
- value = this.generator.generateAttrValue(attr, quote);
- if (value == null) {
- value = NodeImpl.EMPTY_STRING;
- // remove equal too
- ITextRegion equalRegion = attr.getEqualRegion();
- if (equalRegion != null)
- startRegion = equalRegion;
- }
- attr.setValueRegion(valueRegion); // reset value
-
- start += startRegion.getStart();
- // use getTextEnd() because getEnd() may include the tailing
- // spaces
- end += valueRegion.getTextEnd();
- }
- else {
- ITextRegion equalRegion = attr.getEqualRegion();
-
- value = this.generator.generateAttrValue(attr);
- if (value == null) {
- if (equalRegion == null)
- return; // nothng to do
- value = NodeImpl.EMPTY_STRING;
- // remove equal
- start += equalRegion.getStart();
- end += equalRegion.getTextEnd();
- }
- else {
- if (equalRegion != null) {
- // use getTextEnd() because getEnd() may include the
- // tailing spaces
- start += equalRegion.getTextEnd();
- }
- else {
- ITextRegion nameRegion = attr.getNameRegion();
- if (nameRegion == null)
- return; // must never happen
- // use getTextEnd() because getEnd() may include the
- // tailing spaces
- start += nameRegion.getTextEnd();
- value = '=' + value;
- }
- end = start;
- }
- }
-
- replaceSource(value, start, end);
- }
-
- /**
- */
- void changeEndTag(Element element) {
- String source = this.generator.generateEndTag(element);
- if (source == null)
- return;
- int length = source.length();
- if (length == 0)
- return;
-
- ElementImpl impl = (ElementImpl) element;
- int offset = impl.getEndStartOffset();
- int start = offset;
- int end = offset;
- if (impl.hasEndTag()) {
- end = impl.getEndOffset();
- this.gapStructuredDocumentRegion = impl.getEndStructuredDocumentRegion();
- impl.setEndStructuredDocumentRegion(new StructuredDocumentRegionProxy(offset, length));
- }
-
- replaceSource(source, start, end);
- }
-
- /**
- * changeName method
- *
- * @param node
- * org.w3c.dom.Node
- */
- void changeName(Node node) {
- if (node == null)
- return;
- if (getStructuredDocument() == null)
- return;
-
- // support changing name of attribute for setPrefix()
- short nodeType = node.getNodeType();
- if (nodeType == Node.ATTRIBUTE_NODE) {
- changeAttrName((Attr) node);
- return;
- }
-
- // not supported
- return;
- }
-
- void changeRegion(RegionChangedEvent change, IStructuredDocumentRegion flatNode, ITextRegion region) {
- if (change.getOffset() >= flatNode.getStartOffset() + region.getTextEnd()) {
- // change is entirely in white-space
- return;
- }
-
- NodeImpl root = (NodeImpl) this.model.getDocument();
- this.parentNode = root;
- this.nextNode = (NodeImpl) root.getFirstChild();
-
- removeGapStructuredDocumentRegion(flatNode);
- insertGapStructuredDocumentRegionBefore(flatNode.getStart());
- changeStructuredDocumentRegion(flatNode);
- insertGapStructuredDocumentRegionAfter(flatNode.getEnd());
- }
-
- /**
- * This is a fallback method to regenerate the start tag.
- */
- void changeStartTag(Element element) {
- if (element == null)
- return;
- ElementImpl impl = (ElementImpl) element;
-
- if (!impl.hasStartTag() && !impl.hasEndTag()) {
- // need to generate the start and the end tags
- Node parent = element.getParentNode();
- if (parent != null) {
- replaceChild(parent, element, element);
- return;
- }
- // else error
- }
-
- String source = this.generator.generateStartTag(element);
- if (source == null)
- return;
- int length = source.length();
- if (length == 0)
- return;
-
- int offset = impl.getStartOffset();
- int start = offset;
- int end = offset;
- if (impl.hasStartTag()) {
- end = impl.getStartEndOffset();
- this.gapStructuredDocumentRegion = impl.getStartStructuredDocumentRegion();
- }
- impl.setStartStructuredDocumentRegion(new StructuredDocumentRegionProxy(offset, length));
-
- replaceSource(source, start, end);
- }
-
- private void changeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (oldStructuredDocumentRegion == null)
- return; // error
- if (this.parentNode == null)
- return; // error
-
- int oldOffset = oldStructuredDocumentRegion.getStart();
- int oldEnd = oldStructuredDocumentRegion.getEnd();
- boolean isEndTag = false;
-
- // find owner node
- NodeImpl ownerNode = null;
- while (this.parentNode != null) {
- if (this.nextNode != null) {
- IStructuredDocumentRegion nextStructuredDocumentRegion = this.nextNode.getStructuredDocumentRegion();
- if (nextStructuredDocumentRegion != null) {
- if (nextStructuredDocumentRegion == oldStructuredDocumentRegion) {
- ownerNode = this.nextNode;
- break;
- }
- int nextOffset = nextStructuredDocumentRegion.getStart();
- if (nextOffset == oldOffset) { // found
- ownerNode = this.nextNode;
- break;
- }
- if (this.nextNode.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) this.nextNode;
- if (text.hasStructuredDocumentRegion(oldStructuredDocumentRegion)) {
- ownerNode = this.nextNode;
- break;
- }
- int nextEnd = nextStructuredDocumentRegion.getEnd();
- if (nextOffset < oldEnd && nextEnd > oldOffset) {
- ownerNode = this.nextNode;
- break;
- }
- }
- }
-
- Node child = this.nextNode.getFirstChild();
- if (child != null) {
- this.parentNode = this.nextNode;
- this.nextNode = (NodeImpl) child;
- continue;
- }
-
- if (this.nextNode.getNodeType() == Node.ELEMENT_NODE) {
- this.parentNode = this.nextNode;
- this.nextNode = null;
- continue;
- }
-
- this.nextNode = (NodeImpl) this.nextNode.getNextSibling();
- if (this.nextNode != null)
- continue;
- }
-
- if (this.parentNode.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) this.parentNode;
- IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- if (endStructuredDocumentRegion == oldStructuredDocumentRegion) {
- ownerNode = this.parentNode;
- isEndTag = true;
- break;
- }
- int endOffset = endStructuredDocumentRegion.getStart();
- if (endOffset == oldOffset) { // found
- ownerNode = this.parentNode;
- isEndTag = true;
- break;
- }
- }
- }
-
- this.nextNode = (NodeImpl) this.parentNode.getNextSibling();
- this.parentNode = (NodeImpl) this.parentNode.getParentNode();
- }
- if (ownerNode == null)
- throw new StructuredDocumentRegionManagementException();
-
- short nodeType = ownerNode.getNodeType();
- if (nodeType == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) ownerNode;
- if (isEndTag) {
- element.setEndStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- else {
- element.setStartStructuredDocumentRegion(oldStructuredDocumentRegion);
- updateAttrRegions(element, oldStructuredDocumentRegion);
- }
- }
- else if (nodeType == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) ownerNode;
-
- IStructuredDocumentRegion flatNode = text.getStructuredDocumentRegion();
- if (flatNode == oldStructuredDocumentRegion) {
- int newOffset = oldOffset;
- int newEnd = oldEnd;
- if (oldOffset == this.gapOffset) {
- newOffset += this.diff;
- }
- else {
- newEnd = this.gapOffset;
- }
- int newLength = newEnd - newOffset;
- IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(newOffset, newLength, oldStructuredDocumentRegion);
- text.setStructuredDocumentRegion(newStructuredDocumentRegion);
-
- if (oldEnd > newEnd) {
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- return;
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- int offset = proxy.getOffset();
- int end = offset + proxy.getLength();
- if (proxy.getStructuredDocumentRegion() == null) {
- if (offset == oldOffset && end == oldEnd) {
- text.setStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- else {
- if (end > oldEnd) {
- StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
- container.appendStructuredDocumentRegion(oldStructuredDocumentRegion);
- proxy.setOffset(oldEnd);
- proxy.setLength(end - oldEnd);
- container.appendStructuredDocumentRegion(proxy);
- text.setStructuredDocumentRegion(container);
- }
- else {
- proxy.setStructuredDocumentRegion(oldStructuredDocumentRegion);
-
- if (end < oldEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- }
- }
- return;
- }
-
- if (offset >= this.gapOffset) {
- proxy.setOffset(offset + this.diff);
- end += this.diff;
- }
- if (end < oldEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- }
- else if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue; // error
- if (content == oldStructuredDocumentRegion) {
- int newOffset = oldOffset;
- int newEnd = oldEnd;
- if (oldOffset == this.gapOffset) {
- newOffset += this.diff;
- }
- else {
- newEnd = this.gapOffset;
- }
- int newLength = newEnd - newOffset;
- IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(newOffset, newLength, oldStructuredDocumentRegion);
- container.replaceStructuredDocumentRegion(newStructuredDocumentRegion, i);
-
- if (oldEnd > newEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- return;
- }
-
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- int offset = proxy.getOffset();
- int end = offset + proxy.getLength();
- if (end <= oldOffset)
- continue;
- if (proxy.getStructuredDocumentRegion() == null) {
- if (offset == oldOffset && end == oldEnd) {
- container.replaceStructuredDocumentRegion(oldStructuredDocumentRegion, i);
- }
- else {
- if (end > oldEnd) {
- container.insertStructuredDocumentRegion(oldStructuredDocumentRegion, i);
- proxy.setOffset(oldEnd);
- proxy.setLength(end - oldEnd);
- }
- else {
- proxy.setStructuredDocumentRegion(oldStructuredDocumentRegion);
-
- if (end < oldEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- }
- }
- return;
- }
-
- if (offset >= this.gapOffset) {
- proxy.setOffset(offset + this.diff);
- end += this.diff;
- }
- if (end < oldEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- changeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- }
- }
- }
- else {
- throw new StructuredDocumentRegionManagementException();
- }
- }
- else {
- ownerNode.setStructuredDocumentRegion(oldStructuredDocumentRegion);
- }
- }
-
- /**
- */
- private void changeTextData(Text text) {
- if (text == null)
- return;
-
- String source = this.generator.generateSource(text);
- if (source == null)
- source = NodeImpl.EMPTY_STRING;
- int length = source.length();
-
- TextImpl impl = (TextImpl) text;
- int start = impl.getStartOffset();
- int end = impl.getEndOffset();
- int offset = start;
-
- // make sure previous tag is closed
- Node prev = text.getPreviousSibling();
- if (prev != null) {
- String preTag = getCloseTag((IDOMNode) prev);
- if (preTag != null && preTag.length() > 0) {
- offset += preTag.length();
- source = preTag + source;
- }
- }
- else {
- Node parent = text.getParentNode();
- if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) parent;
- String preTag = getStartCloseTag(element);
- if (preTag != null && preTag.length() > 0) {
- offset += preTag.length();
- StringBuffer buffer = new StringBuffer();
- buffer.append(preTag);
- buffer.append(source);
- if (text.getNextSibling() == null && !element.hasEndTag() && (element.isJSPContainer() || element.isCDATAContainer())) {
- // need to generate the end tag
- String postTag = this.generator.generateEndTag(element);
- if (postTag != null) {
- int postLength = postTag.length();
- if (postLength > 0) {
- buffer.append(postTag);
- int postOffset = offset + length;
- IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(postOffset, postLength);
- element.setEndStructuredDocumentRegion(flatNode);
- }
- }
- }
- source = buffer.toString();
- }
- }
- }
-
- this.gapStructuredDocumentRegion = impl.getStructuredDocumentRegion();
- IStructuredDocumentRegion newStructuredDocumentRegion = null;
- if (length > 0)
- newStructuredDocumentRegion = new StructuredDocumentRegionProxy(offset, length);
- impl.setStructuredDocumentRegion(newStructuredDocumentRegion);
-
- replaceSource(source, start, end);
- }
-
- /**
- * changeValue method
- *
- * @param node
- * org.w3c.dom.Node
- */
- void changeValue(Node node) {
- if (node == null)
- return;
- if (getStructuredDocument() == null)
- return;
-
- short nodeType = node.getNodeType();
- if (nodeType == Node.TEXT_NODE) {
- changeTextData((Text) node);
- return;
- }
- if (nodeType == Node.ATTRIBUTE_NODE) {
- changeAttrValue((Attr) node);
- return;
- }
- if (nodeType == Node.ELEMENT_NODE) {
- changeStartTag((Element) node);
- return;
- }
-
- String source = this.generator.generateSource(node);
- if (source == null)
- source = NodeImpl.EMPTY_STRING;
- int length = source.length();
-
- NodeImpl impl = (NodeImpl) node;
- int start = impl.getStartOffset();
- int end = impl.getEndOffset();
-
- this.gapStructuredDocumentRegion = impl.getStructuredDocumentRegion();
- IStructuredDocumentRegion flatNode = null;
- if (length > 0)
- flatNode = new StructuredDocumentRegionProxy(start, length);
- impl.setStructuredDocumentRegion(flatNode);
-
- replaceSource(source, start, end);
- }
-
- /**
- */
- private String getAttrValueClose(IDOMElement element) {
- if (element == null)
- return null;
-
- IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
- if (flatNode == null)
- return null;
- ITextRegion region = StructuredDocumentRegionUtil.getLastRegion(flatNode);
- if (region == null || region.getType() != DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
- return null;
- String value = flatNode.getText(region);
- if (value == null)
- return null;
- int length = value.length();
- if (length == 0)
- return null;
-
- // check open JSP tag
- boolean closeJSPTag = false;
- int offset = value.indexOf(JSPTag.TAG_OPEN);
- while (offset >= 0) {
- offset = value.indexOf(JSPTag.TAG_CLOSE, offset + 2);
- if (offset < 0) {
- closeJSPTag = true;
- break;
- }
- offset = value.indexOf(JSPTag.TAG_OPEN, offset + 2);
- }
-
- // check quote
- boolean closeQuote = false;
- char firstChar = value.charAt(0);
- if (firstChar == '"' || firstChar == '\'') {
- if (closeJSPTag || length == 1 || value.charAt(length - 1) != firstChar) {
- closeQuote = true;
- }
- }
-
- if (!closeJSPTag && !closeQuote)
- return null;
-
- StringBuffer buffer = new StringBuffer();
- if (closeJSPTag)
- buffer.append(JSPTag.TAG_CLOSE);
- if (closeQuote)
- buffer.append(firstChar);
- return buffer.toString();
- }
-
- /**
- * Gather close tags recursively.
- */
- private String getCloseTag(IDOMNode node) {
- if (node == null || node.isClosed())
- return null;
-
- if (node.getNodeType() != Node.ELEMENT_NODE) {
- return this.generator.generateCloseTag(node);
- }
-
- ElementImpl element = (ElementImpl) node;
- if (element.hasEndTag()) {
- // end tag is not closed
- return this.generator.generateCloseTag(element);
- }
-
- // no end tag
- int offset = element.getEndOffset();
- StringBuffer buffer = new StringBuffer();
-
- IDOMNode lastChild = (IDOMNode) element.getLastChild();
- if (lastChild == null) {
- if (!element.isStartTagClosed()) {
- if (element.preferEmptyTag())
- element.setEmptyTag(true);
- String closeTag = getStartCloseTag(element);
- if (closeTag != null) {
- int length = closeTag.length();
- if (length > 0) {
- buffer.append(closeTag);
- offset += length;
- }
- }
- }
- }
- else {
- String closeTag = getCloseTag(lastChild);
- if (closeTag != null) {
- int length = closeTag.length();
- if (length > 0) {
- buffer.append(closeTag);
- offset += length;
- }
- }
- }
-
- String endTag = this.generator.generateEndTag(element);
- if (endTag != null) {
- int length = endTag.length();
- if (length > 0) {
- buffer.append(endTag);
- IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(offset, length);
- element.setEndStructuredDocumentRegion(flatNode);
- }
- }
-
- return buffer.toString();
- }
-
- /**
- */
- private String getStartCloseTag(IDOMElement element) {
- if (element == null || element.isStartTagClosed())
- return null;
-
- StringBuffer buffer = new StringBuffer();
- String attrValueClose = getAttrValueClose(element);
- if (attrValueClose != null)
- buffer.append(attrValueClose);
- String closeTag = this.generator.generateCloseTag(element);
- if (closeTag != null)
- buffer.append(closeTag);
- return buffer.toString();
- }
-
- private IStructuredDocument getStructuredDocument() {
- if (model == null)
- return null;
- return model.getStructuredDocument();
- }
-
- /**
- */
- void initialize() {
- this.gapStructuredDocumentRegion = null;
- this.gapOffset = 0;
- this.gapLength = 0;
- this.diff = 0;
- this.parentNode = null;
- this.nextNode = null;
- }
-
- private void insertGapStructuredDocumentRegionAfter(int endOffset) {
- if (this.gapStructuredDocumentRegion == null)
- return;
-
- if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) this.gapStructuredDocumentRegion;
- IStructuredDocumentRegion flatNode = proxy.getStructuredDocumentRegion();
- if (flatNode != null)
- insertStructuredDocumentRegion(flatNode);
- }
- else if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) this.gapStructuredDocumentRegion;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue;
- if (content.getStart() < endOffset)
- continue;
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- IStructuredDocumentRegion flatNode = proxy.getStructuredDocumentRegion();
- if (flatNode != null)
- insertStructuredDocumentRegion(flatNode);
- }
- else {
- insertStructuredDocumentRegion(content);
- }
- }
- }
- else {
- insertStructuredDocumentRegion(this.gapStructuredDocumentRegion);
- }
- }
-
- private void insertGapStructuredDocumentRegionBefore(int startOffset) {
- if (this.gapStructuredDocumentRegion == null)
- return;
-
- if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) this.gapStructuredDocumentRegion;
- IStructuredDocumentRegion flatNode = proxy.getStructuredDocumentRegion();
- if (flatNode != null)
- insertStructuredDocumentRegion(flatNode);
- }
- else if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) this.gapStructuredDocumentRegion;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue;
- if (content.getStart() >= startOffset)
- return;
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- IStructuredDocumentRegion flatNode = proxy.getStructuredDocumentRegion();
- if (flatNode != null)
- insertStructuredDocumentRegion(flatNode);
- }
- else {
- insertStructuredDocumentRegion(content);
- }
- }
- }
- else {
- insertStructuredDocumentRegion(this.gapStructuredDocumentRegion);
- }
- }
-
- /**
- */
- private void insertStructuredDocumentRegion(IStructuredDocumentRegion newStructuredDocumentRegion) {
- if (newStructuredDocumentRegion == null)
- return; // error
- if (this.parentNode == null)
- return; // error
-
- int newOffset = newStructuredDocumentRegion.getStart();
- int newEnd = newStructuredDocumentRegion.getEnd();
- boolean isEndTag = false;
-
- // find owner node
- NodeImpl ownerNode = null;
- while (this.parentNode != null) {
- if (this.nextNode != null) {
- IStructuredDocumentRegion nextStructuredDocumentRegion = this.nextNode.getStructuredDocumentRegion();
- if (nextStructuredDocumentRegion != null) {
- int nextOffset = nextStructuredDocumentRegion.getStart();
- if (nextOffset == newOffset) { // found
- ownerNode = this.nextNode;
- break;
- }
- if (this.nextNode.getNodeType() == Node.TEXT_NODE) {
- int nextEnd = nextStructuredDocumentRegion.getEnd();
- if (nextOffset < newEnd && nextEnd > newOffset) {
- ownerNode = this.nextNode;
- break;
- }
- }
- }
-
- Node child = this.nextNode.getFirstChild();
- if (child != null) {
- this.parentNode = this.nextNode;
- this.nextNode = (NodeImpl) child;
- continue;
- }
-
- if (this.nextNode.getNodeType() == Node.ELEMENT_NODE) {
- this.parentNode = this.nextNode;
- this.nextNode = null;
- continue;
- }
-
- this.nextNode = (NodeImpl) this.nextNode.getNextSibling();
- if (this.nextNode != null)
- continue;
- }
-
- if (this.parentNode.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) this.parentNode;
- IStructuredDocumentRegion endStructuredDocumentRegion = element.getEndStructuredDocumentRegion();
- if (endStructuredDocumentRegion != null) {
- int endOffset = endStructuredDocumentRegion.getStart();
- if (endOffset == newOffset) { // found
- ownerNode = this.parentNode;
- isEndTag = true;
- break;
- }
- }
- }
-
- this.nextNode = (NodeImpl) this.parentNode.getNextSibling();
- this.parentNode = (NodeImpl) this.parentNode.getParentNode();
- }
- if (ownerNode == null)
- throw new StructuredDocumentRegionManagementException();
-
- short nodeType = ownerNode.getNodeType();
- if (nodeType == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) ownerNode;
- if (isEndTag) {
- element.setEndStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- else {
- element.setStartStructuredDocumentRegion(newStructuredDocumentRegion);
- updateAttrRegions(element, newStructuredDocumentRegion);
- }
- }
- else if (nodeType == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) ownerNode;
- IStructuredDocumentRegion oldStructuredDocumentRegion = text.getStructuredDocumentRegion();
- if (oldStructuredDocumentRegion == null) {
- throw new StructuredDocumentRegionManagementException();
- }
- int oldOffset = oldStructuredDocumentRegion.getStart();
- int oldEnd = oldStructuredDocumentRegion.getEnd();
- if (oldOffset == newOffset && oldEnd == newEnd) {
- text.setStructuredDocumentRegion(newStructuredDocumentRegion);
- return;
- }
-
- if (oldStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) oldStructuredDocumentRegion;
- if (oldEnd > newEnd) {
- StructuredDocumentRegionContainer container = new StructuredDocumentRegionContainer();
- if (oldOffset == newOffset) {
- container.appendStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- else {
- StructuredDocumentRegionProxy newProxy = new StructuredDocumentRegionProxy();
- newProxy.setOffset(oldOffset);
- newProxy.setLength(newEnd - oldOffset);
- newProxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
- container.appendStructuredDocumentRegion(newProxy);
- }
- proxy.setOffset(newEnd);
- proxy.setLength(oldEnd - newEnd);
- container.appendStructuredDocumentRegion(proxy);
- text.setStructuredDocumentRegion(container);
- }
- else {
- proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
-
- if (oldEnd < newEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- insertStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- }
- return;
- }
-
- if (oldStructuredDocumentRegion instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) oldStructuredDocumentRegion;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue; // error
- int offset = content.getStart();
- int end = content.getEnd();
- if (end <= newOffset)
- continue;
- if (offset == newOffset && end == newEnd) {
- container.replaceStructuredDocumentRegion(newStructuredDocumentRegion, i);
- return;
- }
-
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (end > newEnd) {
- if (offset == newOffset) {
- container.insertStructuredDocumentRegion(newStructuredDocumentRegion, i);
- }
- else {
- StructuredDocumentRegionProxy newProxy = new StructuredDocumentRegionProxy();
- newProxy.setOffset(offset);
- newProxy.setLength(newEnd - offset);
- newProxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
- container.insertStructuredDocumentRegion(newProxy, i);
- }
- proxy.setOffset(newEnd);
- proxy.setLength(end - newEnd);
- return;
- }
- else {
- proxy.setStructuredDocumentRegion(newStructuredDocumentRegion);
- if (end == newEnd)
- return;
- }
- }
- }
-
- if (oldEnd < newEnd) { // to be shared
- this.nextNode = (NodeImpl) text.getNextSibling();
- insertStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- return;
- }
- else {
- throw new StructuredDocumentRegionManagementException();
- }
- }
- else {
- ownerNode.setStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- }
-
- private void removeGapStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (this.gapStructuredDocumentRegion == null)
- return;
-
- if (this.gapStructuredDocumentRegion == oldStructuredDocumentRegion) {
- this.gapStructuredDocumentRegion = null;
- return;
- }
-
- if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) this.gapStructuredDocumentRegion;
- IStructuredDocumentRegion flatNode = proxy.getStructuredDocumentRegion();
- if (flatNode == oldStructuredDocumentRegion)
- this.gapStructuredDocumentRegion = null;
- }
- else if (this.gapStructuredDocumentRegion instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) this.gapStructuredDocumentRegion;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue;
- if (content == oldStructuredDocumentRegion) {
- if (count > 1)
- container.removeStructuredDocumentRegion(i);
- else
- this.gapStructuredDocumentRegion = null;
- return;
- }
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- if (count > 1)
- container.removeStructuredDocumentRegion(i);
- else
- this.gapStructuredDocumentRegion = null;
- return;
- }
- }
- }
- }
- }
-
- private void removeStructuredDocumentRegion(IStructuredDocumentRegion oldStructuredDocumentRegion) {
- if (oldStructuredDocumentRegion == null)
- return; // error
- if (this.parentNode == null)
- return; // error
-
- int gapEnd = this.gapOffset + this.gapLength;
- int oldOffset = oldStructuredDocumentRegion.getStart();
- int oldEnd = oldStructuredDocumentRegion.getEnd();
- if (oldOffset >= this.gapOffset && oldEnd <= gapEnd)
- return; // do nothing
- int oldLength = oldEnd - oldOffset;
- if (oldOffset >= gapEnd)
- oldOffset += this.diff;
-
- // find owner node
- NodeImpl ownerNode = null;
- ElementImpl ownerEndTag = null;
- TextImpl ownerText = null;
- while (this.parentNode != null) {
- if (this.nextNode != null) {
- if (this.nextNode.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- ownerNode = this.nextNode;
- break;
- }
- if (this.nextNode.getNodeType() == Node.TEXT_NODE) {
- TextImpl text = (TextImpl) this.nextNode;
- if (text.hasStructuredDocumentRegion(oldStructuredDocumentRegion)) {
- ownerNode = this.nextNode;
- ownerText = text;
- break;
- }
- }
-
- Node child = this.nextNode.getFirstChild();
- if (child != null) {
- this.parentNode = this.nextNode;
- this.nextNode = (NodeImpl) child;
- continue;
- }
-
- if (this.nextNode.getNodeType() == Node.ELEMENT_NODE) {
- this.parentNode = this.nextNode;
- this.nextNode = null;
- continue;
- }
-
- this.nextNode = (NodeImpl) this.nextNode.getNextSibling();
- if (this.nextNode != null)
- continue;
- }
-
- if (this.parentNode.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) this.parentNode;
- if (element.getEndStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- ownerNode = this.parentNode;
- ownerEndTag = element;
- break;
- }
- }
-
- this.nextNode = (NodeImpl) this.parentNode.getNextSibling();
- this.parentNode = (NodeImpl) this.parentNode.getParentNode();
- }
- if (ownerNode == null)
- throw new StructuredDocumentRegionManagementException();
-
- if (ownerText != null) {
- IStructuredDocumentRegion flatNode = ownerText.getStructuredDocumentRegion();
- if (flatNode == oldStructuredDocumentRegion) {
- IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(oldOffset, oldLength);
- ownerText.setStructuredDocumentRegion(newStructuredDocumentRegion);
- return;
- }
-
- if (flatNode instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) flatNode;
- if (proxy.getStructuredDocumentRegion() != oldStructuredDocumentRegion) {
- throw new StructuredDocumentRegionManagementException();
- }
- int offset = proxy.getOffset();
- int end = offset + proxy.getLength();
- if (offset >= this.gapOffset) {
- proxy.setOffset(offset + this.diff);
- }
- proxy.setStructuredDocumentRegion(null);
- if (end < oldEnd && (end < this.gapOffset || oldEnd > gapEnd)) { // has
- // shared
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- }
- else if (flatNode instanceof StructuredDocumentRegionContainer) {
- StructuredDocumentRegionContainer container = (StructuredDocumentRegionContainer) flatNode;
- int count = container.getStructuredDocumentRegionCount();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion content = container.getStructuredDocumentRegion(i);
- if (content == null)
- continue; // error
- if (content == oldStructuredDocumentRegion) {
- IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(oldOffset, oldLength);
- container.replaceStructuredDocumentRegion(newStructuredDocumentRegion, i);
- return;
- }
-
- if (content instanceof StructuredDocumentRegionProxy) {
- StructuredDocumentRegionProxy proxy = (StructuredDocumentRegionProxy) content;
- if (proxy.getStructuredDocumentRegion() == oldStructuredDocumentRegion) {
- int offset = proxy.getOffset();
- int end = offset + proxy.getLength();
- if (offset >= this.gapOffset) {
- proxy.setOffset(offset + this.diff);
- }
- proxy.setStructuredDocumentRegion(null);
- if (end < oldEnd && (end < this.gapOffset || oldEnd > gapEnd)) { // has
- // shared
- removeStructuredDocumentRegion(oldStructuredDocumentRegion);
- return;
- }
- }
- }
- }
- }
- else {
- throw new StructuredDocumentRegionManagementException();
- }
- }
- else {
- IStructuredDocumentRegion newStructuredDocumentRegion = new StructuredDocumentRegionProxy(oldOffset, oldLength);
- if (ownerEndTag != null) {
- ownerEndTag.setEndStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- else {
- ownerNode.setStructuredDocumentRegion(newStructuredDocumentRegion);
- }
- }
- }
-
- /**
- * replaceAttr method
- *
- * @param ownerElement
- * org.w3c.dom.Element
- * @param newAttr
- * org.w3c.dom.Attr
- * @param oldAttr
- * org.w3c.dom.Attr
- */
- void replaceAttr(Element ownerElement, Attr newAttr, Attr oldAttr) {
- if (ownerElement == null)
- return;
- if (getStructuredDocument() == null)
- return;
-
- ElementImpl element = (ElementImpl) ownerElement;
- if (!element.hasStartTag()) {
- changeStartTag(element);
- return;
- }
- if (element.isCommentTag()) {
- changeStartTag(element);
- return;
- }
-
- int offset = element.getStartOffset();
- int start = offset;
- int end = offset;
-
- boolean insertSpace = false;
- String attrValueClose = null;
- if (oldAttr != null) {
- AttrImpl impl = (AttrImpl) oldAttr;
- ITextRegion nameRegion = impl.getNameRegion();
- if (nameRegion == null)
- return; // must never happen
- ITextRegion lastRegion = impl.getValueRegion();
- if (lastRegion != null) {
- end += lastRegion.getEnd();
- }
- else {
- lastRegion = impl.getEqualRegion();
- if (lastRegion != null) {
- end += lastRegion.getEnd();
- }
- else {
- end += nameRegion.getEnd();
- lastRegion = nameRegion;
- }
- }
- // check there are extra space before the last attribute
- IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
- if (flatNode == null)
- return; // must never happen
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return; // must never happen
- ITextRegion prevRegion = null;
- ITextRegion nextRegion = null;
- for (int i = 0; i < regions.size(); i++) {
- ITextRegion region = regions.get(i);
- if (region == nameRegion) {
- if (i > 0) {
- prevRegion = regions.get(i - 1);
- }
- }
- if (region == lastRegion) {
- if (i + 1 < regions.size()) {
- nextRegion = regions.get(i + 1);
- }
- break;
- }
- }
- boolean isLastAttr = false;
- if (nextRegion != null) {
- String regionType = nextRegion.getType();
- if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType)) {
- isLastAttr = true;
- }
- }
- if (isLastAttr && prevRegion != null) {
- start += prevRegion.getTextEnd();
- }
- else {
- start += nameRegion.getStart();
- }
-
- // impl.resetRegions(ownerElement);
- impl.resetRegions(element);
- }
- else { // append attribute
- IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
- if (flatNode == null)
- return; // must never happen
-
- attrValueClose = getAttrValueClose(element);
- if (attrValueClose != null && attrValueClose.length() > 0) {
- insertSpace = true;
- start = flatNode.getEndOffset();
- end = start;
- }
- else {
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return; // must never happen
- int attrStart = 0;
- for (int i = regions.size() - 1; i >= 0; i--) {
- ITextRegion region = regions.get(i);
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType))
- continue;
- int regionEnd = region.getEnd();
- if (regionEnd == region.getTextEnd())
- insertSpace = true;
- attrStart = regionEnd;
- break;
- }
- if (attrStart == 0)
- return; // not found, must never happen
- start += attrStart;
- end = start;
- }
- }
-
- String source = null;
- if (newAttr != null) {
- int size = 2;
- if (attrValueClose != null)
- size += attrValueClose.length();
- String name = this.generator.generateAttrName(newAttr);
- if (name != null)
- size += name.length();
- String value = this.generator.generateAttrValue(newAttr);
- if (value != null)
- size += value.length();
- StringBuffer buffer = new StringBuffer(size);
- if (attrValueClose != null)
- buffer.append(attrValueClose);
- if (insertSpace)
- buffer.append(' ');
- buffer.append(name);
- if (value != null) {
- buffer.append('=');
- buffer.append(value);
- }
- source = buffer.toString();
- }
-
- replaceSource(source, start, end);
- }
-
- protected boolean isNestedTagClose(String regionType) {
- boolean result = false;
- return result;
- }
-
- /**
- * replaceChild method
- *
- * @param parentNode
- * org.w3c.dom.Node
- * @param newChild
- * org.w3c.dom.Node
- * @param oldChild
- * org.w3c.dom.Node
- */
- void replaceChild(Node parentNode, Node newChild, Node oldChild) {
- if (parentNode == null)
- return;
- if (newChild == null && oldChild == null)
- return;
- if (getStructuredDocument() == null)
- return;
-
- int start = 0;
- int end = 0;
- String preTag = null;
- String postTag = null;
- ElementImpl postElement = null;
- if (oldChild != null) {
- NodeImpl node = (NodeImpl) oldChild;
- start = node.getStartOffset();
- end = node.getEndOffset();
- if (oldChild.getNodeType() == Node.TEXT_NODE) {
- this.gapStructuredDocumentRegion = node.getStructuredDocumentRegion();
- }
- node.resetStructuredDocumentRegions(); // reset values from
- // IStructuredDocumentRegion
- }
- else {
- NodeImpl prev = (NodeImpl) newChild.getPreviousSibling();
- if (prev != null) {
- start = prev.getEndOffset();
- end = start;
- preTag = getCloseTag(prev);
- }
- else {
- // first child
- NodeImpl next = (NodeImpl) newChild.getNextSibling();
- if (next != null) {
- start = next.getStartOffset();
- end = start;
- if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
- preTag = getStartCloseTag((IDOMElement) parentNode);
- }
- }
- else {
- // newly having a child
- if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) parentNode;
- if (element.isEmptyTag()) { // empty tag format
- // need to generate the start and the end tags
- end = element.getEndOffset();
- start = end - 2; // for "/>"
- element.setEmptyTag(false);
- preTag = this.generator.generateCloseTag(element);
- postTag = this.generator.generateEndTag(element);
- postElement = element;
- }
- else if (!element.hasStartTag()) {
- start = element.getStartOffset();
- end = start;
- // invalid end tag or implicit tag
- // need to generate the start tag
- preTag = this.generator.generateStartTag(element);
- if (preTag != null) {
- int length = preTag.length();
- if (length > 0) {
- IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(start, length);
- element.setStartStructuredDocumentRegion(flatNode);
- }
- }
- if (!element.hasEndTag()) {
- // implicit tag
- // need to generate the end tags
- postTag = this.generator.generateEndTag(element);
- postElement = element;
- }
- }
- else {
- start = element.getStartEndOffset();
- end = start;
- preTag = getStartCloseTag(element);
- if (preTag != null && preTag.length() > 0) {
- if (!element.hasEndTag() && (element.isJSPContainer() || element.isCDATAContainer())) {
- // need to generate the end tag
- postTag = this.generator.generateEndTag(element);
- postElement = element;
- }
- }
- }
- }
- // else might DOCUMENT_NODE, start and end are 0
- }
- }
- }
-
- String source = null;
- if (newChild != null) {
- StringBuffer buffer = new StringBuffer();
- int offset = start;
- if (preTag != null) {
- int length = preTag.length();
- if (length > 0) {
- offset += length;
- buffer.append(preTag);
- }
- }
-
- NodeImpl node = (NodeImpl) newChild;
- while (node != null) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) node;
- if (element.preferEmptyTag())
- element.setEmptyTag(true);
- IStructuredDocumentRegion flatNode = null;
- String startTag = this.generator.generateStartTag(element);
- if (startTag != null) {
- int length = startTag.length();
- if (length > 0) {
- buffer.append(startTag);
- flatNode = new StructuredDocumentRegionProxy(offset, length);
- offset += length;
- }
- }
- element.setStartStructuredDocumentRegion(flatNode);
- }
- else {
- String content = this.generator.generateSource(node);
- if (content == null)
- content = NodeImpl.EMPTY_STRING;
- int length = content.length();
- IStructuredDocumentRegion flatNode = null;
- if (length > 0) {
- buffer.append(content);
- flatNode = new StructuredDocumentRegionProxy(offset, length);
- offset += length;
- }
- node.setStructuredDocumentRegion(flatNode);
- }
-
- NodeImpl child = (NodeImpl) node.getFirstChild();
- if (child != null) {
- node = child;
- continue;
- }
-
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ElementImpl element = (ElementImpl) node;
- IStructuredDocumentRegion flatNode = null;
- String endTag = this.generator.generateEndTag(element);
- if (endTag != null) {
- int length = endTag.length();
- if (length > 0) {
- buffer.append(endTag);
- flatNode = new StructuredDocumentRegionProxy(offset, length);
- offset += length;
- }
- }
- element.setEndStructuredDocumentRegion(flatNode);
- }
-
- while (node != null) {
- if (node == newChild) {
- node = null;
- break;
- }
- NodeImpl next = (NodeImpl) node.getNextSibling();
- if (next != null) {
- node = next;
- break;
- }
-
- node = (NodeImpl) node.getParentNode();
- if (node.getNodeType() != Node.ELEMENT_NODE)
- continue;
- ElementImpl element = (ElementImpl) node;
- IStructuredDocumentRegion flatNode = null;
- String endTag = this.generator.generateEndTag(element);
- if (endTag != null) {
- int length = endTag.length();
- if (length > 0) {
- buffer.append(endTag);
- flatNode = new StructuredDocumentRegionProxy(offset, length);
- offset += length;
- }
- }
- element.setEndStructuredDocumentRegion(flatNode);
- }
- }
-
- if (postTag != null) {
- int length = postTag.length();
- if (length > 0) {
- buffer.append(postTag);
- if (postElement != null) {
- IStructuredDocumentRegion flatNode = new StructuredDocumentRegionProxy(offset, length);
- postElement.setEndStructuredDocumentRegion(flatNode);
- }
- }
- }
- source = buffer.toString();
- }
-
- if (start == end && (source == null || source.length() == 0)) {
- // no thing changed
- return;
- }
-
- replaceSource(source, start, end);
- }
-
- void replaceRegions(IStructuredDocumentRegion flatNode, ITextRegionList newRegions, ITextRegionList oldRegions) {
- // future_TODO: optimize
-
- NodeImpl root = (NodeImpl) this.model.getDocument();
- this.parentNode = root;
- this.nextNode = (NodeImpl) root.getFirstChild();
-
- removeGapStructuredDocumentRegion(flatNode);
- insertGapStructuredDocumentRegionBefore(flatNode.getStart());
- changeStructuredDocumentRegion(flatNode);
- insertGapStructuredDocumentRegionAfter(flatNode.getEnd());
- }
-
- /**
- * Wraps IStructuredDocumentRegion.replaceText() and sets contextual
- * information.
- */
- private void replaceSource(String source, int start, int end) {
- int inserted = 0;
- if (source == null)
- source = NodeImpl.EMPTY_STRING;
- else
- inserted = source.length();
- int removed = end - start;
- if (inserted == 0 && removed == 0)
- return;
-
- this.gapOffset = start;
- this.gapLength = removed;
- this.diff = inserted - removed;
- // Note: due to bug
- // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3619
- // for now assume "ignore readonly" region is ok -- assume DOM itself
- // checks if
- // ok to insert or not. In reality, we may have to make or "contains"
- // method more
- // better. Or, we may have to "perculate up" the parameter for clients
- // to tell us programatically
- // that its ok to insert/format in a read-only region.
- getStructuredDocument().replaceText(this.model, this.gapOffset, this.gapLength, source, true);
- }
-
- void replaceStructuredDocumentRegions(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
- NodeImpl root = (NodeImpl) this.model.getDocument();
-
- if (oldStructuredDocumentRegions != null) {
- this.parentNode = root;
- this.nextNode = (NodeImpl) root.getFirstChild();
-
- Enumeration e = oldStructuredDocumentRegions.elements();
- while (e.hasMoreElements()) {
- IStructuredDocumentRegion flatNode = (IStructuredDocumentRegion) e.nextElement();
- if (flatNode == null)
- continue;
- removeStructuredDocumentRegion(flatNode);
- removeGapStructuredDocumentRegion(flatNode);
- }
- }
-
- if (newStructuredDocumentRegions != null) {
- this.parentNode = root;
- this.nextNode = (NodeImpl) root.getFirstChild();
-
- IStructuredDocumentRegion lastStructuredDocumentRegion = null;
- Enumeration e = newStructuredDocumentRegions.elements();
- while (e.hasMoreElements()) {
- IStructuredDocumentRegion flatNode = (IStructuredDocumentRegion) e.nextElement();
- if (flatNode == null)
- continue;
- if (lastStructuredDocumentRegion == null)
- insertGapStructuredDocumentRegionBefore(flatNode.getStart());
- insertStructuredDocumentRegion(flatNode);
- lastStructuredDocumentRegion = flatNode;
- }
- if (lastStructuredDocumentRegion != null) {
- insertGapStructuredDocumentRegionAfter(lastStructuredDocumentRegion.getEnd());
- }
- else {
- insertGapStructuredDocumentRegionBefore(this.gapOffset);
- // make sure to restore all backuped StructuredDocumentRegions
- insertGapStructuredDocumentRegionAfter(this.gapOffset);
- }
- }
- else {
- this.parentNode = root;
- this.nextNode = (NodeImpl) root.getFirstChild();
-
- insertGapStructuredDocumentRegionBefore(this.gapOffset);
- // make sure to restore all backuped StructuredDocumentRegions
- insertGapStructuredDocumentRegionAfter(this.gapOffset);
- }
- }
-
- /**
- */
- private void updateAttrRegions(Element element, IStructuredDocumentRegion flatNode) {
-
- // update attributes
- ITextRegionList regions = flatNode.getRegions();
- if (regions == null)
- return;
- NamedNodeMap attributes = element.getAttributes();
- if (attributes == null)
- return;
- int index = -1;
- AttrImpl attr = null;
- Iterator e = regions.iterator();
- while (e.hasNext()) {
- ITextRegion region = (ITextRegion) e.next();
- String regionType = region.getType();
- if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- attr = (AttrImpl) attributes.item(++index);
- if (attr != null) {
- attr.setNameRegion(region);
- // reset other regions
- attr.setEqualRegion(null);
- attr.setValueRegion(null);
- }
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- if (attr != null)
- attr.setEqualRegion(region);
- }
- else if (regionType == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- if (attr != null) {
- attr.setValueRegion(region);
- attr = null;
- }
- }
- }
- }
-}

Back to the top