Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src/org/eclipse')
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/DebugAdapterFactory.java77
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/EveryNodeDebugAdapter.java284
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/IDebugAdapter.java19
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/Logger.java157
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java63
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePlugin.java80
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties47
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/CleanupProcessorXML.java128
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/ElementNodeCleanupHandler.java557
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/NodeCleanupHandler.java63
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/XMLCleanupPreferencesImpl.java142
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementAdapter.java103
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementHandler.java107
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/BasicCommentElementHandler.java135
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementConfiguration.java237
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementRegistry.java84
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/CommentElementFactory.java65
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/TagScanner.java196
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/AbstractResourceEncodingDetector.java258
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ByteReader.java108
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ContentDescriberForXML.java264
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/EncodingParserConstants.java30
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/HeadParserToken.java44
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/IntStack.java114
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/NullMemento.java37
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLDeclDetector.java156
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizer.java1451
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizerConstants.java21
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLResourceEncodingDetector.java142
-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.java355
-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.java915
-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.java1207
-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.java1512
-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.java1139
-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.java1179
-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
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentCharsetDetector.java37
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentLoader.java82
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java1684
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormatterFormatProcessor.java146
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingConstraints.java94
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java179
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/EmbeddedXML.java95
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/ModelHandlerForXML.java59
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/XMLModelLoader.java93
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForEmbeddedXML.java50
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java253
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryUtil.java64
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLCatalogIdResolver.java102
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryAssociationProvider.java60
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryImpl.java38
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/BlockStructuredDocumentRegion.java46
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/ContextRegionContainer.java327
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/IntStack.java112
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/RegionFactory.java49
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XML10Names.java595
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLSourceParser.java645
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredDocumentReParser.java124
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredRegionFactory.java42
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLTokenizer.java1931
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeEqualsRegion.java92
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeNameRegion.java165
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeValueRegion.java162
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EmptyTagCloseRegion.java90
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EndTagOpenRegion.java101
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/GenericTemplateRegion.java102
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionToStringUtil.java29
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionUpdateRule.java209
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagCloseRegion.java89
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagNameRegion.java93
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagOpenRegion.java98
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/WhiteSpaceOnlyRegion.java188
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLCDataTextRegion.java175
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLContentRegion.java175
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserFactory.java25
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserRegion.java107
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLParserRegionFactory.java103
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java81
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java287
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterFactoryImpl.java113
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterImpl.java144
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLCharEntity.java39
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLNamespace.java29
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLPreferenceNames.java55
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/NameValidator.java63
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocType.java49
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocumentTracker.java32
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMNodeWrapper.java21
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/ContentModelAdapter.java54
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/NullContentModel.java101
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contenttype/ContentTypeIdForXML.java54
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMAttr.java128
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocument.java100
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocumentType.java43
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMElement.java196
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMEntity.java33
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMImplementation.java48
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMModel.java59
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMNode.java272
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMText.java129
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/ISourceGenerator.java201
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/CommentNodeFormatter.java101
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/DocumentNodeFormatter.java55
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/ElementNodeFormatter.java425
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java115
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java28
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java753
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/StructuredFormatPreferencesXML.java81
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java385
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/text/IXMLPartitions.java42
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/regions/DOMRegionContext.java69
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapter.java31
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapterImpl.java76
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/MovableModelQuery.java23
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/tasks/XMLFileTaskScanner.java28
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/XMLStructuredDocumentRegion.java36
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/rules/StructuredTextPartitionerForXML.java132
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/AbstractPropagatingValidator.java66
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/Propagator.java54
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/ValidationComponent.java54
-rw-r--r--bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/text/IXMLPartitions.java42
158 files changed, 0 insertions, 37385 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/DebugAdapterFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/DebugAdapterFactory.java
deleted file mode 100644
index 266b80a5fc..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/DebugAdapterFactory.java
+++ /dev/null
@@ -1,77 +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;
-
-import java.util.ArrayList;
-
-import org.eclipse.wst.sse.core.internal.PropagatingAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-
-
-public class DebugAdapterFactory extends AbstractAdapterFactory implements PropagatingAdapterFactory {
-
- /**
- * Constructor for DebugAdapterFactory.
- */
- public DebugAdapterFactory() {
- this(IDebugAdapter.class, true);
- }
-
- /**
- * Constructor for DebugAdapterFactory.
- *
- * @param fAdapterKey
- * @param registerAdapters
- */
- private DebugAdapterFactory(Object adapterKey, boolean registerAdapters) {
- super(adapterKey, registerAdapters);
- }
-
-
- public void addContributedFactories(INodeAdapterFactory factory) {
- //none expected
- }
-
- public INodeAdapterFactory copy() {
- return new DebugAdapterFactory(getAdapterKey(), isShouldRegisterAdapter());
- }
-
- protected INodeAdapter createAdapter(INodeNotifier target) {
- EveryNodeDebugAdapter result = null;
- result = EveryNodeDebugAdapter.getInstance();
- return result;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IAdapterFactory#isFactoryForType(java.lang.Object)
- */
- public boolean isFactoryForType(Object type) {
-
- return IDebugAdapter.class == type;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.PropagatingAdapterFactory#setContributedFactories(java.util.ArrayList)
- */
- public void setContributedFactories(ArrayList list) {
- // none expected
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/EveryNodeDebugAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/EveryNodeDebugAdapter.java
deleted file mode 100644
index baa718c736..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/EveryNodeDebugAdapter.java
+++ /dev/null
@@ -1,284 +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;
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.events.AboutToBeChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.IModelAboutToBeChangedListener;
-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.util.Debug;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-
-
-/**
- * Purely for use in debugging
- */
-public class EveryNodeDebugAdapter implements IDebugAdapter {
-
- static class InternalDocumentListener implements IDocumentListener {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- Debug.println("IdocumentAboutToBeChanged: " + event); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- Debug.println("IdocumentChanged: " + event); //$NON-NLS-1$
-
- }
-
- }
-
- static class InternalModelStateListener implements IModelStateListener {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IModelStateListener#modelAboutToBeChanged(org.eclipse.wst.sse.core.IStructuredModel)
- */
- public void modelAboutToBeChanged(IStructuredModel model) {
- Debug.println("modelAboutToBeChanged: " + model); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IModelStateListener#modelChanged(org.eclipse.wst.sse.core.IStructuredModel)
- */
- public void modelChanged(IStructuredModel model) {
- Debug.println("modelChanged: " + model); //$NON-NLS-1$
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IModelStateListener#modelDirtyStateChanged(org.eclipse.wst.sse.core.IStructuredModel,
- * boolean)
- */
- public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
- Debug.println("modelDirtyStateChanged: " + model); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IModelStateListener#modelResourceDeleted(org.eclipse.wst.sse.core.IStructuredModel)
- */
- public void modelResourceDeleted(IStructuredModel model) {
- Debug.println("modelResourceDeleted: " + model); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.IModelStateListener#modelResourceMoved(org.eclipse.wst.sse.core.IStructuredModel,
- * org.eclipse.wst.sse.core.IStructuredModel)
- */
- public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
- Debug.println("modelResourceMoved: " + "oldModel: " + oldModel + "newModel: " + newModel); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
- Debug.println("modelAboutToBeReinitialized: " + "structuredModel: " + structuredModel); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- public void modelReinitialized(IStructuredModel structuredModel) {
- Debug.println("modelReinitialized: " + "structuredModel: " + structuredModel); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- }
-
- static class InternalStructuredDocumentAboutToChange implements IModelAboutToBeChangedListener {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IModelAboutToBeChangedListener#modelAboutToBeChanged(org.eclipse.wst.sse.core.events.AboutToBeChangedEvent)
- */
- public void modelAboutToBeChanged(AboutToBeChangedEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentAboutToBeChanged: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- }
-
- static class InternalStructuredDocumentListener implements IStructuredDocumentListener {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IStructuredDocumentListener#newModel(org.eclipse.wst.sse.core.events.NewDocumentContentEvent)
- */
- public void newModel(NewDocumentEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentChanged - newModel: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IStructuredDocumentListener#noChange(org.eclipse.wst.sse.core.events.NoChangeEvent)
- */
- public void noChange(NoChangeEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentChanged - noChange: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IStructuredDocumentListener#nodesReplaced(org.eclipse.wst.sse.core.events.StructuredDocumentRegionsReplacedEvent)
- */
- public void nodesReplaced(StructuredDocumentRegionsReplacedEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentChanged - nodesReplaced: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IStructuredDocumentListener#regionChanged(org.eclipse.wst.sse.core.events.RegionChangedEvent)
- */
- public void regionChanged(RegionChangedEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentChanged - regionChanged: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.events.IStructuredDocumentListener#regionsReplaced(org.eclipse.wst.sse.core.events.RegionsReplacedEvent)
- */
- public void regionsReplaced(RegionsReplacedEvent structuredDocumentEvent) {
- Debug.println("structuredDocumentChanged - regionsReplaced: " + structuredDocumentEvent); //$NON-NLS-1$
-
- }
-
- }
-
- private static EveryNodeDebugAdapter singletonInstance;
-
- public static EveryNodeDebugAdapter getInstance() {
- if (singletonInstance == null) {
- singletonInstance = new EveryNodeDebugAdapter();
- }
- return singletonInstance;
- }
-
- InternalDocumentListener fInternalDocumentListener;
- InternalModelStateListener fInternalModelStateListener;
- InternalStructuredDocumentAboutToChange fInternalStructuredDocumentAboutToChange;
- InternalStructuredDocumentListener fInternalStructuredDocumentListener;
- IStructuredModel fModel;
-
- /**
- *
- */
- public EveryNodeDebugAdapter() {
- super();
- fInternalDocumentListener = new InternalDocumentListener();
- fInternalStructuredDocumentAboutToChange = new InternalStructuredDocumentAboutToChange();
- fInternalStructuredDocumentListener = new InternalStructuredDocumentListener();
- fInternalModelStateListener = new InternalModelStateListener();
- }
-
- /**
- * @param target
- */
- public EveryNodeDebugAdapter(INodeNotifier target) {
- this();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.INodeAdapter#isAdapterForType(java.lang.Object)
- */
- public boolean isAdapterForType(Object type) {
- return (type == IDebugAdapter.class);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.INodeAdapter#notifyChanged(org.eclipse.wst.sse.core.INodeNotifier,
- * int, java.lang.Object, java.lang.Object, java.lang.Object, int)
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (notifier instanceof IDOMNode) {
- setModel(((IDOMNode) notifier).getModel());
- }
- Debug.println("notifier: " + notifier + " " + INodeNotifier.EVENT_TYPE_STRINGS[eventType] + " changedFeature: " + changedFeature + " oldValue: " + oldValue + " newValue: " + newValue + " pos: " + pos); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.internal.IDebugAdapter#setDocument(org.eclipse.wst.sse.core.text.IStructuredDocument)
- */
- private void setModel(IStructuredModel structuredModel) {
- if (fModel == structuredModel)
- return;
-
- if (fModel != null) {
- fModel.removeModelStateListener(fInternalModelStateListener);
- //
- IStructuredDocument structuredDocument = fModel.getStructuredDocument();
- if (structuredDocument != null) {
- structuredDocument.removeDocumentListener(fInternalDocumentListener);
- structuredDocument.removeDocumentAboutToChangeListener(fInternalStructuredDocumentAboutToChange);
- structuredDocument.removeDocumentChangedListener(fInternalStructuredDocumentListener);
- }
- }
- fModel = structuredModel;
- if (fModel != null) {
-
- fModel.addModelStateListener(fInternalModelStateListener);
- //
- IStructuredDocument structuredDocument = fModel.getStructuredDocument();
- if (structuredDocument != null) {
- structuredDocument.addDocumentListener(fInternalDocumentListener);
- structuredDocument.addDocumentAboutToChangeListener(fInternalStructuredDocumentAboutToChange);
- structuredDocument.addDocumentChangedListener(fInternalStructuredDocumentListener);
- }
- }
-
-
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/IDebugAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/IDebugAdapter.java
deleted file mode 100644
index 35c5712dae..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/IDebugAdapter.java
+++ /dev/null
@@ -1,19 +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;
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-
-
-public interface IDebugAdapter extends INodeAdapter {
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/Logger.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/Logger.java
deleted file mode 100644
index 798c9bba70..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/Logger.java
+++ /dev/null
@@ -1,157 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal;
-
-import com.ibm.icu.util.StringTokenizer;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.osgi.framework.Bundle;
-
-/**
- * Small convenience class to log messages to plugin's log file and also, if
- * desired, the console. This class should only be used by classes in this
- * plugin. Other plugins should make their own copy, with appropriate ID.
- */
-public class Logger {
- private static final String PLUGIN_ID = "org.eclipse.wst.xml.core"; //$NON-NLS-1$
-
- public static final int ERROR = IStatus.ERROR; // 4
- public static final int ERROR_DEBUG = 200 + ERROR;
- public static final int INFO = IStatus.INFO; // 1
- public static final int INFO_DEBUG = 200 + INFO;
-
- public static final int OK = IStatus.OK; // 0
-
- public static final int OK_DEBUG = 200 + OK;
-
- private static final String TRACEFILTER_LOCATION = "/debug/tracefilter"; //$NON-NLS-1$
- public static final int WARNING = IStatus.WARNING; // 2
- public static final int WARNING_DEBUG = 200 + WARNING;
-
- /**
- * Adds message to log.
- *
- * @param level
- * severity level of the message (OK, INFO, WARNING, ERROR,
- * OK_DEBUG, INFO_DEBUG, WARNING_DEBUG, ERROR_DEBUG)
- * @param message
- * text to add to the log
- * @param exception
- * exception thrown
- */
- protected static void _log(int level, String message, Throwable exception) {
- if (level == OK_DEBUG || level == INFO_DEBUG || level == WARNING_DEBUG || level == ERROR_DEBUG) {
- if (!isDebugging())
- return;
- }
-
- int severity = IStatus.OK;
- switch (level) {
- case INFO_DEBUG :
- case INFO :
- severity = IStatus.INFO;
- break;
- case WARNING_DEBUG :
- case WARNING :
- severity = IStatus.WARNING;
- break;
- case ERROR_DEBUG :
- case ERROR :
- severity = IStatus.ERROR;
- }
- message = (message != null) ? message : "null"; //$NON-NLS-1$
- Status statusObj = new Status(severity, PLUGIN_ID, severity, message, exception);
- Bundle bundle = Platform.getBundle(PLUGIN_ID);
- if (bundle != null)
- Platform.getLog(bundle).log(statusObj);
- }
-
- /**
- * Prints message to log if category matches /debug/tracefilter option.
- *
- * @param message
- * text to print
- * @param category
- * category of the message, to be compared with
- * /debug/tracefilter
- */
- protected static void _trace(String category, String message, Throwable exception) {
- if (isTracing(category)) {
- message = (message != null) ? message : "null"; //$NON-NLS-1$
- Status statusObj = new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, exception);
- Bundle bundle = Platform.getBundle(PLUGIN_ID);
- if (bundle != null)
- Platform.getLog(bundle).log(statusObj);
- }
- }
-
- /**
- * @return true if the platform is debugging
- */
- public static boolean isDebugging() {
- return Platform.inDebugMode();
- }
-
- /**
- * Determines if currently tracing a category
- *
- * @param category
- * @return true if tracing category, false otherwise
- */
- public static boolean isTracing(String category) {
- if (!isDebugging())
- return false;
-
- String traceFilter = Platform.getDebugOption(PLUGIN_ID + TRACEFILTER_LOCATION);
- if (traceFilter != null) {
- StringTokenizer tokenizer = new StringTokenizer(traceFilter, ","); //$NON-NLS-1$
- while (tokenizer.hasMoreTokens()) {
- String cat = tokenizer.nextToken().trim();
- if (category.equals(cat)) {
- return true;
- }
- }
- }
- return false;
- }
-
- public static void log(int level, String message) {
- _log(level, message, null);
- }
-
- public static void log(int level, String message, Throwable exception) {
- _log(level, message, exception);
- }
-
- public static void logException(String message, Throwable exception) {
- _log(ERROR, message, exception);
- }
-
- public static void logException(Throwable exception) {
- _log(ERROR, exception.getMessage(), exception);
- }
-
- public static void trace(String category, String message) {
- _trace(category, message, null);
- }
-
- public static void traceException(String category, String message, Throwable exception) {
- _trace(category, message, exception);
- }
-
- public static void traceException(String category, Throwable exception) {
- _trace(category, exception.getMessage(), exception);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java
deleted file mode 100644
index 831c0a274e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCoreMessages.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2005, 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 - Initial API and implementation
- * Jesper Steen Moeller - Added XML Catalogs 1.1 support
- **********************************************************************/
-package org.eclipse.wst.xml.core.internal;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Strings used by XML Core
- *
- * @plannedfor 1.0
- */
-public class XMLCoreMessages {
- private static final String BUNDLE_NAME = "org.eclipse.wst.xml.core.internal.XMLCorePluginResources";//$NON-NLS-1$
-
- public static String Invalid_character_lt_fo_ERROR_;
- public static String Invalid_character_gt_fo_ERROR_;
- public static String Invalid_character_amp_fo_ERROR_;
- public static String Invalid_character__f_EXC_;
- public static String loading;
- public static String Catalog_entry_key_not_set;
- public static String Catalog_entry_uri_not_set;
- public static String Catalog_rewrite_startString_not_set;
- public static String Catalog_rewrite_prefix_not_set;
- public static String Catalog_suffix_string_not_set;
- public static String Catalog_suffix_uri_not_set;
- public static String Catalog_delegate_prefix_not_set;
- public static String Catalog_delegate_catalog_not_set;
- public static String Catalog_next_catalog_location_uri_not_set;
- public static String Catalog_resolution_null_catalog;
- public static String Catalog_resolution_malformed_url;
- public static String Catalog_resolution_io_exception;
- public static String CMDocument_load_exception;
- public static String End_tag_has_attributes;
- public static String Attribute__is_missing_a_value;
- public static String Attribute__has_no_value;
- public static String Missing_end_tag_;
- public static String Missing_start_tag_;
- public static String ReconcileStepForMarkup_0;
- public static String ReconcileStepForMarkup_1;
- public static String ReconcileStepForMarkup_2;
- public static String ReconcileStepForMarkup_3;
- public static String ReconcileStepForMarkup_4;
- public static String ReconcileStepForMarkup_5;
- public static String ReconcileStepForMarkup_6;
- public static String Indicate_no_grammar_specified_severities_error;
-
- static {
- // load message values from bundle file
- NLS.initializeMessages(BUNDLE_NAME, XMLCoreMessages.class);
- }
-
- private XMLCoreMessages() {
- // cannot create new instance
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePlugin.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePlugin.java
deleted file mode 100644
index bb148a2493..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePlugin.java
+++ /dev/null
@@ -1,80 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal;
-
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.wst.xml.core.internal.catalog.Catalog;
-import org.eclipse.wst.xml.core.internal.catalog.CatalogSet;
-import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
-
-
-/**
- * The main plugin class to be used in the desktop.
- */
-public class XMLCorePlugin extends Plugin {
- // The shared instance.
- private static XMLCorePlugin plugin;
- public static final String USER_CATALOG_ID = "user_catalog"; //$NON-NLS-1$
- public static final String DEFAULT_CATALOG_ID = "default_catalog"; //$NON-NLS-1$
- public static final String SYSTEM_CATALOG_ID = "system_catalog"; //$NON-NLS-1$
- private CatalogSet catalogSet = null;
- private String defaultCatalogFileStateLocation;
-
-
- /**
- * Returns the shared instance.
- */
- public static XMLCorePlugin getDefault() {
- return plugin;
- }
-
- /**
- * @deprecated use ResourcesPlugin.getWorkspace() directly
- */
- public static IWorkspace getWorkspace() {
- return ResourcesPlugin.getWorkspace();
- }
-
- /**
- * The constructor.
- */
- public XMLCorePlugin() {
- super();
- plugin = this;
- }
-
- private String getPluginStateLocation(String fileName) {
- String location = getStateLocation().append(fileName).toString();
- String file_protocol = "file:"; //$NON-NLS-1$
- if (location != null && !location.startsWith(file_protocol)) {
- location = file_protocol + location;
- }
- return location;
- }
-
- public ICatalog getDefaultXMLCatalog() {
- if (catalogSet == null) {
- catalogSet = new CatalogSet();
-
- defaultCatalogFileStateLocation = getPluginStateLocation(Catalog.DEFAULT_CATALOG_FILE);
-
- catalogSet.putCatalogPersistenceLocation(DEFAULT_CATALOG_ID, defaultCatalogFileStateLocation);
- catalogSet.putCatalogPersistenceLocation(SYSTEM_CATALOG_ID, getPluginStateLocation(Catalog.SYSTEM_CATALOG_FILE));
- catalogSet.putCatalogPersistenceLocation(USER_CATALOG_ID, getPluginStateLocation(Catalog.USER_CATALOG_FILE));
- }
- return catalogSet.lookupOrCreateCatalog(DEFAULT_CATALOG_ID, defaultCatalogFileStateLocation);
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties
deleted file mode 100644
index d9f1fb7099..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/XMLCorePluginResources.properties
+++ /dev/null
@@ -1,47 +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
-# Jesper Steen Moeller - Added XML Catalogs 1.1 support
-#
-###############################################################################
-Invalid_character_lt_fo_ERROR_=Invalid character ('<') found
-Invalid_character_gt_fo_ERROR_=Invalid character ('>') found
-Invalid_character_amp_fo_ERROR_=Invalid character ('&') found
-Invalid_character__f_EXC_=Invalid character ('\"') found
-###############################################################################
-# contentmodel strings
-loading=loading
-# catalog strings
-Catalog_entry_key_not_set=Catalog entry key is not set
-Catalog_entry_uri_not_set=Catalog entry URI is not set
-Catalog_rewrite_startString_not_set=Catalog rewrite start string is not set
-Catalog_rewrite_prefix_not_set=Catalog rewrite prefix is not set
-Catalog_suffix_string_not_set=Catalog suffix string is not set
-Catalog_suffix_uri_not_set=Catalog suffix URI is not set
-Catalog_delegate_prefix_not_set=Catalog delegate prefix is not set
-Catalog_delegate_catalog_not_set=Catalog delegate URI is not set
-Catalog_next_catalog_location_uri_not_set=Next catalog location URI is not set
-Catalog_resolution_null_catalog=Catalog resolution attempted with null catalog; ignored
-Catalog_resolution_malformed_url=Malformed URL exception trying to resolve
-Catalog_resolution_io_exception=I/O exception trying to resolve
-CMDocument_load_exception=An error occurred while loading document {0} with publicId {1}
-End_tag_has_attributes=End tag has attributes
-Attribute__is_missing_a_value=Attribute \"{0}\" is missing a value
-Attribute__has_no_value=Attribute \"{0}\" has no value
-Missing_start_tag_=Missing start tag \"{0}\"
-Missing_end_tag_=Missing end tag \"{0}\"
-ReconcileStepForMarkup_0=Missing closing quote
-ReconcileStepForMarkup_1=Missing quotes for attribute value
-ReconcileStepForMarkup_2=A tagname cannot start with a space
-ReconcileStepForMarkup_3=Empty tags are not allowed
-ReconcileStepForMarkup_4=Namespaces are not allowed in a Processing Instruction target
-ReconcileStepForMarkup_5=Spaces are not allowed before a Processing Instruction
-ReconcileStepForMarkup_6=Tag missing closing bracket '>'
-Indicate_no_grammar_specified_severities_error=ErrorCMDocument_load_exception=An error occurred while loading document {0} with publicId {1}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/CleanupProcessorXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/CleanupProcessorXML.java
deleted file mode 100644
index 05a4af4a52..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/CleanupProcessorXML.java
+++ /dev/null
@@ -1,128 +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.cleanup;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences;
-import org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences;
-import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.document.DOMModelImpl;
-import org.eclipse.wst.xml.core.internal.document.TextImpl;
-import org.eclipse.wst.xml.core.internal.formatter.XMLFormatterFormatProcessor;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-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.IDOMNode;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-
-
-public class CleanupProcessorXML extends AbstractStructuredCleanupProcessor {
- protected IStructuredCleanupPreferences fCleanupPreferences = null;
-
- public void cleanupModel(IStructuredModel structuredModel) {
- Preferences preferences = getModelPreferences();
- if (preferences != null && preferences.getBoolean(XMLCorePreferenceNames.FIX_XML_DECLARATION)) {
- IDOMDocument document = ((DOMModelImpl) structuredModel).getDocument();
- if (!fixExistingXmlDecl(document)) {
- String encoding = preferences.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
- Node xml = document.createProcessingInstruction("xml", "version=\"1.0\" " + "encoding=\"" + encoding +"\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- document.insertBefore(xml, document.getFirstChild());
- }
- }
- super.cleanupModel(structuredModel);
- }
-
- /**
- * Is the node an XML declaration
- * @param node
- * @return true if the node is an XML declaration; otherwise, false.
- */
- private boolean isXMLDecl(IDOMNode node) {
- return node != null && node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && "xml".equalsIgnoreCase(((ProcessingInstruction) node).getTarget()); //$NON-NLS-1$
- }
-
- private boolean fixExistingXmlDecl(IDOMDocument document) {
- IDOMNode node = (IDOMNode) document.getFirstChild();
- while (node != null && node.getNodeType() == Node.TEXT_NODE && ((TextImpl) node).isWhitespace())
- node = (IDOMNode) node.getNextSibling();
- if (isXMLDecl(node)) {
- document.insertBefore(node, document.getFirstChild());
- return true;
- }
- return false;
- }
-
- protected IStructuredCleanupHandler getCleanupHandler(Node node) {
- short nodeType = node.getNodeType();
- IStructuredCleanupHandler cleanupHandler = null;
- switch (nodeType) {
- case Node.ELEMENT_NODE : {
- cleanupHandler = new ElementNodeCleanupHandler();
- break;
- }
- case Node.TEXT_NODE : {
- cleanupHandler = new NodeCleanupHandler();
- break;
- }
- default : {
- cleanupHandler = new NodeCleanupHandler();
- }
- }
-
- // init CleanupPreferences
- cleanupHandler.setCleanupPreferences(getCleanupPreferences());
-
- return cleanupHandler;
- }
-
- public IStructuredCleanupPreferences getCleanupPreferences() {
- if (fCleanupPreferences == null) {
- fCleanupPreferences = new StructuredCleanupPreferences();
-
- Preferences preferences = getModelPreferences();
- if (preferences != null) {
- fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
- fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
- fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS));
- fCleanupPreferences.setQuoteAttrValues(preferences.getBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES));
- fCleanupPreferences.setFormatSource(preferences.getBoolean(XMLCorePreferenceNames.FORMAT_SOURCE));
- fCleanupPreferences.setConvertEOLCodes(preferences.getBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES));
- fCleanupPreferences.setEOLCode(preferences.getString(XMLCorePreferenceNames.CLEANUP_EOL_CODE));
- }
- }
-
- return fCleanupPreferences;
- }
-
- protected String getContentType() {
- return ContentTypeIdForXML.ContentTypeID_XML;
- }
-
- protected IStructuredFormatProcessor getFormatProcessor() {
- return new XMLFormatterFormatProcessor();
- }
-
- protected Preferences getModelPreferences() {
- return XMLCorePlugin.getDefault().getPluginPreferences();
- }
-
- protected void refreshCleanupPreferences() {
- fCleanupPreferences = null;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/ElementNodeCleanupHandler.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/ElementNodeCleanupHandler.java
deleted file mode 100644
index 10baa534a3..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/ElementNodeCleanupHandler.java
+++ /dev/null
@@ -1,557 +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
- * David Carver (Intalion) - Cleanup Repeated Conditional check in isXMLType method
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.cleanup;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.text.edits.InsertEdit;
-import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;
-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.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.Logger;
-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.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-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.IDOMModel;
-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.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-
-public class ElementNodeCleanupHandler extends NodeCleanupHandler {
- protected static final char DOUBLE_QUOTE = '\"'; //$NON-NLS-1$
- protected static final String DOUBLE_QUOTES = "\"\""; //$NON-NLS-1$
- protected static final String EMPTY_TAG_CLOSE = "/>"; //$NON-NLS-1$
- protected static final String END_TAG_OPEN = "</"; //$NON-NLS-1$
- protected static final char SINGLE_QUOTE = '\''; //$NON-NLS-1$
- protected static final String SINGLE_QUOTES = "''"; //$NON-NLS-1$
-
- /** Non-NLS strings */
- protected static final String START_TAG_OPEN = "<"; //$NON-NLS-1$
- protected static final String TAG_CLOSE = ">"; //$NON-NLS-1$
-
- public Node cleanup(Node node) {
- Node newNode = cleanupChildren(node);
- IDOMNode renamedNode = newNode instanceof IDOMNode ? (IDOMNode) newNode : null;
-
- // call quoteAttrValue() first so it will close any unclosed attr
- // quoteAttrValue() will return the new start tag if there is a
- // structure change
- renamedNode = quoteAttrValue(renamedNode);
-
- // insert tag close if missing
- // if node is not comment tag
- // and not implicit tag
- if (!isCommentTag(renamedNode) && !isImplicitTag(renamedNode)) {
- IDOMModel structuredModel = renamedNode.getModel();
-
- // save start offset before insertTagClose()
- // or else renamedNode.getStartOffset() will be zero if
- // renamedNode replaced by insertTagClose()
- int startTagStartOffset = renamedNode.getStartOffset();
-
- // for start tag
- IStructuredDocumentRegion startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();
- insertTagClose(structuredModel, startTagStructuredDocumentRegion);
-
- // update renamedNode and startTagStructuredDocumentRegion after
- // insertTagClose()
- renamedNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
- startTagStructuredDocumentRegion = renamedNode.getStartStructuredDocumentRegion();
-
- // for end tag
- IStructuredDocumentRegion endTagStructuredDocumentRegion = renamedNode.getEndStructuredDocumentRegion();
- if (endTagStructuredDocumentRegion != startTagStructuredDocumentRegion)
- insertTagClose(structuredModel, endTagStructuredDocumentRegion);
- }
-
- // call insertMissingTags() next, it will generate implicit tags if
- // there are any
- // insertMissingTags() will return the new missing start tag if one is
- // missing
- renamedNode = insertMissingTags(renamedNode);
-
- renamedNode = compressEmptyElementTag(renamedNode);
-
- renamedNode = insertRequiredAttrs(renamedNode);
-
- return renamedNode;
- }
-
- protected Node cleanupChildren(Node node) {
- Node parentNode = node;
-
- if (node != null) {
- Node childNode = node.getFirstChild();
- while (childNode != null) {
- // get cleanup handler
- IStructuredCleanupHandler cleanupHandler = getCleanupHandler(childNode);
-
- // cleanup each child
- childNode = cleanupHandler.cleanup(childNode);
-
- // get new parent node
- parentNode = childNode.getParentNode();
-
- // get next child node
- childNode = childNode.getNextSibling();
- }
- }
-
- return parentNode;
- }
-
- private IDOMNode compressEmptyElementTag(IDOMNode node) {
- boolean compressEmptyElementTags = getCleanupPreferences().getCompressEmptyElementTags();
- IDOMNode newNode = node;
-
- IStructuredDocumentRegion startTagStructuredDocumentRegion = newNode.getFirstStructuredDocumentRegion();
- IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getLastStructuredDocumentRegion();
-
- if (compressEmptyElementTags && startTagStructuredDocumentRegion != endTagStructuredDocumentRegion && startTagStructuredDocumentRegion != null) {
- ITextRegionList regions = startTagStructuredDocumentRegion.getRegions();
- ITextRegion lastRegion = regions.get(regions.size() - 1);
- // format children and end tag if not empty element tag
- if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- NodeList childNodes = newNode.getChildNodes();
- if (childNodes == null || childNodes.getLength() == 0 || (childNodes.getLength() == 1 && (childNodes.item(0)).getNodeType() == Node.TEXT_NODE && ((childNodes.item(0)).getNodeValue().trim().length() == 0))) {
- IDOMModel structuredModel = newNode.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
-
- int startTagStartOffset = newNode.getStartOffset();
- int offset = endTagStructuredDocumentRegion.getStart();
- int length = endTagStructuredDocumentRegion.getLength();
- structuredDocument.replaceText(structuredDocument, offset, length, ""); //$NON-NLS-1$
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
-
- offset = startTagStructuredDocumentRegion.getStart() + lastRegion.getStart();
- structuredDocument.replaceText(structuredDocument, offset, 0, "/"); //$NON-NLS-1$
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
- }
- }
- }
-
- return newNode;
- }
-
- protected IStructuredCleanupHandler getCleanupHandler(Node node) {
- short nodeType = node.getNodeType();
- IStructuredCleanupHandler cleanupHandler = null;
- switch (nodeType) {
- case org.w3c.dom.Node.ELEMENT_NODE : {
- cleanupHandler = new ElementNodeCleanupHandler();
- break;
- }
- case org.w3c.dom.Node.TEXT_NODE : {
- cleanupHandler = new NodeCleanupHandler();
- break;
- }
- default : {
- cleanupHandler = new NodeCleanupHandler();
- }
- }
-
- // init CleanupPreferences
- cleanupHandler.setCleanupPreferences(getCleanupPreferences());
-
- return cleanupHandler;
- }
-
-
- protected ModelQuery getModelQuery(Node node) {
- if (node.getNodeType() == Node.DOCUMENT_NODE) {
- return ModelQueryUtil.getModelQuery((Document) node);
- } else {
- return ModelQueryUtil.getModelQuery(node.getOwnerDocument());
- }
- }
-
- protected List getRequiredAttrs(Node node) {
- List result = new ArrayList();
-
- ModelQuery modelQuery = getModelQuery(node);
- if (modelQuery != null) {
- CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
- if (elementDecl != null) {
- CMNamedNodeMap attrMap = elementDecl.getAttributes();
- Iterator it = attrMap.iterator();
- CMAttributeDeclaration attr = null;
- while (it.hasNext()) {
- attr = (CMAttributeDeclaration) it.next();
- if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
- result.add(attr);
- }
- }
- }
- }
-
- return result;
- }
-
- private IDOMNode insertEndTag(IDOMNode node) {
- IDOMNode newNode = node;
- IDOMElement element = (IDOMElement) node;
- if (element.isCommentTag())
- return node; // do nothing
-
- int startTagStartOffset = node.getStartOffset();
- IDOMModel structuredModel = node.getModel();
-
- if (isEmptyElement(element)) {
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- IStructuredDocumentRegion startStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
- ITextRegionList regions = startStructuredDocumentRegion.getRegions();
- ITextRegion lastRegion = regions.get(regions.size() - 1);
- structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), lastRegion.getLength(), EMPTY_TAG_CLOSE);
-
- if (regions.size() > 1) {
- ITextRegion regionBeforeTagClose = regions.get(regions.size() - 1 - 1);
-
- // insert a space separator before tag close if the previous
- // region does not have extra spaces
- if (regionBeforeTagClose.getTextLength() == regionBeforeTagClose.getLength())
- structuredDocument.replaceText(structuredDocument, startStructuredDocumentRegion.getStartOffset(lastRegion), 0, " "); //$NON-NLS-1$
- }
- } else {
- String tagName = node.getNodeName();
- String endTag = END_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);
-
- IDOMNode lastChild = (IDOMNode) node.getLastChild();
- int endTagStartOffset = 0;
- if (lastChild != null)
- // if this node has children, insert the end tag after the
- // last child
- endTagStartOffset = lastChild.getEndOffset();
- else
- // if this node does not has children, insert the end tag
- // after the start tag
- endTagStartOffset = node.getEndOffset();
-
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- structuredDocument.replaceText(structuredDocument, endTagStartOffset, 0, endTag);
- }
-
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
- // new
- // node
-
- return newNode;
- }
-
- private IDOMNode insertMissingTags(IDOMNode node) {
- boolean insertMissingTags = getCleanupPreferences().getInsertMissingTags();
- IDOMNode newNode = node;
-
- if (insertMissingTags) {
- IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getStartStructuredDocumentRegion();
- if (startTagStructuredDocumentRegion == null) {
- // implicit start tag; generate tag for it
- newNode = insertStartTag(node);
- startTagStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
- }
-
- IStructuredDocumentRegion endTagStructuredDocumentRegion = newNode.getEndStructuredDocumentRegion();
- ITextRegionList startStructuredDocumentRegionRegions = startTagStructuredDocumentRegion.getRegions();
- if (startTagStructuredDocumentRegion != null && startStructuredDocumentRegionRegions != null && (startStructuredDocumentRegionRegions.get(startStructuredDocumentRegionRegions.size() - 1)).getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
-
- } else {
- if (startTagStructuredDocumentRegion == null) {
- // start tag missing
- if (isStartTagRequired(newNode))
- newNode = insertStartTag(newNode);
- } else if (endTagStructuredDocumentRegion == null) {
- // end tag missing
- if (isEndTagRequired(newNode))
- newNode = insertEndTag(newNode);
- }
- }
- }
-
- return newNode;
- }
-
- private IDOMNode insertRequiredAttrs(IDOMNode node) {
- boolean insertRequiredAttrs = getCleanupPreferences().getInsertRequiredAttrs();
- IDOMNode newNode = node;
-
- if (insertRequiredAttrs) {
- List requiredAttrs = getRequiredAttrs(newNode);
- if (requiredAttrs.size() > 0) {
- NamedNodeMap currentAttrs = node.getAttributes();
- List insertAttrs = new ArrayList();
- if (currentAttrs.getLength() == 0)
- insertAttrs.addAll(requiredAttrs);
- else {
- for (int i = 0; i < requiredAttrs.size(); i++) {
- String requiredAttrName = ((CMAttributeDeclaration) requiredAttrs.get(i)).getAttrName();
- boolean found = false;
- for (int j = 0; j < currentAttrs.getLength(); j++) {
- String currentAttrName = currentAttrs.item(j).getNodeName();
- if (requiredAttrName.compareToIgnoreCase(currentAttrName) == 0) {
- found = true;
- break;
- }
- }
- if (!found)
- insertAttrs.add(requiredAttrs.get(i));
- }
- }
- if (insertAttrs.size() > 0) {
- IStructuredDocumentRegion startStructuredDocumentRegion = newNode.getStartStructuredDocumentRegion();
- int index = startStructuredDocumentRegion.getEndOffset();
- ITextRegion lastRegion = startStructuredDocumentRegion.getLastRegion();
- if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE) {
- index--;
- lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
- } else if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- index = index - 2;
- lastRegion = startStructuredDocumentRegion.getRegionAtCharacterOffset(index - 1);
- }
- MultiTextEdit multiTextEdit = new MultiTextEdit();
- try {
- for (int i = insertAttrs.size() - 1; i >= 0; i--) {
- CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) insertAttrs.get(i);
- String requiredAttributeName = attrDecl.getAttrName();
- String defaultValue = attrDecl.getDefaultValue();
- if (defaultValue == null)
- defaultValue = ""; //$NON-NLS-1$
- String nameAndDefaultValue = " "; //$NON-NLS-1$
- if (i == 0 && lastRegion.getLength() > lastRegion.getTextLength())
- nameAndDefaultValue = ""; //$NON-NLS-1$
- nameAndDefaultValue += requiredAttributeName + "=\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- multiTextEdit.addChild(new InsertEdit(index, nameAndDefaultValue));
- // BUG3381: MultiTextEdit applies all child
- // TextEdit's basing on offsets
- // in the document before the first TextEdit, not
- // after each
- // child TextEdit. Therefore, do not need to
- // advance the index.
- //index += nameAndDefaultValue.length();
- }
- multiTextEdit.apply(newNode.getStructuredDocument());
- } catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- }
- }
- }
-
- return newNode;
- }
-
- private IDOMNode insertStartTag(IDOMNode node) {
- IDOMNode newNode = node;
-
- if (isCommentTag(node))
- return node; // do nothing
-
- String tagName = node.getNodeName();
- String startTag = START_TAG_OPEN.concat(tagName).concat(TAG_CLOSE);
- int startTagStartOffset = node.getStartOffset();
-
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- structuredDocument.replaceText(structuredDocument, startTagStartOffset, 0, startTag);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
- // new
- // node
-
- return newNode;
- }
-
- private void insertTagClose(IDOMModel structuredModel, IStructuredDocumentRegion flatNode) {
- if (flatNode != null) {
- ITextRegionList flatnodeRegions = flatNode.getRegions();
- if (flatnodeRegions != null) {
- ITextRegion lastRegion = flatnodeRegions.get(flatnodeRegions.size() - 1);
- if (lastRegion != null) {
- String regionType = lastRegion.getType();
- if ((regionType != DOMRegionContext.XML_EMPTY_TAG_CLOSE) && (regionType != DOMRegionContext.XML_TAG_CLOSE)) {
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
-
- // insert ">" after lastRegion of flatNode
- // as in "<a</a>" if flatNode is for start tag, or in
- // "<a></a" if flatNode is for end tag
- structuredDocument.replaceText(structuredDocument, flatNode.getTextEndOffset(lastRegion), 0, ">"); //$NON-NLS-1$
- }
- }
- }
- }
- }
-
- /**
- * @param renamedNode
- * @return
- */
- private boolean isCommentTag(Node renamedNode) {
- boolean result = false;
- if (renamedNode instanceof IDOMElement) {
- IDOMElement element = (IDOMElement) renamedNode;
- result = element.isCommentTag();
- }
- return result;
- }
-
- private boolean isEmptyElement(IDOMElement element) {
- Document document = element.getOwnerDocument();
- if (document == null)
- // undefined tag, return default
- return false;
-
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
- if (modelQuery == null)
- // undefined tag, return default
- return false;
-
- CMElementDeclaration decl = modelQuery.getCMElementDeclaration(element);
- if (decl == null)
- // undefined tag, return default
- return false;
-
- return (decl.getContentType() == CMElementDeclaration.EMPTY);
- }
-
- private boolean isEndTagRequired(IDOMNode node) {
- if (node == null)
- return false;
- return node.isContainer();
- }
-
- /**
- * A tag is implicit if it has not corresponding region in document.
- *
- * @param renamedNode
- * @return
- */
- private boolean isImplicitTag(IDOMNode renamedNode) {
- return renamedNode.getStartStructuredDocumentRegion() == null;
- }
-
- /**
- * The end tags of HTML EMPTY content type, such as IMG, and HTML
- * undefined tags are parsed separately from the start tags. So inserting
- * the missing start tag is useless and even harmful.
- */
- private boolean isStartTagRequired(IDOMNode node) {
- if (node == null)
- return false;
- return node.isContainer();
- }
-
- private boolean isXMLType(IDOMModel structuredModel) {
- boolean result = false;
-
- if (structuredModel != null) {
- IDOMDocument document = structuredModel.getDocument();
-
- if (document != null)
- result = document.isXMLType();
- }
-
- return result;
- }
-
- private IDOMNode quoteAttrValue(IDOMNode node) {
- IDOMNode newNode = node;
- //XMLElement element = (XMLElement) node;
- if (isCommentTag(node))
- return node; // do nothing
-
- boolean quoteAttrValues = getCleanupPreferences().getQuoteAttrValues();
-
- if (quoteAttrValues) {
- NamedNodeMap attributes = newNode.getAttributes();
- if (attributes != null) {
- int attributesLength = attributes.getLength();
- ISourceGenerator generator = node.getModel().getGenerator();
-
- for (int i = 0; i < attributesLength; i++) {
- attributes = newNode.getAttributes();
- attributesLength = attributes.getLength();
- IDOMAttr eachAttr = (IDOMAttr) attributes.item(i);
- //ITextRegion oldAttrValueRegion =
- // eachAttr.getValueRegion();
- String oldAttrValue = eachAttr.getValueRegionText();
- if (oldAttrValue == null) {
- IDOMModel structuredModel = node.getModel();
- if (isXMLType(structuredModel)) {
- String newAttrValue = "\"" + eachAttr.getNameRegionText() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
-
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- if (eachAttr.getEqualRegion() != null)
- // equal region exists
- structuredDocument.replaceText(structuredDocument, eachAttr.getEndOffset(), 0, newAttrValue);
- else
- // no equal region
- structuredDocument.replaceText(structuredDocument, eachAttr.getNameRegionTextEndOffset(), 0, "=".concat(newAttrValue)); //$NON-NLS-1$
- newNode = (IDOMNode) structuredModel.getIndexedRegion(node.getStartOffset()); // save
- // new
- // node
- }
- } else {
- //String oldAttrValue = oldAttrValueRegion.getText();
- char quote = StringUtils.isQuoted(oldAttrValue) ? oldAttrValue.charAt(0) : DOUBLE_QUOTE;
- String newAttrValue = generator.generateAttrValue(eachAttr, quote);
-
- // There is a problem in
- // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
- // when the region is instanceof ContextRegion.
- // Workaround for now...
- if (oldAttrValue.length() == 1) {
- char firstChar = oldAttrValue.charAt(0);
- if (firstChar == SINGLE_QUOTE)
- newAttrValue = SINGLE_QUOTES;
- else if (firstChar == DOUBLE_QUOTE)
- newAttrValue = DOUBLE_QUOTES;
- }
-
- if (newAttrValue != null) {
- if (newAttrValue.compareTo(oldAttrValue) != 0) {
- int attrValueStartOffset = eachAttr.getValueRegionStartOffset();
- int attrValueLength = oldAttrValue.length();
- int startTagStartOffset = node.getStartOffset();
-
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- structuredDocument.replaceText(structuredDocument, attrValueStartOffset, attrValueLength, newAttrValue);
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset); // save
- // new
- // node
- }
- }
- }
- }
- }
- }
-
- return newNode;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/NodeCleanupHandler.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/NodeCleanupHandler.java
deleted file mode 100644
index 95c209792b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/NodeCleanupHandler.java
+++ /dev/null
@@ -1,63 +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.cleanup;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupHandler;
-import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences;
-import org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-import org.w3c.dom.Node;
-
-
-public class NodeCleanupHandler implements IStructuredCleanupHandler {
-
- protected IStructuredCleanupPreferences fCleanupPreferences = null;
- protected IProgressMonitor fProgressMonitor = null;
-
-
- public Node cleanup(Node node) {
-
- return node;
- }
-
- public IStructuredCleanupPreferences getCleanupPreferences() {
- if (fCleanupPreferences == null) {
- fCleanupPreferences = new StructuredCleanupPreferences();
-
- Preferences preferences = getModelPreferences();
- if (preferences != null) {
- fCleanupPreferences.setCompressEmptyElementTags(preferences.getBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS));
- fCleanupPreferences.setInsertRequiredAttrs(preferences.getBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS));
- fCleanupPreferences.setInsertMissingTags(preferences.getBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS));
- fCleanupPreferences.setQuoteAttrValues(preferences.getBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES));
- fCleanupPreferences.setFormatSource(preferences.getBoolean(XMLCorePreferenceNames.FORMAT_SOURCE));
- fCleanupPreferences.setConvertEOLCodes(preferences.getBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES));
- fCleanupPreferences.setEOLCode(preferences.getString(XMLCorePreferenceNames.CLEANUP_EOL_CODE));
- }
- }
-
- return fCleanupPreferences;
- }
-
- protected Preferences getModelPreferences() {
- return XMLCorePlugin.getDefault().getPluginPreferences();
- }
-
- public void setCleanupPreferences(IStructuredCleanupPreferences cleanupPreferences) {
-
- fCleanupPreferences = cleanupPreferences;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/XMLCleanupPreferencesImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/XMLCleanupPreferencesImpl.java
deleted file mode 100644
index 473c4875da..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/cleanup/XMLCleanupPreferencesImpl.java
+++ /dev/null
@@ -1,142 +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.cleanup;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.wst.sse.core.internal.SSECorePlugin;
-import org.eclipse.wst.xml.core.internal.provisional.IXMLPreferenceNames;
-
-/**
- * @deprecated renamed to StructuredCleanupPreferences
- *
- * TODO will delete in C5
- */
-public class XMLCleanupPreferencesImpl {
-
- private static XMLCleanupPreferencesImpl fInstance;
-
- public synchronized static XMLCleanupPreferencesImpl getInstance() {
-
- // added for one method in CleanupDialog ... may be better way
- if (fInstance == null) {
- fInstance = new XMLCleanupPreferencesImpl();
- }
- return fInstance;
- }
-
- private int fAttrNameCase;
- private boolean fConvertEOLCodes;
- private String fEOLCode;
- private boolean fFormatSource;
- private boolean fInsertMissingTags;
- // private IPreferenceStore fPreferenceStore = null;
- private Preferences fPreferences = null;
- private boolean fQuoteAttrValues;
- private int fTagNameCase;
-
- public int getAttrNameCase() {
-
- return fAttrNameCase;
- }
-
- public boolean getConvertEOLCodes() {
-
- return fConvertEOLCodes;
- }
-
- public String getEOLCode() {
-
- return fEOLCode;
- }
-
- public boolean getFormatSource() {
-
- return fFormatSource;
- }
-
- public boolean getInsertMissingTags() {
-
- return fInsertMissingTags;
- }
-
- public Preferences getPreferences() {
-
- if (fPreferences == null) {
- fPreferences = SSECorePlugin.getDefault().getPluginPreferences();
- }
- return fPreferences;
- }
-
- public boolean getQuoteAttrValues() {
-
- return fQuoteAttrValues;
- }
-
- public int getTagNameCase() {
-
- return fTagNameCase;
- }
-
- public void setAttrNameCase(int attrNameCase) {
-
- fAttrNameCase = attrNameCase;
- }
-
- public void setConvertEOLCodes(boolean convertEOLCodes) {
-
- fConvertEOLCodes = convertEOLCodes;
- }
-
- public void setEOLCode(String EOLCode) {
-
- fEOLCode = EOLCode;
- }
-
- public void setFormatSource(boolean formatSource) {
-
- fFormatSource = formatSource;
- }
-
- public void setInsertMissingTags(boolean insertMissingTags) {
-
- fInsertMissingTags = insertMissingTags;
- }
-
- public void setPreferences(Preferences prefs) {
-
- fPreferences = prefs;
- updateOptions();
- }
-
- public void setQuoteAttrValues(boolean quoteAttrValues) {
-
- fQuoteAttrValues = quoteAttrValues;
- }
-
- public void setTagNameCase(int tagNameCase) {
-
- fTagNameCase = tagNameCase;
- }
-
- protected void updateOptions() {
-
- Preferences p = getPreferences();
- fTagNameCase = p.getInt(IXMLPreferenceNames.CLEANUP_TAG_NAME_CASE);
- fAttrNameCase = p.getInt(IXMLPreferenceNames.CLEANUP_ATTR_NAME_CASE);
- fInsertMissingTags = p.getBoolean(IXMLPreferenceNames.INSERT_MISSING_TAGS);
- fQuoteAttrValues = p.getBoolean(IXMLPreferenceNames.QUOTE_ATTR_VALUES);
- fFormatSource = p.getBoolean(IXMLPreferenceNames.FORMAT_SOURCE);
- fConvertEOLCodes = p.getBoolean(IXMLPreferenceNames.CONVERT_EOL_CODES);
- fEOLCode = p.getString(IXMLPreferenceNames.CLEANUP_EOL_CODE);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementAdapter.java
deleted file mode 100644
index c06af5e212..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementAdapter.java
+++ /dev/null
@@ -1,103 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.commentelement;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.commentelement.impl.CommentElementConfiguration;
-import org.eclipse.wst.xml.core.internal.document.TagAdapter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-
-
-/**
- */
-public class CommentElementAdapter implements TagAdapter {
- private CommentElementConfiguration fConfiguration;
-
- private boolean fEndTag;
- private CommentElementHandler fHandler;
-
- public CommentElementAdapter(boolean isEndTag, CommentElementHandler handler) {
- fEndTag = isEndTag;
- fHandler = handler;
- }
-
- private String generateCommentClose(IDOMElement element) {
- return (element.isJSPTag()) ? "--%>" : "-->"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private String generateCommentOpen(IDOMElement element) {
- return (element.isJSPTag()) ? "<%--" : "<!--"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private CommentElementConfiguration getConfiguration() {
- return fConfiguration;
- }
-
- public String getEndTag(IDOMElement element) {
- String content = fHandler.generateEndTagContent(element);
- if (content == null) {
- return null;
- }
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(generateCommentOpen(element));
- buffer.append(content);
- buffer.append(generateCommentClose(element));
-
- return buffer.toString();
- }
-
- public String getHandlerID() {
- return getConfiguration().getHandlerID();
- }
-
-
- public String getProperty(String name) {
- return getConfiguration().getProperty(name);
- }
-
- public String getStartTag(IDOMElement element) {
- String content = fHandler.generateStartTagContent(element);
- if (content == null) {
- return null;
- }
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(generateCommentOpen(element));
- buffer.append(content);
- buffer.append(generateCommentClose(element));
-
- return buffer.toString();
- }
-
- public boolean isAdapterForType(Object type) {
- return (type == CommentElementAdapter.class || type == TagAdapter.class);
- }
-
- public boolean isContainer() {
- return (!fHandler.isEmpty());
- }
-
- public boolean isEndTag() {
- return fEndTag;
- }
-
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- }
-
- public void setConfiguration(CommentElementConfiguration configuration) {
- fConfiguration = configuration;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementHandler.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementHandler.java
deleted file mode 100644
index 93e8e6eedb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/CommentElementHandler.java
+++ /dev/null
@@ -1,107 +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.commentelement;
-
-
-
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-/**
- */
-public interface CommentElementHandler {
- /**
- * This method is called when the prefix of the comment content matches
- * the string specified in &lt;startswith prefix=""/&gt; in plugin
- * extension. Comment content is parsed and new DOM element is created in
- * this method. Implementor has to do following:
- * <li>For start tag :
- * <ul>
- * <li>parse comment content and create new element instance.</li>
- * </ul>
- * </li>
- * <li>For end tag :
- * <ul>
- * <li>parse comment content and create new element instance.</li>
- * <li>make isEndTag flag true.</li>
- * <li>Parser framework searches mached start tag element instance after
- * this createElement call, and new instance is just thrown away.</li>
- * </ul>
- * </li>
- * <li>For empty tag :
- * <ul>
- * <li>parse comment content and create new element instance.</li>
- * <li>make isEndTag flag true.</li>
- * </ul>
- * </li>
- *
- * @param document
- * parent DOM document
- * @param data
- * comment content. comment prefix (&lt;!-- or &lt;%--), suffix
- * (--&gt; or --%&gt;), and surrounding spaces are trimmed.
- * @param isJSPTag
- * true if the comment is JSP style comment. This information
- * may be required by handler when the handler accepts both XML
- * style and JSP style comment (namely,
- * commenttype=&quot;both&quot; in plugin.xml).
- * @return comment element instance if the comment content is rightly
- * parsed. if parse failed, returns null.
- */
- Element createElement(Document document, String data, boolean isJSPTag);
-
- /**
- * This method generates the source text of the end tag for the passed
- * element. Do not generate comment prefix (&lt;!-- or &lt;%--) and suffix
- * (--&gt; or --%&gt;). XMLGenerator uses this method to generate XML/HTML
- * source for a comment element.
- *
- * @param element
- * the comment element
- * @return generated tag string
- */
- String generateEndTagContent(IDOMElement element);
-
- /**
- * This method generates the source text of the start tag for the passed
- * element. Do not generate comment prefix (&lt;!-- or &lt;%--) and suffix
- * (--&gt; or --%&gt;). XMLGenerator uses this method to generate XML/HTML
- * source for a comment element.
- *
- * @param element
- * the comment element
- * @return generated tag string
- */
- String generateStartTagContent(IDOMElement element);
-
- /**
- *
- * @param element
- * the element
- * @return boolean whether the element is comment element or not
- */
- boolean isCommentElement(IDOMElement element);
-
- /**
- *
- * @return boolean whether this element can have children or not
- */
- boolean isEmpty();
-
- /**
- * @return String
- */
- // String getElementPrefix();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/BasicCommentElementHandler.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/BasicCommentElementHandler.java
deleted file mode 100644
index caf62283d9..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/BasicCommentElementHandler.java
+++ /dev/null
@@ -1,135 +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.commentelement.impl;
-
-
-
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementHandler;
-import org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory;
-import org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.eclipse.wst.xml.core.internal.provisional.document.ISourceGenerator;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-
-
-/**
- */
-class BasicCommentElementHandler implements CommentElementHandler {
-
- private String elementName;
- private boolean isEmpty;
-
- public BasicCommentElementHandler(String elementName, boolean isEmpty) {
- super();
- this.elementName = elementName;
- this.isEmpty = isEmpty;
- }
-
-
- public Element createElement(Document document, String data, boolean isJSPTag) {
- Element element = null;
- String str = data.trim();
- CommentElementFactory factory = new CommentElementFactory(document, isJSPTag, this);
- if (str.charAt(0) == '/') { // end tag
- TagScanner scanner = new TagScanner(str, 1); // skip '/'
- String name = scanner.nextName();
- if (name.equals(elementName)) {
- element = factory.create(name, CommentElementFactory.IS_END);
- }
- } else { // start tag
- TagScanner scanner = new TagScanner(str, 0);
- String name = scanner.nextName();
- if (name.equals(elementName)) {
- element = factory.create(name, (isEmpty) ? CommentElementFactory.IS_EMPTY : CommentElementFactory.IS_START);
- // set attributes
- String attrName = scanner.nextName();
- while (attrName != null) {
- String attrValue = scanner.nextValue();
- Attr attr = document.createAttribute(attrName);
- if (attr != null) {
- if (attrValue != null)
- ((IDOMAttr) attr).setValueSource(attrValue);
- element.setAttributeNode(attr);
- }
- attrName = scanner.nextName();
- }
- }
- }
- return element;
- }
-
-
- public String generateEndTagContent(IDOMElement element) {
- if (isEmpty) {
- return null;
- }
- ISourceGenerator generator = element.getModel().getGenerator();
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(" /"); //$NON-NLS-1$
- String tagName = generator.generateTagName(element);
- if (tagName != null) {
- buffer.append(tagName);
- }
- buffer.append(' ');
-
- return buffer.toString();
- }
-
- public String generateStartTagContent(IDOMElement element) {
- ISourceGenerator generator = element.getModel().getGenerator();
- StringBuffer buffer = new StringBuffer();
-
- buffer.append(' ');
- String tagName = generator.generateTagName(element);
- if (tagName != null) {
- buffer.append(tagName);
- }
-
- NamedNodeMap attributes = element.getAttributes();
- int length = attributes.getLength();
- for (int i = 0; i < length; i++) {
- Attr attr = (Attr) attributes.item(i);
- if (attr == null) {
- continue;
- }
- buffer.append(' ');
- String attrName = generator.generateAttrName(attr);
- if (attrName != null) {
- buffer.append(attrName);
- }
- String attrValue = generator.generateAttrValue(attr);
- if (attrValue != null) {
- // attr name only for HTML boolean and JSP
- buffer.append('=');
- buffer.append(attrValue);
- }
- }
-
- buffer.append(' ');
-
- return buffer.toString();
- }
-
- public boolean isCommentElement(IDOMElement element) {
- return (element != null && element.getTagName().equals(elementName)) ? true : false;
- }
-
- public boolean isEmpty() {
- return isEmpty;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementConfiguration.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementConfiguration.java
deleted file mode 100644
index ef49f577fb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementConfiguration.java
+++ /dev/null
@@ -1,237 +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.commentelement.impl;
-
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.InvalidRegistryObjectException;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementAdapter;
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementHandler;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-/**
- */
-public class CommentElementConfiguration {
- private Map fAttributes = null;
- private boolean fCustom;
- private IConfigurationElement fElement = null;
-
- private boolean fEmpty;
- private CommentElementHandler fHandler = null;
- private String fID = null;
- private boolean fJSPComment;
- private String[] fPrefix = null;
- private boolean fXMLComment;
-
- CommentElementConfiguration(IConfigurationElement element) {
- super();
- fElement = element;
- fCustom = element.getName().equalsIgnoreCase("handler-custom"); //$NON-NLS-1$
-
- fillAttributes(element);
-
- fXMLComment = fJSPComment = false;
- String commentType = getProperty("commenttype"); //$NON-NLS-1$
- if ("xml".equalsIgnoreCase(commentType)) { //$NON-NLS-1$
- fXMLComment = true;
- } else if ("jsp".equalsIgnoreCase(commentType)) { //$NON-NLS-1$
- fJSPComment = true;
- } else if ("both".equalsIgnoreCase(commentType)) { //$NON-NLS-1$
- fXMLComment = fJSPComment = true;
- }
- String empty = getProperty("isempty"); //$NON-NLS-1$
- fEmpty = Boolean.valueOf(empty).booleanValue(); //$NON-NLS-1$
- }
-
- public boolean acceptJSPComment() {
- return fJSPComment;
- }
-
- public boolean acceptXMLComment() {
- return fXMLComment;
- }
-
- public Element createElement(Document document, String data, boolean isJSPTag) {
- IDOMElement element = (IDOMElement) getHandler().createElement(document, data, isJSPTag);
- if (element != null) {
- CommentElementAdapter adapter = (CommentElementAdapter) element.getAdapterFor(CommentElementAdapter.class);
- if (adapter != null) {
- adapter.setConfiguration(this);
- }
- }
- return element;
- }
-
- private void fillAttributes(IConfigurationElement element) {
- if (fAttributes == null) {
- fAttributes = new HashMap();
- } else {
- fAttributes.clear();
- }
- String[] names = element.getAttributeNames();
- if (names == null) {
- return;
- }
- int length = names.length;
- for (int i = 0; i < length; i++) {
- String name = names[i];
- fAttributes.put(name.toLowerCase(), element.getAttribute(name));
- }
- }
-
- public CommentElementHandler getHandler() {
- if (fHandler == null) {
- if (fElement != null) {
- try {
- if (isCustom()) {
- fHandler = (CommentElementHandler) fElement.createExecutableExtension("class"); //$NON-NLS-1$
- } else {
- String elementName = getProperty("elementname"); //$NON-NLS-1$
- if (elementName != null) {
- fHandler = new BasicCommentElementHandler(elementName, fEmpty);
- }
- }
- // ((AbstractCommentElementHandler)fHandler).setElementPrefix(fElement.getAttribute("prefix"));
- } catch (Exception e) {
- // catch and log (and ignore) ANY exception created
- // by executable extension.
- Logger.logException(e);
- fHandler = null;
- }
- }
- if (fHandler == null) {
- fHandler = new CommentElementHandler() {
- public Element createElement(Document document, String data, boolean isJSPTag) {
- return null;
- }
-
- public String generateEndTagContent(IDOMElement element) {
- return null;
- }
-
- public String generateStartTagContent(IDOMElement element) {
- return null;
- }
-
-// removed in RC2, ro removed "unused" error/warning
-// public String getElementPrefix() {
-// return null;
-// }
-
- public boolean isCommentElement(IDOMElement element) {
- return false;
- }
-
- public boolean isEmpty() {
- return false;
- }
- };
- }
- }
- return fHandler;
- }
-
- public String getHandlerID() {
- if (fID == null) {
- fID = getProperty("id"); //$NON-NLS-1$
- if (fID == null) {
- if (isCustom()) {
- fID = getProperty("class"); //$NON-NLS-1$
- } else {
- StringBuffer buf = new StringBuffer();
- buf.append(fElement.getDeclaringExtension().getNamespace());
- buf.append('.');
- buf.append(getProperty("elementname")); //$NON-NLS-1$
- fID = buf.toString();
- }
- }
- }
- return fID;
- }
-
-
- public String[] getPrefix() {
- if (fPrefix == null) {
- if (fElement != null) {
- if (isCustom()) { // custom
- IConfigurationElement[] prefixes = fElement.getChildren("startwith"); //$NON-NLS-1$
- if (prefixes != null) {
- List prefixValues = new ArrayList(prefixes.length);
- for (int i = 0; i < prefixes.length; i++) {
- String prefix = prefixes[i].getAttribute("prefix"); //$NON-NLS-1$
- if (prefix != null) {
- prefixValues.add(prefix);
- }
- else {
- try {
- Logger.log(Logger.WARNING, "misconfigured comment element in" + fElement.getContributor().getName(), new IllegalArgumentException("startwith")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (InvalidRegistryObjectException e) {
- // stale bundle?
- }
- }
- }
- if (!prefixValues.isEmpty()) {
- fPrefix = (String[]) prefixValues.toArray(new String[prefixValues.size()]);
- }
- }
- } else { // basic
- String name = getProperty("elementname"); //$NON-NLS-1$
- if (name != null) {
- if (isEmpty()) {
- fPrefix = new String[1];
- fPrefix[0] = name;
- } else {
- fPrefix = new String[2];
- fPrefix[0] = name;
- fPrefix[1] = '/' + name;
- }
- }
- }
- }
- }
- if (fPrefix == null) {
- fPrefix = new String[0];
- }
- return fPrefix;
- }
-
- public String getProperty(String name) {
- return (fAttributes != null) ? (String) fAttributes.get(name) : null;
- }
-
- private boolean isCustom() {
- return fCustom;
- }
-
- private boolean isEmpty() {
- return fEmpty;
- }
-
- void setupCommentElement(IDOMElement element) {
- element.setCommentTag(true);
- CommentElementAdapter adapter = new CommentElementAdapter(false, fHandler);
- adapter.setConfiguration(this);
- element.addAdapter(adapter);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementRegistry.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementRegistry.java
deleted file mode 100644
index efd1f67046..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/impl/CommentElementRegistry.java
+++ /dev/null
@@ -1,84 +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.commentelement.impl;
-
-
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementHandler;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-
-
-/**
- */
-public class CommentElementRegistry {
-
- private static CommentElementRegistry fInstance = null;
-
- public synchronized static CommentElementRegistry getInstance() {
- if (fInstance == null) {
- fInstance = new CommentElementRegistry();
- }
- return fInstance;
- }
-
- private String EXTENSION_POINT_ID = "commentElementHandler"; //$NON-NLS-1$
- private CommentElementConfiguration[] fConfigurations = null;
-
- private String PLUGIN_ID = "org.eclipse.wst.sse.core"; //$NON-NLS-1$
-
- /**
- * Constructor for CommentElementRegistry.
- */
- private CommentElementRegistry() {
- super();
- }
-
- public CommentElementConfiguration[] getConfigurations() {
- if (fConfigurations == null) {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint point = registry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID);
- if (point != null) {
- IConfigurationElement[] elements = point.getConfigurationElements();
- fConfigurations = new CommentElementConfiguration[elements.length];
- for (int i = 0; i < elements.length; i++) {
- fConfigurations[i] = new CommentElementConfiguration(elements[i]);
- }
- }
- if (fConfigurations == null) {
- fConfigurations = new CommentElementConfiguration[0];
- }
- }
- return fConfigurations;
- }
-
- public boolean setupCommentElement(IDOMElement element) {
- CommentElementConfiguration configurations[] = getConfigurations();
- int length = configurations.length;
- for (int i = 0; i < length; i++) {
- CommentElementConfiguration conf = configurations[i];
- boolean isJSP = element.isJSPTag();
- if (isJSP && conf.acceptJSPComment() || !isJSP && conf.acceptXMLComment()) {
- CommentElementHandler handler = conf.getHandler();
- if (handler.isCommentElement(element)) {
- conf.setupCommentElement(element);
- return true;
- }
- }
- }
- return false;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/CommentElementFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/CommentElementFactory.java
deleted file mode 100644
index 2ac27ba0b1..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/CommentElementFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.commentelement.util;
-
-
-
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementAdapter;
-import org.eclipse.wst.xml.core.internal.commentelement.CommentElementHandler;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-/**
- */
-public class CommentElementFactory {
- public static final int IS_EMPTY = 4866;
- public static final int IS_END = 1808;
-
- public static final int IS_START = 28011;
-
- private Document fDocument;
- private CommentElementHandler fHandler;
- private boolean fJSPTag;
-
- /**
- * Constructor for CommentElementFactory.
- */
- private CommentElementFactory() {
- super();
- }
-
- public CommentElementFactory(Document document, boolean isJSPTag, CommentElementHandler handler) {
- this();
- fDocument = document;
- fJSPTag = isJSPTag;
- fHandler = handler;
- }
-
- public Element create(String name, int nodeType) {
- IDOMElement element = (IDOMElement) fDocument.createElement(name);
- if (element == null)
- return null;
- element.setCommentTag(true);
- if (nodeType == IS_EMPTY) {
- element.setEmptyTag(true);
- }
- element.setJSPTag(fJSPTag);
-
- CommentElementAdapter adapter = new CommentElementAdapter((nodeType == IS_END), fHandler);
- element.addAdapter(adapter);
-
- return element;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/TagScanner.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/TagScanner.java
deleted file mode 100644
index 1d0d404c86..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/commentelement/util/TagScanner.java
+++ /dev/null
@@ -1,196 +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.commentelement.util;
-
-
-
-/**
- */
-public class TagScanner {
-
- /**
- */
- private static boolean isEqual(char c) {
- return (c == '=');
- }
-
- /**
- */
- private static boolean isQuote(char c) {
- return (c == '"' || c == '\'');
- }
-
- /**
- */
- private static boolean isSpace(char c) {
- return Character.isWhitespace(c);
- }
-
- private int length = 0;
- private int memOffset = 0;
- private int offset = 0;
- private boolean oneLine = false;
-
- private String tag = null;
-
- /**
- */
- public TagScanner(String tag, int offset) {
- super();
-
- this.tag = tag;
- this.offset = offset;
- this.memOffset = -1;
- if (tag != null)
- this.length = tag.length();
- }
-
- /**
- */
- public TagScanner(String tag, int offset, boolean oneLine) {
- this(tag, offset);
-
- this.oneLine = oneLine;
- }
-
- /**
- */
- public int getNextOffset() {
- int i;
- char c;
- for (i = offset; i < length; i++) {
- c = tag.charAt(i);
- if (isEnd(c))
- break;
- if (isQuote(c)) {
- i++;
- break;
- }
- if (!isSpace(c) && !isEqual(c))
- break;
- }
- return i;
- }
-
- /**
- */
- public int getOffset() {
- return this.memOffset;
- }
-
- /**
- */
- private final boolean isEnd(char c) {
- return (this.oneLine && (c == '\r' || c == '\n'));
- }
-
- /**
- */
- public boolean isNewLine() {
- if (oneLine)
- return false;
- char c;
- for (int i = memOffset - 1; 0 <= i; i--) {
- c = tag.charAt(i);
- if (c == '\r' || c == '\n')
- return true;
- if (!isSpace(c))
- return false;
- }
- return false;
- }
-
- /**
- */
- private char nextChar() {
- for (; this.offset < this.length; this.offset++) {
- char c = this.tag.charAt(this.offset);
- if (isEnd(c))
- break;
- if (!isSpace(c))
- return c;
- }
- return 0;
- }
-
- /**
- */
- public String nextName() {
- if (this.tag == null)
- return null;
- if (this.offset >= this.length)
- return null;
-
- if (nextChar() == 0)
- return null;
-
- int nameOffset = this.offset;
- for (; this.offset < this.length; this.offset++) {
- char c = this.tag.charAt(this.offset);
- if (isEnd(c) || isSpace(c))
- break;
- if (isEqual(c) && this.offset > nameOffset)
- break;
- }
- if (this.offset == nameOffset)
- return null;
-
- this.memOffset = nameOffset;
- return this.tag.substring(nameOffset, this.offset);
- }
-
- /**
- */
- public String nextValue() {
- if (this.tag == null)
- return null;
- if (this.offset >= this.length)
- return null;
-
- char seperator = nextChar();
- if (!isEqual(seperator))
- return null;
- this.offset++; // skip '='
- char quote = nextChar();
- if (quote == 0)
- return null;
- if (isQuote(quote))
- this.offset++;
- else
- quote = 0;
-
- int valueOffset = this.offset;
- for (; this.offset < this.length; this.offset++) {
- char c = this.tag.charAt(this.offset);
- if (isEnd(c)) {
- quote = 0;
- break;
- }
- if (quote == 0) {
- if (isSpace(c))
- break;
- } else {
- if (c == quote)
- break;
- }
- }
- int valueEnd = this.offset;
- if (quote != 0 && this.offset < this.length)
- this.offset++;
- if (valueEnd == valueOffset)
- return null;
-
- this.memOffset = valueOffset;
- return this.tag.substring(valueOffset, valueEnd);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/AbstractResourceEncodingDetector.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/AbstractResourceEncodingDetector.java
deleted file mode 100644
index fcbcbea17f..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/AbstractResourceEncodingDetector.java
+++ /dev/null
@@ -1,258 +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.contenttype;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
-
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-
-import org.eclipse.wst.sse.core.internal.encoding.CodedIO;
-import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;
-import org.eclipse.wst.sse.core.internal.encoding.IResourceCharsetDetector;
-
-
-public abstract class AbstractResourceEncodingDetector implements IResourceCharsetDetector {
-
- protected EncodingMemento fEncodingMemento;
-
- protected boolean fHeaderParsed;
-
- protected Reader fReader;
-
- /**
- *
- */
- public AbstractResourceEncodingDetector() {
- super();
- }
-
- /**
- * Note: once this instance is created, trace info still needs to be
- * appended by caller, depending on the context its created.
- */
- private void createEncodingMemento(String detectedCharsetName) {
- fEncodingMemento = new EncodingMemento();
- fEncodingMemento.setJavaCharsetName(getAppropriateJavaCharset(detectedCharsetName));
- fEncodingMemento.setDetectedCharsetName(detectedCharsetName);
- // TODO: if detectedCharset and spec default is
- // null, need to use "work
- // bench based" defaults.
- fEncodingMemento.setAppropriateDefault(getSpecDefaultEncoding());
- }
-
- /**
- * convience method all subclasses can use (but not override)
- *
- * @param detectedCharsetName
- * @param reason
- */
- final protected void createEncodingMemento(String detectedCharsetName, String reason) {
- createEncodingMemento(detectedCharsetName);
- }
-
- /**
- * convience method all subclasses can use (but not override)
- */
- final protected void ensureInputSet() {
- if (fReader == null) {
- throw new IllegalStateException("input must be set before use"); //$NON-NLS-1$
- }
- }
-
- /**
- * This method can return null, if invalid charset name (in which case
- * "appropriateDefault" should be used, if a name is really need for some
- * "save anyway" cases).
- *
- * @param detectedCharsetName
- * @return
- */
- private String getAppropriateJavaCharset(String detectedCharsetName) {
- String result = null;
- // 1. Check explicit mapping overrides from
- // property file -- its here we pick up "rules" for cases
- // that are not even in Java
- result = CodedIO.checkMappingOverrides(detectedCharsetName);
- // 2. Use the "canonical" name from JRE mappings
- // Note: see Charset JavaDoc, the name you get one
- // with can be alias,
- // the name you get back is "standard" name.
- Charset javaCharset = null;
- try {
- javaCharset = Charset.forName(detectedCharsetName);
- } catch (UnsupportedCharsetException e) {
- // only set invalid, if result is same as detected -- they won't
- // be equal if
- // overridden
- if (result != null && result.equals(detectedCharsetName)) {
- fEncodingMemento.setInvalidEncoding(detectedCharsetName);
- }
- } catch (IllegalCharsetNameException e) {
- // only set invalid, if result is same as detected -- they won't
- // be equal if
- // overridden
- if (result != null && result.equals(detectedCharsetName)) {
- fEncodingMemento.setInvalidEncoding(detectedCharsetName);
- }
- }
- // give priority to java cononical name, if present
- if (javaCharset != null) {
- result = javaCharset.name();
- // but still allow overrides
- result = CodedIO.checkMappingOverrides(result);
- }
- return result;
- }
-
- public String getEncoding() throws IOException {
- return getEncodingMemento().getDetectedCharsetName();
- }
-
- // to ensure consist overall rules used, we'll mark as
- // final,
- // and require subclasses to provide certain pieces of
- // the
- // implementation
- public EncodingMemento getEncodingMemento() throws IOException {
- ensureInputSet();
- if (!fHeaderParsed) {
- parseInput();
- // we keep track of if header's already been
- // parse, so can make
- // multiple 'get' calls, without causing
- // reparsing.
- fHeaderParsed = true;
- // Note: there is a "hidden assumption" here
- // that an empty
- // string in content should be treated same as
- // not present.
- }
- if (fEncodingMemento == null) {
- handleSpecDefault();
- }
- if (fEncodingMemento == null) {
- // safty net
- fEncodingMemento = new NullMemento();
- }
- return fEncodingMemento;
- }
-
- /**
- * This is to return a default encoding -- as specified by an industry
- * content type spec -- when not present in the stream, for example, XML
- * specifies UTF-8, JSP specifies ISO-8859-1. This method should return
- * null if there is no such "spec default".
- */
- abstract public String getSpecDefaultEncoding();
-
- public EncodingMemento getSpecDefaultEncodingMemento() {
- resetAll();
- EncodingMemento result = null;
- String enc = getSpecDefaultEncoding();
- if (enc != null) {
- createEncodingMemento(enc, EncodingMemento.DEFAULTS_ASSUMED_FOR_EMPTY_INPUT);
- fEncodingMemento.setAppropriateDefault(enc);
- result = fEncodingMemento;
- }
- return result;
- }
-
- private void handleSpecDefault() {
- String encodingName;
- encodingName = getSpecDefaultEncoding();
- if (encodingName != null) {
- //createEncodingMemento(encodingName,
- // EncodingMemento.USED_CONTENT_TYPE_DEFAULT);
- fEncodingMemento = new EncodingMemento();
- fEncodingMemento.setJavaCharsetName(encodingName);
- fEncodingMemento.setAppropriateDefault(encodingName);
- }
- }
-
- /**
- * Every subclass must provide a way to parse the input. This method has
- * several critical responsibilities:
- * <li>set the fEncodingMemento field appropriately, according to the
- * results of the parse of fReader.</li>
- * <li>set fHarderParsed to true, to avoid wasted re-parsing.</li>
- */
- abstract protected void parseInput() throws IOException;
-
- /**
- *
- */
- protected void resetAll() {
- fReader = null;
- fHeaderParsed = false;
- fEncodingMemento = null;
- }
-
- /**
- *
- */
- public void set(InputStream inputStream) {
- resetAll();
- fReader = new ByteReader(inputStream);
- try {
- fReader.mark(CodedIO.MAX_MARK_SIZE);
- } catch (IOException e) {
- // impossible, since we know ByteReader
- // supports marking
- throw new Error(e);
- }
- }
-
- /**
- *
- */
- public void set(IStorage iStorage) throws CoreException {
- resetAll();
- InputStream inputStream = iStorage.getContents();
- InputStream resettableStream = new BufferedInputStream(inputStream, CodedIO.MAX_BUF_SIZE);
- resettableStream.mark(CodedIO.MAX_MARK_SIZE);
- set(resettableStream);
- // TODO we'll need to "remember" IFile, or
- // get its (or its project's) settings, in case
- // those are needed to handle cases when the
- // encoding is not in the file stream.
- }
-
- /**
- * Note: this is not part of interface to help avoid confusion ... it
- * expected this Reader is a well formed character reader ... that is, its
- * all ready been determined to not be a unicode marked input stream. And,
- * its assumed to be in the correct position, at position zero, ready to
- * read first character.
- */
- public void set(Reader reader) {
- resetAll();
- fReader = reader;
- if (!fReader.markSupported()) {
- fReader = new BufferedReader(fReader);
- }
- try {
- fReader.mark(CodedIO.MAX_MARK_SIZE);
- } catch (IOException e) {
- // impossble, since we just checked if markable
- throw new Error(e);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ByteReader.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ByteReader.java
deleted file mode 100644
index 3d50b3f7a2..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ByteReader.java
+++ /dev/null
@@ -1,108 +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.contenttype;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.eclipse.wst.sse.core.internal.encoding.CodedIO;
-
-/**
- * This is an "adapter" class, simply to get in input stream to act like a
- * reader. We could not use InputStreamReader directly because its internal
- * buffers are not controllable, and it sometimes pulls too much out of input
- * stream (even when it wasn't needed for our purposes).
- *
- * The use of this class is highly specialized and by not means meant to be
- * general purpose. Its use is restricted to those cases where the input
- * stream can be regarded as ascii just long enough to determine what the real
- * encoding should be.
- */
-
-public class ByteReader extends Reader {
-
- public static final int DEFAULT_BUFFER_SIZE = CodedIO.MAX_BUF_SIZE;
-
- protected byte[] fBuffer;
-
- protected InputStream fInputStream;
-
- protected ByteReader() {
- super();
- }
-
- public ByteReader(InputStream inputStream) {
- this(inputStream, DEFAULT_BUFFER_SIZE);
- if (!inputStream.markSupported()) {
- throw new IllegalArgumentException("ByteReader is required to have a resettable stream"); //$NON-NLS-1$
- }
- }
-
- public ByteReader(InputStream inputStream, int size) {
- fInputStream = inputStream;
- if (!inputStream.markSupported()) {
- throw new IllegalArgumentException("ByteReader is required to have a resettable stream"); //$NON-NLS-1$
- }
- fBuffer = new byte[size];
-
- }
-
- public void close() throws IOException {
- fInputStream.close();
- }
-
- public void mark(int readAheadLimit) throws IOException {
- fInputStream.mark(readAheadLimit);
- }
-
- public boolean markSupported() {
- return true;
- }
-
- public int read() throws IOException {
- int b0 = fInputStream.read();
- return (b0 & 0x00FF);
- }
-
- public int read(char ch[], int offset, int length) throws IOException {
- if (length > fBuffer.length) {
- length = fBuffer.length;
- }
-
- int count = fInputStream.read(fBuffer, 0, length);
-
- for (int i = 0; i < count; i++) {
- int b0 = fBuffer[i];
- // the 0x00FF is to "lose" the negative bits filled in the byte to
- // int conversion
- // (and which would be there if cast directly from byte to char).
- char c0 = (char) (b0 & 0x00FF);
- ch[offset + i] = c0;
- }
- return count;
- }
-
- public boolean ready() throws IOException {
- return fInputStream.available() > 0;
- }
-
- public void reset() throws IOException {
- fInputStream.reset();
- }
-
- public long skip(long n) throws IOException {
- return fInputStream.skip(n);
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ContentDescriberForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ContentDescriberForXML.java
deleted file mode 100644
index 9e56e7029e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/ContentDescriberForXML.java
+++ /dev/null
@@ -1,264 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contenttype;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.content.IContentDescriber;
-import org.eclipse.core.runtime.content.IContentDescription;
-import org.eclipse.core.runtime.content.ITextContentDescriber;
-import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;
-import org.eclipse.wst.sse.core.internal.encoding.IContentDescriptionExtended;
-import org.eclipse.wst.sse.core.internal.encoding.IResourceCharsetDetector;
-
-
-public final class ContentDescriberForXML implements ITextContentDescriber {
- private final static QualifiedName[] SUPPORTED_OPTIONS = {IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK, IContentDescriptionExtended.DETECTED_CHARSET, IContentDescriptionExtended.UNSUPPORTED_CHARSET, IContentDescriptionExtended.APPROPRIATE_DEFAULT};
- /**
- * <code>restrictedMode</code> is used just for testing/experiments.
- *
- * If in restrictedMode, our "custom" contentType is seen as valid only in
- * cases that the platform's standard one does not cover.
- */
- private final static boolean restrictedMode = true;
- private IResourceCharsetDetector getDetector() {
- return new XMLResourceEncodingDetector();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.content.IContentDescriber#describe(java.io.InputStream,
- * org.eclipse.core.runtime.content.IContentDescription)
- */
- public int describe(InputStream contents, IContentDescription description) throws IOException {
- // for this special case, always assume invalid, unless
- // our special circumstances are met.
- int result = IContentDescriber.INVALID;
-
- if (description == null) {
- // purely request for validty
- result = determineValidity(result, contents);
- }
- else {
- result = calculateSupportedOptions(result, contents, description);
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.content.ITextContentDescriber#describe(java.io.Reader,
- * org.eclipse.core.runtime.content.IContentDescription)
- */
- public int describe(Reader contents, IContentDescription description) throws IOException {
- // for this special case, always assume invalid, unless
- // our special circumstances are met.
- int result = IContentDescriber.INVALID;
-
- if (description == null) {
- // purely request for validty
- result = determineValidity(result, contents);
- }
- else {
- result = calculateSupportedOptions(result, contents, description);
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.content.IContentDescriber#getSupportedOptions()
- */
- public QualifiedName[] getSupportedOptions() {
-
- return SUPPORTED_OPTIONS;
- }
-
- private int calculateSupportedOptions(int result, InputStream contents, IContentDescription description) throws IOException {
- int returnResult = result;
- if (isRelevent(description)) {
- IResourceCharsetDetector detector = getDetector();
- contents.reset();
- detector.set(contents);
- returnResult = handleCalculations(result, description, detector);
- }
- return returnResult;
- }
-
- private int determineValidity(int result, InputStream contents) throws IOException {
- int returnResult = result;
- IResourceCharsetDetector detector = getDetector();
- contents.reset();
- detector.set(contents);
- returnResult = determineValidity(detector, returnResult);
- return returnResult;
- }
- private int determineValidity(int result, Reader contents) throws IOException {
- int returnResult = result;
- IResourceCharsetDetector detector = getDetector();
- contents.reset();
- detector.set(contents);
- returnResult = determineValidity(detector, returnResult);
- return returnResult;
- }
- /**
- * @param contents
- * @param description
- * @throws IOException
- */
- private int calculateSupportedOptions(int result, Reader contents, IContentDescription description) throws IOException {
- int returnResult = result;
- if (isRelevent(description)) {
- IResourceCharsetDetector detector = getDetector();
- detector.set(contents);
- returnResult = handleCalculations(result, description, detector);
- }
- return returnResult;
- }
-
- private void handleDetectedSpecialCase(IContentDescription description, Object detectedCharset, Object javaCharset) {
- // since equal, we don't need to add, but if our detected version is
- // different than
- // javaCharset, then we should add it. This will happen, for example,
- // if there's
- // differences in case, or differences due to override properties
- if (detectedCharset != null) {
- // if (!detectedCharset.equals(javaCharset)) {
- // description.setProperty(IContentDescriptionExtended.DETECTED_CHARSET,
- // detectedCharset);
- // }
-
- // Once we detected a charset, we should set the property even
- // though it's the same as javaCharset
- // because there are clients that rely on this property to
- // determine if the charset is actually detected in file or not.
- description.setProperty(IContentDescriptionExtended.DETECTED_CHARSET, detectedCharset);
- }
- }
-
- /**
- * @param description
- * @return
- */
- private boolean isRelevent(IContentDescription description) {
- boolean result = false;
- if (description == null)
- result = false;
- else if (description.isRequested(IContentDescription.BYTE_ORDER_MARK))
- result = true;
- else if (description.isRequested(IContentDescription.CHARSET))
- result = true;
- else if (description.isRequested(IContentDescriptionExtended.APPROPRIATE_DEFAULT))
- result = true;
- else if (description.isRequested(IContentDescriptionExtended.DETECTED_CHARSET))
- result = true;
- else if (description.isRequested(IContentDescriptionExtended.UNSUPPORTED_CHARSET))
- result = true;
- return result;
- }
-
- /**
- * @param description
- * @param detector
- * @throws IOException
- */
- private int handleCalculations(int result, IContentDescription description, IResourceCharsetDetector detector) throws IOException {
- int returnResult = result;
- EncodingMemento encodingMemento = ((XMLResourceEncodingDetector) detector).getEncodingMemento();
- if (description != null) {
- // TODO: I need to verify to see if this BOM work is always done
- // by text type.
- Object detectedByteOrderMark = encodingMemento.getUnicodeBOM();
- if (detectedByteOrderMark != null) {
- Object existingByteOrderMark = description.getProperty(IContentDescription.BYTE_ORDER_MARK);
- // not sure why would ever be different, so if is different,
- // may
- // need to "push" up into base.
- if (!detectedByteOrderMark.equals(existingByteOrderMark))
- description.setProperty(IContentDescription.BYTE_ORDER_MARK, detectedByteOrderMark);
- }
-
-
- if (!encodingMemento.isValid()) {
- // note: after setting here, its the mere presence of
- // IContentDescriptionExtended.UNSUPPORTED_CHARSET
- // in the resource's description that can be used to determine
- // if invalid in those cases, the "detected" property contains
- // an "appropriate default" to use.
- description.setProperty(IContentDescriptionExtended.UNSUPPORTED_CHARSET, encodingMemento.getInvalidEncoding());
- description.setProperty(IContentDescriptionExtended.APPROPRIATE_DEFAULT, encodingMemento.getAppropriateDefault());
- }
-
- Object detectedCharset = encodingMemento.getDetectedCharsetName();
- Object javaCharset = encodingMemento.getJavaCharsetName();
-
- // we always include detected, if its different than java
- handleDetectedSpecialCase(description, detectedCharset, javaCharset);
-
- if (javaCharset != null) {
- Object existingCharset = description.getProperty(IContentDescription.CHARSET);
- if (javaCharset.equals(existingCharset)) {
- handleDetectedSpecialCase(description, detectedCharset, javaCharset);
- }
- else {
- // we may need to add what we found, but only need to add
- // if different from the default
- Object defaultCharset = detector.getSpecDefaultEncoding();
- if (defaultCharset != null) {
- if (!defaultCharset.equals(javaCharset)) {
- description.setProperty(IContentDescription.CHARSET, javaCharset);
- }
- }
- else {
- // assuming if there is no spec default, we always
- // need to add.
- // TODO: this is probably a dead branch in current
- // code, should re-examine for removal.
- description.setProperty(IContentDescription.CHARSET, javaCharset);
- }
- }
- }
- }
-
- returnResult = determineValidity(detector, returnResult);
- return returnResult;
- }
-
- private int determineValidity(IResourceCharsetDetector detector, int returnResult) {
- // we always expect XMLResourceEncodingDetector, but just to make safe
- // cast.
- if (detector instanceof XMLResourceEncodingDetector) {
- XMLResourceEncodingDetector xmlResourceDetector = (XMLResourceEncodingDetector) detector;
- if (xmlResourceDetector.isDeclDetected()) {
- if (restrictedMode) {
- // if there is no initial whitespace, then platform's
- // default one will do.
- if (xmlResourceDetector.hasInitialWhiteSpace()) {
- returnResult = IContentDescriber.VALID;
- }
- }
- else {
- returnResult = IContentDescriber.VALID;
- }
- }
- }
- return returnResult;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/EncodingParserConstants.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/EncodingParserConstants.java
deleted file mode 100644
index d4542a43cb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/EncodingParserConstants.java
+++ /dev/null
@@ -1,30 +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.contenttype;
-
-
-public interface EncodingParserConstants {
-
- final String EOF = "EOF"; //$NON-NLS-1$
- final String InvalidTerminatedStringValue = "InvalidTerminatedStringValue"; //$NON-NLS-1$
- final String InvalidTermintatedUnDelimitedStringValue = "InvalidTermintatedUnDelimitedStringValue"; //$NON-NLS-1$
- final String MAX_CHARS_REACHED = "MAX_CHARS_REACHED"; //$NON-NLS-1$
- final String StringValue = "strval"; //$NON-NLS-1$
- final String UnDelimitedStringValue = "UnDelimitedStringValue"; //$NON-NLS-1$
- public final String UTF16BE = "UTF16BE"; //$NON-NLS-1$
- public final String UTF16LE = "UTF16LE"; //$NON-NLS-1$
-
-
- public final String UTF83ByteBOM = "UTF83ByteBOM"; //$NON-NLS-1$
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/HeadParserToken.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/HeadParserToken.java
deleted file mode 100644
index 0f14b8b570..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/HeadParserToken.java
+++ /dev/null
@@ -1,44 +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.contenttype;
-
-public class HeadParserToken {
- private int fStart;
-
- private String fText;
- private String fType;
-
- protected HeadParserToken() {
- super();
- }
-
- public HeadParserToken(String type, int start, String text) {
- this();
- fType = type;
- fStart = start;
- fText = text;
-
- }
-
- public String getText() {
- return fText;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return ("text: " + fText + " offset: " + fStart + " type: " + fType); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/IntStack.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/IntStack.java
deleted file mode 100644
index 52dbae6905..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/IntStack.java
+++ /dev/null
@@ -1,114 +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.contenttype;
-
-/*
- *
- * A non-resizable class implementing the behavior of java.util.Stack, but
- * directly for the <code> integer </code> primitive.
- */
-import java.util.EmptyStackException;
-
-public class IntStack {
- private int[] list = null;
-
- private int size = 0;
-
- public IntStack() {
- this(100);
- }
-
- public IntStack(int maxdepth) {
- super();
- list = new int[maxdepth];
- initialize();
- }
-
- public void clear() {
- initialize();
- }
-
- public boolean empty() {
- return size == 0;
- }
-
- public int get(int slot) {
- return list[slot];
- }
-
- private void initialize() {
- for (int i = 0; i < list.length; i++)
- list[i] = -1;
- }
-
- /**
- * Returns the int at the top of the stack without removing it
- *
- * @return int at the top of this stack.
- * @exception EmptyStackException
- * when empty.
- */
- public int peek() {
- if (size == 0)
- throw new EmptyStackException();
- return list[size - 1];
- }
-
- /**
- * Removes and returns the int at the top of the stack
- *
- * @return int at the top of this stack.
- * @exception EmptyStackException
- * when empty.
- */
- public int pop() {
- int value = peek();
- list[size - 1] = -1;
- size--;
- return value;
- }
-
- /**
- * Pushes an item onto the top of this stack.
- *
- * @param newValue -
- * the int to be pushed onto this stack.
- * @return the <code>newValue</code> argument.
- */
- public int push(int newValue) {
- if (size == list.length) {
- throw new StackOverflowError();
- }
- list[size++] = newValue;
- return newValue;
- }
-
- public int size() {
- return size;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer s = new StringBuffer(getClass().getName() + ":" +size + " [");
- for (int i = 0; i < size; i++) {
- s.append(list[i]);
- if(i < size - 1) {
- s.append(", ");
- }
- }
- s.append("]");
- return s.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/NullMemento.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/NullMemento.java
deleted file mode 100644
index 23f7462181..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/NullMemento.java
+++ /dev/null
@@ -1,37 +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.contenttype;
-
-import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;
-import org.eclipse.wst.sse.core.internal.encoding.NonContentBasedEncodingRules;
-
-
-
-/**
- * This class can be used in place of an EncodingMemento (its super class),
- * when there is not in fact ANY encoding information. For example, when a
- * structuredDocument is created directly from a String
- */
-public class NullMemento extends EncodingMemento {
- /**
- *
- */
- public NullMemento() {
- super();
- String defaultCharset = NonContentBasedEncodingRules.useDefaultNameRules(null);
- setJavaCharsetName(defaultCharset);
- setAppropriateDefault(defaultCharset);
- setDetectedCharsetName(null);
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLDeclDetector.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLDeclDetector.java
deleted file mode 100644
index 4bc3552811..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLDeclDetector.java
+++ /dev/null
@@ -1,156 +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
- * David Carver (STAR) - bug 297006 - String Comparison
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contenttype;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-
-public class XMLDeclDetector {
- private static final int MAX_BUF_SIZE = 1024 * 8;
- private static final int MAX_MARK_SIZE = 1024 * 8;
- protected boolean fHeaderParsed;
- private boolean fIsXML;
- protected Reader fReader;
- //private boolean DEBUG = false;
- private XMLHeadTokenizer fTokenizer;
-
- private boolean canHandleAsUnicodeStream(String tokenType) {
- boolean canHandleAsUnicodeStream = false;
- if (EncodingParserConstants.UTF83ByteBOM.equals(tokenType)) {
- canHandleAsUnicodeStream = true;
- //fUnicode = "UTF-8"; //$NON-NLS-1$
- } else if (EncodingParserConstants.UTF16BE.equals(tokenType)) {
- canHandleAsUnicodeStream = true;
- //fUnicode = "UTF-16BE"; //$NON-NLS-1$
- } else if (EncodingParserConstants.UTF16LE.equals(tokenType)) {
- canHandleAsUnicodeStream = true;
- //fUnicode = "UTF-16"; //$NON-NLS-1$
- }
- return canHandleAsUnicodeStream;
- }
-
- final private void ensureInputSet() {
- if (fReader == null) {
- throw new IllegalStateException("input must be set before use"); //$NON-NLS-1$
- }
- }
-
- //private String fUnicode;
-
- /**
- * @return Returns the tokenizer.
- */
- private XMLHeadTokenizer getTokenizer() {
- if (fTokenizer == null) {
- fTokenizer = new XMLHeadTokenizer();
- }
- return fTokenizer;
- }
-
- /**
- * @return Returns the isXML.
- */
- public boolean isXML() throws IOException {
- ensureInputSet();
- if (!fHeaderParsed) {
- parseInput();
- }
- return fIsXML;
- }
-
- private void parseInput() throws IOException {
- XMLHeadTokenizer tokenizer = getTokenizer();
- tokenizer.reset(fReader);
- HeadParserToken token = null;
- String tokenType = null;
- do {
- token = tokenizer.getNextToken();
- tokenType = token.getType();
- if (canHandleAsUnicodeStream(tokenType)) {
- fReader.reset();
- // this is (obviously) not always true.
- // TODO: need to fix so we "remember" original iFile or
- // inputstream, and
- // create appropriate InputStreamReader.
- // I'm not sure what to do for the set(reader) case ... if its
- // even relevent.
- // plus, ensure against infinite loops!
- fIsXML = true;
- //fReader = new InputStreamReader(fReader, fUnicode);
- // parseInput();
- } else {
- if (XMLHeadTokenizerConstants.XMLDelEncoding.equals(tokenType)) {
- fIsXML = true;
- }
- }
- } while (tokenizer.hasMoreTokens());
-
- }
-
- private void resetAll() {
- fReader = null;
- fHeaderParsed = false;
- fIsXML = false;
- //fUnicode = null;
-
- }
-
- public void set(IFile iFile) throws CoreException {
- resetAll();
- InputStream inputStream = iFile.getContents(true);
- InputStream resettableStream = new BufferedInputStream(inputStream, MAX_BUF_SIZE);
- resettableStream.mark(MAX_MARK_SIZE);
- set(resettableStream);
- }
-
- public void set(InputStream inputStream) {
- resetAll();
- fReader = new ByteReader(inputStream);
- try {
- fReader.mark(MAX_MARK_SIZE);
- } catch (IOException e) {
- // impossible, since we know ByteReader supports marking
- throw new Error(e);
- }
- }
-
- /**
- * Note: this is not part of interface to help avoid confusion ... it
- * expected this Reader is a well formed character reader ... that is, its
- * all ready been determined to not be a unicode marked input stream. And,
- * its assumed to be in the correct position, at position zero, ready to
- * read first character.
- */
- public void set(Reader reader) {
- resetAll();
- fReader = reader;
- if (!fReader.markSupported()) {
- fReader = new BufferedReader(fReader);
- }
-
- try {
- fReader.mark(MAX_MARK_SIZE);
- } catch (IOException e) {
- // impossble, since we just checked if markable
- throw new Error(e);
- }
-
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizer.java
deleted file mode 100644
index 76fb40b2fc..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizer.java
+++ /dev/null
@@ -1,1451 +0,0 @@
-/* The following code was generated by JFlex 1.4.2 on 7/28/08 9:29 AM */
-
-/*******************************************************************************
- * Copyright (c) 2005, 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
- *******************************************************************************/
-/*nlsXXX*/
-package org.eclipse.wst.xml.core.internal.contenttype;
-import java.io.IOException;
-import java.io.Reader;
-
-import org.eclipse.wst.xml.core.internal.contenttype.EncodingParserConstants;
-import org.eclipse.wst.xml.core.internal.contenttype.XMLHeadTokenizerConstants;
-
-
-
-/**
- * This class is a scanner generated by
- * <a href="http://www.jflex.de/">JFlex</a> 1.4.2
- * on 7/28/08 9:29 AM from the specification file
- * <tt>D:/workspaces/wtp301/workspace/org.eclipse.wst.xml.core/DevTimeSupport/HeadParsers/XMLHeadTokenizer.jFlex</tt>
- */
-public class XMLHeadTokenizer {
-
- /** This character denotes the end of file */
- public static final int YYEOF = -1;
-
- /** initial size of the lookahead buffer */
- private static final int ZZ_BUFFERSIZE = 8192;
-
- /** lexical states */
- public static final int YYINITIAL = 0;
- public static final int UnDelimitedString = 10;
- public static final int DQ_STRING = 6;
- public static final int SQ_STRING = 8;
- public static final int ST_XMLDecl = 2;
- public static final int QuotedAttributeValue = 4;
-
- /**
- * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
- * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
- * at the beginning of a line
- * l is of the form l = 2*k, k a non negative integer
- */
- private static final int ZZ_LEXSTATE[] = {
- 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6
- };
-
- /**
- * Translates characters to character classes
- */
- private static final String ZZ_CMAP_PACKED =
- "\1\11\10\0\1\6\1\10\2\0\1\7\22\0\1\6\1\0\1\33"+
- "\2\0\1\35\1\0\1\34\24\0\1\13\1\12\1\32\1\14\3\0"+
- "\1\27\1\30\1\21\1\0\1\31\1\0\1\24\2\0\1\17\1\16"+
- "\1\26\1\25\2\0\1\22\1\23\2\0\1\20\1\0\1\15\12\0"+
- "\1\27\1\30\1\21\1\0\1\31\1\0\1\24\2\0\1\17\1\16"+
- "\1\26\1\25\2\0\1\22\1\23\2\0\1\20\1\0\1\15\102\0"+
- "\1\4\3\0\1\5\17\0\1\3\16\0\1\1\20\0\1\3\16\0"+
- "\1\1\1\2\170\0\1\2\ufe87\0";
-
- /**
- * Translates characters to character classes
- */
- private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
-
- /**
- * Translates DFA states to action switch labels.
- */
- private static final int [] ZZ_ACTION = zzUnpackAction();
-
- private static final String ZZ_ACTION_PACKED_0 =
- "\7\0\13\1\2\2\1\1\1\2\1\3\1\4\1\5"+
- "\1\6\1\1\1\5\1\7\1\1\1\5\1\10\1\1"+
- "\1\11\1\12\1\13\12\0\1\14\5\0\1\2\1\3"+
- "\1\4\1\6\2\0\1\15\1\7\2\0\1\10\1\11"+
- "\1\16\3\0\1\14\4\0\1\2\1\15\14\0\1\17"+
- "\5\0\1\17\6\0\1\20\3\0\1\20\2\0\1\21"+
- "\1\0\1\21\1\0";
-
- private static int [] zzUnpackAction() {
- int [] result = new int[111];
- int offset = 0;
- offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackAction(String packed, int offset, int [] result) {
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- do result[j++] = value; while (--count > 0);
- }
- return j;
- }
-
-
- /* error codes */
- private static final int ZZ_UNKNOWN_ERROR = 0;
- private static final int ZZ_NO_MATCH = 1;
- private static final int ZZ_PUSHBACK_2BIG = 2;
-
- /* error messages for the codes above */
- private static final String ZZ_ERROR_MSG[] = {
- "Unkown internal scanner error",
- "Error: could not match input",
- "Error: pushback value was too large"
- };
-
- /** the input device */
- private java.io.Reader zzReader;
-
- /** the current state of the DFA */
- private int zzState;
-
- /** the current lexical state */
- private int zzLexicalState = YYINITIAL;
-
- /** this buffer contains the current text to be matched and is
- the source of the yytext() string */
- private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
-
- /** the textposition at the last accepting state */
- private int zzMarkedPos;
-
- /** the current text position in the buffer */
- private int zzCurrentPos;
-
- /** startRead marks the beginning of the yytext() string in the buffer */
- private int zzStartRead;
-
- /** endRead marks the last character in the buffer, that has been read
- from input */
- private int zzEndRead;
-
- /** number of newlines encountered up to the start of the matched text */
-// private int yyline;
-
- /** the number of characters up to the start of the matched text */
- private int yychar;
-
- /**
- * the number of characters from the last newline up to the start of the
- * matched text
- */
-// private int yycolumn;
-
- /**
- * zzAtBOL == true <=> the scanner is currently at the beginning of a line
- */
- private boolean zzAtBOL = true;
-
- /** zzAtEOF == true <=> the scanner is at the EOF */
- private boolean zzAtEOF;
-
- /** denotes if the user-EOF-code has already been executed */
- private boolean zzEOFDone;
-
- /* user code: */
-
-
- private boolean hasMore = true;
- private final static int MAX_TO_SCAN = 8000;
- StringBuffer string = new StringBuffer();
- // state stack for easier state handling
- private IntStack fStateStack = new IntStack();
- private String valueText = null;
-
-
- public XMLHeadTokenizer() {
- super();
- }
-
- public void reset (Reader in) {
- /* the input device */
- zzReader = in;
-
- /* the current state of the DFA */
- zzState = 0;
-
- /* the current lexical state */
- zzLexicalState = YYINITIAL;
-
- /* this buffer contains the current text to be matched and is
- the source of the yytext() string */
- java.util.Arrays.fill(zzBuffer, (char)0);
-
- /* the textposition at the last accepting state */
- zzMarkedPos = 0;
-
- /* the textposition at the last state to be included in yytext */
-// zzPushbackPos = 0;
-
- /* the current text position in the buffer */
- zzCurrentPos = 0;
-
- /* startRead marks the beginning of the yytext() string in the buffer */
- zzStartRead = 0;
-
- /**
- * endRead marks the last character in the buffer, that has been read
- * from input
- */
- zzEndRead = 0;
-
- /* number of newlines encountered up to the start of the matched text */
-// yyline = 0;
-
- /* the number of characters up to the start of the matched text */
- yychar = 0;
-
- /**
- * the number of characters from the last newline up to the start
- * of the matched text
- */
-// yycolumn = 0;
-
- /**
- * yy_atBOL == true <=> the scanner is currently at the beginning
- * of a line
- */
- zzAtBOL = true;
-
- /* yy_atEOF == true <=> the scanner has returned a value for EOF */
- zzAtEOF = false;
-
- /* denotes if the user-EOF-code has already been executed */
- zzEOFDone = false;
-
-
- fStateStack.clear();
-
- hasMore = true;
-
- }
-
-
- public final HeadParserToken getNextToken() throws IOException {
- String context = null;
- context = primGetNextToken();
- HeadParserToken result = null;
- if (valueText != null) {
- result = createToken(context, yychar, valueText);
- valueText = null;
- } else {
- result = createToken(context, yychar, yytext());
- }
- return result;
- }
-
- public final boolean hasMoreTokens() {
- return hasMore && yychar < MAX_TO_SCAN;
- }
- private void pushCurrentState() {
- fStateStack.push(yystate());
-
- }
-
- private void popState() {
- yybegin(fStateStack.pop());
- }
-
- private HeadParserToken createToken(String context, int start, String text) {
- return new HeadParserToken(context, start, text);
- }
-
-
-
- /**
- * Creates a new scanner
- * There is also a java.io.InputStream version of this constructor.
- *
- * @param in the java.io.Reader to read input from.
- */
- public XMLHeadTokenizer(java.io.Reader in) {
- this.zzReader = in;
- }
-
- /**
- * Creates a new scanner.
- * There is also java.io.Reader version of this constructor.
- *
- * @param in the java.io.Inputstream to read input from.
- */
- public XMLHeadTokenizer(java.io.InputStream in) {
- this(new java.io.InputStreamReader(in));
- }
-
- /**
- * Unpacks the compressed character translation table.
- *
- * @param packed the packed character translation table
- * @return the unpacked character translation table
- */
- private static char [] zzUnpackCMap(String packed) {
- char [] map = new char[0x10000];
- int i = 0; /* index in packed string */
- int j = 0; /* index in unpacked array */
- while (i < 150) {
- int count = packed.charAt(i++);
- char value = packed.charAt(i++);
- do map[j++] = value; while (--count > 0);
- }
- return map;
- }
-
-
- /**
- * Refills the input buffer.
- *
- * @return <code>false</code>, iff there was new input.
- *
- * @exception java.io.IOException if any I/O-Error occurs
- */
- private boolean zzRefill() throws java.io.IOException {
-
- /* first: make room (if you can) */
- if (zzStartRead > 0) {
- System.arraycopy(zzBuffer, zzStartRead,
- zzBuffer, 0,
- zzEndRead-zzStartRead);
-
- /* translate stored positions */
- zzEndRead-= zzStartRead;
- zzCurrentPos-= zzStartRead;
- zzMarkedPos-= zzStartRead;
- zzStartRead = 0;
- }
-
- /* is the buffer big enough? */
- if (zzCurrentPos >= zzBuffer.length) {
- /* if not: blow it up */
- char newBuffer[] = new char[zzCurrentPos*2];
- System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
- zzBuffer = newBuffer;
- }
-
- /* finally: fill the buffer with new input */
- int numRead = zzReader.read(zzBuffer, zzEndRead,
- zzBuffer.length-zzEndRead);
-
- if (numRead > 0) {
- zzEndRead+= numRead;
- return false;
- }
- // unlikely but not impossible: read 0 characters, but not at end of stream
- if (numRead == 0) {
- int c = zzReader.read();
- if (c == -1) {
- return true;
- } else {
- zzBuffer[zzEndRead++] = (char) c;
- return false;
- }
- }
-
- // numRead < 0
- return true;
- }
-
-
- /**
- * Closes the input stream.
- */
- public final void yyclose() throws java.io.IOException {
- zzAtEOF = true; /* indicate end of file */
- zzEndRead = zzStartRead; /* invalidate buffer */
-
- if (zzReader != null)
- zzReader.close();
- }
-
-
- /**
- * Resets the scanner to read from a new input stream.
- * Does not close the old reader.
- *
- * All internal variables are reset, the old input stream
- * <b>cannot</b> be reused (internal buffer is discarded and lost).
- * Lexical state is set to <tt>ZZ_INITIAL</tt>.
- *
- * @param reader the new input stream
- */
- public final void yyreset(java.io.Reader reader) {
- zzReader = reader;
- zzAtBOL = true;
- zzAtEOF = false;
- zzEndRead = zzStartRead = 0;
- zzCurrentPos = zzMarkedPos = 0;
- yychar = 0;
- zzLexicalState = YYINITIAL;
- }
-
-
- /**
- * Returns the current lexical state.
- */
- public final int yystate() {
- return zzLexicalState;
- }
-
-
- /**
- * Enters a new lexical state
- *
- * @param newState the new lexical state
- */
- public final void yybegin(int newState) {
- zzLexicalState = newState;
- }
-
-
- /**
- * Returns the text matched by the current regular expression.
- */
- public final String yytext() {
- return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
- }
-
-
- /**
- * Returns the character at position <tt>pos</tt> from the
- * matched text.
- *
- * It is equivalent to yytext().charAt(pos), but faster
- *
- * @param pos the position of the character to fetch.
- * A value from 0 to yylength()-1.
- *
- * @return the character at position pos
- */
- public final char yycharat(int pos) {
- return zzBuffer[zzStartRead+pos];
- }
-
-
- /**
- * Returns the length of the matched text region.
- */
- public final int yylength() {
- return zzMarkedPos-zzStartRead;
- }
-
-
- /**
- * Reports an error that occured while scanning.
- *
- * In a wellformed scanner (no or only correct usage of
- * yypushback(int) and a match-all fallback rule) this method
- * will only be called with things that "Can't Possibly Happen".
- * If this method is called, something is seriously wrong
- * (e.g. a JFlex bug producing a faulty scanner etc.).
- *
- * Usual syntax/scanner level error handling should be done
- * in error fallback rules.
- *
- * @param errorCode the code of the errormessage to display
- */
- private void zzScanError(int errorCode) {
- String message;
- try {
- message = ZZ_ERROR_MSG[errorCode];
- }
- catch (ArrayIndexOutOfBoundsException e) {
- message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
- }
-
- throw new Error(message);
- }
-
-
- /**
- * Pushes the specified amount of characters back into the input stream.
- *
- * They will be read again by then next call of the scanning method
- *
- * @param number the number of characters to be read again.
- * This number must not be greater than yylength()!
- */
- public void yypushback(int number) {
- if ( number > yylength() )
- zzScanError(ZZ_PUSHBACK_2BIG);
-
- zzMarkedPos -= number;
- }
-
-
- /**
- * Contains user EOF-code, which will be executed exactly once,
- * when the end of file is reached
- */
- private void zzDoEOF() {
- if (!zzEOFDone) {
- zzEOFDone = true;
- hasMore=false;
-
- }
- }
-
-
- /**
- * Resumes scanning until the next regular expression is matched,
- * the end of input is encountered or an I/O-Error occurs.
- *
- * @return the next token
- * @exception java.io.IOException if any I/O-Error occurs
- */
- public String primGetNextToken() throws java.io.IOException {
- int zzInput;
- int zzAction;
-
- // cached fields:
- int zzCurrentPosL;
- int zzMarkedPosL;
- int zzEndReadL = zzEndRead;
- char [] zzBufferL = zzBuffer;
- char [] zzCMapL = ZZ_CMAP;
-
-
- while (true) {
- zzMarkedPosL = zzMarkedPos;
-
- yychar+= zzMarkedPosL-zzStartRead;
-
- if (zzMarkedPosL > zzStartRead) {
- switch (zzBufferL[zzMarkedPosL-1]) {
- case '\n':
- case '\u000B':
- case '\u000C':
- case '\u0085':
- case '\u2028':
- case '\u2029':
- zzAtBOL = true;
- break;
- case '\r':
- if (zzMarkedPosL < zzEndReadL)
- zzAtBOL = zzBufferL[zzMarkedPosL] != '\n';
- else if (zzAtEOF)
- zzAtBOL = false;
- else {
- boolean eof = zzRefill();
- zzMarkedPosL = zzMarkedPos;
- zzEndReadL = zzEndRead;
- zzBufferL = zzBuffer;
- if (eof)
- zzAtBOL = false;
- else
- zzAtBOL = zzBufferL[zzMarkedPosL] != '\n';
- }
- break;
- default:
- zzAtBOL = false;
- }
- }
- zzAction = -1;
-
- zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
-
- if (zzAtBOL)
- zzState = ZZ_LEXSTATE[zzLexicalState+1];
- else
- zzState = ZZ_LEXSTATE[zzLexicalState];
-
-
- zzForAction: {
- while (true) {
-
- if (zzCurrentPosL < zzEndReadL)
- zzInput = zzBufferL[zzCurrentPosL++];
- else if (zzAtEOF) {
- zzInput = YYEOF;
- break zzForAction;
- }
- else {
- // store back cached positions
- zzCurrentPos = zzCurrentPosL;
- zzMarkedPos = zzMarkedPosL;
- boolean eof = zzRefill();
- // get translated positions and possibly new buffer
- zzCurrentPosL = zzCurrentPos;
- zzMarkedPosL = zzMarkedPos;
- zzBufferL = zzBuffer;
- zzEndReadL = zzEndRead;
- if (eof) {
- zzInput = YYEOF;
- break zzForAction;
- }
- else {
- zzInput = zzBufferL[zzCurrentPosL++];
- }
- }
- zzInput = zzCMapL[zzInput];
-
- boolean zzIsFinal = false;
- boolean zzNoLookAhead = false;
-
- zzForNext: { switch (zzState) {
- case 0:
- switch (zzInput) {
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 7; break zzForNext;
- }
-
- case 1:
- switch (zzInput) {
- case 1: zzIsFinal = true; zzState = 8; break zzForNext;
- case 2: zzIsFinal = true; zzState = 9; break zzForNext;
- case 3: zzIsFinal = true; zzState = 10; break zzForNext;
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 11; break zzForNext;
- case 9: zzIsFinal = true; zzState = 12; break zzForNext;
- case 11: zzIsFinal = true; zzState = 13; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 7; break zzForNext;
- }
-
- case 2:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzState = 14; break zzForNext;
- case 12: zzIsFinal = true; zzState = 15; break zzForNext;
- case 16: zzIsFinal = true; zzState = 16; break zzForNext;
- case 17: zzIsFinal = true; zzState = 17; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 7; break zzForNext;
- }
-
- case 3:
- switch (zzInput) {
- case 6:
- case 7: zzIsFinal = true; zzState = 19; break zzForNext;
- case 8: zzIsFinal = true; zzState = 20; break zzForNext;
- case 9: zzIsFinal = true; zzState = 21; break zzForNext;
- case 27: zzIsFinal = true; zzState = 22; break zzForNext;
- case 28: zzIsFinal = true; zzState = 23; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 18; break zzForNext;
- }
-
- case 4:
- switch (zzInput) {
- case 7:
- case 8:
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 9: zzIsFinal = true; zzState = 26; break zzForNext;
- case 12: zzIsFinal = true; zzState = 27; break zzForNext;
- case 27: zzIsFinal = true; zzState = 28; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 24; break zzForNext;
- }
-
- case 5:
- switch (zzInput) {
- case 7:
- case 8:
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 28: zzIsFinal = true; zzState = 28; break zzForNext;
- case 9: zzIsFinal = true; zzState = 29; break zzForNext;
- case 29: zzIsFinal = true; zzState = 30; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 24; break zzForNext;
- }
-
- case 6:
- switch (zzInput) {
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 12: zzIsFinal = true; zzState = 30; break zzForNext;
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 31; break zzForNext;
- case 9: zzIsFinal = true; zzState = 32; break zzForNext;
- case 27:
- case 28: zzIsFinal = true; zzState = 33; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 24; break zzForNext;
- }
-
- case 8:
- switch (zzInput) {
- case 2: zzIsFinal = true; zzNoLookAhead = true; zzState = 34; break zzForNext;
- default: break zzForAction;
- }
-
- case 9:
- switch (zzInput) {
- case 1: zzIsFinal = true; zzNoLookAhead = true; zzState = 35; break zzForNext;
- default: break zzForAction;
- }
-
- case 10:
- switch (zzInput) {
- case 4: zzState = 36; break zzForNext;
- default: break zzForAction;
- }
-
- case 11:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 37; break zzForNext;
- case 9: zzState = 38; break zzForNext;
- case 11: zzState = 39; break zzForNext;
- default: break zzForAction;
- }
-
- case 12:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 37; break zzForNext;
- case 11: zzState = 39; break zzForNext;
- default: break zzForAction;
- }
-
- case 13:
- switch (zzInput) {
- case 9: zzState = 40; break zzForNext;
- case 12: zzState = 41; break zzForNext;
- default: break zzForAction;
- }
-
- case 14:
- switch (zzInput) {
- case 12: zzState = 42; break zzForNext;
- case 16: zzState = 43; break zzForNext;
- case 17: zzState = 44; break zzForNext;
- default: break zzForAction;
- }
-
- case 15:
- switch (zzInput) {
- case 9: zzState = 45; break zzForNext;
- case 26: zzIsFinal = true; zzState = 46; break zzForNext;
- default: break zzForAction;
- }
-
- case 16:
- switch (zzInput) {
- case 9: zzState = 47; break zzForNext;
- case 17: zzState = 48; break zzForNext;
- default: break zzForAction;
- }
-
- case 17:
- switch (zzInput) {
- case 9: zzState = 49; break zzForNext;
- case 22: zzState = 50; break zzForNext;
- default: break zzForAction;
- }
-
- case 19:
- switch (zzInput) {
- case 6:
- case 7: zzIsFinal = true; break zzForNext;
- case 8: zzState = 51; break zzForNext;
- case 9: zzIsFinal = true; zzState = 52; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 18; break zzForNext;
- }
-
- case 20:
- switch (zzInput) {
- case 6:
- case 7: zzIsFinal = true; zzState = 19; break zzForNext;
- case 8: zzState = 51; break zzForNext;
- case 9: zzIsFinal = true; zzState = 52; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 18; break zzForNext;
- }
-
- case 21:
- switch (zzInput) {
- case 27: zzIsFinal = true; zzState = 22; break zzForNext;
- case 28: zzIsFinal = true; zzState = 23; break zzForNext;
- case 6:
- case 7:
- case 8: zzState = 51; break zzForNext;
- default: break zzForAction;
- }
-
- case 22:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 53; break zzForNext;
- default: break zzForAction;
- }
-
- case 23:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 54; break zzForNext;
- default: break zzForAction;
- }
-
- case 25:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 55; break zzForNext;
- default: break zzForAction;
- }
-
- case 26:
- switch (zzInput) {
- case 7:
- case 8:
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 27: zzIsFinal = true; zzState = 28; break zzForNext;
- case 12: zzState = 56; break zzForNext;
- default: break zzForAction;
- }
-
- case 27:
- switch (zzInput) {
- case 9: zzState = 57; break zzForNext;
- case 26: zzIsFinal = true; zzState = 58; break zzForNext;
- default: break zzForAction;
- }
-
- case 28:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 59; break zzForNext;
- default: break zzForAction;
- }
-
- case 29:
- switch (zzInput) {
- case 7:
- case 8:
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 28: zzIsFinal = true; zzState = 28; break zzForNext;
- case 29: zzState = 60; break zzForNext;
- default: break zzForAction;
- }
-
- case 30:
- switch (zzInput) {
- case 26: zzIsFinal = true; zzState = 25; break zzForNext;
- case 9: zzState = 61; break zzForNext;
- default: break zzForAction;
- }
-
- case 31:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 62; break zzForNext;
- default: break zzForAction;
- }
-
- case 32:
- switch (zzInput) {
- case 11: zzIsFinal = true; zzState = 25; break zzForNext;
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 31; break zzForNext;
- case 27:
- case 28: zzIsFinal = true; zzState = 33; break zzForNext;
- case 12: zzState = 60; break zzForNext;
- default: break zzForAction;
- }
-
- case 33:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 63; break zzForNext;
- default: break zzForAction;
- }
-
- case 36:
- switch (zzInput) {
- case 5: zzIsFinal = true; zzNoLookAhead = true; zzState = 64; break zzForNext;
- default: break zzForAction;
- }
-
- case 37:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: break zzForNext;
- case 9: zzState = 38; break zzForNext;
- case 11: zzState = 39; break zzForNext;
- default: break zzForAction;
- }
-
- case 38:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 37; break zzForNext;
- case 11: zzState = 39; break zzForNext;
- case 9: zzState = 65; break zzForNext;
- default: break zzForAction;
- }
-
- case 39:
- switch (zzInput) {
- case 9: zzState = 40; break zzForNext;
- case 12: zzState = 41; break zzForNext;
- default: break zzForAction;
- }
-
- case 40:
- switch (zzInput) {
- case 12: zzState = 41; break zzForNext;
- default: break zzForAction;
- }
-
- case 41:
- switch (zzInput) {
- case 9: zzState = 66; break zzForNext;
- case 13: zzState = 67; break zzForNext;
- default: break zzForAction;
- }
-
- case 42:
- switch (zzInput) {
- case 9: zzState = 45; break zzForNext;
- case 26: zzIsFinal = true; zzState = 46; break zzForNext;
- default: break zzForAction;
- }
-
- case 43:
- switch (zzInput) {
- case 9: zzState = 47; break zzForNext;
- case 17: zzState = 48; break zzForNext;
- default: break zzForAction;
- }
-
- case 44:
- switch (zzInput) {
- case 9: zzState = 49; break zzForNext;
- case 22: zzState = 50; break zzForNext;
- default: break zzForAction;
- }
-
- case 45:
- switch (zzInput) {
- case 26: zzIsFinal = true; zzState = 46; break zzForNext;
- default: break zzForAction;
- }
-
- case 46:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 68; break zzForNext;
- default: break zzForAction;
- }
-
- case 47:
- switch (zzInput) {
- case 17: zzState = 48; break zzForNext;
- default: break zzForAction;
- }
-
- case 48:
- switch (zzInput) {
- case 9: zzState = 69; break zzForNext;
- case 18: zzState = 70; break zzForNext;
- default: break zzForAction;
- }
-
- case 49:
- switch (zzInput) {
- case 22: zzState = 50; break zzForNext;
- default: break zzForAction;
- }
-
- case 50:
- switch (zzInput) {
- case 9: zzState = 71; break zzForNext;
- case 23: zzState = 72; break zzForNext;
- default: break zzForAction;
- }
-
- case 51:
- switch (zzInput) {
- case 6:
- case 7: zzIsFinal = true; zzState = 19; break zzForNext;
- case 8: break zzForNext;
- case 9: zzIsFinal = true; zzState = 52; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 18; break zzForNext;
- }
-
- case 52:
- switch (zzInput) {
- case 6:
- case 7: zzIsFinal = true; zzState = 19; break zzForNext;
- case 8: zzState = 51; break zzForNext;
- case 9: zzIsFinal = true; zzState = 73; break zzForNext;
- default: zzIsFinal = true; zzNoLookAhead = true; zzState = 18; break zzForNext;
- }
-
- case 56:
- switch (zzInput) {
- case 9: zzState = 57; break zzForNext;
- case 26: zzIsFinal = true; zzState = 58; break zzForNext;
- default: break zzForAction;
- }
-
- case 57:
- switch (zzInput) {
- case 26: zzIsFinal = true; zzState = 58; break zzForNext;
- default: break zzForAction;
- }
-
- case 58:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzNoLookAhead = true; zzState = 74; break zzForNext;
- default: break zzForAction;
- }
-
- case 60:
- switch (zzInput) {
- case 26: zzIsFinal = true; zzState = 25; break zzForNext;
- case 9: zzState = 61; break zzForNext;
- default: break zzForAction;
- }
-
- case 61:
- switch (zzInput) {
- case 26: zzIsFinal = true; zzState = 25; break zzForNext;
- default: break zzForAction;
- }
-
- case 65:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 37; break zzForNext;
- case 11: zzState = 39; break zzForNext;
- default: break zzForAction;
- }
-
- case 66:
- switch (zzInput) {
- case 13: zzState = 67; break zzForNext;
- default: break zzForAction;
- }
-
- case 67:
- switch (zzInput) {
- case 9: zzState = 75; break zzForNext;
- case 14: zzState = 76; break zzForNext;
- default: break zzForAction;
- }
-
- case 69:
- switch (zzInput) {
- case 18: zzState = 70; break zzForNext;
- default: break zzForAction;
- }
-
- case 70:
- switch (zzInput) {
- case 9: zzState = 77; break zzForNext;
- case 19: zzState = 78; break zzForNext;
- default: break zzForAction;
- }
-
- case 71:
- switch (zzInput) {
- case 23: zzState = 72; break zzForNext;
- default: break zzForAction;
- }
-
- case 72:
- switch (zzInput) {
- case 9: zzState = 79; break zzForNext;
- case 21: zzState = 80; break zzForNext;
- default: break zzForAction;
- }
-
- case 73:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 51; break zzForNext;
- default: break zzForAction;
- }
-
- case 75:
- switch (zzInput) {
- case 14: zzState = 76; break zzForNext;
- default: break zzForAction;
- }
-
- case 76:
- switch (zzInput) {
- case 9: zzState = 81; break zzForNext;
- case 15: zzState = 82; break zzForNext;
- default: break zzForAction;
- }
-
- case 77:
- switch (zzInput) {
- case 19: zzState = 78; break zzForNext;
- default: break zzForAction;
- }
-
- case 78:
- switch (zzInput) {
- case 9: zzState = 83; break zzForNext;
- case 20: zzState = 84; break zzForNext;
- default: break zzForAction;
- }
-
- case 79:
- switch (zzInput) {
- case 21: zzState = 80; break zzForNext;
- default: break zzForAction;
- }
-
- case 80:
- switch (zzInput) {
- case 9: zzState = 85; break zzForNext;
- case 24: zzState = 86; break zzForNext;
- default: break zzForAction;
- }
-
- case 81:
- switch (zzInput) {
- case 15: zzState = 82; break zzForNext;
- default: break zzForAction;
- }
-
- case 82:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 87; break zzForNext;
- case 9: zzState = 88; break zzForNext;
- default: break zzForAction;
- }
-
- case 83:
- switch (zzInput) {
- case 20: zzState = 84; break zzForNext;
- default: break zzForAction;
- }
-
- case 84:
- switch (zzInput) {
- case 9: zzState = 89; break zzForNext;
- case 21: zzState = 90; break zzForNext;
- default: break zzForAction;
- }
-
- case 85:
- switch (zzInput) {
- case 24: zzState = 86; break zzForNext;
- default: break zzForAction;
- }
-
- case 86:
- switch (zzInput) {
- case 9: zzState = 91; break zzForNext;
- case 20: zzState = 92; break zzForNext;
- default: break zzForAction;
- }
-
- case 87:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; break zzForNext;
- case 9: zzIsFinal = true; zzState = 93; break zzForNext;
- default: break zzForAction;
- }
-
- case 88:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 87; break zzForNext;
- case 9: zzState = 94; break zzForNext;
- default: break zzForAction;
- }
-
- case 89:
- switch (zzInput) {
- case 21: zzState = 90; break zzForNext;
- default: break zzForAction;
- }
-
- case 90:
- switch (zzInput) {
- case 9: zzState = 95; break zzForNext;
- case 22: zzState = 96; break zzForNext;
- default: break zzForAction;
- }
-
- case 91:
- switch (zzInput) {
- case 20: zzState = 92; break zzForNext;
- default: break zzForAction;
- }
-
- case 92:
- switch (zzInput) {
- case 9: zzState = 97; break zzForNext;
- case 22: zzState = 98; break zzForNext;
- default: break zzForAction;
- }
-
- case 93:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 87; break zzForNext;
- case 9: zzState = 94; break zzForNext;
- default: break zzForAction;
- }
-
- case 94:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 87; break zzForNext;
- default: break zzForAction;
- }
-
- case 95:
- switch (zzInput) {
- case 22: zzState = 96; break zzForNext;
- default: break zzForAction;
- }
-
- case 96:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: break zzForNext;
- case 9: zzState = 99; break zzForNext;
- case 10: zzIsFinal = true; zzState = 100; break zzForNext;
- default: break zzForAction;
- }
-
- case 97:
- switch (zzInput) {
- case 22: zzState = 98; break zzForNext;
- default: break zzForAction;
- }
-
- case 98:
- switch (zzInput) {
- case 9: zzState = 101; break zzForNext;
- case 25: zzState = 102; break zzForNext;
- default: break zzForAction;
- }
-
- case 99:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 96; break zzForNext;
- case 10: zzIsFinal = true; zzState = 100; break zzForNext;
- case 9: zzState = 103; break zzForNext;
- default: break zzForAction;
- }
-
- case 100:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 104; break zzForNext;
- case 9: zzState = 105; break zzForNext;
- default: break zzForAction;
- }
-
- case 101:
- switch (zzInput) {
- case 25: zzState = 102; break zzForNext;
- default: break zzForAction;
- }
-
- case 102:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: break zzForNext;
- case 9: zzState = 106; break zzForNext;
- case 10: zzIsFinal = true; zzState = 107; break zzForNext;
- default: break zzForAction;
- }
-
- case 103:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 96; break zzForNext;
- default: break zzForAction;
- }
-
- case 104:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzState = 100; break zzForNext;
- case 6:
- case 7:
- case 8: zzIsFinal = true; break zzForNext;
- default: break zzForAction;
- }
-
- case 105:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 104; break zzForNext;
- default: break zzForAction;
- }
-
- case 106:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 102; break zzForNext;
- case 10: zzIsFinal = true; zzState = 107; break zzForNext;
- case 9: zzState = 108; break zzForNext;
- default: break zzForAction;
- }
-
- case 107:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 109; break zzForNext;
- case 9: zzState = 110; break zzForNext;
- default: break zzForAction;
- }
-
- case 108:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzState = 102; break zzForNext;
- default: break zzForAction;
- }
-
- case 109:
- switch (zzInput) {
- case 9: zzIsFinal = true; zzState = 107; break zzForNext;
- case 6:
- case 7:
- case 8: zzIsFinal = true; break zzForNext;
- default: break zzForAction;
- }
-
- case 110:
- switch (zzInput) {
- case 6:
- case 7:
- case 8: zzIsFinal = true; zzState = 109; break zzForNext;
- default: break zzForAction;
- }
-
- default:
- // if this is ever reached, there is a serious bug in JFlex
- zzScanError(ZZ_UNKNOWN_ERROR);
- break;
- } }
-
- if ( zzIsFinal ) {
- zzAction = zzState;
- zzMarkedPosL = zzCurrentPosL;
- if ( zzNoLookAhead ) break zzForAction;
- }
-
- }
- }
-
- // store back cached position
- zzMarkedPos = zzMarkedPosL;
-
- switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
- case 12:
- { yybegin(YYINITIAL); hasMore = false; return XMLHeadTokenizerConstants.XMLDeclEnd;
- }
- case 18: break;
- case 14:
- { if (yychar == 0 ) {hasMore = false; return EncodingParserConstants.UTF83ByteBOM;}
- }
- case 19: break;
- case 9:
- { yypushback(yylength());popState(); valueText = string.toString(); return EncodingParserConstants.InvalidTermintatedUnDelimitedStringValue;
- }
- case 20: break;
- case 2:
- { yypushback(1); yybegin(UnDelimitedString); string.setLength(0);
- }
- case 21: break;
- case 7:
- { popState(); valueText = string.toString(); return EncodingParserConstants.StringValue;
- }
- case 22: break;
- case 10:
- { if (yychar == 0 ) {hasMore = false; return EncodingParserConstants.UTF16BE;}
- }
- case 23: break;
- case 1:
- { if(yychar > MAX_TO_SCAN) {hasMore=false; return EncodingParserConstants.MAX_CHARS_REACHED;}
- }
- case 24: break;
- case 6:
- { yypushback(yylength());popState(); valueText = string.toString(); return EncodingParserConstants.InvalidTerminatedStringValue;
- }
- case 25: break;
- case 5:
- { string.append( yytext() );
- }
- case 26: break;
- case 13:
- { yypushback(yylength()); popState(); valueText = string.toString(); return EncodingParserConstants.InvalidTerminatedStringValue;
- }
- case 27: break;
- case 4:
- { yybegin(SQ_STRING); string.setLength(0);
- }
- case 28: break;
- case 3:
- { yybegin(DQ_STRING); string.setLength(0);
- }
- case 29: break;
- case 8:
- { yypushback(yylength());popState(); valueText = string.toString(); return EncodingParserConstants.UnDelimitedStringValue;
- }
- case 30: break;
- case 17:
- { pushCurrentState(); yybegin(QuotedAttributeValue); return XMLHeadTokenizerConstants.XMLDelEncoding;
- }
- case 31: break;
- case 15:
- { if (yychar == 0 ) {yybegin(ST_XMLDecl); return XMLHeadTokenizerConstants.XMLDeclStart;}
- }
- case 32: break;
- case 11:
- { if (yychar == 0 ) {hasMore = false; return EncodingParserConstants.UTF16LE;}
- }
- case 33: break;
- case 16:
- { pushCurrentState(); yybegin(QuotedAttributeValue); return XMLHeadTokenizerConstants.XMLDeclVersion;
- }
- case 34: break;
- default:
- if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
- zzAtEOF = true;
- zzDoEOF();
- {
- hasMore = false; return EncodingParserConstants.EOF;
- }
- }
- else {
- zzScanError(ZZ_NO_MATCH);
- }
- }
- }
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizerConstants.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizerConstants.java
deleted file mode 100644
index ccf23f8aa9..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLHeadTokenizerConstants.java
+++ /dev/null
@@ -1,21 +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.contenttype;
-
-public interface XMLHeadTokenizerConstants extends EncodingParserConstants {
-
- final String XMLDeclEnd = "XMLDeclEnd"; //$NON-NLS-1$
- final String XMLDeclStart = "XMLDeclStart"; //$NON-NLS-1$
- final String XMLDelEncoding = "XMLDelEncoding"; //$NON-NLS-1$
- final String XMLDeclVersion = "XMLDeclVersion"; //$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLResourceEncodingDetector.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLResourceEncodingDetector.java
deleted file mode 100644
index 1f1079b37d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/contenttype/XMLResourceEncodingDetector.java
+++ /dev/null
@@ -1,142 +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
- * David Carver (STAR) - bug 297006 - String Comparison
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contenttype;
-
-import java.io.IOException;
-
-import org.eclipse.core.runtime.content.IContentDescription;
-import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;
-import org.eclipse.wst.sse.core.internal.encoding.IResourceCharsetDetector;
-
-
-public class XMLResourceEncodingDetector extends AbstractResourceEncodingDetector implements IResourceCharsetDetector {
- private XMLHeadTokenizer fTokenizer;
- private boolean fDeclDetected = false;
- private boolean fInitialWhiteSpace = false;
-
- private boolean canHandleAsUnicodeStream(String tokenType) {
- boolean canHandleAsUnicodeStream = false;
- if (EncodingParserConstants.UTF83ByteBOM.equals(tokenType)) {
- canHandleAsUnicodeStream = true;
- String enc = "UTF-8"; //$NON-NLS-1$
- createEncodingMemento(enc, EncodingMemento.DETECTED_STANDARD_UNICODE_BYTES);
- fEncodingMemento.setUTF83ByteBOMUsed(true);
- }
- else if (EncodingParserConstants.UTF16BE.equals(tokenType) || EncodingParserConstants.UTF16LE.equals(tokenType)) {
- canHandleAsUnicodeStream = true;
- String enc = "UTF-16"; //$NON-NLS-1$
- byte[] bom = (EncodingParserConstants.UTF16BE.equals(tokenType)) ? IContentDescription.BOM_UTF_16BE : IContentDescription.BOM_UTF_16LE;
- createEncodingMemento(enc, EncodingMemento.DETECTED_STANDARD_UNICODE_BYTES);
- fEncodingMemento.setUnicodeStream(true);
- fEncodingMemento.setUnicodeBOM(bom);
- }
- return canHandleAsUnicodeStream;
- }
-
- public String getSpecDefaultEncoding() {
- // by default, UTF-8 as per XML spec
- final String enc = "UTF-8"; //$NON-NLS-1$
- return enc;
- }
-
- /**
- * @return Returns the tokenizer.
- */
- private XMLHeadTokenizer getTokenizer() {
- // TODO: need to work on 'reset' in tokenizer, so new instance isn't
- // always needed
- // if (fTokenizer == null) {
- fTokenizer = new XMLHeadTokenizer();
- // }
- return fTokenizer;
- }
-
- private boolean isLegalString(String valueTokenType) {
- if (valueTokenType == null)
- return false;
- else
- return valueTokenType.equals(EncodingParserConstants.StringValue) || valueTokenType.equals(EncodingParserConstants.UnDelimitedStringValue) || valueTokenType.equals(EncodingParserConstants.InvalidTerminatedStringValue) || valueTokenType.equals(EncodingParserConstants.InvalidTermintatedUnDelimitedStringValue);
- }
-
- protected void parseInput() throws IOException {
- XMLHeadTokenizer tokenizer = getTokenizer();
- tokenizer.reset(fReader);
- HeadParserToken token = null;
- String tokenType = null;
- do {
- token = tokenizer.getNextToken();
- tokenType = token.getType();
-
- // handle xml content type detection
- if (tokenType == XMLHeadTokenizerConstants.XMLDeclStart) {
- fDeclDetected = true;
- String declText = token.getText();
- if (declText.startsWith("<?")) { //$NON-NLS-1$
- fInitialWhiteSpace = false;
- }
- else {
- fInitialWhiteSpace = true;
- }
- }
-
- // handle encoding detection
- if (canHandleAsUnicodeStream(tokenType)) {
- // side effect of canHandle is to create appropriate memento
- }
- else {
- if (tokenType == XMLHeadTokenizerConstants.XMLDelEncoding) {
- if (tokenizer.hasMoreTokens()) {
- token = tokenizer.getNextToken();
- tokenType = token.getType();
- if (isLegalString(tokenType)) {
- String enc = token.getText();
- if (enc != null && enc.length() > 0) {
- createEncodingMemento(enc, EncodingMemento.FOUND_ENCODING_IN_CONTENT);
- }
- }
- }
- }
- }
- }
- while (tokenizer.hasMoreTokens());
-
- }
-
- public boolean isDeclDetected() {
- if (!fHeaderParsed) {
- try {
- parseInput();
- }
- catch (IOException e) {
- fDeclDetected = false;
- }
- // we keep track of if header's already been
- // parse, so can make
- // multiple 'get' calls, without causing
- // reparsing.
- fHeaderParsed = true;
- }
- // fDeclDetected is set as part of parsing.
- return fDeclDetected;
- }
-
- public boolean hasInitialWhiteSpace() {
- return fInitialWhiteSpace;
- }
-
- protected void resetAll() {
- super.resetAll();
- fDeclDetected = false;
- fInitialWhiteSpace = false;
- }
-}
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 d1b931e1b1..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/CharacterDataImpl.java
+++ /dev/null
@@ -1,355 +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
- * 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) {
- throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessages.INDEX_SIZE_ERR);
- }
- 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 562f4b1934..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() {
- }
-
- static String DOMSTRING_SIZE_ERR;
- static String HIERARCHY_REQUEST_ERR;
- static String INDEX_SIZE_ERR;
- static String INUSE_ATTRIBUTE_ERR;
- static String INVALID_ACCESS_ERR;
- static String INVALID_CHARACTER_ERR;
- static String INVALID_MODIFICATION_ERR;
- static String INVALID_STATE_ERR;
- static String NAMESPACE_ERR;
- static String NO_DATA_ALLOWED_ERR;
- static String NO_MODIFICATION_ALLOWED_ERR;
- static String NOT_FOUND_ERR;
- static String NOT_SUPPORTED_ERR;
- static String SYNTAX_ERR;
- static String TYPE_MISMATCH_ERR;
- static String VALIDATION_ERR;
- 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 d0eac25e87..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=Incorrect Index 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 feeb87c838..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DOMModelImpl.java
+++ /dev/null
@@ -1,915 +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.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.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 listners 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 {
- return null;
- }
-
- /**
- * 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 {
- parser.replaceStructuredDocumentRegions(getStructuredDocument().getRegionList(), null);
- }
- catch (Exception ex) {
- Logger.logException(ex);
- }
- finally {
- setActive(null);
- if (!isChanging)
- notifier.endChanging();
- this.refresh = false;
- }
- }
-
- /**
- * 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 4082ff77ff..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/DocumentImpl.java
+++ /dev/null
@@ -1,1207 +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()
- * 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) {
- CMElementDeclaration decl = ModelQueryUtil.getModelQuery(this).getCMElementDeclaration(element);
- 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 89aa7beae0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ElementImpl.java
+++ /dev/null
@@ -1,1512 +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
- *
- * 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 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;
- 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;
-
- /**
- * 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 = new ElementImpl(this);
- if (deep)
- cloneChildNodes(cloned, deep);
-
- notifyUserDataHandlers(UserDataHandler.NODE_CLONED, cloned);
- return cloned;
- }
-
- /**
- * 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) {
- String defaultValue = getDefaultValue(name);
- return (defaultValue != null) ? defaultValue : NodeImpl.EMPTY_STRING;
- }
- return attr.getValue();
- }
-
- /**
- * get the default value for attribute <code>name</code>. Returns an empty string
- * @param name
- * @return
- */
- private String getDefaultValue(String 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 NodeImpl.EMPTY_STRING;
- }
-
- /**
- * getAttributeNode method
- *
- * @return org.w3c.dom.Attr
- * @param name
- * java.lang.String
- */
- public Attr getAttributeNode(String name) {
- if (name == null)
- return null; // invalid parameter
- if (this.attrNodes == null)
- return null; // no attribute
-
- int length = this.attrNodes.getLength();
- char[] nameChars = name.toCharArray();
- for (int i = 0; i < length; i++) {
- AttrImpl attr = (AttrImpl) this.attrNodes.item(i);
- if (attr == null)
- continue;
- if (attr.matchName(nameChars))
- return attr; // found
- }
-
- return null; // not found
- }
-
- /**
- */
- 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
- }
-
- /**
- */
- 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) {
- String defaultValue = getDefaultValue(name);
- 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);
- }
-
- /**
- * 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() {
- 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();
- }
-
- if (this.fNamespaceURI == null)
- return null;
- return new String(this.fNamespaceURI);
- }
-
- /**
- * 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);
- }
-
- /**
- * removeAttribute method
- *
- * @param name
- * java.lang.String
- */
- public void removeAttribute(String name) throws DOMException {
- removeAttributeNode(name);
- }
-
- /**
- * 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);
- }
-
- /**
- * removeAttributeNode method
- *
- * @return org.w3c.dom.Attr
- * @param name
- * java.lang.String
- */
- public Attr removeAttributeNode(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;
- if (!attr.matchName(name))
- continue;
-
- // found
- this.attrNodes.removeNode(i);
- attr.setOwnerElement(null);
-
- notifyAttrReplaced(null, attr);
- return attr;
- }
-
- 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 = getAttributeNode(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);
- }
-
- /**
- * setAttributeNode method
- *
- * @return org.w3c.dom.Attr
- * @param newAttr
- * 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());
- 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 = CharacterStringPool.getCharString(tagName);
- }
-
- /**
- * 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 b8f6d66940..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, 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
- * 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)
- 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 938deb8517..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/NodeImpl.java
+++ /dev/null
@@ -1,1139 +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 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;
- }
-
- /**
- * getNodeValue method
- *
- * @return java.lang.String
- */
- 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();
- }
-
- /**
- */
- public boolean hasAttributes() {
- return false;
- }
-
- /**
- * hasChildNodes method
- *
- * @return boolean
- */
- 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$
- }
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String getTextContent() 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 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 cad3207ab5..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/TextImpl.java
+++ /dev/null
@@ -1,1179 +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$
- }
-
- /**
- * getNodeType method
- *
- * @return short
- */
- 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 || end > 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);
- }
-
- public String getWholeText() {
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not Implemented in this version."); //$NON-NLS-1$
- }
- /**
- * 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;
- }
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentCharsetDetector.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentCharsetDetector.java
deleted file mode 100644
index 697f649ebe..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentCharsetDetector.java
+++ /dev/null
@@ -1,37 +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.encoding;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.wst.sse.core.internal.document.DocumentReader;
-import org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector;
-import org.eclipse.wst.xml.core.internal.contenttype.XMLResourceEncodingDetector;
-
-
-/**
- * This class reads and parses first of XML file to get encoding.
- *
- */
-public class XMLDocumentCharsetDetector extends XMLResourceEncodingDetector implements IDocumentCharsetDetector {
-
- /**
- * XMLLoader constructor comment.
- */
- public XMLDocumentCharsetDetector() {
- super();
- }
-
- public void set(IDocument document) {
- set(new DocumentReader(document, 0));
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentLoader.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentLoader.java
deleted file mode 100644
index 2316b34c44..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/encoding/XMLDocumentLoader.java
+++ /dev/null
@@ -1,82 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.encoding;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.wst.sse.core.internal.document.AbstractDocumentLoader;
-import org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector;
-import org.eclipse.wst.sse.core.internal.document.IDocumentLoader;
-import org.eclipse.wst.sse.core.internal.document.StructuredDocumentFactory;
-import org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences;
-import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;
-import org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
-import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser;
-import org.eclipse.wst.xml.core.internal.parser.XMLStructuredDocumentReParser;
-import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
-import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML;
-
-
-/**
- * This class reads an XML file and creates an XML Structured Model.
- *
- */
-public class XMLDocumentLoader extends AbstractDocumentLoader {
-
- public XMLDocumentLoader() {
- super();
- }
-
- public IDocumentPartitioner getDefaultDocumentPartitioner() {
- return new StructuredTextPartitionerForXML();
- }
-
- public IDocumentCharsetDetector getDocumentEncodingDetector() {
- if (fDocumentEncodingDetector == null) {
- fDocumentEncodingDetector = new XMLDocumentCharsetDetector();
- }
- return fDocumentEncodingDetector;
- }
-
- public RegionParser getParser() {
- return new XMLSourceParser();
- }
-
- protected String getPreferredNewLineDelimiter(IFile file) {
- String delimiter = ContentTypeEncodingPreferences.getPreferredNewLineDelimiter(ContentTypeIdForXML.ContentTypeID_XML);
- if (delimiter == null)
- delimiter = super.getPreferredNewLineDelimiter(file);
- return delimiter;
- }
-
- protected String getSpecDefaultEncoding() {
- // by default, UTF-8 as per XML spec
- final String enc = "UTF-8"; //$NON-NLS-1$
- return enc;
- }
-
- protected IEncodedDocument newEncodedDocument() {
- IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
- if (structuredDocument instanceof BasicStructuredDocument) {
- ((BasicStructuredDocument) structuredDocument).setReParser(new XMLStructuredDocumentReParser());
- }
- return structuredDocument;
- }
-
- public IDocumentLoader newInstance() {
- return new XMLDocumentLoader();
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java
deleted file mode 100644
index 66b4b8d4d6..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/DefaultXMLPartitionFormatter.java
+++ /dev/null
@@ -1,1684 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 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
- * David Carver (STAR) - bug 297006 - String Comparison
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.formatter;
-
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.text.edits.DeleteEdit;
-import org.eclipse.text.edits.InsertEdit;
-import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-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.Logger;
-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.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-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.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class DefaultXMLPartitionFormatter {
- /**
- * Just a small container class that holds a DOMNode & documentRegion that
- * should represent each other.
- */
- protected class DOMRegion {
- public IDOMNode domNode;
- public IStructuredDocumentRegion documentRegion;
- }
-
- static private final String PRESERVE = "preserve";//$NON-NLS-1$
- static private final String COLLAPSE = "collapse";//$NON-NLS-1$
- static private final String REPLACE = "replace";//$NON-NLS-1$
- static private final String PRESERVE_QUOTED = "\"preserve\"";//$NON-NLS-1$
- static private final String XML_SPACE = "xml:space";//$NON-NLS-1$
- static private final String XSL_NAMESPACE = "http://www.w3.org/1999/XSL/Transform"; //$NON-NLS-1$
- static private final String XSL_ATTRIBUTE = "attribute"; //$NON-NLS-1$
- static private final String XSL_TEXT = "text"; //$NON-NLS-1$
- static private final String SPACE = " "; //$NON-NLS-1$
- static private final String EMPTY = ""; //$NON-NLS-1$
- static private final String PROPERTY_WHITESPACE_FACET = "org.eclipse.wst.xsd.cm.properties/whitespace"; //$NON-NLS-1$
-
- private XMLFormattingPreferences fPreferences = null;
- private IProgressMonitor fProgressMonitor;
-
- private int replaceSpaces(TextEdit textEdit, int spaceStartOffset, int availableLineWidth, String whitespaceRun) {
- StringBuffer buff = new StringBuffer(whitespaceRun);
- for(int i = 0; i < buff.length(); i++) {
- buff.setCharAt(i, ' '); //$NON-NLS-1$
- }
- String replacementString = buff.toString();
- if (!replacementString.equals(whitespaceRun)) {
- ReplaceEdit replaceEdit = new ReplaceEdit(spaceStartOffset, whitespaceRun.length(), replacementString);
- textEdit.addChild(replaceEdit);
- }
- return availableLineWidth;
- }
-
- private int collapseSpaces(TextEdit textEdit, int spaceStartOffset, int availableLineWidth, String whitespaceRun) {
- // prefer to use use existing whitespace
- int existingWhitespaceOffset = whitespaceRun.indexOf(' ');
- if (existingWhitespaceOffset > -1) {
- // delete whitespaces before and after existing whitespace
- if (existingWhitespaceOffset > 0) {
- DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset, existingWhitespaceOffset);
- textEdit.addChild(deleteEdit);
- }
- if (existingWhitespaceOffset < whitespaceRun.length() - 1) {
- int nextOffset = existingWhitespaceOffset + 1;
- DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset + nextOffset, whitespaceRun.length() - nextOffset);
- textEdit.addChild(deleteEdit);
- }
- }
- else {
- // delete all whitespace and insert new one
- // collapse whitespace by deleting whitespace
- DeleteEdit deleteEdit = new DeleteEdit(spaceStartOffset, whitespaceRun.length());
- textEdit.addChild(deleteEdit);
- // then insert one space
- InsertEdit insertEdit = new InsertEdit(spaceStartOffset, SPACE);
- textEdit.addChild(insertEdit);
- }
- // remember to account for space added
- --availableLineWidth;
- return availableLineWidth;
- }
-
- private int collapseAndIndent(TextEdit textEdit, int spaceStartOffset, int availableLineWidth, int indentLevel, String whitespaceRun, IStructuredDocumentRegion currentRegion) {
- // Need to keep blank lines, but still collapse the whitespace
- String lineDelimiters = null;
- if (!getFormattingPreferences().getClearAllBlankLines()) {
- lineDelimiters = extractLineDelimiters(whitespaceRun, currentRegion);
- String formattedLine = lineDelimiters + getIndentString(indentLevel);
- if(lineDelimiters.length() > 0 && !formattedLine.equals(whitespaceRun)) {
- textEdit.addChild(new ReplaceEdit(spaceStartOffset, whitespaceRun.length(), formattedLine));
- availableLineWidth = getFormattingPreferences().getMaxLineWidth() - indentLevel;
- }
- }
- if (lineDelimiters == null || lineDelimiters.length() == 0) {
- availableLineWidth = collapseSpaces(textEdit, spaceStartOffset, availableLineWidth, whitespaceRun);
- }
- return availableLineWidth;
- }
-
- private void deleteTrailingSpaces(TextEdit textEdit, ITextRegion currentTextRegion, IStructuredDocumentRegion currentDocumentRegion) {
- int textEnd = currentTextRegion.getTextEnd();
- int textEndOffset = currentDocumentRegion.getStartOffset() + textEnd;
- int difference = currentTextRegion.getEnd() - textEnd;
- DeleteEdit deleteEdit = new DeleteEdit(textEndOffset, difference);
- textEdit.addChild(deleteEdit);
- }
-
- public TextEdit format(IDocument document, int start, int length) {
- return format(document, start, length, new XMLFormattingPreferences());
- }
-
- public TextEdit format(IDocument document, int start, int length, XMLFormattingPreferences preferences) {
- TextEdit edit = null;
- if (document instanceof IStructuredDocument) {
- IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
- if (model != null) {
- try {
- edit = format(model, start, length, preferences);
- }
- finally {
- model.releaseFromEdit();
- }
- }
- }
- return edit;
- }
-
- public TextEdit format(IStructuredModel model, int start, int length) {
- return format(model, start, length, new XMLFormattingPreferences());
- }
-
- public TextEdit format(IStructuredModel model, int start, int length, XMLFormattingPreferences preferences) {
- setFormattingPreferences(preferences);
-
- TextEdit edit = new MultiTextEdit();
- IStructuredDocument document = model.getStructuredDocument();
- // get initial document region
- IStructuredDocumentRegion currentRegion = document.getRegionAtCharacterOffset(start);
- if (currentRegion != null) {
- int startOffset = currentRegion.getStartOffset();
-
- // get initial dom node
- IndexedRegion currentIndexedRegion = model.getIndexedRegion(startOffset);
- if (currentIndexedRegion instanceof IDOMNode) {
- // set up domRegion which will contain current region to be
- // formatted
- IDOMNode currentDOMNode = (IDOMNode) currentIndexedRegion;
- DOMRegion domRegion = new DOMRegion();
- domRegion.documentRegion = currentRegion;
- domRegion.domNode = currentDOMNode;
-
- XMLFormattingConstraints parentConstraints = getRegionConstraints(currentDOMNode);
-
- /* if the whitespace strategy is declared as default, get it from the preferences */
- if(XMLFormattingConstraints.DEFAULT.equals(parentConstraints.getWhitespaceStrategy()))
- parentConstraints.setWhitespaceStrategy(preferences.getElementWhitespaceStrategy());
-
- // TODO: initialize indentLevel
- // initialize available line width
- int lineWidth = getFormattingPreferences().getMaxLineWidth();
- try {
- IRegion lineInfo = document.getLineInformationOfOffset(startOffset);
- lineWidth = lineWidth - (startOffset - lineInfo.getOffset());
- }
- catch (BadLocationException e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- parentConstraints.setAvailableLineWidth(lineWidth);
-
- // format all siblings (and their children) as long they
- // overlap with start/length
- Position formatRange = new Position(start, length);
- formatSiblings(edit, domRegion, parentConstraints, formatRange);
- }
- }
- return edit;
- }
-
- /**
- * Determines the formatting constraints for a specified node based on
- * its ancestors' formatting. In particular, if any ancestor node either
- * explicitly defines whitespace preservation or ignorance, that
- * whitespace strategy should be used for <code>currentNode</code> and
- * all of its descendants.
- *
- * @param currentNode the node to investigate the ancestry of to determine
- * formatting constraints
- *
- * @return formatting constraints defined by an ancestor
- */
- private XMLFormattingConstraints getRegionConstraints(IDOMNode currentNode) {
- IDOMNode iterator = currentNode;
- XMLFormattingConstraints result = new XMLFormattingConstraints();
- DOMRegion region = new DOMRegion();
- XMLFormattingConstraints parentConstraints = new XMLFormattingConstraints();
- boolean parent = true;
-
- /* Iterate through the ancestry to find if any explicit whitespace strategy has
- * been defined
- */
- while(iterator != null && iterator.getNodeType() != Node.DOCUMENT_NODE) {
- iterator = (IDOMNode) iterator.getParentNode();
- region.domNode = iterator;
- region.documentRegion = iterator.getFirstStructuredDocumentRegion();
-
- updateFormattingConstraints(null, null, result, region);
-
- /* If this is the parent of the current node, keep the constraints
- * in case no other constraints are identified
- */
- if(parent) {
- parentConstraints.copyConstraints(result);
- parent = false;
- }
-
- /* A parent who has defined a specific whitespace strategy was found */
- if(XMLFormattingConstraints.PRESERVE.equals(result.getWhitespaceStrategy()) || XMLFormattingConstraints.DEFAULT.equals(result.getWhitespaceStrategy()))
- return result;
- }
-
- return parentConstraints;
- }
-// private XMLFormattingConstraints getRegionConstraints(IDOMNode currentNode) {
-// IDOMNode iterator = (IDOMNode) currentNode.getParentNode();
-// XMLFormattingConstraints result = new XMLFormattingConstraints();
-// DOMRegion region = new DOMRegion();
-//
-// /* Iterate through the ancestry to find if any explicit whitespace strategy has
-// * been defined
-// */
-// while(iterator != null && iterator.getNodeType() != Node.DOCUMENT_NODE) {
-
-// region.domNode = iterator;
-// region.documentRegion = iterator.getFirstStructuredDocumentRegion();
-//
-// updateFormattingConstraints(null, null, result, region);
-//
-// /* A parent who has defined a specific whitespace strategy was found */
-// if(XMLFormattingConstraints.PRESERVE == result.getWhitespaceStrategy() || XMLFormattingConstraints.DEFAULT == result.getWhitespaceStrategy())
-// return result;
-//
-// iterator = (IDOMNode) iterator.getParentNode();
-// }
-//
-// return null;
-// }
-
- /**
- * Formats the given xml content region
- *
- * @param textEdit
- * @param formatRange
- * @param parentConstraints
- * @param currentDOMRegion
- * @param previousRegion
- */
- private void formatContent(TextEdit textEdit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousRegion) {
- IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
- String fullText = currentDOMRegion.domNode.getSource();
-
- // check if in preserve space mode, if so, don't touch anything but
- // make sure to update available line width
- String whitespaceMode = parentConstraints.getWhitespaceStrategy();
- if (XMLFormattingConstraints.PRESERVE.equals(whitespaceMode)) {
- int availableLineWidth = parentConstraints.getAvailableLineWidth();
- availableLineWidth = updateLineWidthWithLastLine(fullText, availableLineWidth);
-
- // update available line width in constraints
- parentConstraints.setAvailableLineWidth(availableLineWidth);
- // A text node can contain multiple structured document regions - sync the documentRegion
- // with the last region of the node since the text from all regions was formatted
- currentDOMRegion.documentRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
- return;
- }
-
- // if content is just whitespace and there's something after it
- // just skip over this region because region will take care of it
- boolean isAllWhitespace = ((IDOMText) currentDOMRegion.domNode).isElementContentWhitespace();
- IStructuredDocumentRegion nextDocumentRegion = null;
- if (isAllWhitespace) {
- parentConstraints.setAvailableLineWidth(fPreferences.getMaxLineWidth());
- nextDocumentRegion = currentRegion.getNext();
- if (nextDocumentRegion != null)
- return;
- }
-
- // special handling if text follows an entity or cdata region
- if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode) && previousRegion != null) {
- String previouRegionType = previousRegion.getType();
- if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(previouRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(previouRegionType))
- whitespaceMode = XMLFormattingConstraints.COLLAPSE;
- }
- // also, special handling if text is before an entity or cdata region
- if (!XMLFormattingConstraints.COLLAPSE.equals(whitespaceMode)) {
- // get next document region if dont already have it
- if (nextDocumentRegion == null)
- nextDocumentRegion = currentRegion.getNext();
- if (nextDocumentRegion != null) {
- String nextRegionType = nextDocumentRegion.getType();
- if (DOMRegionContext.XML_ENTITY_REFERENCE.equals(nextRegionType) || DOMRegionContext.XML_CDATA_TEXT.equals(nextRegionType))
- whitespaceMode = XMLFormattingConstraints.COLLAPSE;
- }
- }
- formatTextInContent(textEdit, parentConstraints, currentRegion, fullText, whitespaceMode);
- // A text node can contain multiple structured document regions - sync the documentRegion
- // with the last region of the node since the text from all regions was formatted
- currentDOMRegion.documentRegion = currentDOMRegion.domNode.getLastStructuredDocumentRegion();
- }
-
- private void formatEmptyStartTagWithNoAttr(TextEdit textEdit, XMLFormattingConstraints constraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion, int availableLineWidth, String indentStrategy, String whitespaceStrategy, ITextRegion currentTextRegion) {
- // get preference if there should be a space or not between tag
- // name and empty tag close
- // <tagName />
- boolean oneSpaceInTagName = getFormattingPreferences().getSpaceBeforeEmptyCloseTag();
-
- // calculate available line width
- int tagNameLineWidth = currentTextRegion.getTextLength() + 3;
- if (oneSpaceInTagName) {
- // add one more to account for space before empty tag close
- ++tagNameLineWidth;
- }
- availableLineWidth -= tagNameLineWidth;
-
- if (XMLFormattingConstraints.INLINE.equals(indentStrategy)) {
- // if was inlining, need to check if out of available line
- // width
- if (availableLineWidth < 0) {
- // need to indent if possible
- int lineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, true);
- // update available line width
- if (lineWidth > 0)
- availableLineWidth = lineWidth - tagNameLineWidth;
- else
- availableLineWidth -= tagNameLineWidth;
- }
- else {
- // no need to indent
- // just make sure to delete previous whitespace if
- // needed
- if ((DOMRegionContext.XML_CONTENT.equals(previousDocumentRegion.getType())) && (previousDocumentRegion.getFullText().trim().length() == 0)) {
- availableLineWidth = collapseSpaces(textEdit, previousDocumentRegion.getStartOffset(), availableLineWidth, previousDocumentRegion.getFullText());
- }
- }
- }
-
- // delete any trail spaces after tag name
- int textLength = currentTextRegion.getTextLength();
- int regionLength = currentTextRegion.getLength();
-
- boolean thereAreSpaces = textLength < regionLength;
- if (!oneSpaceInTagName && thereAreSpaces) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- }
- else if(oneSpaceInTagName) {
- insertSpaceAndCollapse(textEdit, currentDocumentRegion, availableLineWidth, currentTextRegion);
- }
- constraints.setAvailableLineWidth(availableLineWidth);
- }
-
- /**
- * Formats an end tag
- *
- * @param textEdit
- * @param currentRegion
- * @param textRegions
- */
- private void formatEndTag(TextEdit textEdit, Position formatRange, XMLFormattingConstraints constraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousDocumentRegion) {
- IStructuredDocumentRegion currentDocumentRegion = currentDOMRegion.documentRegion;
-
- String whitespaceStrategy = constraints.getWhitespaceStrategy();
- String indentStrategy = constraints.getIndentStrategy();
-
- // do not format space before start tag if preserving spaces
- if (whitespaceStrategy != XMLFormattingConstraints.PRESERVE) {
- // format like indent strategy says
- if (XMLFormattingConstraints.INDENT.equals(indentStrategy) || XMLFormattingConstraints.NEW_LINE.equals(indentStrategy)) {
- int availableLineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, false);
- constraints.setAvailableLineWidth(availableLineWidth);
- }
- }
- // format the end tag itself
- formatWithinEndTag(textEdit, constraints, currentDocumentRegion, previousDocumentRegion);
- }
-
- /**
- * Formats the given region (and all its children) contained in domRegion.
- *
- * @param edit
- * edits required to format
- * @param formatRange
- * document range to format (only format content within this
- * range)
- * @param parentConstraints
- * @param domRegion
- * assumes dom node & region are not null
- * @param previousRegion
- * could be null
- * @return Returns the last region formatted
- */
- private DOMRegion formatRegion(TextEdit edit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion domRegion, IStructuredDocumentRegion previousRegion) {
- IStructuredDocumentRegion currentRegion = domRegion.documentRegion;
- String regionType = currentRegion.getType();
- if (DOMRegionContext.XML_TAG_NAME.equals(regionType)) {
- ITextRegion textRegion = currentRegion.getFirstRegion();
- String textRegionType = textRegion.getType();
- if (DOMRegionContext.XML_TAG_OPEN.equals(textRegionType)) {
- domRegion = formatStartTag(edit, formatRange, parentConstraints, domRegion, previousRegion);
- }
- else if (DOMRegionContext.XML_END_TAG_OPEN.equals(textRegionType)) {
- formatEndTag(edit, formatRange, parentConstraints, domRegion, previousRegion);
- }
- }
- else if (DOMRegionContext.XML_CONTENT.equals(regionType) || domRegion.domNode.getNodeType() == Node.TEXT_NODE) {
- formatContent(edit, formatRange, parentConstraints, domRegion, previousRegion);
- }
- else if (DOMRegionContext.XML_COMMENT_TEXT.equals(regionType)) {
- formatComment(edit, formatRange, parentConstraints, domRegion, previousRegion);
- }
- else {
- // unknown, so just leave alone for now but make sure to update
- // available line width
- String fullText = currentRegion.getFullText();
- int width = updateLineWidthWithLastLine(fullText, parentConstraints.getAvailableLineWidth());
- parentConstraints.setAvailableLineWidth(width);
- }
- return domRegion;
- }
-
- /**
- * Formats the domRegion and all of its children and siblings
- *
- * @param edit
- * @param domRegion
- * @param parentConstraints
- * @param formatRange
- */
- private void formatSiblings(TextEdit edit, DOMRegion domRegion, XMLFormattingConstraints parentConstraints, Position formatRange) {
- IStructuredDocumentRegion previousRegion = null;
- IStructuredDocumentRegion currentRegion = domRegion.documentRegion;
- IDOMNode currentDOMNode = domRegion.domNode;
- while (currentDOMNode != null && currentRegion != null && formatRange.overlapsWith(currentRegion.getStartOffset(), currentRegion.getLength()) && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) {
- domRegion.documentRegion = currentRegion;
- domRegion.domNode = currentDOMNode;
-
- // need to make sure current document region and current
- // dom node match up
- if (currentDOMNode.getFirstStructuredDocumentRegion().equals(currentRegion)) {
- // format this document region/node, formatRegion will
- // return the last node/region formatted
- domRegion = formatRegion(edit, formatRange, parentConstraints, domRegion, previousRegion);
- }
- else {
- // TODO: need to figure out what to do if they don't
- // match up
- }
- previousRegion = domRegion.documentRegion;
- // get the next sibling information
- if (domRegion.domNode != null)
- currentDOMNode = (IDOMNode) domRegion.domNode.getNextSibling();
- else
- currentDOMNode = null;
- currentRegion = previousRegion.getNext();
- }
- }
-
- /**
- * Formats a start tag
- *
- * @param textEdit
- * @param currentRegion
- * @param textRegions
- */
- private DOMRegion formatStartTag(TextEdit textEdit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousDocumentRegion) {
- // determine proper indent by referring to parent constraints,
- // previous node, and current node
- IStructuredDocumentRegion currentDocumentRegion = currentDOMRegion.documentRegion;
- IDOMNode currentDOMNode = currentDOMRegion.domNode;
-
- // create a constraint for this tag
- XMLFormattingConstraints thisConstraints = new XMLFormattingConstraints();
- XMLFormattingConstraints childrenConstraints = new XMLFormattingConstraints();
- updateFormattingConstraints(parentConstraints, thisConstraints, childrenConstraints, currentDOMRegion);
-
- if(XMLFormattingConstraints.DEFAULT.equals(childrenConstraints.getWhitespaceStrategy()))
- childrenConstraints.setWhitespaceStrategy((new XMLFormattingPreferences()).getElementWhitespaceStrategy());
-
- String whitespaceStrategy = thisConstraints.getWhitespaceStrategy();
- String indentStrategy = thisConstraints.getIndentStrategy();
- int availableLineWidth = thisConstraints.getAvailableLineWidth();
-
- // format space before start tag
- // do not format space before start tag if preserving spaces
- if (!XMLFormattingConstraints.PRESERVE.equals(whitespaceStrategy)) {
- // format like indent strategy says
- if (XMLFormattingConstraints.INDENT.equals(indentStrategy) || XMLFormattingConstraints.NEW_LINE.equals(indentStrategy)) {
- availableLineWidth = indentIfPossible(textEdit, thisConstraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, true);
- if (availableLineWidth > 0)
- thisConstraints.setAvailableLineWidth(availableLineWidth);
- }
- }
- // format the start tag itself
- boolean tagEnded = formatWithinTag(textEdit, thisConstraints, currentDocumentRegion, previousDocumentRegion);
-
- // format children
- if (!tagEnded) {
- // update childConstraints with thisConstraint's indentLevel &
- // availableLineWidth
- childrenConstraints.setIndentLevel(thisConstraints.getIndentLevel());
- childrenConstraints.setAvailableLineWidth(thisConstraints.getAvailableLineWidth());
-
- previousDocumentRegion = currentDocumentRegion;
- IDOMNode childDOMNode = (IDOMNode) currentDOMNode.getFirstChild();
- IStructuredDocumentRegion nextRegion = currentDocumentRegion.getNext();
- boolean passedFormatRange = false;
- // as long as there is one child
- if (childDOMNode != null && nextRegion != null) {
- while (childDOMNode != null && nextRegion != null && !passedFormatRange && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) {
- DOMRegion childDOMRegion = new DOMRegion();
- childDOMRegion.documentRegion = nextRegion;
- childDOMRegion.domNode = childDOMNode;
- if (nextRegion.equals(childDOMNode.getFirstStructuredDocumentRegion())) {
- // format children. pass in child constraints
- childDOMRegion = formatRegion(textEdit, formatRange, childrenConstraints, childDOMRegion, previousDocumentRegion);
- }
- else {
- // TODO: what happens if they dont match up?
- }
-
- // update childDOMRegion with next dom/region node
- if (childDOMRegion.domNode != null) {
- childDOMNode = (IDOMNode) childDOMRegion.domNode.getNextSibling();
- }
- else {
- childDOMNode = null;
- }
- previousDocumentRegion = childDOMRegion.documentRegion;
- nextRegion = previousDocumentRegion.getNext();
- if (nextRegion != null)
- passedFormatRange = !formatRange.overlapsWith(nextRegion.getStartOffset(), nextRegion.getLength());
- }
- }
- else {
- // there were no children, so keep end tag inlined
- childrenConstraints.setWhitespaceStrategy(XMLFormattingConstraints.COLLAPSE);
- childrenConstraints.setIndentStrategy(XMLFormattingConstraints.INLINE);
- }
-
- if (!passedFormatRange) {
- // update the dom region with the last formatted region/dom
- // node should be end tag and this tag's DOMNode
- currentDOMRegion.documentRegion = nextRegion;
- currentDOMRegion.domNode = currentDOMNode;
-
- // end tag's indent level should be same as start tag's
- childrenConstraints.setIndentLevel(thisConstraints.getIndentLevel());
- // format end tag
- boolean formatEndTag = false;
- if (nextRegion != null && currentDOMNode != null) {
- ITextRegionList rs = nextRegion.getRegions();
- if (rs.size() > 1) {
- ITextRegion r = rs.get(0);
- if (r != null && DOMRegionContext.XML_END_TAG_OPEN.equals(r.getType())) {
- r = rs.get(1);
- if (r != null && DOMRegionContext.XML_TAG_NAME.equals(r.getType())) {
- String tagName = nextRegion.getText(r);
- if (tagName != null && tagName.equals(currentDOMNode.getNodeName()))
- formatEndTag = true;
- }
- }
-
- }
- }
- if (formatEndTag)
- formatEndTag(textEdit, formatRange, childrenConstraints, currentDOMRegion, previousDocumentRegion);
- else {
- // missing end tag so return last formatted document
- // region
- currentDOMRegion.documentRegion = previousDocumentRegion;
- }
- }
- else {
- // passed format range before could finish, so update dom
- // region to last known formatted region
- currentDOMRegion.documentRegion = nextRegion;
- currentDOMRegion.domNode = childDOMNode;
- }
-
- // update parent constraint since this is what is passed back
- parentConstraints.setAvailableLineWidth(childrenConstraints.getAvailableLineWidth());
- }
- else {
- // update available line width
- parentConstraints.setAvailableLineWidth(thisConstraints.getAvailableLineWidth());
- }
- return currentDOMRegion;
- }
-
- private void formatStartTagWithNoAttr(TextEdit textEdit, XMLFormattingConstraints constraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion, int availableLineWidth, String indentStrategy, String whitespaceStrategy, ITextRegion currentTextRegion) {
- // calculate available line width
- int tagNameLineWidth = currentTextRegion.getTextLength() + 2;
- availableLineWidth -= tagNameLineWidth;
-
- if (XMLFormattingConstraints.INLINE.equals(indentStrategy)) {
- // if was inlining, need to check if out of available line
- // width
- if (availableLineWidth < 0) {
- // need to indent if possible
- int lineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, true);
- // update available line width
- if (lineWidth > 0)
- availableLineWidth = lineWidth - tagNameLineWidth;
- else
- availableLineWidth -= tagNameLineWidth;
- }
- else {
- // no need to indent
- // just make sure to delete previous whitespace if
- // needed
- if (previousDocumentRegion != null) {
- if (DOMRegionContext.XML_CONTENT.equals(previousDocumentRegion.getType())) {
- String previousDocumentRegionText = previousDocumentRegion.getFullText();
- if (previousDocumentRegionText.trim().length() == 0) {
- availableLineWidth = collapseSpaces(textEdit, previousDocumentRegion.getStartOffset(), availableLineWidth, previousDocumentRegionText);
- }
- }
- }
- }
- }
-
- // delete any trail spaces after tag name
- if (currentTextRegion.getTextLength() < currentTextRegion.getLength()) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- }
- constraints.setAvailableLineWidth(availableLineWidth);
- }
-
- /**
- * Format the text in xml content
- *
- * @param textEdit
- * @param parentConstraints
- * @param currentRegion
- * @param fullText
- * @param whitespaceMode
- */
- private void formatTextInContent(TextEdit textEdit, XMLFormattingConstraints parentConstraints, IStructuredDocumentRegion currentRegion, String fullText, String whitespaceMode) {
- int availableLineWidth = parentConstraints.getAvailableLineWidth();
-
- // determine indentation
- boolean forceInitialIndent = false;
- int indentLevel = parentConstraints.getIndentLevel() + 1;
- String indentMode = parentConstraints.getIndentStrategy();
- if (XMLFormattingConstraints.INDENT.equals(indentMode)) {
- forceInitialIndent = true;
- }
- if (XMLFormattingConstraints.NEW_LINE.equals(indentMode)) {
- indentLevel = parentConstraints.getIndentLevel();
- forceInitialIndent = true;
- }
-
- int fullTextOffset = 0;
- char[] fullTextArray = fullText.toCharArray();
- while (fullTextOffset < fullTextArray.length) {
- // gather all whitespaces
- String whitespaceRun = getCharacterRun(fullTextArray, fullTextOffset, true);
- if (whitespaceRun.length() > 0) {
- // offset where whitespace starts
- int whitespaceStart = fullTextOffset;
- // update current offset in fullText
- fullTextOffset += whitespaceRun.length();
-
- // gather following word
- String characterRun = getCharacterRun(fullTextArray, fullTextOffset, false);
- int characterRunLength = characterRun.length();
- if (characterRunLength > 0) {
- // indent if word is too long or forcing initial
- // indent
- availableLineWidth -= characterRunLength;
- // offset where indent/collapse will happen
- int startOffset = currentRegion.getStartOffset() + whitespaceStart;
- if (forceInitialIndent || (availableLineWidth <= 0)) {
- // indent if not already indented
- availableLineWidth = indentIfNotAlreadyIndented(textEdit, currentRegion, indentLevel, startOffset, whitespaceRun);
- // remember to subtract word length
- availableLineWidth -= characterRunLength;
- forceInitialIndent = false; // initial indent done
- }
- else {
- // just collapse spaces, but adjust for any indenting that may result from preserving line delimiters
- if (whitespaceStart == 0 && XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceMode)) {
- // if ignore, trim
- DeleteEdit deleteTrailing = new DeleteEdit(startOffset, whitespaceRun.length());
- textEdit.addChild(deleteTrailing);
- }
- else if(XMLFormattingConstraints.REPLACE.equals(whitespaceMode))
- availableLineWidth = replaceSpaces(textEdit, startOffset, availableLineWidth, whitespaceRun);
- else
- availableLineWidth = collapseAndIndent(textEdit, startOffset, availableLineWidth, indentLevel, whitespaceRun, currentRegion);
- }
-
- fullTextOffset += characterRunLength;
- }
- else {
- // handle trailing whitespace
- int whitespaceOffset = currentRegion.getStartOffset() + whitespaceStart;
- if (XMLFormattingConstraints.REPLACE.equals(whitespaceMode))
- availableLineWidth = replaceSpaces(textEdit, whitespaceOffset, availableLineWidth, whitespaceRun);
- else if (XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceMode)) {
- // always trim
- DeleteEdit deleteTrailing = new DeleteEdit(whitespaceOffset, whitespaceRun.length());
- textEdit.addChild(deleteTrailing);
- }
- else if(getFormattingPreferences().getClearAllBlankLines()) {
- if (XMLFormattingConstraints.IGNORE.equals(whitespaceMode)) {
- // if ignore, trim
- DeleteEdit deleteTrailing = new DeleteEdit(whitespaceOffset, whitespaceRun.length());
- textEdit.addChild(deleteTrailing);
- }
- else {
- // if collapse, leave a space. but what if end up
- // wanting to add indent? then need to delete space
- // added and add indent instead
- availableLineWidth = collapseSpaces(textEdit, whitespaceOffset, availableLineWidth, whitespaceRun);
- }
- }
- }
- }
- else {
- // gather word
- String characterRun = getCharacterRun(fullTextArray, fullTextOffset, false);
- int characterRunLength = characterRun.length();
- if (characterRunLength > 0) {
- // indent if word is too long or forcing initial
- // indent
- // [243091] - characterRunLength should only be subtracted once or text formatting wraps prematurely
- // availableLineWidth = availableLineWidth - characterRunLength;
- if ((XMLFormattingConstraints.IGNORE.equals(whitespaceMode) || XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceMode)) && (forceInitialIndent || (availableLineWidth <= 0))) {
- // indent if not already indented
- availableLineWidth = indentIfNotAlreadyIndented(textEdit, currentRegion, indentLevel, currentRegion.getStartOffset(), whitespaceRun);
- // remember to subtract word length
- availableLineWidth -= characterRunLength;
- forceInitialIndent = false; // initial indent done
- }
- else {
- // just collapse spaces
- availableLineWidth -= characterRunLength;
- }
-
- fullTextOffset += characterRunLength;
- }
- }
- }
- // update available line width
- parentConstraints.setAvailableLineWidth(availableLineWidth);
- }
-
- private void formatWithinEndTag(TextEdit textEdit, XMLFormattingConstraints constraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion) {
- String indentStrategy = constraints.getIndentStrategy();
- String whitespaceStrategy = constraints.getWhitespaceStrategy();
- int availableLineWidth = constraints.getAvailableLineWidth();
- ITextRegionList textRegions = currentDocumentRegion.getRegions();
- int currentNumberOfRegions = currentDocumentRegion.getNumberOfRegions();
- int currentTextRegionIndex = 1;
-
- ITextRegion currentTextRegion = textRegions.get(currentTextRegionIndex);
- String currentType = currentTextRegion.getType();
- // tag name should always be the first text region
- if (DOMRegionContext.XML_TAG_NAME.equals(currentType) && currentTextRegionIndex < currentNumberOfRegions - 1) {
- ITextRegion nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
- // Bug 221279 - Some non well-formed documents will not contribute a next region
- if (nextTextRegion != null && DOMRegionContext.XML_TAG_CLOSE.equals(nextTextRegion.getType())) {
- // calculate available line width
- int tagNameLineWidth = currentTextRegion.getTextLength() + 3;
- availableLineWidth -= tagNameLineWidth;
-
- if (XMLFormattingConstraints.INLINE.equals(indentStrategy)) {
- // if was inlining, need to check if out of available line
- // width - Whitespace may have been corrected in the text content
- if (availableLineWidth < 0 && XMLFormattingConstraints.IGNORE.equals(whitespaceStrategy)) {
- // need to deindent if possible
- int lineWidth = indentIfPossible(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, whitespaceStrategy, indentStrategy, false);
- // update available line width
- if (lineWidth > 0)
- availableLineWidth = lineWidth - tagNameLineWidth;
- }
- else {
- // no need to indent
- // just make sure to delete previous whitespace if
- // needed
- if (previousDocumentRegion != null) {
- if (DOMRegionContext.XML_CONTENT.equals(previousDocumentRegion.getType())) {
- String previousDocumentRegionText = previousDocumentRegion.getFullText();
- if (previousDocumentRegionText.trim().length() == 0) {
- availableLineWidth = collapseSpaces(textEdit, previousDocumentRegion.getStartOffset(), availableLineWidth, previousDocumentRegionText);
- }
- }
- }
- }
- }
- // delete any trail spaces after tag name
- if (currentTextRegion.getTextLength() < currentTextRegion.getLength()) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- }
- }
- }
- else {
- // end tag has unexpected stuff, so just leave it alone
- }
- constraints.setAvailableLineWidth(availableLineWidth);
- }
-
- /**
- * Formats the contents within a tag like tag name and attributes
- *
- * @param textEdit
- * @param currentDocumentRegion
- * @param textRegions
- * contains at least 3 regions
- * @return true if tag was ended, false otherwise
- */
- private boolean formatWithinTag(TextEdit textEdit, XMLFormattingConstraints constraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion) {
- int availableLineWidth = constraints.getAvailableLineWidth();
- String indentStrategy = constraints.getIndentStrategy();
- String whitespaceStrategy = constraints.getWhitespaceStrategy();
- int indentLevel = constraints.getIndentLevel();
- ITextRegionList textRegions = currentDocumentRegion.getRegions();
- int currentTextRegionIndex = 1;
-
- ITextRegion currentTextRegion = textRegions.get(currentTextRegionIndex);
- String currentType = currentTextRegion.getType();
- // tag name should always be the first text region
- if (DOMRegionContext.XML_TAG_NAME.equals(currentType)) {
- ITextRegion nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
- String nextType = (nextTextRegion != null) ? nextTextRegion.getType() : null;
- if (DOMRegionContext.XML_TAG_CLOSE.equals(nextType)) {
- // already at tag close
- formatStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
- return false;
- }
- else if (DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(nextType)) {
- // already at empty tag close
- formatEmptyStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
- return true;
- }
- else {
- availableLineWidth -= (currentTextRegion.getTextLength() + 2);
- boolean alignFinalBracket = getFormattingPreferences().getAlignFinalBracket();
- boolean oneSpaceInTagName = getFormattingPreferences().getSpaceBeforeEmptyCloseTag();
- boolean indentMultipleAttribute = getFormattingPreferences().getIndentMultipleAttributes();
- // indicates if tag spanned more than one line
- boolean spanMoreThan1Line = false;
- // indicates if all attributes should be indented
- boolean indentAllAttributes = false;
- if (indentMultipleAttribute) {
- int attributesCount = 0;
- int i = 2;
- while (i < textRegions.size() && attributesCount < 2) {
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegions.get(i).getType()))
- ++attributesCount;
- }
- indentAllAttributes = (attributesCount > 1);
- }
-
- while ((currentTextRegionIndex + 1) < textRegions.size()) {
- nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
- nextType = nextTextRegion.getType();
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(nextType)) {
- boolean indentAttribute = indentAllAttributes;
- if (!indentAttribute)
- indentAttribute = shouldIndentBeforeAttribute(constraints, textRegions, availableLineWidth, currentTextRegionIndex, currentTextRegion, nextTextRegion);
- if (indentAttribute) {
- availableLineWidth = indentIfNotAlreadyIndented(textEdit, indentLevel + 1, currentDocumentRegion, currentTextRegion);
- spanMoreThan1Line = true;
- }
- else {
- // otherwise, insertSpaceAndCollapse
- insertSpaceAndCollapse(textEdit, currentDocumentRegion, availableLineWidth, currentTextRegion);
- // update available line width
- availableLineWidth -= (currentTextRegion.getTextLength() + 1);
- }
- }
- else if (DOMRegionContext.XML_TAG_CLOSE.equals(nextType)) {
- // if need to align bracket on next line, indent
- if (alignFinalBracket && spanMoreThan1Line) {
- availableLineWidth = indentIfNotAlreadyIndented(textEdit, indentLevel, currentDocumentRegion, currentTextRegion);
- --availableLineWidth; // for tag close itself
- }
- else {
- // otherwise, just delete space before tag close
- if (currentTextRegion.getTextLength() < currentTextRegion.getLength()) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- availableLineWidth -= (currentTextRegion.getTextLength() + 1);
- }
- }
- // update line width
- constraints.setAvailableLineWidth(availableLineWidth);
- return false;
- }
- else if (DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(nextType)) {
- int textLength = currentTextRegion.getTextLength();
- int regionLength = currentTextRegion.getLength();
-
- boolean thereAreSpaces = textLength < regionLength;
- if (!oneSpaceInTagName && thereAreSpaces) {
- // delete any trail spaces after tag name
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- availableLineWidth -= (currentTextRegion.getTextLength() + 2);
- }
- // insert a space and collapse ONLY IF it's specified
- else if (oneSpaceInTagName) {
- insertSpaceAndCollapse(textEdit, currentDocumentRegion, availableLineWidth, currentTextRegion);
- availableLineWidth -= (currentTextRegion.getTextLength() + 3);
- }
- // update line width
- constraints.setAvailableLineWidth(availableLineWidth);
- return true;
- }
- else {
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(currentType) && DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(nextType)) {
- if (currentTextRegion.getTextLength() < currentTextRegion.getLength()) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- }
- // update available width
- availableLineWidth -= currentTextRegion.getTextLength();
- }
- else if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(currentType) && DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(nextType)) {
- if (currentTextRegion.getTextLength() < currentTextRegion.getLength()) {
- deleteTrailingSpaces(textEdit, currentTextRegion, currentDocumentRegion);
- }
- // update available width
- availableLineWidth -= currentTextRegion.getTextLength();
- }
- else {
- // otherwise, insertSpaceAndCollapse
- insertSpaceAndCollapse(textEdit, currentDocumentRegion, availableLineWidth, currentTextRegion);
- // update available line width
- availableLineWidth -= (currentTextRegion.getTextLength() + 1);
- }
- }
- currentTextRegion = nextTextRegion;
- currentType = nextType;
- ++currentTextRegionIndex;
- }
- }
- }
- // update line width
- constraints.setAvailableLineWidth(availableLineWidth);
- return false;
- }
-
- /**
- * Format an XML comment structured document region.
- */
- private void formatComment(TextEdit textEdit, Position formatRange, XMLFormattingConstraints parentConstraints, DOMRegion currentDOMRegion, IStructuredDocumentRegion previousRegion) {
- IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
- int lineWidth = parentConstraints.getAvailableLineWidth() - currentRegion.getFullText().length();
- // Don't format if we're not exceeding the available line width, or if the whitespace
- // strategy is to preserve whitespace - But update line width.
- if(currentRegion == null || XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy()) || !fPreferences.getFormatCommentText()) {
- parentConstraints.setAvailableLineWidth(lineWidth);
- return;
- }
-
- Iterator it = currentRegion.getRegions().iterator();
- ITextRegion previous = null;
- if (previousRegion == null)
- previousRegion = currentRegion.getPrevious();
- // Iterate over each text region of the comment
- Node parent = currentDOMRegion.domNode.getParentNode();
- while(it.hasNext()) {
- ITextRegion text = (ITextRegion) it.next();
- String type = text.getType();
- if (type == DOMRegionContext.XML_COMMENT_OPEN) {
- int indentLevel = (parent != null && parent.getNodeType() == Node.DOCUMENT_NODE) ? 0 : 1;
- int width = formatCommentStart(textEdit, parentConstraints, indentLevel, currentRegion, previousRegion, text);
- parentConstraints.setAvailableLineWidth(width);
- }
- else if (type == DOMRegionContext.XML_COMMENT_TEXT) {
- int indentLevel = (parent != null && parent.getNodeType() == Node.DOCUMENT_NODE) ? -1 : parentConstraints.getIndentLevel();
- formatCommentContent(textEdit, parentConstraints, indentLevel, currentRegion, previous, text);
- }
- previous = text;
- }
- }
-
- private void formatCommentContent(TextEdit textEdit, XMLFormattingConstraints parentConstraints, int indentLevel, IStructuredDocumentRegion currentRegion, ITextRegion previous, ITextRegion region) {
- int lineWidth = parentConstraints.getAvailableLineWidth() - currentRegion.getFullText(previous).length();
- // If there's more text than line width available, format
- String text = currentRegion.getFullText(region);
- compressContent(textEdit, currentRegion, currentRegion.getStartOffset(region), indentLevel + 1, lineWidth, text);
- }
-
- private void compressContent(TextEdit textEdit, IStructuredDocumentRegion region, int startOffset, int indentLevel, int lineWidth, String text) {
- int length = text.length();
- int start = 0, end = 0;
- char c = 0;
- int resultLength = 0;
- boolean joinLines = fPreferences.getJoinCommentLines();
- boolean onOwnLine = false;
-
- String indent = getIndentString(indentLevel + 1);
-
- for (int i = 0; i < length; i++) {
- c = text.charAt(i);
- // Compress whitespace unless its a line delimiter and formatting does not permit joining lines
- if (Character.isWhitespace(c)) {
- if ((c != '\r' && c!= '\n') || joinLines) {
- // Just came off of a word
- if (start == end) {
- start = end = i;
- }
- end++;
- resultLength++;
- }
- else {
- // correct the indent of this line
- lineWidth = fPreferences.getMaxLineWidth();
- resultLength = 0;
- onOwnLine = true;
-
- // Compress any whitespace before the line delimiter
- if (start != end) {
- int replaceLength = end - start;
- textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, EMPTY));
- start = end = i;
- }
- }
- }
- else {
- // Transitioned to a new word
- if (start != end) {
- int replaceLength = end - start;
- if (onOwnLine) {
- // If content is on its own line, replace leading whitespace with proper indent
- textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, indent));
- resultLength -= (replaceLength - indent.length());
- onOwnLine = false;
- }
- else if (!(replaceLength == 1 && text.charAt(start) == ' ')) {
- textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, SPACE));
- resultLength -= (replaceLength - 1);
- }
- start = end = i;
- // Make sure the word starts on a new line
- if (resultLength > lineWidth) {
- lineWidth = fPreferences.getMaxLineWidth();
- resultLength = 0;
- textEdit.addChild(new InsertEdit(start + startOffset, getLineDelimiter(region) + indent));
- }
- }
- // Word is immediately after line delimiters, indent appropriately
- if (onOwnLine) {
- textEdit.addChild(new InsertEdit(i + startOffset, indent));
- onOwnLine = false;
- }
- resultLength++;
- }
- }
-
- // Clean up any dangling whitespace
- int replaceLength = end - start;
- indent = getIndentString(indentLevel);
- if (replaceLength == 0) { // No trailing whitespace
- textEdit.addChild(new InsertEdit(length + startOffset, (onOwnLine) ? indent : SPACE));
- }
- else {
- String whitespace = text.substring(start);
- String replacement = (onOwnLine) ? indent : SPACE;
- if (!whitespace.equals(replacement)) {
- textEdit.addChild(new ReplaceEdit(start + startOffset, replaceLength, replacement));
- }
- }
- }
-
- private int formatCommentStart(TextEdit textEdit, XMLFormattingConstraints parentConstraints, int indentLevel, IStructuredDocumentRegion currentRegion, IStructuredDocumentRegion previousRegion, ITextRegion region) {
- int lineWidth = parentConstraints.getAvailableLineWidth();
- if (previousRegion!=null&&(DOMRegionContext.XML_CONTENT.equals(previousRegion.getType()))) {
- String previousText = previousRegion.getFullText();
- String trailingWhitespace = getTrailingWhitespace(previousText);
- String delimiters = extractLineDelimiters(trailingWhitespace, previousRegion);
- if (delimiters != null && delimiters.length() > 0){// && previousText.length() == trailingWhitespace.length()) {
- // Format the comment if it's on a new line
- int offset = previousRegion.getEnd() - trailingWhitespace.length();
- lineWidth = indentIfNotAlreadyIndented(textEdit, currentRegion, parentConstraints.getIndentLevel() + indentLevel, offset, trailingWhitespace);
- }
- }
- return lineWidth;
- }
-
- /**
- * Returns either a String of whitespace or characters depending on
- * forWhitespace
- *
- * @param fullTextArray
- * the text array to look in
- * @param textOffset
- * the start offset to start searching
- * @param forWhitespace
- * true if should return whitespaces, false otherwise
- * @return a String of either all whitespace or all characters. Never
- * returns null
- */
- private String getCharacterRun(char[] fullTextArray, int textOffset, boolean forWhitespace) {
- StringBuffer characterRun = new StringBuffer();
- boolean nonCharacterFound = false;
- while (textOffset < fullTextArray.length && !nonCharacterFound) {
- char c = fullTextArray[textOffset];
- boolean isWhitespace = Character.isWhitespace(c);
- if ((forWhitespace && isWhitespace) || (!forWhitespace && !isWhitespace))
- characterRun.append(c);
- else
- nonCharacterFound = true;
- ++textOffset;
- }
- return characterRun.toString();
- }
-
- private String getTrailingWhitespace(String text) {
- StringBuffer whitespaceRun = new StringBuffer();
- int index = text.length() - 1;
- while(index >= 0) {
- char c = text.charAt(index--);
- if (Character.isWhitespace(c))
- whitespaceRun.insert(0, c);
- else
- break;
- }
- return whitespaceRun.toString();
- }
-
- private String getIndentString(int indentLevel) {
- StringBuffer indentString = new StringBuffer();
- String indent = getFormattingPreferences().getOneIndent();
- for (int i = 0; i < indentLevel; ++i) {
- indentString.append(indent);
- }
- return indentString.toString();
- }
-
- protected XMLFormattingPreferences getFormattingPreferences() {
- if (fPreferences == null)
- fPreferences = new XMLFormattingPreferences();
- return fPreferences;
- }
-
- protected void setFormattingPreferences(XMLFormattingPreferences preferences) {
- fPreferences = preferences;
- }
-
- /**
- * Indent if whitespaceRun does not already contain an indent
- *
- * @param textEdit
- * @param indentLevel
- * @param indentStartOffset
- * @param maxAvailableLineWidth
- * @param whitespaceRun
- * @return new available line width up to where indented
- */
- private int indentIfNotAlreadyIndented(TextEdit textEdit, IStructuredDocumentRegion currentRegion, int indentLevel, int indentStartOffset, String whitespaceRun) {
- int maxAvailableLineWidth = getFormattingPreferences().getMaxLineWidth();
-
- int availableLineWidth;
- String indentString = getIndentString(indentLevel);
- String lineDelimiter = getLineDelimiter(currentRegion);
- String newLineAndIndent = lineDelimiter + indentString;
-
- TextEdit indentation = null;
-
- // if not already correctly indented
- if (!newLineAndIndent.equals(whitespaceRun)) {
- if (getFormattingPreferences().getClearAllBlankLines()) {
- if (whitespaceRun != null) {
- // replace existing whitespace run
- indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
- }
- else {
- // just insert correct indent
- indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
- }
- }
- // Keep the empty lines
- else {
- // just insert correct indent
- if(whitespaceRun == null)
- indentation = new InsertEdit(indentStartOffset, newLineAndIndent);
- // Need to preserve the number of empty lines, but still indent on the current line properly
- else {
- String existingDelimiters = extractLineDelimiters(whitespaceRun, currentRegion);
- if(existingDelimiters != null && existingDelimiters.length() > 0) {
- String formatted = existingDelimiters + indentString;
- // Don't perform a replace if the formatted string is the same as the existing whitespaceRun
- if(!formatted.equals(whitespaceRun))
- indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), formatted);
- }
- // No blank lines to preserve - correct the indent
- else
- indentation = new ReplaceEdit(indentStartOffset, whitespaceRun.length(), newLineAndIndent);
- }
- }
- }
-
- if(indentation != null)
- textEdit.addChild(indentation);
- // update line width
- availableLineWidth = maxAvailableLineWidth - indentString.length();
- return availableLineWidth;
- }
-
- private int indentIfNotAlreadyIndented(TextEdit textEdit, int indentLevel, IStructuredDocumentRegion currentDocumentRegion, ITextRegion currentTextRegion) {
- // indent if not already indented
- int textLength = currentTextRegion.getTextLength();
- int regionLength = currentTextRegion.getLength();
- int indentStartOffset = currentDocumentRegion.getTextEndOffset(currentTextRegion);
- String fullText = currentDocumentRegion.getFullText(currentTextRegion);
- String whitespaceRun = fullText.substring(textLength, regionLength);
-
- // update line width
- int availableLineWidth = indentIfNotAlreadyIndented(textEdit, currentDocumentRegion, indentLevel, indentStartOffset, whitespaceRun);
- return availableLineWidth;
- }
-
- private int indentIfPossible(TextEdit textEdit, XMLFormattingConstraints thisConstraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion, String whitespaceStrategy, String indentStrategy, boolean addIndent) {
- int availableLineWidth = -1;
- // if there is no previous document region, there is no need to indent
- // because we're at beginning of document
- if (previousDocumentRegion == null)
- return availableLineWidth;
-
- // only indent if ignoring whitespace or if collapsing and
- // there was a whitespace character before this region
- boolean canIndent = false;
- String previousRegionFullText = null;
- String previousRegionType = null;
-
- if ((XMLFormattingConstraints.IGNORE.equals(whitespaceStrategy)) || XMLFormattingConstraints.IGNOREANDTRIM.equals(whitespaceStrategy)) {
- // if ignoring, need to check if previous region was cdata
- previousRegionType = previousDocumentRegion.getType();
- if (DOMRegionContext.XML_CDATA_TEXT.equals(previousRegionType))
- canIndent = false;
- else
- canIndent = true;
- }
- else if (XMLFormattingConstraints.COLLAPSE.equals(whitespaceStrategy)) {
- // if collapsing, need to check if previous region ended in a
- // whitespace
- previousRegionType = previousDocumentRegion.getType();
- if (DOMRegionContext.XML_CONTENT.equals(previousRegionType)) {
- previousRegionFullText = previousDocumentRegion.getFullText();
- int length = previousRegionFullText.length();
- if (length > 1)
- canIndent = Character.isWhitespace(previousRegionFullText.charAt(length - 1));
- }
- }
- if (canIndent) {
- int indentStartOffset = currentDocumentRegion.getStartOffset();
- String whitespaceRun = null;
-
- // get previous region type if it was not previously retrieved
- if (previousRegionType == null)
- previousRegionType = previousDocumentRegion.getType();
-
- // get previous region's text if it was not previously retrieved
- if (previousRegionFullText == null && DOMRegionContext.XML_CONTENT.equals(previousRegionType))
- previousRegionFullText = previousDocumentRegion.getFullText();
-
- // if previous region was only whitespace, this may
- // already be indented, so need to make sure
- if ((previousRegionFullText != null) && (previousRegionFullText.trim().length() == 0)) {
- indentStartOffset = previousDocumentRegion.getStartOffset();
- whitespaceRun = previousRegionFullText;
- }
- if ((previousRegionFullText != null) && (whitespaceRun == null) && !getFormattingPreferences().getClearAllBlankLines()) {
- whitespaceRun = getTrailingWhitespace(previousRegionFullText);
- indentStartOffset = previousDocumentRegion.getEndOffset() - whitespaceRun.length();
- }
-
- int indentLevel = thisConstraints.getIndentLevel();
- if (addIndent && XMLFormattingConstraints.INDENT.equals(indentStrategy)) {
- ++indentLevel;
- thisConstraints.setIndentLevel(indentLevel);
- }
-
- // indent if not already indented
- availableLineWidth = indentIfNotAlreadyIndented(textEdit, currentDocumentRegion, indentLevel, indentStartOffset, whitespaceRun);
- }
- return availableLineWidth;
- }
-
- /**
- * Allow exactly one whitespace in currentTextRegion. If there are more,
- * collapse to one. If there are none, insert one.
- *
- * @param textEdit
- * @param currentDocumentRegion
- * @param availableLineWidth
- * @param currentTextRegion
- */
- private void insertSpaceAndCollapse(TextEdit textEdit, IStructuredDocumentRegion currentDocumentRegion, int availableLineWidth, ITextRegion currentTextRegion) {
- int textLength = currentTextRegion.getTextLength();
- int regionLength = currentTextRegion.getLength();
- boolean thereAreSpaces = textLength < regionLength;
- int spacesStartOffset = currentDocumentRegion.getStartOffset(currentTextRegion) + textLength;
-
- if (thereAreSpaces) {
- String fullTagName = currentDocumentRegion.getFullText(currentTextRegion);
- String whitespaceRun = fullTagName.substring(textLength, regionLength);
- collapseSpaces(textEdit, spacesStartOffset, availableLineWidth, whitespaceRun);
- }
- else {
- // insert a space
- InsertEdit insertEdit = new InsertEdit(spacesStartOffset, SPACE);
- textEdit.addChild(insertEdit);
- }
- }
-
- private boolean shouldIndentBeforeAttribute(XMLFormattingConstraints constraints, ITextRegionList textRegions, int availableLineWidth, int currentTextRegionIndex, ITextRegion currentTextRegion, ITextRegion nextTextRegion) {
- boolean indentAttribute = false;
-
- // look ahead to see if going to hit max line width
- // something attrName
- int currentWidth = currentTextRegion.getTextLength() + nextTextRegion.getTextLength() + 1;
- if (currentWidth > availableLineWidth)
- indentAttribute = true;
- else {
- if ((currentTextRegionIndex + 2) < textRegions.size()) {
- // still okay, so try next region
- // something attrName=
- ITextRegion textRegion = textRegions.get(currentTextRegionIndex + 2);
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(textRegion.getType())) {
- ++currentWidth;
- if (currentWidth > availableLineWidth)
- indentAttribute = true;
- else {
- if ((currentTextRegionIndex + 3) < textRegions.size()) {
- // still okay, so try next region
- // something attrName=attrValue
- textRegion = textRegions.get(currentTextRegionIndex + 3);
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(textRegion.getType())) {
- currentWidth = +textRegion.getTextLength();
- if (currentWidth > availableLineWidth)
- indentAttribute = true;
- }
- }
- }
- }
- }
- }
- return indentAttribute;
- }
-
- /**
- * Given the provided information (parentConstraints & currentDOMRegion),
- * update the formatting constraints (for this & child)
- *
- * @param parentConstraints
- * can be null
- * @param thisConstraints
- * can be null
- * @param childConstraints
- * can be null
- * @param currentDOMRegion
- * cannot be null
- */
- protected void updateFormattingConstraints(XMLFormattingConstraints parentConstraints, XMLFormattingConstraints thisConstraints, XMLFormattingConstraints childConstraints, DOMRegion currentDOMRegion) {
- IStructuredDocumentRegion currentRegion = currentDOMRegion.documentRegion;
- IDOMNode currentNode = currentDOMRegion.domNode;
-
- // default to whatever parent's constraint said to do
- if (parentConstraints != null) {
- if (thisConstraints != null) {
- thisConstraints.copyConstraints(parentConstraints);
- }
- if (childConstraints != null) {
- childConstraints.copyConstraints(parentConstraints);
- // if whitespace strategy was only a hint, null it out so
- // defaults are taken instead
- if (parentConstraints.isWhitespaceStrategyAHint())
- childConstraints.setWhitespaceStrategy(null);
- }
- }
-
- // set up constraints for direct children of document root
- Node parentNode = currentNode.getParentNode();
- if (parentNode != null && parentNode.getNodeType() == Node.DOCUMENT_NODE) {
- if (thisConstraints != null) {
- thisConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
- thisConstraints.setIndentStrategy(XMLFormattingConstraints.NEW_LINE);
- thisConstraints.setIndentLevel(0);
- }
- if (childConstraints != null) {
- childConstraints.setWhitespaceStrategy(null);
- childConstraints.setIndentStrategy(null);
- childConstraints.setIndentLevel(0);
- }
- }
-
- // other conditions to check when setting up child constraints
- if (childConstraints != null) {
- XMLFormattingPreferences preferences = getFormattingPreferences();
-
- // if we're at document root, child tags should always just start
- // on a new line and have an indent level of 0
- if (currentNode.getNodeType() == Node.DOCUMENT_NODE) {
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
- childConstraints.setIndentStrategy(XMLFormattingConstraints.NEW_LINE);
- childConstraints.setIndentLevel(0);
- }
- else {
- // BUG108074 & BUG84688 - preserve whitespace in xsl:text &
- // xsl:attribute
- String nodeNamespaceURI = currentNode.getNamespaceURI();
- if (XSL_NAMESPACE.equals(nodeNamespaceURI)) {
- String nodeName = ((Element) currentNode).getLocalName();
- if (XSL_ATTRIBUTE.equals(nodeName) || XSL_TEXT.equals(nodeName)) {
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
- }
- }
- else {
- // search within current tag for xml:space attribute
- ITextRegionList textRegions = currentRegion.getRegions();
- int i = 0;
- boolean xmlSpaceFound = false;
- boolean preserveFound = false;
- while (i < textRegions.size() && !xmlSpaceFound) {
- ITextRegion textRegion = textRegions.get(i);
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegion.getType())) {
- String regionText = currentRegion.getText(textRegion);
- if (XML_SPACE.equals(regionText)) {
- if ((i + 1) < textRegions.size()) {
- ++i;
- textRegion = textRegions.get(i);
- if (DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS.equals(textRegion.getType()) && ((i + 1) < textRegions.size())) {
- ++i;
- textRegion = textRegions.get(i);
- regionText = currentRegion.getText(textRegion);
- if (PRESERVE.equals(regionText) || PRESERVE_QUOTED.equals(regionText)) {
- preserveFound = true;
- }
- }
- }
- xmlSpaceFound = true;
- }
- }
- ++i;
- }
- if (xmlSpaceFound) {
- if (preserveFound) {
- // preserve was found so set the strategy
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
- }
- else {
- // xml:space was found but it was not collapse, so
- // use default whitespace strategy
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.DEFAULT);
- }
- }
- else {
- // how to hande nodes that have nonwhitespace text
- // content
- NodeList nodeList = currentNode.getChildNodes();
- int length = nodeList.getLength();
- int index = 0;
- boolean textNodeFound = false;
- // BUG214516 - If the parent constraint is to preserve whitespace, child constraints should
- // still reflect the parent constraints
- while (index < length && !textNodeFound && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
- Node childNode = nodeList.item(index);
- if (childNode.getNodeType() == Node.TEXT_NODE) {
- textNodeFound = !((IDOMText) childNode).isElementContentWhitespace();
- }
- ++index;
- }
- if (textNodeFound) {
- if (length > 1) {
- // more in here than just text, so consider
- // this mixed content
- childConstraints.setWhitespaceStrategy(preferences.getMixedWhitespaceStrategy());
- childConstraints.setIndentStrategy(preferences.getMixedIndentStrategy());
- }
- else {
- // there's only text
- childConstraints.setWhitespaceStrategy(preferences.getTextWhitespaceStrategy());
- childConstraints.setIndentStrategy(preferences.getTextIndentStrategy());
- }
- childConstraints.setIsWhitespaceStrategyAHint(true);
- childConstraints.setIsIndentStrategyAHint(true);
- }
-
- // try referring to content model for information on
- // whitespace & indent strategy
- ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) currentNode.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
- CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(currentNode);
- if (elementDeclaration != null) {
- // follow whitespace strategy preference for
- // pcdata content
- int contentType = elementDeclaration.getContentType();
-
- String facetValue = null;
- if(elementDeclaration.getDataType() != null)
- facetValue = (String) elementDeclaration.getDataType().getProperty(PROPERTY_WHITESPACE_FACET);
- if(facetValue != null) {
- if(PRESERVE.equals(facetValue))
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
- // For XSD types, "collapse" corresponds to the IGNOREANDTRIM strategy
- else if(COLLAPSE.equals(facetValue))
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNOREANDTRIM);
- else if(REPLACE.equals(facetValue))
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.REPLACE);
- }
- else if (contentType == CMElementDeclaration.PCDATA && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
- childConstraints.setWhitespaceStrategy(preferences.getPCDataWhitespaceStrategy());
- }
- else if (contentType == CMElementDeclaration.ELEMENT && parentConstraints != null && !XMLFormattingConstraints.PRESERVE.equals(parentConstraints.getWhitespaceStrategy())) {
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.IGNORE);
- childConstraints.setIndentStrategy(XMLFormattingConstraints.INDENT);
- childConstraints.setIsWhitespaceStrategyAHint(true);
- childConstraints.setIsIndentStrategyAHint(true);
- }
- else {
- // look for xml:space in content model
- CMNamedNodeMap cmAttributes = elementDeclaration.getAttributes();
-
- // Not needed - we're looking for xml:space
- //CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(cmAttributes);
- //List nodes = ModelQueryUtil.getModelQuery(currentNode.getOwnerDocument()).getAvailableContent((Element) currentNode, elementDeclaration, ModelQuery.INCLUDE_ATTRIBUTES);
- //for (int k = 0; k < nodes.size(); k++) {
- // CMNode cmnode = (CMNode) nodes.get(k);
- // if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
- // allAttributes.put(cmnode);
- // }
- //}
- //cmAttributes = allAttributes;
-
- // Check implied values from the DTD way.
- CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
- if (attributeDeclaration != null) {
- // CMAttributeDeclaration found, check
- // it
- // out.
-
- //BUG214516/196544 - Fixed NPE that was caused by an attr having
- // a null attr type
- String defaultValue = null;
- CMDataType attrType = attributeDeclaration.getAttrType();
- if (attrType != null) {
- if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && attrType.getImpliedValue() != null)
- defaultValue = attrType.getImpliedValue();
- else if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
- defaultValue = attrType.getEnumeratedValues()[0];
- }
- }
-
- // xml:space="preserve" means preserve
- // space,
- // everything else means back to
- // default.
- if (PRESERVE.equals(defaultValue))
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.PRESERVE);
- else
- childConstraints.setWhitespaceStrategy(XMLFormattingConstraints.DEFAULT);
- }
- // If the node has no attributes, inherit the parents whitespace strategy
- else {
- if (parentConstraints != null)
- childConstraints.setWhitespaceStrategy(parentConstraints.getWhitespaceStrategy());
- else
- childConstraints.setWhitespaceStrategy(null);
- }
- }
- }
- }
- }
- }
- // set default values according to preferences
- if (childConstraints.getWhitespaceStrategy() == null) {
- childConstraints.setWhitespaceStrategy(preferences.getElementWhitespaceStrategy());
- }
- if (childConstraints.getIndentStrategy() == null) {
- childConstraints.setIndentStrategy(preferences.getElementIndentStrategy());
- }
- }
- }
-
- /**
- * Calculates the current available line width given fullText.
- *
- * @param fullText
- * @param availableLineWidth
- * @param maxAvailableLineWidth
- * @return
- */
- private int updateLineWidthWithLastLine(String fullText, int availableLineWidth) {
- int maxAvailableLineWidth = getFormattingPreferences().getMaxLineWidth();
- int lineWidth = availableLineWidth;
- if (fullText != null) {
- int textLength = fullText.length();
- // update available line width
- // find last newline
- int lastLFOffset = fullText.lastIndexOf('\n');
- int lastCROffset = fullText.lastIndexOf('\r');
- // all text was on 1 line
- if (lastLFOffset == -1 && lastCROffset == -1) {
- // just subtract text length from current
- // available line width
- lineWidth -= fullText.length();
- }
- else {
- // calculate available line width of last line
- int lastNewLine = Math.max(lastLFOffset, lastCROffset);
- lineWidth = maxAvailableLineWidth - (textLength - lastNewLine);
- }
- }
- return lineWidth;
- }
-
- private String getLineDelimiter(IStructuredDocumentRegion currentRegion) {
- IStructuredDocument doc = currentRegion.getParentDocument();
- int line = doc.getLineOfOffset(currentRegion.getStartOffset());
- String lineDelimiter = doc.getLineDelimiter();
- try {
- if (line > 0) {
- lineDelimiter = doc.getLineDelimiter(line - 1);
- }
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- // BUG115716: if cannot get line delimiter from current line, just
- // use default line delimiter
- if (lineDelimiter == null)
- lineDelimiter = doc.getLineDelimiter();
- return lineDelimiter;
- }
-
- private String extractLineDelimiters(String base, IStructuredDocumentRegion currentRegion) {
- String lineDelimiter = getLineDelimiter(currentRegion);
- StringBuffer sb = new StringBuffer();
- for(int index = 0; index < base.length();) {
- index = base.indexOf(lineDelimiter, index);
- if(index++ >= 0)
- sb.append(lineDelimiter);
- else
- break;
- }
- return sb.toString();
- }
-
- void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor = monitor;
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormatterFormatProcessor.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormatterFormatProcessor.java
deleted file mode 100644
index e02ee7e4cb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormatterFormatProcessor.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 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
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.formatter;
-
-import java.io.IOException;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jface.text.DocumentRewriteSession;
-import org.eclipse.jface.text.DocumentRewriteSessionType;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension4;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Node;
-
-/**
- * This is a wrapper for the new xml formatter so that it can be still
- * considered an IStruturedFormatProcessor
- */
-public class XMLFormatterFormatProcessor implements IStructuredFormatProcessor {
- private DefaultXMLPartitionFormatter fFormatter = null;
- private IProgressMonitor fProgressMonitor = null;
-
- public void formatDocument(IDocument document, int start, int length) throws IOException, CoreException {
- if (document instanceof IStructuredDocument) {
- IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
- if (model != null) {
- try {
- formatModel(model, start, length);
- }
- finally {
- model.releaseFromEdit();
- }
- }
- }
- }
-
- public void formatFile(IFile file) throws IOException, CoreException {
- if (file == null)
- return;
-
- IStructuredModel structuredModel = null;
- // OutputStream outputStream = null;
- try {
- // setup structuredModel
- // Note: We are getting model for edit. Will save model if model
- // changed.
- structuredModel = StructuredModelManager.getModelManager().getModelForEdit(file);
-
- // format
- formatModel(structuredModel);
-
- // save model if needed
- if (!structuredModel.isSharedForEdit() && structuredModel.isSaveNeeded())
- structuredModel.save();
- }
- finally {
- // ensureClosed(outputStream, null);
- // release from model manager
- if (structuredModel != null) {
- structuredModel.releaseFromEdit();
- }
-
- }
- }
-
- public void formatModel(IStructuredModel structuredModel) {
- int start = 0;
- int length = structuredModel.getStructuredDocument().getLength();
-
- formatModel(structuredModel, start, length);
- }
-
- public void formatModel(IStructuredModel structuredModel, int start, int length) {
- if(fProgressMonitor != null)
- fProgressMonitor.beginTask("", 2);
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- DocumentRewriteSession activeRewriteSession = ((IDocumentExtension4) structuredDocument).getActiveRewriteSession();
- boolean startedRewriteSession = false;
- if (activeRewriteSession == null) {
- activeRewriteSession = ((IDocumentExtension4) structuredDocument).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
- startedRewriteSession = true;
- }
- getFormatter().setProgressMonitor(new NullProgressMonitor() {
- public boolean isCanceled() {
- return fProgressMonitor != null && fProgressMonitor.isCanceled();
- }
- });
- TextEdit edit = getFormatter().format(structuredModel, start, length);
- if(fProgressMonitor != null)
- fProgressMonitor.worked(1);
-
- try {
- structuredModel.aboutToChangeModel();
- edit.apply(structuredDocument);
- if(fProgressMonitor != null)
- fProgressMonitor.worked(1);
- }
- catch (Exception e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- finally {
- if (startedRewriteSession && activeRewriteSession != null) {
- ((IDocumentExtension4) structuredDocument).stopRewriteSession(activeRewriteSession);
- }
- structuredModel.changedModel();
- if(fProgressMonitor != null)
- fProgressMonitor.done();
- }
- }
-
- public void formatNode(Node node) {
- if (node instanceof IDOMNode) {
- IDOMNode domNode = (IDOMNode) node;
- formatModel(domNode.getModel(), domNode.getStartOffset(), domNode.getLength());
- }
- }
-
- public void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor = monitor;
- }
-
- private DefaultXMLPartitionFormatter getFormatter() {
- if (fFormatter == null) {
- fFormatter = new DefaultXMLPartitionFormatter();
- }
- return fFormatter;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingConstraints.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingConstraints.java
deleted file mode 100644
index fa2a53b45c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingConstraints.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 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
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.formatter;
-
-
-public class XMLFormattingConstraints {
- public final static String PRESERVE = "PRESERVE"; //$NON-NLS-1$
- public final static String COLLAPSE = "COLLAPSE"; //$NON-NLS-1$
- public final static String IGNORE = "IGNORE"; //$NON-NLS-1$
- public final static String IGNOREANDTRIM = "IGNOREANDTRIM"; //$NON-NLS-1$
- public final static String DEFAULT = "DEFAULT"; //$NON-NLS-1$
- public final static String REPLACE = "REPLACE"; //$NON-NLS-1$
-
- public final static String INDENT = "INDENT"; //$NON-NLS-1$
- public final static String NEW_LINE = "NEW_LINE"; //$NON-NLS-1$
- public final static String INLINE = "INLINE"; //$NON-NLS-1$
-
- private int fAvailableLineWidth = 0;
- private int fIndentLevel = 0;
- private String fIndentStrategy;
- private String fWhitespaceStrategy;
- private boolean fIsIndentStrategyAHint = false;
- private boolean fIsWhitespaceStrategyAHint = false;
-
- /**
- * Initializes the values in this formatting constraint with values from
- * constraints
- *
- * @param constraints
- * cannot be null
- */
- public void copyConstraints(XMLFormattingConstraints constraints) {
- setAvailableLineWidth(constraints.getAvailableLineWidth());
- setIndentLevel(constraints.getIndentLevel());
- setIndentStrategy(constraints.getIndentStrategy());
- setWhitespaceStrategy(constraints.getWhitespaceStrategy());
- }
-
- public int getAvailableLineWidth() {
- return fAvailableLineWidth;
- }
-
- public void setAvailableLineWidth(int lineWidth) {
- fAvailableLineWidth = lineWidth;
- }
-
- public int getIndentLevel() {
- return fIndentLevel;
- }
-
- public void setIndentLevel(int indentLevel) {
- fIndentLevel = indentLevel;
- }
-
- public String getIndentStrategy() {
- return fIndentStrategy;
- }
-
- public void setIndentStrategy(String indentStrategy) {
- fIndentStrategy = indentStrategy;
- }
-
- public String getWhitespaceStrategy() {
- return fWhitespaceStrategy;
- }
-
- public void setWhitespaceStrategy(String whitespaceStrategy) {
- fWhitespaceStrategy = whitespaceStrategy;
- }
-
- public boolean isIndentStrategyAHint() {
- return fIsIndentStrategyAHint;
- }
-
- public void setIsIndentStrategyAHint(boolean isIndentStrategyAHint) {
- fIsIndentStrategyAHint = isIndentStrategyAHint;
- }
-
- public boolean isWhitespaceStrategyAHint() {
- return fIsWhitespaceStrategyAHint;
- }
-
- public void setIsWhitespaceStrategyAHint(boolean isWhitespaceStrategyAHint) {
- fIsWhitespaceStrategyAHint = isWhitespaceStrategyAHint;
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java
deleted file mode 100644
index 61c1b46fb0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/formatter/XMLFormattingPreferences.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 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
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.formatter;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-
-public class XMLFormattingPreferences {
- public final static String PRESERVE = XMLFormattingConstraints.PRESERVE;
- public final static String COLLAPSE = XMLFormattingConstraints.COLLAPSE;
- public final static String IGNORE = XMLFormattingConstraints.IGNORE;
-
- public final static String INDENT = XMLFormattingConstraints.INDENT;
- public final static String NEW_LINE = XMLFormattingConstraints.NEW_LINE;
- public final static String INLINE = XMLFormattingConstraints.INLINE;
-
- private int fMaxLineWidth = 72;
- private boolean fAlignFinalBracket = false;
- private boolean fSpaceBeforeEmptyCloseTag = true;
- private boolean fIndentMultipleAttributes = false;
- private boolean fFormatCommentText = true;
- private boolean fJoinCommentLines = false;
-
- private String fPCDataWhitespaceStrategy = XMLFormattingConstraints.PRESERVE;
- private String fTextIndentStrategy = XMLFormattingConstraints.INLINE;
- private String fTextWhitespaceStrategy = XMLFormattingConstraints.COLLAPSE;
- private String fElementIndentStrategy = XMLFormattingConstraints.INDENT;
- private String fElementWhitespaceStrategy = XMLFormattingConstraints.IGNORE;
- private String fMixedIndentStrategy = XMLFormattingConstraints.INDENT;
- private String fMixedWhitespaceStrategy = XMLFormattingConstraints.IGNORE;
- private String fOneIndent = "\t"; //$NON-NLS-1$
- private boolean fClearAllBlankLines = false;
-
- public XMLFormattingPreferences() {
- Preferences preferences = XMLCorePlugin.getDefault().getPluginPreferences();
- if (preferences != null) {
- setFormatCommentText(preferences.getBoolean(XMLCorePreferenceNames.FORMAT_COMMENT_TEXT));
- setJoinCommentLines(preferences.getBoolean(XMLCorePreferenceNames.FORMAT_COMMENT_JOIN_LINES));
-
- setMaxLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
- setIndentMultipleAttributes(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
- setAlignFinalBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
- setSpaceBeforeEmptyCloseTag(preferences.getBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG));
-
- boolean preservepcdata = preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT);
- if (preservepcdata)
- fPCDataWhitespaceStrategy = XMLFormattingPreferences.PRESERVE;
- else
- fPCDataWhitespaceStrategy = XMLFormattingPreferences.COLLAPSE;
-
- char indentChar = ' ';
- String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
- if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
- indentChar = '\t';
- }
- int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
-
- StringBuffer indent = new StringBuffer();
- for (int i = 0; i < indentationWidth; i++) {
- indent.append(indentChar);
- }
- setOneIndent(indent.toString());
- setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
- }
- }
-
- public int getMaxLineWidth() {
- return fMaxLineWidth;
- }
-
- public boolean getFormatCommentText() {
- return fFormatCommentText;
- }
-
- public boolean getAlignFinalBracket() {
- return fAlignFinalBracket;
- }
-
- public boolean getSpaceBeforeEmptyCloseTag() {
- return fSpaceBeforeEmptyCloseTag;
- }
-
- public boolean getIndentMultipleAttributes() {
- return fIndentMultipleAttributes;
- }
-
- public String getPCDataWhitespaceStrategy() {
- return fPCDataWhitespaceStrategy;
- }
-
- public String getTextIndentStrategy() {
- return fTextIndentStrategy;
- }
-
- public String getTextWhitespaceStrategy() {
- return fTextWhitespaceStrategy;
- }
-
- public String getElementIndentStrategy() {
- return fElementIndentStrategy;
- }
-
- public String getElementWhitespaceStrategy() {
- return fElementWhitespaceStrategy;
- }
-
- public boolean getJoinCommentLines() {
- return fJoinCommentLines;
- }
-
- public void setJoinCommentLines(boolean joinCommentLines) {
- fJoinCommentLines = joinCommentLines;
- }
-
- public void setFormatCommentText(boolean formatCommentText) {
- fFormatCommentText = formatCommentText;
- }
-
- public void setSpaceBeforeEmptyCloseTag(boolean spaceBeforeEmptyCloseTag) {
- fSpaceBeforeEmptyCloseTag = spaceBeforeEmptyCloseTag;
- }
-
- public void setIndentMultipleAttributes(boolean indentMultipleAttributes) {
- fIndentMultipleAttributes = indentMultipleAttributes;
- }
-
- public void setPCDataWhitespaceStrategy(String dataWhitespaceStrategy) {
- fPCDataWhitespaceStrategy = dataWhitespaceStrategy;
- }
-
- public void setAlignFinalBracket(boolean alignFinalBracket) {
- fAlignFinalBracket = alignFinalBracket;
- }
-
- public String getMixedIndentStrategy() {
- return fMixedIndentStrategy;
- }
-
- public void setMixedIndentStrategy(String mixedIndentStrategy) {
- fMixedIndentStrategy = mixedIndentStrategy;
- }
-
- public String getMixedWhitespaceStrategy() {
- return fMixedWhitespaceStrategy;
- }
-
- public void setMixedWhitespaceStrategy(String mixedWhitespaceStrategy) {
- fMixedWhitespaceStrategy = mixedWhitespaceStrategy;
- }
-
- public String getOneIndent() {
- return fOneIndent;
- }
-
- protected void setMaxLineWidth(int maxLineWidth) {
- fMaxLineWidth = maxLineWidth;
- }
-
- protected void setOneIndent(String oneIndent) {
- fOneIndent = oneIndent;
- }
-
- public boolean getClearAllBlankLines() {
- return fClearAllBlankLines;
- }
-
- public void setClearAllBlankLines(boolean clearAllBlankLines) {
- fClearAllBlankLines = clearAllBlankLines;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/EmbeddedXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/EmbeddedXML.java
deleted file mode 100644
index abff1a4b8a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/EmbeddedXML.java
+++ /dev/null
@@ -1,95 +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.modelhandler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler;
-import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;
-import org.eclipse.wst.sse.core.internal.model.FactoryRegistry;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryAdapterFactoryForEmbeddedXML;
-
-
-public class EmbeddedXML implements EmbeddedTypeHandler {
-
- private static List supportedMimeTypes;
- public String ContentTypeID_EmbeddedXML = "org.eclipse.wst.xml.core.contenttype.EmbeddedXML"; //$NON-NLS-1$
-
- /**
- * Constructor for EmbeddedXML.
- */
- public EmbeddedXML() {
- super();
- }
-
- /*
- * @see EmbeddedContentType#getAdapterFactories()
- */
- public List getAdapterFactories() {
- List factories = new ArrayList();
- factories.add(new ModelQueryAdapterFactoryForEmbeddedXML());
- // factories.addAll(PluginContributedFactoryReader.getInstance().getFactories(this));
- return factories;
- }
-
- /**
- * @see EmbeddedContentType#getFamilyId()
- */
- public String getFamilyId() {
- return ModelHandlerForXML.AssociatedContentTypeID;
- }
-
- public List getSupportedMimeTypes() {
- if (supportedMimeTypes == null) {
- supportedMimeTypes = new ArrayList();
- supportedMimeTypes.add("application/xml"); //$NON-NLS-1$
- supportedMimeTypes.add("text/xml"); //$NON-NLS-1$
- }
- return supportedMimeTypes;
- }
-
- public void initializeFactoryRegistry(FactoryRegistry registry) {
- //TODO: initialize
- }
-
- public void initializeParser(RegionParser parser) {
- // nothing to initialize for "pure" XML
- // compare with XHTML
- }
-
- public boolean isDefault() {
- return false;
- }
-
- public EmbeddedTypeHandler newInstance() {
- return new EmbeddedXML();
- }
-
- public void uninitializeFactoryRegistry(FactoryRegistry registry) {
- // TODO: need to undo anything we did in initialize
-
- }
-
- public void uninitializeParser(RegionParser parser) {
- // need to undo anything we did in initialize
- }
-
- public boolean canHandleMimeType(String mimeType) {
- boolean canHandle = getSupportedMimeTypes().contains(mimeType);
- if(!canHandle) {
- canHandle = mimeType.endsWith("+xml"); //$NON-NLS-1$
- }
- return canHandle;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/ModelHandlerForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/ModelHandlerForXML.java
deleted file mode 100644
index f4bdf3c8be..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/ModelHandlerForXML.java
+++ /dev/null
@@ -1,59 +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.modelhandler;
-
-import org.eclipse.wst.sse.core.internal.document.IDocumentCharsetDetector;
-import org.eclipse.wst.sse.core.internal.document.IDocumentLoader;
-import org.eclipse.wst.sse.core.internal.ltk.modelhandler.AbstractModelHandler;
-import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler;
-import org.eclipse.wst.sse.core.internal.provisional.IModelLoader;
-import org.eclipse.wst.xml.core.internal.encoding.XMLDocumentCharsetDetector;
-import org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader;
-
-
-/**
- * Provides generic XML model handling. It is also marked as the default
- * content type handler. There should be only one implementation of the
- * default.
- */
-public class ModelHandlerForXML extends AbstractModelHandler implements IModelHandler {
- /**
- * Needs to match what's in plugin registry. In fact, can be overwritten
- * at run time with what's in registry! (so should never be 'final')
- */
- static String AssociatedContentTypeID = "org.eclipse.core.runtime.xml"; //$NON-NLS-1$
- /**
- * Needs to match what's in plugin registry. In fact, can be overwritten
- * at run time with what's in registry! (so should never be 'final')
- */
- private static String ModelHandlerID = "org.eclipse.wst.xml.core.modelhandler"; //$NON-NLS-1$
-
- public ModelHandlerForXML() {
- super();
- setId(ModelHandlerID);
- setAssociatedContentTypeId(AssociatedContentTypeID);
- }
-
- public IDocumentLoader getDocumentLoader() {
- return new XMLDocumentLoader();
- }
-
- public IDocumentCharsetDetector getEncodingDetector() {
- return new XMLDocumentCharsetDetector();
- }
-
- public IModelLoader getModelLoader() {
- return new XMLModelLoader();
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/XMLModelLoader.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/XMLModelLoader.java
deleted file mode 100644
index ecf9223690..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelhandler/XMLModelLoader.java
+++ /dev/null
@@ -1,93 +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.modelhandler;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.PropagatingAdapter;
-import org.eclipse.wst.sse.core.internal.document.IDocumentLoader;
-import org.eclipse.wst.sse.core.internal.model.AbstractModelLoader;
-import org.eclipse.wst.sse.core.internal.provisional.IModelLoader;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.xml.core.internal.DebugAdapterFactory;
-import org.eclipse.wst.xml.core.internal.document.DOMModelImpl;
-import org.eclipse.wst.xml.core.internal.encoding.XMLDocumentLoader;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryAdapterFactoryForXML;
-import org.eclipse.wst.xml.core.internal.propagate.PropagatingAdapterFactoryImpl;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-
-
-/**
- * This class reads an XML file and creates an XML Structured Model.
- *
- */
-public class XMLModelLoader extends AbstractModelLoader {
-
- // private static final String STR_ENCODING = "encoding"; //$NON-NLS-1$
-
- /**
- * XMLLoader constructor comment.
- */
- public XMLModelLoader() {
- super();
- }
-
- public List getAdapterFactories() {
- List result = new ArrayList();
- INodeAdapterFactory factory = null;
- factory = new ModelQueryAdapterFactoryForXML();
- result.add(factory);
- // Does XML need propagating adapter? Or just JSP?
- factory = new PropagatingAdapterFactoryImpl();
- result.add(factory);
- return result;
- }
-
- public IDocumentLoader getDocumentLoader() {
- if (documentLoaderInstance == null) {
- documentLoaderInstance = new XMLDocumentLoader();
- }
- return documentLoaderInstance;
- }
-
- public IModelLoader newInstance() {
- return new XMLModelLoader();
- }
-
- public IStructuredModel newModel() {
- return new DOMModelImpl();
- }
-
- protected void preLoadAdapt(IStructuredModel structuredModel) {
- super.preLoadAdapt(structuredModel);
- IDOMModel domModel = (IDOMModel) structuredModel;
- // if there is a model in the adapter, this will adapt it to
- // first node. After that the PropagatingAdater spreads over the
- // children being
- // created. Each time that happends, a side effect is to
- // also "spread" sprecific registered adapters,
- // they two can propigate is needed.
- ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
-
- if (Debug.debugNotificationAndEvents) {
- PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
- propagatingAdapter.addAdaptOnCreateFactory(new DebugAdapterFactory());
- }
-
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForEmbeddedXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForEmbeddedXML.java
deleted file mode 100644
index 805a9c1a23..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForEmbeddedXML.java
+++ /dev/null
@@ -1,50 +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.modelquery;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
-
-
-public class ModelQueryAdapterFactoryForEmbeddedXML extends ModelQueryAdapterFactoryForXML {
-
-
- /**
- * Constructor for ModelQueryAdapterFactoryForEmbeddedXML.
- */
- public ModelQueryAdapterFactoryForEmbeddedXML() {
- super(ModelQueryAdapter.class, false);
- }
-
- protected void configureDocumentManager(CMDocumentManager mgr) {
- super.configureDocumentManager(mgr);
- mgr.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
- }
-
- /**
- * ISSUE: this "forces" a new one to always be created/returned,
- * not "cached" on the node. That seems incorrect.
- * Simply using shouldRegisterFalse should work, except,
- * there might have been one there that someone else already
- * explicitly put there, so this is only way I know to
- * override that. Especially complicated here since a number
- * of adapters are for ModelQueryAdapter.class.
- */
- public INodeAdapter adapt(INodeNotifier object) {
- return adaptNew(object);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java
deleted file mode 100644
index cbb4add74b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryAdapterFactoryForXML.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.modelquery;
-
-
-
-import java.io.File;
-import java.net.URI;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapterImpl;
-
-
-public class ModelQueryAdapterFactoryForXML extends AbstractAdapterFactory {
-
- protected ModelQueryAdapterImpl modelQueryAdapterImpl;
- IStructuredModel stateNotifier = null;
- private InternalModelStateListener internalModelStateListener;
-
- /**
- * ModelQueryAdapterFactoryForXML constructor comment.
- */
- public ModelQueryAdapterFactoryForXML() {
- this(ModelQueryAdapter.class, true);
- }
-
- /**
- * ModelQueryAdapterFactoryForXML constructor comment.
- *
- * @param adapterKey
- * java.lang.Object
- * @param registerAdapters
- * boolean
- */
- protected ModelQueryAdapterFactoryForXML(Object adapterKey, boolean registerAdapters) {
- super(adapterKey, registerAdapters);
- }
-
- class InternalModelStateListener implements IModelStateListener {
-
- /**
- * @see IModelStateListener#modelAboutToBeChanged(IStructuredModel)
- */
- public void modelAboutToBeChanged(IStructuredModel model) {
- }
-
- /**
- * @see IModelStateListener#modelChanged(IStructuredModel)
- */
- public void modelChanged(IStructuredModel model) {
- }
-
- /**
- * @see IModelStateListener#modelDirtyStateChanged(IStructuredModel,
- * boolean)
- */
- public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
- }
-
- /**
- * @see IModelStateListener#modelResourceDeleted(IStructuredModel)
- */
- public void modelResourceDeleted(IStructuredModel model) {
- }
-
- /**
- * @see IModelStateListener#modelResourceMoved(IStructuredModel,
- * IStructuredModel)
- */
- public void modelResourceMoved(IStructuredModel oldModel, IStructuredModel newModel) {
- stateNotifier.removeModelStateListener(this);
- stateNotifier = newModel;
- updateResolver(stateNotifier);
- stateNotifier.addModelStateListener(this);
- }
-
- public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
- // TODO Auto-generated method stub
-
- }
-
- public void modelReinitialized(IStructuredModel structuredModel) {
- updateResolver(structuredModel);
-
- }
-
-
- }
-
- protected boolean autoLoadCM() {
- // until the existence of a CMDocumentRequesterFactory to create the
- // load requests,
- // return true
- return true;
- }
-
- protected void configureDocumentManager(CMDocumentManager mgr) {
- // this depends on there being a CMDocumentRequesterFactory installed
- mgr.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, autoLoadCM());
- }
-
- public INodeAdapterFactory copy() {
-
- return new ModelQueryAdapterFactoryForXML(getAdapterKey(), isShouldRegisterAdapter());
- }
-
- /**
- * createAdapter method comment.
- */
- protected INodeAdapter createAdapter(INodeNotifier target) {
-
- if (org.eclipse.wst.sse.core.internal.util.Debug.displayInfo)
- System.out.println("-----------------------ModelQueryAdapterFactoryForXML.createAdapter" + target); //$NON-NLS-1$
- if (modelQueryAdapterImpl == null) {
- if (target instanceof IDOMNode) {
- IDOMNode xmlNode = (IDOMNode) target;
- IStructuredModel model = xmlNode.getModel();
- stateNotifier = xmlNode.getModel();
- stateNotifier.addModelStateListener(getInternalModelStateListener());
-
- org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
- if (Debug.displayInfo)
- System.out.println("----------------ModelQueryAdapterFactoryForXML... baseLocation : " + resolver.getFileBaseLocation()); //$NON-NLS-1$
-
- /**
- * XMLCatalogIdResolver currently requires a filesystem
- * location string. Customarily this will be what is in the
- * deprecated SSE URIResolver and required by the Common URI
- * Resolver.
- */
- URIResolver idResolver = null;
- if (resolver != null) {
- idResolver = new XMLCatalogIdResolver(resolver.getFileBaseLocation(), resolver);
- }
- else {
- /*
- * 203649 - this block may be necessary due to ordering of
- * setting the resolver into the model
- */
- String baseLocation = null;
- String modelsBaseLocation = model.getBaseLocation();
- if (modelsBaseLocation != null) {
- File file = new Path(modelsBaseLocation).toFile();
- if (file.exists()) {
- baseLocation = file.getAbsolutePath();
- }
- else {
- IPath basePath = new Path(model.getBaseLocation());
- IResource derivedResource = null;
- if (basePath.segmentCount() > 1)
- derivedResource = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
- else
- derivedResource = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0));
- IPath derivedPath = derivedResource.getLocation();
- if (derivedPath != null) {
- baseLocation = derivedPath.toString();
- }
- else {
- URI uri = derivedResource.getLocationURI();
- if (uri != null) {
- baseLocation = uri.toString();
- }
- }
- }
- if(baseLocation == null) {
- baseLocation = modelsBaseLocation;
- }
- }
- idResolver = new XMLCatalogIdResolver(baseLocation, null);
- }
-
- CMDocumentCache cmDocumentCache = new CMDocumentCache();
- ModelQuery modelQuery = new XMLModelQueryImpl(cmDocumentCache, idResolver);
-
- // cs todo...
- // for now we create a CMDocumentCache on a 'per editor' basis
- // in the future we need to support a CMDocumentCache that is
- // shared between editors
- // nsd comment: may not be appropriate depending on
- CMDocumentManager documentManager = modelQuery.getCMDocumentManager();
- if (documentManager != null) {
- configureDocumentManager(documentManager);
- }
- modelQueryAdapterImpl = new ModelQueryAdapterImpl(cmDocumentCache, modelQuery, idResolver);
- }
- }
- return modelQueryAdapterImpl;
- }
-
- public void release() {
- super.release();
- if (stateNotifier != null)
- stateNotifier.removeModelStateListener(getInternalModelStateListener());
- stateNotifier = null;
- if (modelQueryAdapterImpl != null)
- modelQueryAdapterImpl.release();
- }
-
- protected void updateResolver(IStructuredModel model) {
-
- String baseLocation = model.getBaseLocation();
- IFile baseFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(model.getBaseLocation()));
- if (baseFile != null) {
- if (baseFile.getLocation() != null) {
- baseLocation = baseFile.getLocation().toString();
- }
- if (baseLocation == null && baseFile.getLocationURI() != null) {
- baseLocation = baseFile.getLocationURI().toString();
- }
- if (baseLocation == null) {
- baseLocation = baseFile.getFullPath().toString();
- }
- }
- else {
- baseLocation = model.getBaseLocation();
- }
- modelQueryAdapterImpl.setIdResolver(new XMLCatalogIdResolver(baseLocation, model.getResolver()));
- }
-
- private final InternalModelStateListener getInternalModelStateListener() {
- if (internalModelStateListener == null) {
- internalModelStateListener = new InternalModelStateListener();
- }
- return internalModelStateListener;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryUtil.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryUtil.java
deleted file mode 100644
index eae3e89082..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/ModelQueryUtil.java
+++ /dev/null
@@ -1,64 +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.modelquery;
-
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
-import org.w3c.dom.Document;
-
-
-/**
- * This class is used to associate ModelQuery (and related data) with a
- * Document (or IStructuredModel).
- */
-public class ModelQueryUtil {
-
- public static CMDocumentCache getCMDocumentCache(Document node) {
- ModelQueryAdapter modelQueryAdapter = getModelQueryAdapter(node);
- return modelQueryAdapter != null ? modelQueryAdapter.getCMDocumentCache() : null;
- }
-
- public static URIResolver getIdResolver(Document node) {
- ModelQueryAdapter modelQueryAdapter = getModelQueryAdapter(node);
- return modelQueryAdapter != null ? modelQueryAdapter.getIdResolver() : null;
- }
-
- public static ModelQuery getModelQuery(Document node) {
- ModelQueryAdapter modelQueryAdapter = getModelQueryAdapter(node);
- return modelQueryAdapter != null ? modelQueryAdapter.getModelQuery() : null;
- }
-
- public static ModelQuery getModelQuery(IStructuredModel model) {
- if ((!(model instanceof IDOMModel)) || model == null)
- return null;
- return getModelQuery(((IDOMModel) model).getDocument());
- }
-
- public static ModelQueryAdapter getModelQueryAdapter(Document node) {
- ModelQueryAdapter result = null;
-
- if (node instanceof INodeNotifier) {
- INodeNotifier notifier = (INodeNotifier) node;
- result = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
- }
-
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLCatalogIdResolver.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLCatalogIdResolver.java
deleted file mode 100644
index 61852f9ab6..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLCatalogIdResolver.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.modelquery;
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin;
-import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
-import org.eclipse.wst.sse.core.internal.util.URIResolver;
-import org.eclipse.wst.xml.core.internal.Logger;
-
-
-// TODO cs : remove this class and utilize the common URIResolver directly
-// We need to update some of the ModelQuery related code to pass the
-// 'baseLocation' thru
-// and then there'll be node need for this class.
-//
-public class XMLCatalogIdResolver implements org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver {
- protected String resourceLocation;
-
- protected URIResolver uriresolver;
-
- private XMLCatalogIdResolver() {
- super();
- }
-
- private XMLCatalogIdResolver(String resourceLocation) {
- this();
- this.resourceLocation = resourceLocation;
- }
-
- public XMLCatalogIdResolver(String resourceLocation, URIResolver uriresolver) {
- this(resourceLocation);
-// this constructor should not be called with two null arguments.
-// If so, an assert will occur later when resolve is called.
-// See 118371 XMLCatalogIdResolver#resolve throws AssertionFailedException
-//
-// but, I'm not enabling this check now due to lateness in cycle.
-// if (resourceLocation == null && uriresolver == null) {
-// throw new IllegalArgumentException("both location and resolver can not be null");
-// }
- this.uriresolver = uriresolver;
- }
-
-
- /**
- * Gets the resourceLocation.
- *
- * @return Returns a String
- */
- private String getResourceLocation() {
- String location = resourceLocation;
- if (location == null) {
- if (uriresolver != null)
- location = uriresolver.getFileBaseLocation();
- }
- return location;
- }
-
-
- public String resolve(String base, String publicId, String systemId) {
-
- String result = systemId;
- if (base == null) {
- base = getResourceLocation();
- // bug 117320, ensure base URI is 'protocal' qualified before
- // passing it thru to URIResolver
- // bug 117424, we should be able to assume that the base location
- // is non-null
-
- /**
- * We shouldn't assert a failure because the catalog does not
- * require a base location to operate and it will be called from
- * non-file-based scenarios.
- *
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=206176
- */
- // Assert.isNotNull(base, "Base location is expected to be non null."); //$NON-NLS-1$
- if (base != null) {
- base = URIHelper.addImpliedFileProtocol(base);
- }
- }
- result = URIResolverPlugin.createResolver().resolve(base, publicId, systemId);
- return result;
- }
-
- public String resolvePhysicalLocation(String baseLocation, String publicId, String logicalLocation) {
- // This class should never be called to perform physical resolution!
- // If it does we should log it as an error
- Logger.log(Logger.ERROR_DEBUG, "XMLCatalogIDResolver.resolvePhysicalLocation() called unexpectedly"); //$NON-NLS-1$
- return logicalLocation;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryAssociationProvider.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryAssociationProvider.java
deleted file mode 100644
index 74d14abb92..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryAssociationProvider.java
+++ /dev/null
@@ -1,60 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.modelquery;
-
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.XMLAssociationProvider;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-import org.w3c.dom.Document;
-
-/**
- * XMLModelQueryAssociationProvider
- *
- * This added and/or made public specifically for experimentation. It will
- * change as this functionality becomes API. See
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=119084
- *
- */
-public class XMLModelQueryAssociationProvider extends XMLAssociationProvider {
-
- protected URIResolver idResolver;
-
- public XMLModelQueryAssociationProvider(CMDocumentCache cache, URIResolver idResolver) {
- super(cache);
- this.idResolver = idResolver;
- }
-
- protected String resolveGrammarURI(Document document, String publicId, String systemId) {
-
- // CS : spooky code alert!
- // this look really strange because we're passing null in as the first
- // argument
- // however we're assuming the use of a 'fudged' URIResolver that knows
- // the
- // correct baseLocation and will call to the URIResolver framework
- // properly
-
- // CS : note that we should never call resolvePhysical at this point.
- // Physical resolution should only occur when we're interesting to
- // opening the actual stream.
- // The CMDocumentFactory implementation would be responsible for
- // calling resolvePhysical.
- // All we need to do here is return a 'logical' URI
-
- if (idResolver == null)
- return null;
- return idResolver.resolve(null, publicId, systemId);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryImpl.java
deleted file mode 100644
index 7bfa0014f0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/modelquery/XMLModelQueryImpl.java
+++ /dev/null
@@ -1,38 +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.modelquery;
-
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.MovableModelQuery;
-
-
-public class XMLModelQueryImpl extends ModelQueryImpl implements MovableModelQuery {
-
- protected CMDocumentCache fCache = null;
-
- public XMLModelQueryImpl(CMDocumentCache cache, URIResolver idResolver) {
- super(new XMLModelQueryAssociationProvider(cache, idResolver));
- fCache = cache;
- }
-
- /**
- * @see MovableModelQuery#setIdResolver(URIResolver)
- */
- public void setIdResolver(URIResolver newIdResolver) {
- modelQueryAssociationProvider = new XMLModelQueryAssociationProvider(fCache, newIdResolver);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/BlockStructuredDocumentRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/BlockStructuredDocumentRegion.java
deleted file mode 100644
index 7754a80622..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/BlockStructuredDocumentRegion.java
+++ /dev/null
@@ -1,46 +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.parser;
-
-
-
-import org.eclipse.wst.sse.core.internal.ltk.parser.IBlockedStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion;
-
-
-public class BlockStructuredDocumentRegion extends BasicStructuredDocumentRegion implements IBlockedStructuredDocumentRegion {
-
- private String partitionType;
-
- /**
- * A BlockStructuredDocumentRegion is like a IStructuredDocumentRegion,
- * but is the result of a "block scan".
- */
- public BlockStructuredDocumentRegion() {
- super();
- }
-
- public String getPartitionType() {
- if (partitionType == null) {
- // eventually can look up surroundingTag name
- // but this field is primarily entended for future
- // extensibility. This may change.
- //partitionType = "org.eclipse.wst.sse.core." + tagname;
- }
- return partitionType;
- }
-
- public void setPartitionType(String partitionType) {
- this.partitionType = partitionType;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/ContextRegionContainer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/ContextRegionContainer.java
deleted file mode 100644
index 0de33025b0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/ContextRegionContainer.java
+++ /dev/null
@@ -1,327 +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.parser;
-
-
-
-import org.eclipse.jface.text.BadLocationException;
-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.ITextRegionCollection;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
-import org.eclipse.wst.sse.core.internal.text.TextRegionListImpl;
-import org.eclipse.wst.xml.core.internal.Logger;
-
-
-public class ContextRegionContainer implements ITextRegionContainer {
- protected int length;
- protected ITextRegionCollection parent;
- protected ITextRegionList regions;
- protected int start;
- protected int textLength;
- protected String type;
-
- public ContextRegionContainer() {
- super();
- regions = new TextRegionListImpl();
-
- }
-
- /**
- * these "deep" parenting is not normal, but just in case.
- */
- private IStructuredDocument _getParentDocument() {
- // go up enough parents to get to document
- ITextRegionCollection parent = getParent();
- while (!(parent instanceof IStructuredDocumentRegion)) {
- // would be an error not to be container, but
- // won't check for it now
- parent = ((ITextRegionContainer) parent).getParent();
- }
- return ((IStructuredDocumentRegion) parent).getParentDocument();
- }
-
-
- public void adjust(int i) {
-
- start += i;
- // I erroneously added length and textLength
- // TODO: may want to rename this method to adjustStart
- //length += i;
- //textLength += i;
-
- }
-
- public void adjustLength(int i) {
- length += i;
- }
-
- public void adjustStart(int i) {
- start += i;
- }
-
-
- public void adjustTextLength(int i) {
- textLength += i;
-
- }
-
- public boolean containsOffset(int i) {
-
- return getStartOffset() <= i && i < getEndOffset();
- }
-
- public boolean containsOffset(ITextRegion containedRegion, int offset) {
- return getStartOffset(containedRegion) <= offset && offset < getEndOffset(containedRegion);
- }
-
- /**
- * This method is just to equate positions. clients may (will probably)
- * still need to make calls to equate regions, parent, etc.
- */
- public void equatePositions(ITextRegion region) {
- start = region.getStart();
- length = region.getLength();
- textLength = region.getTextLength();
- }
-
- public int getEnd() {
- return start + length;
- }
-
- public int getEndOffset() {
- // our startOffset take into account our parent, and our start
- return getStartOffset() + getLength();
- }
-
- public int getEndOffset(ITextRegion containedRegion) {
- return getStartOffset(containedRegion) + containedRegion.getLength();
- }
-
- public ITextRegion getFirstRegion() {
- return getRegions().get(0);
- }
-
- public String getFullText() {
- return getParent().getFullText(this);
- }
-
- public String getFullText(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion aRegion) {
- // Must be proxied here since aRegion should always be a child of
- // *this* container and indexed from
- // this container's offset
- return parent.getFullText().substring(start + aRegion.getStart(), start + aRegion.getEnd());
- }
-
- public ITextRegion getLastRegion() {
- return getRegions().get(getRegions().size() - 1);
- }
-
- public int getLength() {
- return length;
- }
-
-
- public int getNumberOfRegions() {
- return getRegions().size();
- }
-
- public ITextRegionCollection getParent() {
- return parent;
- }
-
- /**
- * The parameter offset refers to the overall offset in the document.
- */
- public ITextRegion getRegionAtCharacterOffset(int offset) {
- ITextRegion result = null;
- if (regions != null) {
- int thisStartOffset = getStartOffset();
- if (offset < thisStartOffset)
- return null;
- int thisEndOffset = getStartOffset() + getLength();
- if (offset > thisEndOffset)
- return null;
- // transform the requested offset to the "scale" that
- // regions are stored in, which are all relative to the
- // start point.
- //int transformedOffset = offset - getStartOffset();
- //
- ITextRegionList regions = getRegions();
- int length = regions.size();
- int low = 0;
- int high = length;
- int mid = 0;
- // Binary search for the region
- while (low < high) {
- mid = low + ((high - low) >> 1);
- ITextRegion region = regions.get(mid);
- if (org.eclipse.wst.sse.core.internal.util.Debug.debugStructuredDocument) {
- System.out.println("region(s) in IStructuredDocumentRegion::getRegionAtCharacterOffset: " + region); //$NON-NLS-1$
- System.out.println(" midpoint of search:" + mid); //$NON-NLS-1$
- System.out.println(" requested offset: " + offset); //$NON-NLS-1$
- //System.out.println(" transformedOffset: " +
- // transformedOffset); //$NON-NLS-1$
- System.out.println(" region start: " + region.getStart()); //$NON-NLS-1$
- System.out.println(" region end: " + region.getEnd()); //$NON-NLS-1$
- System.out.println(" region type: " + region.getType()); //$NON-NLS-1$
- System.out.println(" region class: " + region.getClass()); //$NON-NLS-1$
-
- }
- // Region is before this one
- if (offset < region.getStart() + thisStartOffset)
- high = mid;
- else if (offset > (region.getEnd() + thisStartOffset - 1))
- low = mid + 1;
- else
- return region;
- }
- return null;
- }
- return result;
- }
-
- public ITextRegionList getRegions() {
- return regions;
- }
-
- public int getStart() {
- return start;
- }
-
- public int getStartOffset() {
- return getParent().getStartOffset() + getStart();
- }
-
- public int getStartOffset(ITextRegion containedRegion) {
- // it is an error to pass null to this method
- // ISSUE: need better "spec" on error behavior:
- // for now will return zero as this will roughly
- // work for some cases (and avoid NPE).
- if (containedRegion == null) {
- return getStartOffset();
- }
- return getStartOffset() + containedRegion.getStart();
- }
-
- /**
- * same as getFullText for this region type ... do we need to take white
- * space off?
- */
-
- public String getText() {
- String result = null;
- try {
- IStructuredDocument parentDocument = _getParentDocument();
- result = parentDocument.get(start, length);
- } catch (BadLocationException e) {
- Logger.logException("program error: unreachable exception", e); //$NON-NLS-1$
- }
- return result;
- }
-
- public String getText(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion aRegion) {
- // Must be proxied here since aRegion should always be a child of
- // *this* container and indexed from
- // this container's offset
- return parent.getText().substring(start + aRegion.getStart(), start + aRegion.getTextEnd());
- }
-
- public int getTextEnd() {
- return start + textLength;
- }
-
- public int getTextEndOffset() {
- ITextRegion region = regions.get(regions.size() - 1);
- // our startOffset take into account our parent, and our start
- // (pa) 10/4 changed to be based on text end
- // it used to return incorrect value for embedded region containers
- //
-
- // TODO CRITICAL -- need to re-work this work around, so doesn't
- // depend on XMLRegionContext
- // // this is a workaround for 226823///////////
- // for (int i = regions.size() - 1; i >= 0 && region.getType() ==
- // XMLRegionContext.WHITE_SPACE; i--)
- // region = (ITextRegion) regions.get(i);
- // /////////////////////////////////////////////
-
- return getStartOffset() + region.getTextEnd();
- }
-
- public int getTextEndOffset(ITextRegion containedRegion) {
- int result = 0;
- if (regions != null) {
- int length = getRegions().size();
- for (int i = 0; i < length; i++) {
- ITextRegion region = getRegions().get(i);
- if (region == containedRegion) {
- result = getStartOffset(region) + region.getTextEnd();
- break;
- }
- }
- }
- return result;
- }
-
- public int getTextLength() {
- return textLength;
- }
-
- public String getType() {
- return type;
- }
-
- public void setLength(int i) {
- length = i;
- }
-
- public void setParent(ITextRegionCollection parentRegion) {
- parent = parentRegion;
- }
-
- public void setRegions(ITextRegionList containedRegions) {
- regions = containedRegions;
- }
-
- public void setStart(int i) {
- start = i;
- }
-
- public void setTextLength(int i) {
- textLength = i;
- }
-
- public void setType(String string) {
- type = string;
- }
-
- public String toString() {
- String className = getClass().getName();
- String shortClassName = className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$
- String result = "Container!!! " + shortClassName + "--> " + getType() + ": " + getStart() + "-" + getTextEnd() + (getTextEnd() != getEnd() ? ("/" + getEnd()) : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- return result;
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent result = null;
- // FUTURE_TO_DO: need to implement region level parsing in
- // ITextRegionContainer::updateModel
- // never being called?
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/IntStack.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/IntStack.java
deleted file mode 100644
index 5cb8d5a6f8..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/IntStack.java
+++ /dev/null
@@ -1,112 +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.parser;
-
-
-
-/*
- *
- * A non-resizable class implementing the behavior of java.util.Stack, but
- * directly for the <code> integer </code> primitive.
- */
-import java.util.EmptyStackException;
-
-public class IntStack {
- private int[] list = null;
-
- private int size = 0;
-
- public IntStack() {
- this(100);
- }
-
- public IntStack(int maxdepth) {
- super();
- list = new int[maxdepth];
- initialize();
- }
-
- public boolean empty() {
- return size == 0;
- }
-
- public int get(int slot) {
- return list[slot];
- }
-
- void initialize() {
- for (int i = 0; i < list.length; i++)
- list[i] = -1;
- }
-
- /**
- * Returns the int at the top of the stack without removing it
- *
- * @return int at the top of this stack.
- * @exception EmptyStackException
- * when empty.
- */
- public int peek() {
- if (size == 0)
- throw new EmptyStackException();
- return list[size - 1];
- }
-
- /**
- * Removes and returns the int at the top of the stack
- *
- * @return int at the top of this stack.
- * @exception EmptyStackException
- * when empty.
- */
- public int pop() {
- int value = peek();
- list[size - 1] = -1;
- size--;
- return value;
- }
-
- /**
- * Pushes an item onto the top of this stack.
- *
- * @param newValue -
- * the int to be pushed onto this stack.
- * @return the <code>newValue</code> argument.
- */
- public int push(int newValue) {
- if (size == list.length) {
- throw new StackOverflowError();
- }
- list[size++] = newValue;
- return newValue;
- }
-
- public int size() {
- return size;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer s = new StringBuffer(getClass().getName() + ":" +size + " [");
- for (int i = 0; i < size; i++) {
- s.append(list[i]);
- if(i < size - 1) {
- s.append(", ");
- }
- }
- s.append("]");
- return s.toString();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/RegionFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/RegionFactory.java
deleted file mode 100644
index 1315a77980..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/RegionFactory.java
+++ /dev/null
@@ -1,49 +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.parser;
-
-
-
-import org.eclipse.wst.sse.core.internal.parser.ContextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-
-
-public class RegionFactory {
-
- public RegionFactory() {
- super();
- }
-
- public ITextRegion createToken(ITextRegionContainer parent, String context, int start, int textLength, int length) {
- return this.createToken(parent, context, start, textLength, length, null, null);
- }
-
- public ITextRegion createToken(ITextRegionContainer parent, String context, int start, int textLength, int length, String lang, String surroundingTag) {
- ITextRegion newRegion = createToken(context, start, textLength, length);
- // DW, 4/16/2003 token regions no longer have parents
- //newRegion.setParent(parent);
- return newRegion;
- }
-
- public ITextRegion createToken(String context, int start, int textLength, int length) {
- return this.createToken(context, start, textLength, length, null, null);
- }
-
- public ITextRegion createToken(String context, int start, int textLength, int length, String lang, String surroundingTag) {
- ITextRegion newRegion = new ContextRegion(context, start, textLength, length);
- return newRegion;
-
-
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XML10Names.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XML10Names.java
deleted file mode 100644
index af91c63cf0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XML10Names.java
+++ /dev/null
@@ -1,595 +0,0 @@
-/* The following code was generated by JFlex 1.4 on 2/25/08 10:25 AM */
-
-/*******************************************************************************
- * Copyright (c) 2004,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
- * kb.huang - Bug 214416 Dot char is not escaped in XML10Names.jFlex
- *******************************************************************************/
-/*nlsXXX*/
-package org.eclipse.wst.xml.core.internal.parser;
-
-
-
-
-/**
- * This class is a scanner generated by
- * <a href="http://www.jflex.de/">JFlex</a> 1.4
- * on 2/25/08 10:25 AM from the specification file
- * <tt>XML10Names.jflex</tt>
- */
-public final class XML10Names {
-
- /** This character denotes the end of file */
- private static final int YYEOF = -1;
-
- /** initial size of the lookahead buffer */
- private static final int ZZ_BUFFERSIZE = 2048;
-
- /** lexical states */
- private static final int YYINITIAL = 0;
-
- /**
- * Translates characters to character classes
- */
- private static final String ZZ_CMAP_PACKED =
- "\12\0\1\3\42\0\1\2\1\2\1\0\12\2\1\1\6\0\32\1"+
- "\4\0\1\1\1\0\32\1\74\0\1\2\10\0\27\1\1\0\37\1"+
- "\1\0\72\1\2\0\13\1\2\0\10\1\1\0\65\1\1\0\104\1"+
- "\11\0\44\1\3\0\2\1\4\0\36\1\70\0\131\1\22\0\7\1"+
- "\16\0\2\2\56\0\106\2\32\0\2\2\44\0\1\1\1\2\3\1"+
- "\1\0\1\1\1\0\24\1\1\0\54\1\1\0\7\1\3\0\1\1"+
- "\1\0\1\1\1\0\1\1\1\0\1\1\1\0\22\1\15\0\14\1"+
- "\1\0\102\1\1\0\14\1\1\0\44\1\1\0\4\2\11\0\65\1"+
- "\2\0\2\1\2\0\2\1\3\0\34\1\2\0\10\1\2\0\2\1"+
- "\67\0\46\1\2\0\1\1\7\0\46\1\12\0\21\2\1\0\27\2"+
- "\1\0\3\2\1\0\1\2\1\0\2\2\1\0\1\2\13\0\33\1"+
- "\5\0\3\1\56\0\32\1\5\0\1\2\12\1\10\2\15\0\12\2"+
- "\6\0\1\2\107\1\2\0\5\1\1\0\17\1\1\0\4\1\1\0"+
- "\1\1\17\2\2\1\2\2\1\0\4\2\2\0\12\2\u0207\0\3\2"+
- "\1\0\65\1\2\0\1\2\1\1\20\2\3\0\4\2\3\0\12\1"+
- "\2\2\2\0\12\2\21\0\3\2\1\0\10\1\2\0\2\1\2\0"+
- "\26\1\1\0\7\1\1\0\1\1\3\0\4\1\2\0\1\2\1\0"+
- "\7\2\2\0\2\2\2\0\3\2\11\0\1\2\4\0\2\1\1\0"+
- "\3\1\2\2\2\0\12\2\2\1\20\0\1\2\2\0\6\1\4\0"+
- "\2\1\2\0\26\1\1\0\7\1\1\0\2\1\1\0\2\1\1\0"+
- "\2\1\2\0\1\2\1\0\5\2\4\0\2\2\2\0\3\2\13\0"+
- "\4\1\1\0\1\1\7\0\12\2\2\2\3\1\14\0\3\2\1\0"+
- "\7\1\1\0\1\1\1\0\3\1\1\0\26\1\1\0\7\1\1\0"+
- "\2\1\1\0\5\1\2\0\1\2\1\1\10\2\1\0\3\2\1\0"+
- "\3\2\22\0\1\1\5\0\12\2\21\0\3\2\1\0\10\1\2\0"+
- "\2\1\2\0\26\1\1\0\7\1\1\0\2\1\2\0\4\1\2\0"+
- "\1\2\1\1\6\2\3\0\2\2\2\0\3\2\10\0\2\2\4\0"+
- "\2\1\1\0\3\1\4\0\12\2\22\0\2\2\1\0\6\1\3\0"+
- "\3\1\1\0\4\1\3\0\2\1\1\0\1\1\1\0\2\1\3\0"+
- "\2\1\3\0\3\1\3\0\10\1\1\0\3\1\4\0\5\2\3\0"+
- "\3\2\1\0\4\2\11\0\1\2\17\0\11\2\21\0\3\2\1\0"+
- "\10\1\1\0\3\1\1\0\27\1\1\0\12\1\1\0\5\1\4\0"+
- "\7\2\1\0\3\2\1\0\4\2\7\0\2\2\11\0\2\1\4\0"+
- "\12\2\22\0\2\2\1\0\10\1\1\0\3\1\1\0\27\1\1\0"+
- "\12\1\1\0\5\1\4\0\7\2\1\0\3\2\1\0\4\2\7\0"+
- "\2\2\7\0\1\1\1\0\2\1\4\0\12\2\22\0\2\2\1\0"+
- "\10\1\1\0\3\1\1\0\27\1\1\0\20\1\4\0\6\2\2\0"+
- "\3\2\1\0\4\2\11\0\1\2\10\0\2\1\4\0\12\2\221\0"+
- "\56\1\1\0\1\1\1\2\2\1\7\2\5\0\6\1\1\2\10\2"+
- "\1\0\12\2\47\0\2\1\1\0\1\1\2\0\2\1\1\0\1\1"+
- "\2\0\1\1\6\0\4\1\1\0\7\1\1\0\3\1\1\0\1\1"+
- "\1\0\1\1\2\0\2\1\1\0\2\1\1\0\1\1\1\2\2\1"+
- "\6\2\1\0\2\2\1\1\2\0\5\1\1\0\1\2\1\0\6\2"+
- "\2\0\12\2\76\0\2\2\6\0\12\2\13\0\1\2\1\0\1\2"+
- "\1\0\1\2\4\0\2\2\10\1\1\0\41\1\7\0\24\2\1\0"+
- "\6\2\4\0\6\2\1\0\1\2\1\0\25\2\3\0\7\2\1\0"+
- "\1\2\346\0\46\1\12\0\47\1\11\0\1\1\1\0\2\1\1\0"+
- "\3\1\1\0\1\1\1\0\2\1\1\0\5\1\51\0\1\1\1\0"+
- "\1\1\1\0\1\1\13\0\1\1\1\0\1\1\1\0\1\1\3\0"+
- "\2\1\3\0\1\1\5\0\3\1\1\0\1\1\1\0\1\1\1\0"+
- "\1\1\1\0\1\1\3\0\2\1\3\0\2\1\1\0\1\1\50\0"+
- "\1\1\11\0\1\1\2\0\1\1\2\0\2\1\7\0\2\1\1\0"+
- "\1\1\1\0\7\1\50\0\1\1\4\0\1\1\10\0\1\1\u0c06\0"+
- "\234\1\4\0\132\1\6\0\26\1\2\0\6\1\2\0\46\1\2\0"+
- "\6\1\2\0\10\1\1\0\1\1\1\0\1\1\1\0\1\1\1\0"+
- "\37\1\2\0\65\1\1\0\7\1\1\0\1\1\3\0\3\1\1\0"+
- "\7\1\3\0\4\1\2\0\6\1\4\0\15\1\5\0\3\1\1\0"+
- "\7\1\323\0\15\2\4\0\1\2\104\0\1\1\3\0\2\1\2\0"+
- "\1\1\121\0\3\1\u0e82\0\1\2\1\0\1\1\31\0\11\1\6\2"+
- "\1\0\5\2\13\0\124\1\4\0\2\2\2\0\2\2\2\0\132\1"+
- "\1\0\3\2\6\0\50\1\u1cd3\0\u51a6\1\u0c5a\0\u2ba4\1\u285c\0";
-
- /**
- * Translates characters to character classes
- */
- private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
-
- /**
- * Translates DFA states to action switch labels.
- */
- private static final int [] ZZ_ACTION = zzUnpackAction();
-
- private static final String ZZ_ACTION_PACKED_0 =
- "\1\0\1\1\1\2\1\3";
-
- private static int [] zzUnpackAction() {
- int [] result = new int[4];
- int offset = 0;
- offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackAction(String packed, int offset, int [] result) {
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- do result[j++] = value; while (--count > 0);
- }
- return j;
- }
-
-
- /**
- * Translates a state to a row index in the transition table
- */
- private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
-
- private static final String ZZ_ROWMAP_PACKED_0 =
- "\0\0\0\4\0\10\0\14";
-
- private static int [] zzUnpackRowMap() {
- int [] result = new int[4];
- int offset = 0;
- offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackRowMap(String packed, int offset, int [] result) {
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int high = packed.charAt(i++) << 16;
- result[j++] = high | packed.charAt(i++);
- }
- return j;
- }
-
- /**
- * The transition table of the DFA
- */
- private static final int ZZ_TRANS [] = {
- 1, 2, 1, -1, -1, -1, -1, -1, 3, 2,
- 2, -1, 3, 3, 3, -1
- };
-
- /* error codes */
- private static final int ZZ_UNKNOWN_ERROR = 0;
- private static final int ZZ_NO_MATCH = 1;
-// private static final int ZZ_PUSHBACK_2BIG = 2;
-
- /* error messages for the codes above */
- private static final String ZZ_ERROR_MSG[] = {
- "Unkown internal scanner error",
- "Error: could not match input",
- "Error: pushback value was too large"
- };
-
- /**
- * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
- */
- private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
-
- private static final String ZZ_ATTRIBUTE_PACKED_0 =
- "\1\0\1\11\2\1";
-
- private static int [] zzUnpackAttribute() {
- int [] result = new int[4];
- int offset = 0;
- offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackAttribute(String packed, int offset, int [] result) {
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- do result[j++] = value; while (--count > 0);
- }
- return j;
- }
-
- /** the input device */
- private java.io.Reader zzReader;
-
- /** the current state of the DFA */
- private int zzState;
-
- /** the current lexical state */
- private int zzLexicalState = YYINITIAL;
-
- /** this buffer contains the current text to be matched and is
- the source of the yytext() string */
- private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
-
- /** the textposition at the last accepting state */
- private int zzMarkedPos;
-
- /** the textposition at the last state to be included in yytext */
- private int zzPushbackPos;
-
- /** the current text position in the buffer */
- private int zzCurrentPos;
-
- /** startRead marks the beginning of the yytext() string in the buffer */
- private int zzStartRead;
-
- /** endRead marks the last character in the buffer, that has been read
- from input */
- private int zzEndRead;
-
- /** number of newlines encountered up to the start of the matched text */
-// private int yyline;
-
- /** the number of characters up to the start of the matched text */
-// private int yychar;
-
- /**
- * the number of characters from the last newline up to the start of the
- * matched text
- */
-// private int yycolumn;
-
- /**
- * zzAtBOL == true <=> the scanner is currently at the beginning of a line
- */
-// private boolean zzAtBOL = true;
-
- /** zzAtEOF == true <=> the scanner is at the EOF */
- private boolean zzAtEOF;
-
- /* user code: */
- boolean result;
- /**
- * Creates a new scanner
- */
- public XML10Names() {
- this.zzReader = null;
- }
-
- public boolean isValidXML10Name(String stringToCheck) {
- boolean result = false;
- yyreset(new java.io.StringReader(stringToCheck));
- try {
- result = isValidXML10Name();
- }
- catch (java.io.IOException e) {
- // should be impossible with strings, but if occurs, just means
- // "not"
- result = false;
- }
- return result;
- }
-
-
-
- /**
- * Creates a new scanner
- * There is also a java.io.InputStream version of this constructor.
- *
- * @param in the java.io.Reader to read input from.
- */
- public XML10Names(java.io.Reader in) {
- this.zzReader = in;
- }
-
- /**
- * Creates a new scanner.
- * There is also java.io.Reader version of this constructor.
- *
- * @param in the java.io.Inputstream to read input from.
- */
- public XML10Names(java.io.InputStream in) {
- this(new java.io.InputStreamReader(in));
- }
-
- /**
- * Unpacks the compressed character translation table.
- *
- * @param packed the packed character translation table
- * @return the unpacked character translation table
- */
- private static char [] zzUnpackCMap(String packed) {
- char [] map = new char[0x10000];
- int i = 0; /* index in packed string */
- int j = 0; /* index in unpacked array */
- while (i < 1218) {
- int count = packed.charAt(i++);
- char value = packed.charAt(i++);
- do map[j++] = value; while (--count > 0);
- }
- return map;
- }
-
-
- /**
- * Refills the input buffer.
- *
- * @return <code>false</code>, iff there was new input.
- *
- * @exception java.io.IOException if any I/O-Error occurs
- */
- private boolean zzRefill() throws java.io.IOException {
-
- /* first: make room (if you can) */
- if (zzStartRead > 0) {
- System.arraycopy(zzBuffer, zzStartRead,
- zzBuffer, 0,
- zzEndRead-zzStartRead);
-
- /* translate stored positions */
- zzEndRead-= zzStartRead;
- zzCurrentPos-= zzStartRead;
- zzMarkedPos-= zzStartRead;
- zzPushbackPos-= zzStartRead;
- zzStartRead = 0;
- }
-
- /* is the buffer big enough? */
- if (zzCurrentPos >= zzBuffer.length) {
- /* if not: blow it up */
- char newBuffer[] = new char[zzCurrentPos*2];
- System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
- zzBuffer = newBuffer;
- }
-
- /* finally: fill the buffer with new input */
- int numRead = zzReader.read(zzBuffer, zzEndRead,
- zzBuffer.length-zzEndRead);
-
- if (numRead < 0) {
- return true;
- }
- else {
- zzEndRead+= numRead;
- return false;
- }
- }
-
-
- /**
- * Closes the input stream.
- */
-// private final void yyclose() throws java.io.IOException {
-// zzAtEOF = true; /* indicate end of file */
-// zzEndRead = zzStartRead; /* invalidate buffer */
-//
-// if (zzReader != null)
-// zzReader.close();
-// }
-
-
- /**
- * Resets the scanner to read from a new input stream.
- * Does not close the old reader.
- *
- * All internal variables are reset, the old input stream
- * <b>cannot</b> be reused (internal buffer is discarded and lost).
- * Lexical state is set to <tt>ZZ_INITIAL</tt>.
- *
- * @param reader the new input stream
- */
- private final void yyreset(java.io.Reader reader) {
- zzReader = reader;
-// zzAtBOL = true;
- zzAtEOF = false;
- zzEndRead = zzStartRead = 0;
- zzCurrentPos = zzMarkedPos = zzPushbackPos = 0;
-// yyline = yychar = yycolumn = 0;
- zzLexicalState = YYINITIAL;
- }
-
-
- /**
- * Returns the current lexical state.
- */
-// private final int yystate() {
-// return zzLexicalState;
-// }
-
-
- /**
- * Enters a new lexical state
- *
- * @param newState the new lexical state
- */
-// private final void yybegin(int newState) {
-// zzLexicalState = newState;
-// }
-
-
- /**
- * Returns the text matched by the current regular expression.
- */
-// private final String yytext() {
-// return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
-// }
-
-
- /**
- * Returns the character at position <tt>pos</tt> from the
- * matched text.
- *
- * It is equivalent to yytext().charAt(pos), but faster
- *
- * @param pos the position of the character to fetch.
- * A value from 0 to yylength()-1.
- *
- * @return the character at position pos
- */
-// private final char yycharat(int pos) {
-// return zzBuffer[zzStartRead+pos];
-// }
-
-
- /**
- * Returns the length of the matched text region.
- */
-// private final int yylength() {
-// return zzMarkedPos-zzStartRead;
-// }
-
-
- /**
- * Reports an error that occured while scanning.
- *
- * In a wellformed scanner (no or only correct usage of
- * yypushback(int) and a match-all fallback rule) this method
- * will only be called with things that "Can't Possibly Happen".
- * If this method is called, something is seriously wrong
- * (e.g. a JFlex bug producing a faulty scanner etc.).
- *
- * Usual syntax/scanner level error handling should be done
- * in error fallback rules.
- *
- * @param errorCode the code of the errormessage to display
- */
- private void zzScanError(int errorCode) {
- String message;
- try {
- message = ZZ_ERROR_MSG[errorCode];
- }
- catch (ArrayIndexOutOfBoundsException e) {
- message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
- }
-
- throw new Error(message);
- }
-
-
- /**
- * Pushes the specified amount of characters back into the input stream.
- *
- * They will be read again by then next call of the scanning method
- *
- * @param number the number of characters to be read again.
- * This number must not be greater than yylength()!
- */
-// private void yypushback(int number) {
-// if ( number > yylength() )
-// zzScanError(ZZ_PUSHBACK_2BIG);
-//
-// zzMarkedPos -= number;
-// }
-
-
- /**
- * Resumes scanning until the next regular expression is matched,
- * the end of input is encountered or an I/O-Error occurs.
- *
- * @return the next token
- * @exception java.io.IOException if any I/O-Error occurs
- */
- private boolean isValidXML10Name() throws java.io.IOException {
- int zzInput;
- int zzAction;
-
- // cached fields:
- int zzCurrentPosL;
- int zzMarkedPosL;
- int zzEndReadL = zzEndRead;
- char [] zzBufferL = zzBuffer;
- char [] zzCMapL = ZZ_CMAP;
-
- int [] zzTransL = ZZ_TRANS;
- int [] zzRowMapL = ZZ_ROWMAP;
- int [] zzAttrL = ZZ_ATTRIBUTE;
-
- while (true) {
- zzMarkedPosL = zzMarkedPos;
-
- zzAction = -1;
-
- zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
-
- zzState = zzLexicalState;
-
-
- zzForAction: {
- while (true) {
-
- if (zzCurrentPosL < zzEndReadL)
- zzInput = zzBufferL[zzCurrentPosL++];
- else if (zzAtEOF) {
- zzInput = YYEOF;
- break zzForAction;
- }
- else {
- // store back cached positions
- zzCurrentPos = zzCurrentPosL;
- zzMarkedPos = zzMarkedPosL;
- boolean eof = zzRefill();
- // get translated positions and possibly new buffer
- zzCurrentPosL = zzCurrentPos;
- zzMarkedPosL = zzMarkedPos;
- zzBufferL = zzBuffer;
- zzEndReadL = zzEndRead;
- if (eof) {
- zzInput = YYEOF;
- break zzForAction;
- }
- else {
- zzInput = zzBufferL[zzCurrentPosL++];
- }
- }
- int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
- if (zzNext == -1) break zzForAction;
- zzState = zzNext;
-
- int zzAttributes = zzAttrL[zzState];
- if ( (zzAttributes & 1) == 1 ) {
- zzAction = zzState;
- zzMarkedPosL = zzCurrentPosL;
- if ( (zzAttributes & 8) == 8 ) break zzForAction;
- }
-
- }
- }
-
- // store back cached position
- zzMarkedPos = zzMarkedPosL;
-
- switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
- case 1:
- { return false; /* matched wild */
- }
- case 4: break;
- case 2:
- { return true; /* exact name */
- }
- case 5: break;
- case 3:
- { return false; /* more than name */
- }
- case 6: break;
- default:
- if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
- zzAtEOF = true;
- { {return false; /* hit end with no match */} }
- }
- else {
- zzScanError(ZZ_NO_MATCH);
- }
- }
- }
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLSourceParser.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLSourceParser.java
deleted file mode 100644
index 4a8791c4f7..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLSourceParser.java
+++ /dev/null
@@ -1,645 +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.parser;
-
-
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.wst.sse.core.internal.document.DocumentReader;
-import org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker;
-import org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser;
-import org.eclipse.wst.sse.core.internal.ltk.parser.BlockTokenizer;
-import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;
-import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler;
-import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser;
-import org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension;
-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.sse.core.internal.text.CharSequenceReader;
-import org.eclipse.wst.sse.core.internal.text.IRegionComparible;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-/**
- * Takes input from the HTMLTokenizer and creates a tag list
- */
-
-public class XMLSourceParser implements RegionParser, BlockTagParser, StructuredDocumentRegionParser, IRegionComparible, StructuredDocumentRegionParserExtension {
- // made public to aid access from inner classes in hierarchy.
- // TODO: in future, figure out how to solve without exposing data.
- public CharSequence fCharSequenceSource = null;
- private IDocument fDocumentInput;
- protected int fOffset = 0;
- // DMW: 2/12/03. Removed some state data, since not really needed,
- // and since it added a lot to overhead (since so many regions are
- // created.
- // protected IStructuredDocumentRegion fCurrentNode = null;
- // protected IStructuredDocumentRegion fNodes = null;
- // protected List fRegions = null;
- // protected Object fInput = null;
- protected String fStringInput = null;
- protected List fStructuredDocumentRegionHandlers;
-
- protected BlockTokenizer fTokenizer = null;
- protected long startTime;
- protected long stopTime;
-
- /**
- * HTMLSourceParser constructor comment.
- */
- public XMLSourceParser() {
- super();
- fStructuredDocumentRegionHandlers = new ArrayList();
- }
-
- /**
- * This is a simple utility to count nodes. Used only for debug
- * statements.
- */
- protected int _countNodes(IStructuredDocumentRegion nodes) {
- int result = 0;
- IStructuredDocumentRegion countNode = nodes;
- while (countNode != null) {
- result++;
- countNode = countNode.getNext();
- }
- return result;
- }
-
- public void addBlockMarker(BlockMarker marker) {
- getTokenizer().addBlockMarker(marker);
- }
-
- public synchronized void addStructuredDocumentRegionHandler(StructuredDocumentRegionHandler handler) {
- if (fStructuredDocumentRegionHandlers == null)
- fStructuredDocumentRegionHandlers = new ArrayList();
- synchronized (fStructuredDocumentRegionHandlers) {
- fStructuredDocumentRegionHandlers.add(handler);
- }
- }
-
- public void beginBlockScan(String newTagName) {
- getTokenizer().beginBlockTagScan(newTagName);
- }
-
- /**
- * @return IStructuredDocumentRegion
- */
- protected IStructuredDocumentRegion createStructuredDocumentRegion(String type) {
- IStructuredDocumentRegion newNode = null;
- if (type == DOMRegionContext.BLOCK_TEXT)
- newNode = XMLStructuredRegionFactory.createRegion(XMLStructuredRegionFactory.XML_BLOCK);
- else
- newNode = XMLStructuredRegionFactory.createRegion(XMLStructuredRegionFactory.XML);
- return newNode;
- }
-
- protected void fireNodeParsed(IStructuredDocumentRegion fCurrentNode) {
- /*
- * Never let an Exceptions from foreign code interfere with completion
- * of parsing. To get an exception here is definitely a program error
- * somewhere, but we can't afford to interrupt the flow of control. or
- * backwards typing can result!
- *
- * Protect the user's data above everything.
- */
- Object[] handlers = null;
- synchronized (fStructuredDocumentRegionHandlers) {
- if (fStructuredDocumentRegionHandlers == null)
- return;
-
- handlers = fStructuredDocumentRegionHandlers.toArray();
- }
- if (fCurrentNode != null && handlers != null) {
- for (int i = 0; i < handlers.length; i++) {
- try {
- ((StructuredDocumentRegionHandler) handlers[i]).nodeParsed(fCurrentNode);
- }
- catch (Exception e) {
- Logger.log(Logger.ERROR, "Error occurred while firing Node Parsed event", e); //$NON-NLS-1$
- }
- }
- }
- }
-
- public BlockMarker getBlockMarker(String tagName) {
- List markers = getTokenizer().getBlockMarkers();
- for (int i = 0; i < markers.size(); i++) {
- BlockMarker marker = (BlockMarker) markers.get(i);
- if (marker.isCaseSensitive()) {
- if (marker.getTagName().equals(tagName))
- return marker;
- }
- else {
- if (marker.getTagName().equalsIgnoreCase(tagName))
- return marker;
- }
- }
- return null;
- }
-
- public List getBlockMarkers() {
- return getTokenizer().getBlockMarkers();
- }
-
- /**
- * @return IStructuredDocumentRegion
- */
- public IStructuredDocumentRegion getDocumentRegions() {
- IStructuredDocumentRegion headnode = null;
- if (headnode == null) {
- if (Debug.perfTest) {
- startTime = System.currentTimeMillis();
- }
- headnode = parseNodes();
- if (Debug.perfTest) {
- stopTime = System.currentTimeMillis();
- System.out.println(" -- creating nodes of IStructuredDocument -- "); //$NON-NLS-1$
- System.out.println(" Time parse and init all regions: " + (stopTime - startTime) + " (msecs)"); //$NON-NLS-2$//$NON-NLS-1$
- // System.out.println(" for " + fRegions.size() + "
- // Regions");//$NON-NLS-2$//$NON-NLS-1$
- System.out.println(" and " + _countNodes(headnode) + " Nodes"); //$NON-NLS-2$//$NON-NLS-1$
- }
- }
- return headnode;
- }
-
- protected ITextRegion getNextRegion() {
- ITextRegion region = null;
- try {
- region = getTokenizer().getNextToken();
- // DMW: 2/12/03 Removed state
- // if (region != null) {
- // fRegions.add(region);
- // }
- return region;
- }
- catch (StackOverflowError e) {
- Logger.logException(getClass().getName() + ": input could not be parsed correctly at position " + getTokenizer().getOffset(), e); //$NON-NLS-1$
- throw e;
- }
- catch (Exception e) {
- Logger.logException(getClass().getName() + ": input could not be parsed correctly at position " + getTokenizer().getOffset() + " (" + e.getLocalizedMessage() + ")", e); //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * Return the full list of known regions. Typically getNodes should be
- * used instead of this method.
- */
- public List getRegions() {
- IStructuredDocumentRegion headNode = null;
- if (!getTokenizer().isEOF()) {
- headNode = getDocumentRegions();
- // throw new IllegalStateException("parsing has not finished");
- }
- // for memory recovery, we assume if someone
- // requests all regions, we can reset our big
- // memory consuming objects
- // but the new "getRegions" method is then more expensive.
- // I don't think its used much, though.
- List localRegionsList = getRegions(headNode);
- primReset();
- return localRegionsList;
- }
-
- /**
- * Method getRegions.
- *
- * @param headNode
- * @return List
- */
- protected List getRegions(IStructuredDocumentRegion headNode) {
- List allRegions = new ArrayList();
- IStructuredDocumentRegion currentNode = headNode;
- while (currentNode != null) {
- ITextRegionList nodeRegions = currentNode.getRegions();
- for (int i = 0; i < nodeRegions.size(); i++) {
- allRegions.add(nodeRegions.get(i));
- }
- currentNode = currentNode.getNext();
- }
- return allRegions;
- }
-
- /**
- * @deprecated - use the add/remove methods instead
- * @return java.util.List
- */
- public List getStructuredDocumentRegionHandlers() {
- if (fStructuredDocumentRegionHandlers == null) {
- fStructuredDocumentRegionHandlers = new ArrayList(0);
- }
- return fStructuredDocumentRegionHandlers;
- }
-
- /**
- * Returns text from the current input. Text is only valid before
- * getNodes() has been called and only when a raw String or DocumentReader
- * is given as the input.
- */
- public String getText(int offset, int length) {
- String text = null;
- if (fCharSequenceSource != null) {
- int start = fOffset + offset;
- int end = start + length;
- text = fCharSequenceSource.subSequence(start, end).toString();
- }
- else if (fDocumentInput != null) {
- try {
- text = fDocumentInput.get(offset, length);
- }
- catch (BadLocationException e) {
- text = ""; //$NON-NLS-1$
- }
- }
- else {
- if (fStringInput == null || fStringInput.length() == 0 || offset + length > fStringInput.length() || offset < 0) {
- text = ""; //$NON-NLS-1$
- }
- else {
- // offset is entirely valid during parsing as the parse
- // numbers haven't been adjusted.
- text = fStringInput.substring(offset, offset + length);
- }
- }
- return text;
- }
-
- protected BlockTokenizer getTokenizer() {
- if (fTokenizer == null) {
- fTokenizer = new XMLTokenizer();
- }
- return fTokenizer;
- }
-
-
- public RegionParser newInstance() {
- XMLSourceParser newInstance = new XMLSourceParser();
- newInstance.setTokenizer(getTokenizer().newInstance());
- return newInstance;
- }
-
- protected IStructuredDocumentRegion parseNodes() {
- // regions are initially reported as complete offsets within the
- // scanned input
- // they are adjusted here to be indexes from the currentNode's start
- // offset
- IStructuredDocumentRegion headNode = null;
- IStructuredDocumentRegion lastNode = null;
- ITextRegion region = null;
- IStructuredDocumentRegion currentNode = null;
- String type = null;
-
- while ((region = getNextRegion()) != null) {
- type = region.getType();
- // these types (might) demand a IStructuredDocumentRegion for each
- // of them
- if (type == DOMRegionContext.BLOCK_TEXT) {
- if (currentNode != null && currentNode.getLastRegion().getType() == DOMRegionContext.BLOCK_TEXT) {
- // multiple block texts indicated embedded containers; no
- // new IStructuredDocumentRegion
- currentNode.addRegion(region);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- region.adjustStart(-currentNode.getStart());
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- }
- else {
- // not continuing a IStructuredDocumentRegion
- if (currentNode != null) {
- // ensure that any existing node is at least
- // terminated
- if (!currentNode.isEnded()) {
- currentNode.setLength(region.getStart() - currentNode.getStart());
- // fCurrentNode.setTextLength(region.getStart() -
- // fCurrentNode.getStart());
- }
- lastNode = currentNode;
- }
- fireNodeParsed(currentNode);
- currentNode = createStructuredDocumentRegion(type);
- if (lastNode != null) {
- lastNode.setNext(currentNode);
- }
- currentNode.setPrevious(lastNode);
- currentNode.setStart(region.getStart());
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- currentNode.setEnded(true);
- region.adjustStart(-currentNode.getStart());
- currentNode.addRegion(region);
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- }
- }
- // the following contexts OPEN new StructuredDocumentRegions
- else if ((currentNode != null && currentNode.isEnded()) || (type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE) || (type == DOMRegionContext.XML_PI_OPEN) || (type == DOMRegionContext.XML_TAG_OPEN) || (type == DOMRegionContext.XML_END_TAG_OPEN) || (type == DOMRegionContext.XML_COMMENT_OPEN) || (type == DOMRegionContext.XML_CDATA_OPEN) || (type == DOMRegionContext.XML_DECLARATION_OPEN)) {
- if (currentNode != null) {
- // ensure that any existing node is at least terminated
- if (!currentNode.isEnded()) {
- currentNode.setLength(region.getStart() - currentNode.getStart());
- // fCurrentNode.setTextLength(region.getStart() -
- // fCurrentNode.getStart());
- }
- lastNode = currentNode;
- }
- fireNodeParsed(currentNode);
- currentNode = createStructuredDocumentRegion(type);
- if (lastNode != null) {
- lastNode.setNext(currentNode);
- }
- currentNode.setPrevious(lastNode);
- currentNode.setStart(region.getStart());
- currentNode.addRegion(region);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- region.adjustStart(-currentNode.getStart());
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- }
- // the following contexts neither open nor close
- // StructuredDocumentRegions; just add to them
- else if ((type == DOMRegionContext.XML_TAG_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) || (type == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) || (type == DOMRegionContext.XML_COMMENT_TEXT) || (type == DOMRegionContext.XML_PI_CONTENT) || (type == DOMRegionContext.XML_DOCTYPE_INTERNAL_SUBSET)) {
- currentNode.addRegion(region);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- region.adjustStart(-currentNode.getStart());
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- }
- // the following contexts close off StructuredDocumentRegions
- // cleanly
- else if ((type == DOMRegionContext.XML_PI_CLOSE) || (type == DOMRegionContext.XML_TAG_CLOSE) || (type == DOMRegionContext.XML_EMPTY_TAG_CLOSE) || (type == DOMRegionContext.XML_COMMENT_CLOSE) || (type == DOMRegionContext.XML_DECLARATION_CLOSE) || (type == DOMRegionContext.XML_CDATA_CLOSE)) {
- currentNode.setEnded(true);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- currentNode.addRegion(region);
- region.adjustStart(-currentNode.getStart());
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- }
- // this is extremely rare, but valid
- else if (type == DOMRegionContext.WHITE_SPACE) {
- ITextRegion lastRegion = currentNode.getLastRegion();
- // pack the embedded container with this region
- if (lastRegion instanceof ITextRegionContainer) {
- ITextRegionContainer container = (ITextRegionContainer) lastRegion;
- container.getRegions().add(region);
- // containers must have parent set ...
- // setting for EACH subregion is redundent, but not sure
- // where else to do, so will do here for now.
- container.setParent(currentNode);
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(container);
- region.adjustStart(container.getLength() - region.getStart());
- }
- currentNode.getLastRegion().adjustLength(region.getLength());
- currentNode.adjustLength(region.getLength());
- }
- else if (type == DOMRegionContext.UNDEFINED && currentNode != null) {
- // skip on a very-first region situation as the default
- // behavior is good enough
- // combine with previous if also undefined
- if (currentNode.getLastRegion() != null && currentNode.getLastRegion().getType() == DOMRegionContext.UNDEFINED) {
- currentNode.getLastRegion().adjustLength(region.getLength());
- currentNode.adjustLength(region.getLength());
- }
- // previous wasn't undefined
- else {
- currentNode.addRegion(region);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- region.adjustStart(-currentNode.getStart());
- }
- }
- else {
- // if an unknown type is the first region in the document,
- // ensure that a node exists
- if (currentNode == null) {
- currentNode = createStructuredDocumentRegion(type);
- currentNode.setStart(region.getStart());
- }
- currentNode.addRegion(region);
- currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
- region.adjustStart(-currentNode.getStart());
- // DW 4/16/2003 regions no longer have parents
- // region.setParent(currentNode);
- if (Debug.debugTokenizer)
- System.out.println(getClass().getName() + " found region of not specifically handled type " + region.getType() + " @ " + region.getStart() + "[" + region.getLength() + "]"); //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
- }
-
- // these regions also get their own node, so close them cleanly
- // NOTE: these regions have new StructuredDocumentRegions created
- // for them above; it may
- // be more readable if that is handled here as well, but the
- // current layout
- // ensures that they open StructuredDocumentRegions the same way
- if ((type == DOMRegionContext.XML_CONTENT) || (type == DOMRegionContext.XML_CHAR_REFERENCE) || (type == DOMRegionContext.XML_ENTITY_REFERENCE)) {
- currentNode.setEnded(true);
- }
- if (headNode == null && currentNode != null) {
- headNode = currentNode;
- }
- }
- if (currentNode != null) {
- fireNodeParsed(currentNode);
- currentNode.setPrevious(lastNode);
- }
- // fStringInput = null;
- primReset();
- return headNode;
- }
-
- protected void primReset() {
- // fNodes = null;
- // fRegions = null;
- // fInput = null;
- fStringInput = null;
- fCharSequenceSource = null;
- fDocumentInput = null;
- fOffset = 0;
- // fCurrentNode = null;
- // DMW: also reset tokenizer so it doesn't hold on
- // to large arrays
- getTokenizer().reset(new char[0]);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.internal.text.IRegionComparible#regionMatches(int,
- * int, java.lang.String)
- */
- public boolean regionMatches(int offset, int length, String stringToCompare) {
- // by definition
- if (stringToCompare == null)
- return false;
-
- int ajustedOffset = fOffset + offset;
- boolean result = false;
- if (fCharSequenceSource != null && fCharSequenceSource instanceof IRegionComparible) {
- result = ((IRegionComparible) fCharSequenceSource).regionMatches(ajustedOffset, length, stringToCompare);
- }
- else {
- // old fashioned ways
- String test = null;
- if (fCharSequenceSource != null) {
- test = fCharSequenceSource.subSequence(ajustedOffset, ajustedOffset + length).toString();
- }
- else if (fStringInput != null) {
- test = fStringInput.substring(ajustedOffset, ajustedOffset + length);
- }
- result = stringToCompare.equals(test);
- }
- return result;
- }
-
- public boolean regionMatchesIgnoreCase(int offset, int length, String stringToCompare) {
- // by definition
- if (stringToCompare == null)
- return false;
-
- int ajustedOffset = fOffset + offset;
- boolean result = false;
- if (fCharSequenceSource != null && fCharSequenceSource instanceof IRegionComparible) {
- result = ((IRegionComparible) fCharSequenceSource).regionMatchesIgnoreCase(ajustedOffset, length, stringToCompare);
- }
- else {
- // old fashioned ways
- String test = null;
- if (fCharSequenceSource != null) {
- test = fCharSequenceSource.subSequence(ajustedOffset, ajustedOffset + length).toString();
- }
- else if (fStringInput != null) {
- test = fStringInput.substring(ajustedOffset, ajustedOffset + length);
- }
- result = stringToCompare.equalsIgnoreCase(test);
- }
- return result;
- }
-
- public void removeBlockMarker(BlockMarker marker) {
- getTokenizer().removeBlockMarker(marker);
- }
-
- public void removeBlockMarker(String tagName) {
- getTokenizer().removeBlockMarker(tagName);
- }
-
- public void removeStructuredDocumentRegionHandler(StructuredDocumentRegionHandler handler) {
- if (fStructuredDocumentRegionHandlers == null)
- return;
- synchronized (fStructuredDocumentRegionHandlers) {
- fStructuredDocumentRegionHandlers.remove(handler);
- }
- }
-
- /**
- * Resets the input.
- */
- public void reset(java.io.FileInputStream instream) {
- primReset();
- // fInput = instream;
- getTokenizer().reset(instream);
- }
-
- /**
- * Resets the input.
- */
- public void reset(java.io.Reader reader) {
- reset(reader, 0);
- }
-
- /**
- * Resets the input.
- */
- public void reset(java.io.Reader reader, int position) {
- primReset();
- fOffset = position;
- getTokenizer().reset(reader, position);
- if (reader instanceof DocumentReader) {
- IDocument doc = ((DocumentReader) reader).getDocument();
- if (doc instanceof CharSequence) {
- fCharSequenceSource = (CharSequence) doc;
- }
- else {
- // old fashioned IDocument
- fDocumentInput = ((DocumentReader) reader).getDocument();
- }
-
- }
- else if (reader instanceof CharSequenceReader) {
- fCharSequenceSource = ((CharSequenceReader) reader).getOriginalSource();
- }
- }
-
- /**
- * Resets the input. Use this version to allow text to be retrieved
- * <em>during</em> parsing, such as by the
- * StructuredDocumentRegionHandler.
- */
- public void reset(String sourceString) {
- reset(new StringReader(sourceString));
- fStringInput = sourceString;
- }
-
- /**
- * Resets the input. Use this version to allow text to be retrieved
- * <em>during</em> parsing, such as by the
- * StructuredDocumentRegionHandler.
- */
- public void reset(String sourceString, int position) {
- StringReader reader = new StringReader(sourceString);
- reset(reader, position);
- fStringInput = sourceString;
- }
-
- public void resetHandlers() {
- Object[] handlers = null;
- synchronized (fStructuredDocumentRegionHandlers) {
- if (fStructuredDocumentRegionHandlers == null)
- return;
-
- handlers = fStructuredDocumentRegionHandlers.toArray();
- }
- for (int i = 0; i < handlers.length; i++) {
- try {
- ((StructuredDocumentRegionHandler) handlers[i]).resetNodes();
- }
- catch (Exception e) {
- Logger.log(Logger.ERROR, "Error occurred while resetting handlers", e); //$NON-NLS-1$
- }
- }
- }
-
- /**
- *
- * @param List
- */
- public void setStructuredDocumentRegionHandlers(List newStructuredDocumentRegionHandlers) {
- fStructuredDocumentRegionHandlers = newStructuredDocumentRegionHandlers;
- }
-
- protected void setTokenizer(BlockTokenizer newTokenizer) {
- // DMW: changed from private to protected, so subclass could use in
- // creation of 'newInstance'.
- fTokenizer = newTokenizer;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredDocumentReParser.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredDocumentReParser.java
deleted file mode 100644
index c185520fa7..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredDocumentReParser.java
+++ /dev/null
@@ -1,124 +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.parser;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextReParser;
-import org.eclipse.wst.sse.core.internal.text.StructuredDocumentReParser;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class XMLStructuredDocumentReParser extends StructuredDocumentReParser {
-
- public XMLStructuredDocumentReParser() {
- super();
- }
-
- protected IStructuredDocumentRegion findDirtyEnd(int end) {
- // Caution: here's one place we have to cast
- IStructuredDocumentRegion result = fStructuredDocument.getRegionAtCharacterOffset(end);
- // if not well formed, get one past, if there is something there
- if ((result != null) && (!result.isEnded())) {
- if (result.getNext() != null) {
- result = result.getNext();
- }
- }
- // also, get one past if exactly equal to the end (this was needed
- // as a simple fix to when a whole exact region is deleted.
- // there's probably a better way.
- if ((result != null) && (end == result.getEnd())) {
- if (result.getNext() != null) {
- result = result.getNext();
- }
- }
-
- // 12/6/2001 - Since we've changed the parser/scanner to allow a lone
- // '<' without
- // always interpretting it as start of a tag name, we need to be a
- // little fancier, in order
- // to "skip" over any plain 'ol content between the lone '<' and any
- // potential meating
- // regions past plain 'ol content.
- if (isLoneOpenFollowedByContent(result) && (result.getNext() != null)) {
- result = result.getNext();
- }
-
- if (result != null)
- fStructuredDocument.setCachedDocumentRegion(result);
- dirtyEnd = result;
-
- return dirtyEnd;
- }
-
- protected void findDirtyStart(int start) {
- IStructuredDocumentRegion result = fStructuredDocument.getRegionAtCharacterOffset(start);
- // heuristic: if the postion is exactly equal to the start, then
- // go back one more, if it exists. This prevents problems with
- // insertions
- // of text that should be merged with the previous node instead of
- // simply hung
- // off of it as a separate node (ex.: XML content inserted right
- // before an open
- // bracket should become part of the previous content node)
- if (result != null) {
- IStructuredDocumentRegion previous = result.getPrevious();
- if ((previous != null) && ((!(previous.isEnded())) || (start == result.getStart()))) {
- result = previous;
- }
- // If we are now at the end of a "tag dependent" content area (or
- // JSP area)
- // then we need to back up all the way to the beginning of that.
- IStructuredDocumentRegion potential = result;
- while (isPartOfBlockRegion(potential)) {
- potential = potential.getPrevious();
- }
- if (potential != null) {
- result = potential;
- fStructuredDocument.setCachedDocumentRegion(result);
- }
- }
- dirtyStart = result;
- }
-
- /**
- * The rule is, that is we are content, preceded by lone <, then we need
- * to advance one more for dirty end.
- */
- protected boolean isLoneOpenFollowedByContent(IStructuredDocumentRegion flatNode) {
- boolean result = false;
- String type = flatNode.getType();
- if (type == DOMRegionContext.XML_CONTENT) {
- IStructuredDocumentRegion previous = flatNode.getPrevious();
- String previousType = null;
- if (previous != null) {
- previousType = previous.getType();
- }
- if (previousType != null) {
- result = (previousType == DOMRegionContext.XML_TAG_OPEN);
- }
- }
- return result;
- }
-
- protected boolean isPartOfBlockRegion(IStructuredDocumentRegion flatNode) {
- boolean result = false;
- String type = flatNode.getType();
- result = (type == DOMRegionContext.BLOCK_TEXT);
- return result;
- }
-
- public IStructuredTextReParser newInstance() {
- return new XMLStructuredDocumentReParser();
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredRegionFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredRegionFactory.java
deleted file mode 100644
index 8a98dc2d9b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLStructuredRegionFactory.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.parser;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.text.XMLStructuredDocumentRegion;
-
-
-/**
- * A simple class to generate instances of StructuredRegions.
- */
-public class XMLStructuredRegionFactory {
- public final static int JSP_DIRECTIVE = 1003;
- public final static int XML = 1001;
- public final static int XML_BLOCK = 1002;
-
- public static IStructuredDocumentRegion createRegion(int type) {
- IStructuredDocumentRegion instance = null;
- switch (type) {
- case XML :
- instance = new XMLStructuredDocumentRegion();
- break;
- case XML_BLOCK :
- instance = new BlockStructuredDocumentRegion();
- break;
- default :
- throw new IllegalArgumentException("AbstractRegion::createRegion. Invalid type."); //$NON-NLS-1$
- }
- return instance;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLTokenizer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLTokenizer.java
deleted file mode 100644
index 09a385073c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/XMLTokenizer.java
+++ /dev/null
@@ -1,1931 +0,0 @@
-/* The following code was generated by JFlex 1.2.2 on 6/29/10 1:04 PM */
-
-/*******************************************************************************
- * Copyright (c) 2004, 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.parser;
-
-import java.io.CharArrayReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker;
-import org.eclipse.wst.sse.core.internal.ltk.parser.BlockTokenizer;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-import org.eclipse.wst.sse.core.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.parser.regions.XMLParserRegionFactory;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-/**
- * This class is a scanner generated by
- * <a href="http://www.informatik.tu-muenchen.de/~kleing/jflex/">JFlex</a> 1.2.2
- * on 6/29/10 1:04 PM from the specification file
- * <tt>file:/D:/eclipse.wtp/workspace/org.eclipse.wst.sse.core/DevTimeSupport/SedModel/HTMLTokenizer/devel/XMLTokenizer.jflex</tt>
- */
-public class XMLTokenizer implements BlockTokenizer, DOMRegionContext {
-
- /** this character denotes the end of file */
- final public static int YYEOF = -1;
-
- /** lexical states */
- final public static int ST_XML_DOCTYPE_EXTERNAL_ID = 23;
- final public static int ST_XML_ELEMENT_DECLARATION_CONTENT = 27;
- final public static int ST_DHTML_ATTRIBUTE_NAME = 12;
- final public static int ST_XML_PI_TAG_CLOSE = 11;
- final public static int ST_XML_DECLARATION_CLOSE = 21;
- final public static int ST_XML_PI_ATTRIBUTE_VALUE = 10;
- final public static int ST_DHTML_EQUALS = 13;
- final public static int ST_XML_TAG_NAME = 16;
- final public static int ST_XML_ATTRIBUTE_VALUE = 19;
- final public static int ST_DHTML_ATTRIBUTE_VALUE = 14;
- final public static int ST_XML_DOCTYPE_ID_SYSTEM = 25;
- final public static int ST_XML_ATTRIBUTE_NAME = 17;
- final public static int ST_XML_ELEMENT_DECLARATION = 26;
- final public static int ST_XML_DOCTYPE_DECLARATION = 22;
- final public static int ST_XML_ATTLIST_DECLARATION = 28;
- final public static int ST_XML_COMMENT_END = 4;
- final public static int ST_CDATA_TEXT = 1;
- final public static int ST_DHTML_TAG_CLOSE = 15;
- final public static int ST_XML_COMMENT = 3;
- final public static int ST_PI_CONTENT = 7;
- final public static int ST_PI_WS = 6;
- final public static int ST_CDATA_END = 2;
- final public static int ST_XML_ATTLIST_DECLARATION_CONTENT = 29;
- final public static int ST_BLOCK_TAG_SCAN = 30;
- final public static int ST_XML_PI_EQUALS = 9;
- final public static int ST_XML_DECLARATION = 20;
- final public static int YYINITIAL = 0;
- final public static int ST_XML_DOCTYPE_ID_PUBLIC = 24;
- final public static int ST_XML_EQUALS = 18;
- final public static int ST_PI = 5;
- final public static int ST_XML_PI_ATTRIBUTE_NAME = 8;
-
- /**
- * Translates characters to character classes
- */
- final private static String yycmap_packed =
- "\11\0\1\5\1\22\2\0\1\14\22\0\1\14\1\21\1\11\1\55"+
- "\1\16\1\17\1\12\1\13\1\16\1\16\1\16\1\16\1\16\1\7"+
- "\1\6\1\3\12\15\1\10\1\61\1\1\1\45\1\2\1\4\1\16"+
- "\1\34\1\62\1\32\1\33\1\50\1\57\1\36\1\36\1\42\1\36"+
- "\1\36\1\27\1\25\1\44\1\43\1\47\1\36\1\40\1\56\1\35"+
- "\1\60\2\36\1\23\1\46\1\36\1\31\1\0\1\20\1\0\1\10"+
- "\1\0\1\52\1\62\1\63\1\53\1\37\1\57\1\36\1\66\1\42"+
- "\2\36\1\30\1\26\1\44\1\43\1\47\1\36\1\40\1\41\1\51"+
- "\1\60\1\36\1\36\1\24\1\54\1\36\1\0\1\0\72\0\1\65"+
- "\10\0\27\64\1\0\37\64\1\0\72\64\2\0\13\64\2\0\10\64"+
- "\1\0\65\64\1\0\104\64\11\0\44\64\3\0\2\64\4\0\36\64"+
- "\70\0\131\64\22\0\7\64\16\0\2\65\56\0\106\65\32\0\2\65"+
- "\44\0\1\64\1\65\3\64\1\0\1\64\1\0\24\64\1\0\54\64"+
- "\1\0\7\64\3\0\1\64\1\0\1\64\1\0\1\64\1\0\1\64"+
- "\1\0\22\64\15\0\14\64\1\0\102\64\1\0\14\64\1\0\44\64"+
- "\1\0\4\65\11\0\65\64\2\0\2\64\2\0\2\64\3\0\34\64"+
- "\2\0\10\64\2\0\2\64\67\0\46\64\2\0\1\64\7\0\46\64"+
- "\12\0\21\65\1\0\27\65\1\0\3\65\1\0\1\65\1\0\2\65"+
- "\1\0\1\65\13\0\33\64\5\0\3\64\56\0\32\64\5\0\1\65"+
- "\12\64\10\65\15\0\12\65\6\0\1\65\107\64\2\0\5\64\1\0"+
- "\17\64\1\0\4\64\1\0\1\64\17\65\2\64\2\65\1\0\4\65"+
- "\2\0\12\65\u0207\0\3\65\1\0\65\64\2\0\1\65\1\64\20\65"+
- "\3\0\4\65\3\0\12\64\2\65\2\0\12\65\21\0\3\65\1\0"+
- "\10\64\2\0\2\64\2\0\26\64\1\0\7\64\1\0\1\64\3\0"+
- "\4\64\2\0\1\65\1\0\7\65\2\0\2\65\2\0\3\65\11\0"+
- "\1\65\4\0\2\64\1\0\3\64\2\65\2\0\12\65\2\64\20\0"+
- "\1\65\2\0\6\64\4\0\2\64\2\0\26\64\1\0\7\64\1\0"+
- "\2\64\1\0\2\64\1\0\2\64\2\0\1\65\1\0\5\65\4\0"+
- "\2\65\2\0\3\65\13\0\4\64\1\0\1\64\7\0\12\65\2\65"+
- "\3\64\14\0\3\65\1\0\7\64\1\0\1\64\1\0\3\64\1\0"+
- "\26\64\1\0\7\64\1\0\2\64\1\0\5\64\2\0\1\65\1\64"+
- "\10\65\1\0\3\65\1\0\3\65\22\0\1\64\5\0\12\65\21\0"+
- "\3\65\1\0\10\64\2\0\2\64\2\0\26\64\1\0\7\64\1\0"+
- "\2\64\2\0\4\64\2\0\1\65\1\64\6\65\3\0\2\65\2\0"+
- "\3\65\10\0\2\65\4\0\2\64\1\0\3\64\4\0\12\65\22\0"+
- "\2\65\1\0\6\64\3\0\3\64\1\0\4\64\3\0\2\64\1\0"+
- "\1\64\1\0\2\64\3\0\2\64\3\0\3\64\3\0\10\64\1\0"+
- "\3\64\4\0\5\65\3\0\3\65\1\0\4\65\11\0\1\65\17\0"+
- "\11\65\21\0\3\65\1\0\10\64\1\0\3\64\1\0\27\64\1\0"+
- "\12\64\1\0\5\64\4\0\7\65\1\0\3\65\1\0\4\65\7\0"+
- "\2\65\11\0\2\64\4\0\12\65\22\0\2\65\1\0\10\64\1\0"+
- "\3\64\1\0\27\64\1\0\12\64\1\0\5\64\4\0\7\65\1\0"+
- "\3\65\1\0\4\65\7\0\2\65\7\0\1\64\1\0\2\64\4\0"+
- "\12\65\22\0\2\65\1\0\10\64\1\0\3\64\1\0\27\64\1\0"+
- "\20\64\4\0\6\65\2\0\3\65\1\0\4\65\11\0\1\65\10\0"+
- "\2\64\4\0\12\65\221\0\56\64\1\0\1\64\1\65\2\64\7\65"+
- "\5\0\6\64\1\65\10\65\1\0\12\65\47\0\2\64\1\0\1\64"+
- "\2\0\2\64\1\0\1\64\2\0\1\64\6\0\4\64\1\0\7\64"+
- "\1\0\3\64\1\0\1\64\1\0\1\64\2\0\2\64\1\0\2\64"+
- "\1\0\1\64\1\65\2\64\6\65\1\0\2\65\1\64\2\0\5\64"+
- "\1\0\1\65\1\0\6\65\2\0\12\65\76\0\2\65\6\0\12\65"+
- "\13\0\1\65\1\0\1\65\1\0\1\65\4\0\2\65\10\64\1\0"+
- "\41\64\7\0\24\65\1\0\6\65\4\0\6\65\1\0\1\65\1\0"+
- "\25\65\3\0\7\65\1\0\1\65\346\0\46\64\12\0\47\64\11\0"+
- "\1\64\1\0\2\64\1\0\3\64\1\0\1\64\1\0\2\64\1\0"+
- "\5\64\51\0\1\64\1\0\1\64\1\0\1\64\13\0\1\64\1\0"+
- "\1\64\1\0\1\64\3\0\2\64\3\0\1\64\5\0\3\64\1\0"+
- "\1\64\1\0\1\64\1\0\1\64\1\0\1\64\3\0\2\64\3\0"+
- "\2\64\1\0\1\64\50\0\1\64\11\0\1\64\2\0\1\64\2\0"+
- "\2\64\7\0\2\64\1\0\1\64\1\0\7\64\50\0\1\64\4\0"+
- "\1\64\10\0\1\64\u0c06\0\234\64\4\0\132\64\6\0\26\64\2\0"+
- "\6\64\2\0\46\64\2\0\6\64\2\0\10\64\1\0\1\64\1\0"+
- "\1\64\1\0\1\64\1\0\37\64\2\0\65\64\1\0\7\64\1\0"+
- "\1\64\3\0\3\64\1\0\7\64\3\0\4\64\2\0\6\64\4\0"+
- "\15\64\5\0\3\64\1\0\7\64\323\0\15\65\4\0\1\65\104\0"+
- "\1\64\3\0\2\64\2\0\1\64\121\0\3\64\u0e82\0\1\65\1\0"+
- "\1\64\31\0\11\64\6\65\1\0\5\65\13\0\124\64\4\0\2\65"+
- "\2\0\2\65\2\0\132\64\1\0\3\65\6\0\50\64\u1cd3\0\u51a6\64"+
- "\u0c5a\0\u2ba4\64\134\0\u0800\0\u1ffe\0\2\0";
-
- /**
- * Translates characters to character classes
- */
- final private static char [] yycmap = yy_unpack_cmap(yycmap_packed);
-
- /**
- * Translates a state to a row index in the transition table
- */
- final private static int yy_rowMap [] = {
- 0, 55, 110, 165, 220, 275, 330, 385, 440, 495,
- 550, 605, 660, 715, 770, 825, 880, 935, 990, 1045,
- 1100, 1155, 1210, 1265, 1320, 1375, 1430, 1485, 1540, 1595,
- 1650, 1705, 1760, 1815, 1870, 1925, 1980, 1925, 1980, 2035,
- 1925, 1925, 1980, 2090, 2145, 2200, 2255, 2310, 2365, 2420,
- 2475, 1925, 1980, 2530, 2585, 2640, 1925, 2695, 2695, 2750,
- 2805, 2860, 2530, 1925, 2915, 2970, 1925, 3025, 3080, 3135,
- 3190, 3245, 3300, 1925, 3355, 3410, 3465, 3520, 1925, 3575,
- 3630, 3685, 3740, 3795, 1925, 3850, 3905, 3960, 4015, 4070,
- 4125, 4180, 4235, 4235, 4290, 4345, 4400, 4455, 4455, 4510,
- 4565, 4620, 4675, 4675, 4730, 4785, 4840, 4895, 1925, 4950,
- 4950, 5005, 5060, 5115, 5170, 1925, 1925, 1980, 1925, 1925,
- 5225, 5280, 5335, 5390, 5445, 5500, 5555, 5610, 1925, 5665,
- 5720, 5775, 1925, 1925, 2695, 5830, 2805, 1925, 5885, 2860,
- 2915, 3025, 3080, 5940, 3135, 1925, 5995, 3190, 1925, 3575,
- 6050, 3685, 1925, 6105, 3740, 5225, 6160, 6215, 6270, 4015,
- 1925, 6325, 6380, 4235, 6435, 4290, 1925, 6490, 6545, 6600,
- 6600, 6655, 6710, 4400, 4235, 4455, 6765, 4510, 1925, 6820,
- 4565, 4620, 4455, 4675, 6875, 4730, 1925, 6930, 6985, 7040,
- 7040, 7095, 7150, 7205, 4950, 7260, 5005, 1925, 7315, 7370,
- 7425, 7425, 7480, 7535, 7590, 7645, 7700, 7755, 7810, 1925,
- 7865, 7920, 1925, 1925, 1925, 2255, 7975, 8030, 8085, 8140,
- 8195, 8250, 8305, 6490, 8360, 8360, 6930, 8415, 8415, 8470,
- 7315, 8525, 8525, 8580, 1925, 8635, 8690, 1925, 8745, 8800,
- 8855, 8910, 8965, 9020, 9075, 9130, 6655, 7095, 9185, 7480,
- 9240, 9295, 9350, 9405, 9460, 9515, 9570, 9625, 9680, 9735,
- 9790, 9845, 9900, 9955, 10010, 10065, 10120, 1925, 1925, 10175,
- 10230, 10285, 10340, 10395, 1925, 1925, 1925, 10450, 10505, 10560,
- 10615, 10670, 10725, 1925, 10780, 4840, 5115, 10835, 10890, 10945,
- 11000, 2255
- };
-
- /**
- * The packed transition table of the DFA
- */
- final private static String yy_packed =
- "\1\40\1\41\10\40\1\42\4\40\1\43\47\40\1\44"+
- "\1\45\65\44\1\46\1\47\16\46\1\50\1\46\1\51"+
- "\44\46\1\52\1\53\65\52\1\46\1\47\5\46\1\54"+
- "\12\46\1\51\45\46\1\47\2\46\1\55\1\56\2\46"+
- "\1\57\3\46\1\56\5\46\1\56\1\60\1\61\4\57"+
- "\1\46\10\57\1\62\2\57\1\46\7\57\1\46\3\57"+
- "\1\46\3\57\1\46\1\57\1\46\1\47\2\46\1\55"+
- "\1\63\6\46\1\63\5\46\1\63\44\46\1\64\1\65"+
- "\2\64\1\66\15\64\1\51\44\64\1\46\1\47\2\46"+
- "\1\67\1\56\2\46\1\70\3\46\1\56\5\46\1\56"+
- "\6\70\1\46\13\70\1\46\7\70\1\46\3\70\1\46"+
- "\3\70\1\46\1\70\1\46\1\47\2\46\1\67\1\56"+
- "\2\46\1\70\3\46\1\56\5\46\1\56\6\70\1\46"+
- "\13\70\1\71\7\70\1\46\3\70\1\46\3\70\1\46"+
- "\1\70\1\72\1\47\1\46\1\73\1\74\1\56\3\72"+
- "\1\75\1\72\1\76\1\56\5\72\1\56\44\72\1\46"+
- "\1\47\2\46\1\77\15\46\1\51\45\46\1\47\1\100"+
- "\1\101\1\46\1\56\2\46\1\102\3\46\1\56\5\46"+
- "\1\56\6\102\1\46\13\102\1\46\7\102\1\46\3\102"+
- "\1\46\3\102\1\46\1\102\1\46\1\47\1\100\1\101"+
- "\1\46\1\56\2\46\1\102\3\46\1\56\5\46\1\56"+
- "\6\102\1\46\13\102\1\103\7\102\1\46\3\102\1\46"+
- "\3\102\1\46\1\102\1\104\1\47\1\100\1\105\1\104"+
- "\1\56\3\104\1\106\1\104\1\107\1\56\5\104\1\56"+
- "\44\104\1\46\1\47\3\46\1\56\6\46\1\56\5\46"+
- "\1\56\44\46\1\110\1\111\1\112\1\113\4\110\1\114"+
- "\12\110\6\115\1\110\13\115\1\110\7\115\1\110\3\115"+
- "\1\110\3\115\1\110\1\115\1\46\1\111\1\112\1\113"+
- "\1\46\1\56\2\46\1\116\3\46\1\56\5\46\1\56"+
- "\6\116\1\46\13\116\1\46\7\116\1\46\3\116\1\46"+
- "\3\116\1\46\1\116\1\46\1\111\1\112\1\113\1\46"+
- "\1\56\2\46\1\116\3\46\1\56\5\46\1\56\6\116"+
- "\1\46\13\116\1\117\7\116\1\46\3\116\1\46\3\116"+
- "\1\46\1\116\1\120\1\111\1\112\1\121\1\120\1\56"+
- "\3\120\1\122\1\120\1\123\1\56\5\120\1\56\44\120"+
- "\1\46\1\124\1\125\2\46\1\56\6\46\1\56\5\46"+
- "\1\56\10\46\1\126\1\127\2\46\1\130\10\46\1\130"+
- "\1\46\1\127\1\126\14\46\1\47\1\125\2\46\1\56"+
- "\6\46\1\56\5\46\1\56\6\46\1\131\36\46\1\47"+
- "\1\125\2\46\1\56\2\46\1\132\3\46\1\56\5\46"+
- "\1\56\6\132\1\131\13\132\1\46\7\132\1\46\3\132"+
- "\1\46\3\132\1\46\1\132\1\46\1\47\1\125\2\46"+
- "\1\56\6\46\1\56\5\46\1\56\6\46\1\131\7\46"+
- "\1\133\5\46\1\134\6\46\1\133\10\46\1\135\1\47"+
- "\1\125\1\136\1\135\1\56\3\135\1\137\1\135\1\140"+
- "\1\56\5\135\1\56\6\135\1\141\35\135\1\142\1\47"+
- "\1\125\1\143\1\142\1\56\3\142\1\144\1\142\1\145"+
- "\1\56\5\142\1\56\6\142\1\146\35\142\1\147\1\47"+
- "\1\125\1\150\1\147\1\56\3\147\1\151\1\147\1\152"+
- "\1\56\5\147\1\56\44\147\1\153\1\154\1\155\64\153"+
- "\1\156\1\47\1\125\1\157\1\156\1\56\3\156\1\160"+
- "\1\156\1\161\1\56\5\156\1\56\44\156\1\162\1\163"+
- "\1\164\64\162\1\165\1\166\65\165\1\40\1\0\10\40"+
- "\1\0\4\40\1\0\47\40\3\0\1\167\1\170\14\0"+
- "\1\171\52\0\1\172\2\0\1\173\3\0\1\172\5\0"+
- "\1\172\6\173\1\0\13\173\1\0\7\173\1\174\3\173"+
- "\1\0\3\173\1\0\1\173\5\0\1\172\2\0\1\175"+
- "\3\0\1\172\5\0\1\172\6\175\1\0\13\175\1\0"+
- "\7\175\1\0\3\175\1\0\3\175\1\0\1\175\110\0"+
- "\1\176\65\0\1\177\55\0\1\200\61\0\1\201\71\0"+
- "\1\56\6\0\1\56\5\0\1\56\52\0\3\57\4\0"+
- "\1\57\5\0\6\57\1\0\13\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\6\0\3\57\4\0\1\57\5\0"+
- "\2\57\2\202\2\57\1\0\13\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\6\0\3\57\4\0\1\57\5\0"+
- "\2\57\1\202\1\203\2\57\1\0\13\57\1\0\7\57"+
- "\1\0\3\57\1\0\5\57\6\0\3\57\4\0\1\57"+
- "\5\0\2\57\2\204\2\57\1\0\13\57\1\0\7\57"+
- "\1\0\3\57\1\0\5\57\5\0\1\63\6\0\1\63"+
- "\5\0\1\63\46\0\1\205\66\0\1\206\72\0\3\70"+
- "\4\0\1\70\5\0\6\70\1\0\13\70\1\0\7\70"+
- "\1\0\3\70\1\0\5\70\1\72\2\0\1\207\1\72"+
- "\1\0\3\72\1\0\1\72\2\0\5\72\1\0\45\72"+
- "\1\0\1\206\1\207\1\72\1\0\3\72\1\0\1\72"+
- "\2\0\5\72\1\0\44\72\1\75\2\210\1\211\1\75"+
- "\1\210\3\75\1\212\1\75\2\210\5\75\1\210\44\75"+
- "\1\76\2\213\1\214\1\76\1\213\3\76\1\213\1\76"+
- "\1\212\1\213\5\76\1\213\44\76\2\0\1\100\1\215"+
- "\71\0\3\102\4\0\1\102\5\0\6\102\1\0\13\102"+
- "\1\0\7\102\1\0\3\102\1\0\5\102\1\104\2\0"+
- "\1\216\1\104\1\0\3\104\1\0\1\104\2\0\5\104"+
- "\1\0\45\104\1\0\1\100\1\217\1\104\1\0\3\104"+
- "\1\0\1\104\2\0\5\104\1\0\44\104\1\106\2\220"+
- "\1\221\1\106\1\220\3\106\1\222\1\106\2\220\5\106"+
- "\1\220\44\106\1\107\2\223\1\224\1\107\1\223\3\107"+
- "\1\223\1\107\1\222\1\223\5\107\1\223\44\107\1\110"+
- "\3\0\17\110\6\0\1\110\13\0\1\110\7\0\1\110"+
- "\3\0\1\110\3\0\1\110\4\0\1\167\15\0\1\171"+
- "\47\0\1\225\64\0\1\110\3\0\2\110\3\114\4\110"+
- "\1\114\5\110\6\115\1\110\13\115\1\110\7\115\1\110"+
- "\3\115\1\110\3\115\1\114\1\115\6\0\3\115\4\0"+
- "\1\115\5\0\6\115\1\0\13\115\1\0\7\115\1\0"+
- "\3\115\1\0\5\115\6\0\3\116\4\0\1\116\5\0"+
- "\6\116\1\0\13\116\1\0\7\116\1\0\3\116\1\0"+
- "\5\116\1\120\2\0\1\226\1\120\1\0\3\120\1\0"+
- "\1\120\2\0\5\120\1\0\45\120\1\0\1\225\1\226"+
- "\1\120\1\0\3\120\1\0\1\120\2\0\5\120\1\0"+
- "\44\120\1\122\2\227\1\230\1\122\1\227\3\122\1\231"+
- "\1\122\2\227\5\122\1\227\44\122\1\123\2\232\1\233"+
- "\1\123\1\232\3\123\1\232\1\123\1\231\1\232\5\123"+
- "\1\232\44\123\3\0\1\167\15\0\1\234\110\0\1\235"+
- "\60\0\1\236\13\0\1\236\44\0\2\237\36\0\20\240"+
- "\1\241\46\240\6\0\3\132\4\0\1\132\5\0\6\132"+
- "\1\0\13\132\1\0\7\132\1\0\3\132\1\0\5\132"+
- "\46\0\1\242\5\0\1\242\72\0\1\243\6\0\1\135"+
- "\2\0\1\244\1\135\1\0\3\135\1\0\1\135\2\0"+
- "\5\135\1\0\44\135\1\137\2\245\1\246\1\137\1\245"+
- "\3\137\1\247\1\137\2\245\5\137\1\245\44\137\1\250"+
- "\2\251\1\252\1\253\1\251\3\253\1\251\1\250\1\254"+
- "\1\255\3\253\1\250\1\253\1\255\6\253\1\250\32\253"+
- "\2\250\1\253\1\141\2\240\1\256\1\141\1\240\3\141"+
- "\1\240\1\141\2\240\3\141\1\257\1\141\1\240\44\141"+
- "\1\142\2\0\1\260\1\142\1\0\3\142\1\0\1\142"+
- "\2\0\5\142\1\0\44\142\1\144\2\261\1\262\1\144"+
- "\1\261\3\144\1\263\1\144\2\261\5\144\1\261\44\144"+
- "\1\145\2\264\1\265\1\145\1\264\3\145\1\264\1\145"+
- "\1\263\1\264\5\145\1\264\44\145\1\146\2\240\1\266"+
- "\1\146\1\240\3\146\1\240\1\146\2\240\3\146\1\267"+
- "\1\146\1\240\44\146\1\147\2\0\1\270\1\147\1\0"+
- "\3\147\1\0\1\147\2\0\5\147\1\0\44\147\1\151"+
- "\2\271\1\272\1\151\1\271\3\151\1\273\1\151\2\271"+
- "\5\151\1\271\44\151\1\274\2\275\1\276\1\277\1\275"+
- "\3\277\1\275\1\274\1\300\1\301\3\277\1\274\1\277"+
- "\1\301\6\277\1\274\32\277\2\274\1\277\2\153\1\0"+
- "\66\153\1\0\16\153\1\302\45\153\1\156\2\0\1\303"+
- "\1\156\1\0\3\156\1\0\1\156\2\0\5\156\1\0"+
- "\44\156\1\160\2\304\1\305\1\160\1\304\3\160\1\306"+
- "\1\160\2\304\5\160\1\304\44\160\1\307\2\310\1\311"+
- "\1\312\1\310\3\312\1\310\1\307\1\313\1\314\3\312"+
- "\1\307\1\312\1\314\6\312\1\307\32\312\2\307\1\312"+
- "\2\162\1\0\66\162\1\0\16\162\1\315\45\162\7\0"+
- "\1\316\21\0\1\317\42\0\1\172\2\0\1\40\3\0"+
- "\1\172\5\0\1\172\6\40\1\0\13\40\1\0\7\40"+
- "\1\0\3\40\1\0\3\40\1\0\1\40\1\320\1\0"+
- "\3\320\1\321\3\173\1\320\1\0\1\320\1\321\1\173"+
- "\1\320\1\0\2\320\1\321\6\173\1\320\13\173\1\320"+
- "\7\173\1\320\3\173\1\322\5\173\15\0\1\323\6\0"+
- "\1\324\42\0\1\320\1\0\3\320\1\321\3\175\1\320"+
- "\1\0\1\320\1\321\1\175\1\320\1\0\2\320\1\321"+
- "\6\175\1\320\13\175\1\320\7\175\1\320\3\175\1\325"+
- "\5\175\31\0\1\317\37\0\1\326\66\0\1\327\72\0"+
- "\3\57\4\0\1\57\5\0\4\57\2\330\1\0\13\57"+
- "\1\0\7\57\1\0\3\57\1\0\5\57\6\0\3\57"+
- "\4\0\1\57\5\0\4\57\1\330\1\331\1\0\13\57"+
- "\1\0\7\57\1\0\3\57\1\0\5\57\6\0\3\57"+
- "\4\0\1\57\5\0\6\57\1\0\13\57\1\0\1\57"+
- "\1\332\5\57\1\0\3\57\1\0\5\57\11\210\1\212"+
- "\55\210\13\213\1\212\53\213\11\220\1\222\55\220\13\223"+
- "\1\222\53\223\11\227\1\231\55\227\13\232\1\231\53\232"+
- "\32\0\1\333\30\0\1\333\40\0\1\334\13\0\1\334"+
- "\54\0\1\335\10\0\1\335\57\0\1\336\14\0\1\336"+
- "\72\0\1\337\4\0\11\245\1\247\55\245\1\250\2\251"+
- "\1\340\1\250\1\251\3\250\1\251\1\250\1\247\1\251"+
- "\5\250\1\251\44\250\13\251\1\247\53\251\1\250\2\251"+
- "\1\340\1\250\1\251\3\250\1\251\1\250\1\341\1\251"+
- "\5\250\1\251\44\250\13\0\1\342\53\0\13\251\1\341"+
- "\53\251\11\261\1\263\55\261\13\264\1\263\53\264\11\271"+
- "\1\273\55\271\1\274\2\275\1\343\1\274\1\275\3\274"+
- "\1\275\1\274\1\273\1\275\5\274\1\275\44\274\13\275"+
- "\1\273\53\275\1\274\2\275\1\343\1\274\1\275\3\274"+
- "\1\275\1\274\1\344\1\275\5\274\1\275\44\274\13\0"+
- "\1\345\53\0\13\275\1\344\53\275\2\153\1\0\26\153"+
- "\1\346\35\153\11\304\1\306\55\304\1\307\2\310\1\347"+
- "\1\307\1\310\3\307\1\310\1\307\1\306\1\310\5\307"+
- "\1\310\44\307\13\310\1\306\53\310\1\307\2\310\1\347"+
- "\1\307\1\310\3\307\1\310\1\307\1\350\1\310\5\307"+
- "\1\310\44\307\13\0\1\351\53\0\13\310\1\350\53\310"+
- "\2\162\1\0\26\162\1\352\35\162\7\0\1\353\111\0"+
- "\1\354\34\0\1\320\1\0\10\320\1\0\4\320\1\0"+
- "\41\320\1\0\6\320\1\0\3\320\1\321\4\320\1\0"+
- "\1\320\1\321\2\320\1\0\2\320\1\321\36\320\1\355"+
- "\5\320\15\0\1\323\43\0\1\356\22\0\1\357\14\0"+
- "\3\357\2\0\1\357\10\0\1\357\1\0\2\357\3\0"+
- "\1\357\2\0\2\357\11\0\1\57\1\360\1\57\4\0"+
- "\1\57\5\0\6\57\1\0\13\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\6\0\3\57\4\0\1\57\5\0"+
- "\6\57\1\0\11\57\1\361\1\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\35\0\1\362\13\0\1\362\44\0"+
- "\2\363\63\0\2\364\75\0\1\365\13\0\1\365\44\0"+
- "\2\366\41\0\2\367\1\0\3\367\2\0\1\254\4\367"+
- "\1\0\10\367\1\0\32\367\2\0\1\367\3\0\2\370"+
- "\1\0\3\370\2\0\1\300\4\370\1\0\10\370\1\0"+
- "\32\370\2\0\1\370\2\153\1\0\27\153\1\371\34\153"+
- "\3\0\2\372\1\0\3\372\2\0\1\313\4\372\1\0"+
- "\10\372\1\0\32\372\2\0\1\372\2\162\1\0\27\162"+
- "\1\373\34\162\33\0\1\374\114\0\1\355\22\0\1\357"+
- "\14\0\3\357\2\0\1\357\10\0\1\357\1\0\2\357"+
- "\3\0\1\357\1\0\1\356\2\357\11\0\3\57\4\0"+
- "\1\57\5\0\6\57\1\0\7\57\1\375\3\57\1\0"+
- "\7\57\1\0\3\57\1\0\5\57\6\0\3\57\4\0"+
- "\1\57\5\0\6\57\1\0\6\57\1\376\4\57\1\0"+
- "\7\57\1\0\3\57\1\0\5\57\46\0\1\377\5\0"+
- "\1\377\54\0\1\u0100\63\0\1\u0101\10\0\1\u0101\55\0"+
- "\1\u0102\10\0\1\u0102\60\0\1\u0103\24\0\2\153\1\0"+
- "\30\153\1\u0104\33\153\2\162\1\0\30\162\1\u0105\33\162"+
- "\34\0\1\u0106\40\0\3\57\4\0\1\57\5\0\6\57"+
- "\1\0\13\57\1\0\3\57\1\u0107\3\57\1\0\3\57"+
- "\1\0\5\57\6\0\3\57\4\0\1\57\5\0\6\57"+
- "\1\0\3\57\1\u0108\7\57\1\0\3\57\1\u0108\3\57"+
- "\1\0\3\57\1\0\5\57\47\0\1\u0109\60\0\1\u010a"+
- "\14\0\1\u010a\54\0\1\u010b\47\0\2\u010c\72\0\1\u010d"+
- "\30\0\1\u010d\3\0\2\153\1\0\31\153\1\u010e\32\153"+
- "\2\162\1\0\31\162\1\u010f\32\162\35\0\1\u0110\37\0"+
- "\3\57\4\0\1\57\5\0\6\57\1\0\13\57\1\0"+
- "\6\57\1\u0111\1\0\3\57\1\0\5\57\5\0\1\u0112"+
- "\3\57\3\0\1\u0112\1\57\4\0\1\u0112\6\57\1\0"+
- "\13\57\1\0\7\57\1\0\3\57\1\0\5\57\37\0"+
- "\1\u0113\10\0\1\u0113\53\0\1\u0114\13\0\1\u0114\52\0"+
- "\1\u0115\13\0\1\u0115\15\0\2\153\1\0\32\153\1\u0116"+
- "\31\153\2\162\1\0\32\162\1\u0117\31\162\34\0\1\u0118"+
- "\40\0\3\57\4\0\1\57\5\0\5\57\1\u0119\1\0"+
- "\13\57\1\0\7\57\1\0\3\57\1\0\5\57\5\0"+
- "\1\u0112\6\0\1\u0112\5\0\1\u0112\44\0\2\153\1\0"+
- "\31\153\1\u011a\32\153\2\162\1\0\31\162\1\u011b\32\162"+
- "\31\0\1\u011c\43\0\3\57\4\0\1\57\5\0\6\57"+
- "\1\0\5\57\1\u011d\5\57\1\0\7\57\1\0\3\57"+
- "\1\0\5\57\2\153\1\0\26\153\1\u011e\35\153\2\162"+
- "\1\0\26\162\1\u011f\35\162\6\0\3\57\4\0\1\57"+
- "\5\0\6\57\1\0\7\57\1\u0120\3\57\1\0\7\57"+
- "\1\0\3\57\1\0\5\57\6\0\3\57\4\0\1\57"+
- "\5\0\6\57\1\0\13\57\1\0\7\57\1\0\3\57"+
- "\1\0\4\57\1\u0121\6\0\3\57\4\0\1\57\5\0"+
- "\6\57\1\0\5\57\1\u0122\5\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\6\0\3\57\4\0\1\57\5\0"+
- "\6\57\1\0\5\57\1\u0123\5\57\1\0\7\57\1\0"+
- "\3\57\1\0\5\57\6\0\3\57\4\0\1\57\5\0"+
- "\6\57\1\0\13\57\1\0\3\57\1\u0124\3\57\1\0"+
- "\3\57\1\0\5\57";
-
- /**
- * The transition table of the DFA
- */
- final private static int yytrans [] = yy_unpack(yy_packed);
-
-
- /* error codes */
- final private static int YY_UNKNOWN_ERROR = 0;
- // final private static int YY_ILLEGAL_STATE = 1;
- final private static int YY_NO_MATCH = 2;
- final private static int YY_PUSHBACK_2BIG = 3;
-
- /* error messages for the codes above */
- final private static String YY_ERROR_MSG[] = {
- "Unkown internal scanner error", //$NON-NLS-1$
- "Internal error: unknown state", //$NON-NLS-1$
- "Error: could not match input", //$NON-NLS-1$
- "Error: pushback value was too large" //$NON-NLS-1$
- };
-
- /**
- * YY_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
- */
- private final static byte YY_ATTRIBUTE[] = {
- 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
- 1, 1, 1, 9, 1, 9, 1, 1, 9, 9, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 9, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 9,
- 1, 1, 9, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 9, 1,
- 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1,
- 1, 1, 1, 9, 9, 1, 9, 9, 1, 0, 1, 0, 1, 0, 0, 0,
- 9, 1, 1, 1, 9, 9, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0,
- 0, 9, 0, 0, 9, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0,
- 9, 0, 0, 0, 0, 0, 9, 1, 0, 0, 1, 1, 0, 0, 1, 0,
- 0, 0, 9, 0, 0, 0, 1, 0, 0, 0, 9, 1, 0, 0, 1, 1,
- 0, 1, 0, 0, 0, 9, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
- 1, 9, 0, 0, 9, 9, 9, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 9, 0, 1, 9, 0, 1,
- 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0,
- 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 9, 9, 1, 1, 0,
- 1, 1, 9, 9, 9, 1, 1, 0, 1, 1, 1, 9, 1, 1, 1, 1,
- 1, 1, 1, 1
- };
-
- /** the input device */
- private java.io.Reader yy_reader;
-
- /** the current state of the DFA */
- private int yy_state;
-
- /** the current lexical state */
- private int yy_lexical_state = YYINITIAL;
-
- /** this buffer contains the current text to be matched and is
- the source of the yytext() string */
- private char yy_buffer[] = new char[16384];
-
- /** the textposition at the last accepting state */
- private int yy_markedPos;
-
- /** the textposition at the last state to be included in yytext */
- private int yy_pushbackPos;
-
- /** the current text position in the buffer */
- private int yy_currentPos;
-
- /** startRead marks the beginning of the yytext() string in the buffer */
- private int yy_startRead;
-
- /** endRead marks the last character in the buffer, that has been read
- from input */
- private int yy_endRead;
-
- /** number of newlines encountered up to the start of the matched text */
- private int yyline;
-
- /** the number of characters up to the start of the matched text */
- private int yychar;
-
- /**
- * the number of characters from the last newline up to the start of the
- * matched text
- */
- // private int yycolumn;
-
- /**
- * yy_atBOL == true <=> the scanner is currently at the beginning of a line
- */
- // private boolean yy_atBOL;
-
- /** yy_atEOF == true <=> the scanner has returned a value for EOF */
- private boolean yy_atEOF;
-
- /** denotes if the user-EOF-code has already been executed */
- private boolean yy_eof_done;
-
- /* user code: */
- private int fTokenCount = 0;
-
- // required holders for white-space compacting
- private boolean fShouldLoadBuffered = false;
- private String fBufferedContext = null;
- private int fBufferedStart = 1;
- private int fBufferedLength = 0;
- private String f_context = null;
-
- // state stack for handling embedded regions
- private IntStack fStateStack = new IntStack();
-
- private String context = null;
- private int start = 0;
- private int textLength = 0;
- private int length = 0;
-
- // offset for tracking position specific block tags
- private int fOffset = 0;
-
- // the name of the current tag being opened
- private String fCurrentTagName = null;
-
- // the list of tag name BlockMarkers
- private List fBlockMarkers = new ArrayList();
-
- // required to not seek text blocks on an end tag
- private boolean fIsBlockingEnabled = false;
- private boolean fIsCaseSensitiveBlocking = true;
-
- private XMLParserRegionFactory fRegionFactory = new XMLParserRegionFactory();
-/**
- * user method
- */
-public final void addBlockMarker(BlockMarker marker) {
- if(containsTagName(marker.getTagName()))
- return;
- fBlockMarkers.add(marker);
-}
-/**
- * user method
- */
-public final void removeBlockMarker(BlockMarker marker) {
- fBlockMarkers.remove(marker);
-}
-/**
- * user method
- */
-public final void removeBlockMarker(String tagname) {
- if (fBlockMarkers != null) {
- Iterator blocks = fBlockMarkers.iterator();
- while (blocks.hasNext()) {
- if (((BlockMarker) blocks.next()).getTagName().equals(tagname))
- blocks.remove();
- }
- }
-}
-/* user method */
-public final boolean isCaseSensitiveBlocking() {
- return fIsCaseSensitiveBlocking;
-}
-/* user method */
-public final void setCaseSensitiveBlocking(boolean newValue) {
- fIsCaseSensitiveBlocking = newValue;
-}
-/* user method */
-public boolean getBlockMarkerCaseSensitivity() {
- return getBlockMarkerCaseSensitivity(fCurrentTagName);
-}
-/* user method */
-public boolean getBlockMarkerCaseSensitivity(String name) {
- Iterator iterator = fBlockMarkers.iterator();
- while(iterator.hasNext()) {
- BlockMarker marker = (BlockMarker)iterator.next();
- boolean casesensitive = marker.isCaseSensitive();
- if(casesensitive && marker.getTagName().equals(name))
- return casesensitive;
- else if(!casesensitive && marker.getTagName().equalsIgnoreCase(name))
- return casesensitive;
- }
- return true;
-}
-/* user method */
-public String getBlockMarkerContext() {
- return getBlockMarkerContext(fCurrentTagName);
-}
-/* user method */
-public String getBlockMarkerContext(String name) {
- Iterator iterator = fBlockMarkers.iterator();
- while(iterator.hasNext()) {
- BlockMarker marker = (BlockMarker)iterator.next();
- if(marker.getTagName().equals(name))
- return marker.getContext();
- }
- return BLOCK_TEXT;
-}
-/* user method */
-public List getBlockMarkers() {
- return fBlockMarkers;
-}
-/* user method */
-public final int getOffset() {
- return fOffset + yychar;
-}
-private final boolean isBlockMarker() {
- return isBlockMarker(fCurrentTagName);
-}
-private final boolean isBlockMarker(String tagName) {
- if (!fIsBlockingEnabled)
- return false;
- return containsTagName(tagName);
-}
-/**
- * user method
- */
-public final void beginBlockTagScan(String newTagName) {
- beginBlockMarkerScan(newTagName, BLOCK_TEXT);
-}
-/**
- * user method
- *
- * Special tokenizer setup. Allows tokenization to be initiated at the
- * start of a text block within a "newTagName" tag.
- *
- * Example:
- * Tokenizer toker = new Tokenizer();
- * toker.setCaseSensitiveBlocking(false);
- * toker.reset(new java.io.StringReader("afiuhqwkejhtasihgalkwhtq</scripter></scr></script>asgdasga"));
- * toker.beginBlockMarkerScan("script", BLOCK_TEXT);
- * toker.getRegions();
- *
- * Returns:
- * BLOCK_TEXT: 0-40
- * XML_END_TAG_OPEN: 41-42
- * XML_TAG_NAME: 43-48
- * XML_TAG_CLOSE: 49-49
- * XML_CONTENT: 50-57
- *
- */
-public final void beginBlockMarkerScan(String newTagName, String blockcontext) {
- yybegin(ST_BLOCK_TAG_SCAN);
- fCurrentTagName = newTagName;
-}
-/**
- * Method doScan.
- *
- * Returns a context region for all of the text from the current position upto the end of input or
- * to right *before* the first occurence of searchString
- *
- * @param searchString - target string to search for ex.: "-->", "</tagname"
- * @param requireTailSeparator - whether the target must be immediately followed by whitespace or '>'
- * @param context - the context of the scanned region if non-zero length
- * @param exitState - the state to go to if the region was of non-zero length
- * @param abortState - the state to go to if the searchString was found immediately
- * @return String - the context found: the desired context on a non-zero length match, the abortContext on immediate success
- * @throws IOException
- */
-private final String doScan(String searchString, boolean requireTailSeparator, String searchContext, int exitState, int immediateFallbackState) throws IOException {
- boolean stillSearching = true;
- // Disable further block (probably)
- fIsBlockingEnabled = false;
- int searchStringLength = searchString.length();
- int n = 0;
- char lastCheckChar;
- int i;
- boolean same = false;
- while (stillSearching) {
- n = 0;
- // Ensure that enough data from the input exists to compare against the search String.
- n = yy_advance();
- while(n != YYEOF && yy_currentPos < searchStringLength)
- n = yy_advance();
- // If the input was too short or we've exhausted the input, stop immediately.
- if (n == YYEOF) {
- stillSearching = false;
- }
- else {
- same = true;
- // Ensure that we've not encountered a complete block (<%%>) that was *shorter* than the closeTagString and
- // thus found twice at current-targetLength [since the first scan would have come out this far anyway].
- // Check the characters in the target versus the last targetLength characters read from the buffer
- // and see if it matches
-
- // safety check for array accesses (yy_currentPos is the *last* character we can check against)
- if(yy_currentPos >= searchStringLength && yy_currentPos <= yy_buffer.length) {
- for(i = 0; i < searchStringLength; i++) {
- if(same && fIsCaseSensitiveBlocking)
- same = yy_buffer[i + yy_currentPos - searchStringLength] == searchString.charAt(i);
- else if(same && !fIsCaseSensitiveBlocking)
- same = Character.toLowerCase(yy_buffer[i + yy_currentPos - searchStringLength]) == Character.toLowerCase(searchString.charAt(i));
- }
- }
- // safety check failed; no match is possible right now
- else {
- same = false;
- }
- if (same && requireTailSeparator && yy_currentPos < yy_buffer.length) {
- // Additional check for close tags to ensure that targetString="</script" doesn't match
- // "</scriptS"
- lastCheckChar = yy_buffer[yy_currentPos];
- // Succeed on "</script>" and "</script "
- if(lastCheckChar == '>' || Character.isWhitespace(lastCheckChar))
- stillSearching = false;
- }
- else {
- stillSearching = !same || (yy_currentPos < yy_startRead + searchStringLength);
- }
- }
- }
- if (n != YYEOF || same) {
- // We've stopped short of the end or definitely found a match
- yy_markedPos = yy_currentPos - searchStringLength;
- yy_currentPos = yy_markedPos + 1;
- // If the searchString occurs at the very beginning of what would have
- // been a Block, resume scanning normally immediately
- if (yy_markedPos == yy_startRead) {
- yybegin(immediateFallbackState);
- return primGetNextToken();
- }
- }
- else {
- // We ran through the rest of the input
- yy_markedPos = yy_currentPos;
- yy_currentPos++;
- }
- yybegin(exitState);
- // If the ending occurs at the very beginning of what would have
- // been a Block, resume scanning normally immediately
- if(yy_markedPos == yy_startRead)
- return primGetNextToken();
- return searchContext;
-}
-/**
- * user method
- *
- * A generic lookahead-like operation
- */
-private final String doBlockScan(String target, String targetContext, int immediateFallbackState) throws IOException {
- return doScan(target, false, targetContext, immediateFallbackState, immediateFallbackState);
-}
-/**
- * user method
- * does a lookahead for the current tag name
- */
-private final String doBlockTagScan() throws IOException {
- fIsCaseSensitiveBlocking = getBlockMarkerCaseSensitivity();
- return doScan("</" + fCurrentTagName, true, getBlockMarkerContext(fCurrentTagName), YYINITIAL, YYINITIAL);
-}
-/**
- * user method
- *
- * Converts the raw context String returned by the primGetNextToken()
- * method into a full ITextRegion by pulling in values for the
- * current offset within the scanning text.
- *
- * Returns null when EOF is encountered and attaches intermittently
- * discovered whitespace onto the end of useful regions.
- *
- * Note that this algorithm caches the token following the one being returned
- * so that whitespace can be collapsed.
- */
-public final ITextRegion getNextToken() throws IOException {
- // load the starting non-whitespace token (assume that it is so)
- if (fShouldLoadBuffered) {
- context = fBufferedContext;
- start = fBufferedStart;
- textLength = length = fBufferedLength;
- fShouldLoadBuffered = false;
- }
- else {
- context = primGetNextToken();
- if (context == XML_TAG_NAME) {
- if(containsTagName(yy_buffer, yy_startRead, yy_markedPos-yy_startRead))
- fCurrentTagName = yytext();
- else
- fCurrentTagName = null;
- }
- else if (context == XML_TAG_OPEN) {
- fIsBlockingEnabled = true;
- }
- else if (context == XML_END_TAG_OPEN) {
- fIsBlockingEnabled = false;
- }
- start = yychar;
- textLength = length = yylength();
- if (yy_atEOF) {
- fTokenCount++;
- return null;
- }
- }
- // store the next token
- f_context = primGetNextToken();
- if (f_context == XML_TAG_NAME) {
- if(containsTagName(yy_buffer, yy_startRead, yy_markedPos-yy_startRead))
- fCurrentTagName = yytext();
- else
- fCurrentTagName = null;
- }
- else if (f_context == XML_TAG_OPEN) {
- fIsBlockingEnabled = true;
- }
- else if (f_context == XML_END_TAG_OPEN) {
- fIsBlockingEnabled = false;
- }
- fBufferedContext = f_context;
- fBufferedStart = yychar;
- fBufferedLength = yylength();
- fShouldLoadBuffered = true;
- if (fBufferedContext == WHITE_SPACE) {
- fShouldLoadBuffered = false;
- length += fBufferedLength;
- }
- if (context == null) {
- // EOF
- if (Debug.debugTokenizer) {
- System.out.println(getClass().getName() + " discovered " + fTokenCount + " tokens."); //$NON-NLS-2$//$NON-NLS-1$
- }
- return null;
- }
- fTokenCount++;
- return fRegionFactory.createToken(context, start, textLength, length, null, fCurrentTagName);
-}
-/* user method */
-public XMLTokenizer(){
- super();
-}
-/* user method */
-public XMLTokenizer(char[] charArray){
- this(new CharArrayReader(charArray));
-}
-/* user method */
-public void reset(char[] charArray) {
- reset(new CharArrayReader(charArray), 0);
-}
-/* user method */
-public void reset(char[] charArray, int newOffset) {
- reset(new CharArrayReader(charArray), newOffset);
-}
-/* user method */
-public void reset(java.io.InputStream in) {
- reset(new java.io.InputStreamReader(in), 0);
-}
-/* user method */
-public void reset(java.io.InputStream in, int newOffset) {
- reset(new java.io.InputStreamReader(in), newOffset);
-}
-/* user method */
-public void reset(java.io.Reader in) {
- reset(in, 0);
-}
-/**
- * user method *
- *
- * Reset internal counters and vars to "newly created" values, in the hopes
- * that resetting a pre-existing tokenizer is faster than creating a new one.
- *
- * This method contains code blocks that were essentially duplicated from the
- * <em>generated</em> output of this specification before this method was
- * added. Those code blocks were under the above copyright.
- */
-public void reset(java.io.Reader in, int newOffset) {
- if (Debug.debugTokenizer) {
- System.out.println("resetting tokenizer");//$NON-NLS-1$
- }
- fOffset = newOffset;
-
- /* the input device */
- yy_reader = in;
-
- /* the current state of the DFA */
- yy_state = 0;
-
- /* the current lexical state */
- yy_lexical_state = YYINITIAL;
-
- /* this buffer contains the current text to be matched and is
- the source of the yytext() string */
- java.util.Arrays.fill(yy_buffer, (char)0);
-
- /* the textposition at the last accepting state */
- yy_markedPos = 0;
-
- /* the textposition at the last state to be included in yytext */
- yy_pushbackPos = 0;
-
- /* the current text position in the buffer */
- yy_currentPos = 0;
-
- /* startRead marks the beginning of the yytext() string in the buffer */
- yy_startRead = 0;
-
- /**
- * endRead marks the last character in the buffer, that has been read
- * from input
- */
- yy_endRead = 0;
-
- /* number of newlines encountered up to the start of the matched text */
- yyline = 0;
-
- /* the number of characters up to the start of the matched text */
- yychar = 0;
-
- /* yy_atEOF == true <=> the scanner has returned a value for EOF */
- yy_atEOF = false;
-
- /* denotes if the user-EOF-code has already been executed */
- yy_eof_done = false;
-
-
- /* user vars: */
- fTokenCount = 0;
-
- fShouldLoadBuffered = false;
- fBufferedContext = null;
- fBufferedStart = 1;
- fBufferedLength = 0;
- fStateStack = new IntStack();
-
- context = null;
- start = 0;
- textLength = 0;
- length = 0;
-}
-
- /**
- * user method
- *
- */
- public BlockTokenizer newInstance() {
- XMLTokenizer newInstance = new XMLTokenizer();
- // global tagmarkers can be shared; they have no state and
- // are never destroyed (e.g. 'release')
- for(int i = 0; i < fBlockMarkers.size(); i++) {
- BlockMarker blockMarker = (BlockMarker) fBlockMarkers.get(i);
- if(blockMarker.isGlobal())
- newInstance.addBlockMarker(blockMarker);
- }
- return newInstance;
- }
-/* user method */
-private final String scanXMLCommentText() throws IOException {
- // Scan for '-->' and return the text up to that point as
- // XML_COMMENT_TEXT unless the string occurs IMMEDIATELY, in which
- // case change to the ST_XML_COMMENT_END state and return the next
- // context as usual.
- return doScan("-->", false, XML_COMMENT_TEXT, ST_XML_COMMENT_END, ST_XML_COMMENT_END);
-}
-
-
- /**
- * Creates a new scanner
- * There is also a java.io.InputStream version of this constructor.
- *
- * @param in the java.io.Reader to read input from.
- */
- public XMLTokenizer(java.io.Reader in) {
- this.yy_reader = in;
- }
-
- /**
- * Creates a new scanner.
- * There is also java.io.Reader version of this constructor.
- *
- * @param in the java.io.Inputstream to read input from.
- */
- public XMLTokenizer(java.io.InputStream in) {
- this(new java.io.InputStreamReader(in));
- }
-
- /**
- * Unpacks the compressed DFA transition table.
- *
- * @param packed the packed transition table
- * @return the unpacked transition table
- */
- private static int [] yy_unpack(String packed) {
- int [] trans = new int[11055];
- int i = 0; /* index in packed string */
- int j = 0; /* index in unpacked array */
- while (i < 3638) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- value--;
- do trans[j++] = value; while (--count > 0);
- }
- return trans;
- }
-
- /**
- * Unpacks the compressed character translation table.
- *
- * @param packed the packed character translation table
- * @return the unpacked character translation table
- */
- private static char [] yy_unpack_cmap(String packed) {
- char [] map = new char[0x10000];
- int i = 0; /* index in packed string */
- int j = 0; /* index in unpacked array */
- while (i < 1372) {
- int count = packed.charAt(i++);
- char value = packed.charAt(i++);
- do map[j++] = value; while (--count > 0);
- }
- return map;
- }
-
-
- /**
- * Gets the next input character.
- *
- * @return the next character of the input stream, EOF if the
- * end of the stream is reached.
- * @exception IOException if any I/O-Error occurs
- */
- private int yy_advance() throws java.io.IOException {
-
- /* standard case */
- if (yy_currentPos < yy_endRead) return yy_buffer[yy_currentPos++];
-
- /* if the eof is reached, we don't need to work hard */
- if (yy_atEOF) return YYEOF;
-
- /* otherwise: need to refill the buffer */
-
- /* first: make room (if you can) */
- if (yy_startRead > 0) {
- System.arraycopy(yy_buffer, yy_startRead,
- yy_buffer, 0,
- yy_endRead-yy_startRead);
-
- /* translate stored positions */
- yy_endRead-= yy_startRead;
- yy_currentPos-= yy_startRead;
- yy_markedPos-= yy_startRead;
- yy_pushbackPos-= yy_startRead;
- yy_startRead = 0;
- }
-
- /* is the buffer big enough? */
- if (yy_currentPos >= yy_buffer.length) {
- /* if not: blow it up */
- char newBuffer[] = new char[yy_currentPos*2];
- System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length);
- yy_buffer = newBuffer;
- }
-
- /* finally: fill the buffer with new input */
- int numRead = yy_reader.read(yy_buffer, yy_endRead,
- yy_buffer.length-yy_endRead);
-
- if ( numRead == -1 ) return YYEOF;
-
- yy_endRead+= numRead;
-
- return yy_buffer[yy_currentPos++];
- }
-
-
- /**
- * Closes the input stream.
- */
- final public void yyclose() throws java.io.IOException {
- yy_atEOF = true; /* indicate end of file */
- yy_endRead = yy_startRead; /* invalidate buffer */
- yy_reader.close();
- }
-
-
- /**
- * Returns the current lexical state.
- */
- final public int yystate() {
- return yy_lexical_state;
- }
-
- /**
- * Enters a new lexical state
- *
- * @param newState the new lexical state
- */
- final public void yybegin(int newState) {
- yy_lexical_state = newState;
- }
-
-
- /**
- * Returns the text matched by the current regular expression.
- */
- final public String yytext() {
- return new String( yy_buffer, yy_startRead, yy_markedPos-yy_startRead );
- }
-
- /**
- * Returns the length of the matched text region.
- */
- final public int yylength() {
- return yy_markedPos-yy_startRead;
- }
-
-
- /**
- * Reports an error that occured while scanning - from the SED JFlex skeleton
- *
- * @param errorCode the code of the errormessage to display
- */
- private void yy_ScanError(int errorCode) {
- try {
- Logger.log(Logger.ERROR, YY_ERROR_MSG[errorCode]);
- }
- catch (ArrayIndexOutOfBoundsException e) {
- Logger.log(Logger.ERROR, YY_ERROR_MSG[YY_UNKNOWN_ERROR]);
- }
- // DO NOT EXIT the VM on an error
- // System.exit(1);
- }
-
-
- /**
- * Pushes the specified amount of characters back into the input stream.
- *
- * They will be read again by then next call of the scanning method
- *
- * @param number the number of characters to be read again.
- * This number must not be greater than yylength()!
- */
- void yypushback(int number) {
- if ( number > yylength() )
- yy_ScanError(YY_PUSHBACK_2BIG);
-
- yy_markedPos -= number;
- }
-
- /**
- * user method - skeleton.sed
- */
- protected final boolean containsTagName(char[] markerTagName, int offset, int tagnameLength) {
- for(int j = 0; j < fBlockMarkers.size(); j++) {
- BlockMarker marker = (BlockMarker)fBlockMarkers.get(j);
- if(marker.getTagName().length() == tagnameLength) {
- boolean matchesSoFar = true;
- for(int i = 0; i < tagnameLength && matchesSoFar; i++) {
- if(marker.isCaseSensitive()) {
- if(marker.getTagName().charAt(i) != markerTagName[i + offset])
- matchesSoFar = false;
- }
- else {
- if(Character.toLowerCase(marker.getTagName().charAt(i)) != Character.toLowerCase(markerTagName[i + offset]))
- matchesSoFar = false;
- }
- }
- if(matchesSoFar)
- return true;
- }
- }
- return false;
- }
-
- /**
- * user method - skeleton.sed
- *
- * Return ALL of the regions scannable within the remaining text
- * Note: for verification use
- */
- public final List getRegions() {
- List tokens = new ArrayList();
- ITextRegion region = null;
- try {
- region = getNextToken();
- while(region != null) {
- if (region != null) {
- tokens.add(region);
- }
- region = getNextToken();
- }
- }
- catch (StackOverflowError e) {
- Logger.logException(getClass().getName()+": input could not be tokenized correctly at position " + getOffset(), e);//$NON-NLS-1$
- throw e;
- }
- catch (Exception e) {
- // Since this is convenience method and NOT the recommended
- // way of getting tokens, many errors are simply hidden
- Logger.logException("Exception not handled retrieving regions: " + e.getLocalizedMessage(), e);//$NON-NLS-1$
- }
- return tokens;
- }
- /**
- * user method - skeleton.sed
- */
- private final void dump(String s) {
- if (Debug.debugTokenizer) {
- System.out.println(s + " (" + yychar + "-" + //$NON-NLS-2$//$NON-NLS-1$
- (yylength() + yychar) + "):\'" +//$NON-NLS-1$
- StringUtils.escape(yytext()) + "\'");//$NON-NLS-1$
- }
- }
- /* user method - skeleton.sed */
- public final boolean isEOF() {
- return yy_atEOF;
- }
-/* user method - skeleton.sed */
-protected final boolean containsTagName(String markerTagName) {
- Iterator blocks = fBlockMarkers.iterator();
- while(blocks.hasNext()) {
- BlockMarker marker = (BlockMarker)blocks.next();
- if(marker.isCaseSensitive()) {
- if(marker.getTagName().equals(markerTagName))
- return true;
- }
- else {
- if(marker.getTagName().equalsIgnoreCase(markerTagName))
- return true;
- }
- }
- return false;
-}
-
- /**
- * Contains user EOF-code, which will be executed exactly once,
- * when the end of file is reached
- */
- private void yy_do_eof() {
- if (!yy_eof_done) {
- yy_eof_done = true;
- // do nothing, this is the downstream parser's job
-
- }
- }
-
-
- /**
- * Resumes scanning until the next regular expression is matched,
- * the end of input is encountered or an I/O-Error occurs.
- *
- * @return the next token
- * @exception IOException if any I/O-Error occurs
- */
- public String primGetNextToken() throws java.io.IOException {
- int yy_input;
- int yy_action;
-
-
- while (true) {
-
- yychar+= yylength();
-
- boolean yy_counted = false;
- for (yy_currentPos = yy_startRead; yy_currentPos < yy_markedPos;
- yy_currentPos++) {
- switch (yy_buffer[yy_currentPos]) {
- case '\r':
- yyline++;
- yy_counted = true;
- break;
- case '\n':
- if (yy_counted)
- yy_counted = false;
- else {
- yyline++;
- }
- break;
- default:
- yy_counted = false;
- }
- }
-
- if (yy_counted) {
- if ( yy_advance() == '\n' ) yyline--;
- if ( !yy_atEOF ) yy_currentPos--;
- }
-
- yy_action = -1;
-
- yy_currentPos = yy_startRead = yy_markedPos;
-
- yy_state = yy_lexical_state;
-
-
- yy_forAction: {
- while (true) {
-
- yy_input = yy_advance();
-
- if ( yy_input == YYEOF ) break yy_forAction;
-
- int yy_next = yytrans[ yy_rowMap[yy_state] + yycmap[yy_input] ];
- if (yy_next == -1) break yy_forAction;
- yy_state = yy_next;
-
- int yy_attributes = YY_ATTRIBUTE[yy_state];
- if ( (yy_attributes & 1) > 0 ) {
- yy_action = yy_state;
- yy_markedPos = yy_currentPos;
- if ( (yy_attributes & 8) > 0 ) break yy_forAction;
- }
-
- }
- }
-
-
- switch (yy_action) {
-
- case 291:
- {
- if(Debug.debugTokenizer)
- dump("XSL processing instruction target");//$NON-NLS-1$
- yybegin(ST_XML_PI_ATTRIBUTE_NAME);
- return XML_TAG_NAME;
- }
- case 293: break;
- case 283:
- case 285:
- case 286:
- {
- if(Debug.debugTokenizer)
- dump("\nCDATA start");//$NON-NLS-1$
- fStateStack.push(yystate());
- yybegin(ST_CDATA_TEXT);
- return XML_CDATA_OPEN;
- }
- case 294: break;
- case 276:
- {
- if(Debug.debugTokenizer)
- dump("element");//$NON-NLS-1$
- yybegin(ST_XML_ELEMENT_DECLARATION);
- return XML_ELEMENT_DECLARATION;
- }
- case 295: break;
- case 275:
- {
- if(Debug.debugTokenizer)
- dump("attlist");//$NON-NLS-1$
- yybegin(ST_XML_ATTLIST_DECLARATION);
- return XML_ATTLIST_DECLARATION;
- }
- case 296: break;
- case 274:
- {
- if(Debug.debugTokenizer)
- dump("doctype");//$NON-NLS-1$
- yybegin(ST_XML_DOCTYPE_DECLARATION);
- return XML_DOCTYPE_DECLARATION;
- }
- case 297: break;
- case 268:
- {
- if(Debug.debugTokenizer)
- dump("doctype external id");//$NON-NLS-1$
- yybegin(ST_XML_DOCTYPE_ID_PUBLIC);
- return XML_DOCTYPE_EXTERNAL_ID_PUBLIC;
- }
- case 298: break;
- case 267:
- {
- if(Debug.debugTokenizer)
- dump("doctype external id");//$NON-NLS-1$
- yybegin(ST_XML_DOCTYPE_ID_SYSTEM);
- return XML_DOCTYPE_EXTERNAL_ID_SYSTEM;
- }
- case 299: break;
- case 263:
- case 273:
- {
- if(Debug.debugTokenizer)
- dump("DHTML processing instruction target");//$NON-NLS-1$
- yybegin(ST_DHTML_ATTRIBUTE_NAME);
- return XML_TAG_NAME;
- }
- case 300: break;
- case 237:
- {
- if(Debug.debugTokenizer)
- dump("\nCharRef");//$NON-NLS-1$
- return XML_CHAR_REFERENCE;
- }
- case 301: break;
- case 234:
- {
- if(Debug.debugTokenizer)
- dump("\ncomment start");//$NON-NLS-1$
- yybegin(ST_XML_COMMENT);
- return XML_COMMENT_OPEN;
- }
- case 302: break;
- case 215:
- case 216:
- {
- if(Debug.debugTokenizer)
- dump("XML processing instruction target");//$NON-NLS-1$
- yybegin(ST_XML_PI_ATTRIBUTE_NAME);
- return XML_TAG_NAME;
- }
- case 303: break;
- case 214:
- {
- if(Debug.debugTokenizer)
- dump("comment end");//$NON-NLS-1$
- yybegin(YYINITIAL);
- return XML_COMMENT_CLOSE;
- }
- case 304: break;
- case 213:
- {
- if(Debug.debugTokenizer)
- dump("CDATA end");//$NON-NLS-1$
- yybegin(fStateStack.pop());
- return XML_CDATA_CLOSE;
- }
- case 305: break;
- case 212:
- {
- if(Debug.debugTokenizer)
- dump("\nPEReference");//$NON-NLS-1$
- return XML_PE_REFERENCE;
- }
- case 306: break;
- case 209:
- {
- if(Debug.debugTokenizer)
- dump("\nEntityRef");//$NON-NLS-1$
- return XML_ENTITY_REFERENCE;
- }
- case 307: break;
- case 160:
- case 174:
- case 182:
- {
- return XML_DOCTYPE_INTERNAL_SUBSET;
- }
- case 308: break;
- case 148:
- {
- yybegin(YYINITIAL);
- if(Debug.debugTokenizer)
- dump("empty tag close");//$NON-NLS-1$
- return XML_EMPTY_TAG_CLOSE;
- }
- case 309: break;
- case 133:
- {
- if(Debug.debugTokenizer)
- dump("XML processing instruction end");//$NON-NLS-1$
- yybegin(YYINITIAL);
- return XML_PI_CLOSE;
- }
- case 310: break;
- case 132:
- {
- // ended with nothing inside
- yybegin(YYINITIAL);
- return XML_PI_CLOSE;
- }
- case 311: break;
- case 128:
- {
- if(Debug.debugTokenizer)
- dump("processing instruction end");//$NON-NLS-1$
- yybegin(YYINITIAL);
- return XML_PI_CLOSE;
- }
- case 312: break;
- case 120:
- {
- fStateStack.push(yystate());
- if(Debug.debugTokenizer)
- dump("\ndeclaration start");//$NON-NLS-1$
- yybegin(ST_XML_DECLARATION);
- return XML_DECLARATION_OPEN;
- }
- case 313: break;
- case 119:
- {
- if(Debug.debugTokenizer)
- dump("\nprocessing instruction start");//$NON-NLS-1$
- yybegin(ST_PI);
- return XML_PI_OPEN;
- }
- case 314: break;
- case 63:
- {
- if(Debug.debugTokenizer)
- dump("DHTML processing instruction end");//$NON-NLS-1$
- yybegin(YYINITIAL);
- return XML_PI_CLOSE;
- }
- case 315: break;
- case 57:
- case 59:
- case 60:
- case 61:
- case 137:
- {
- if(Debug.debugTokenizer)
- dump("XML processing instruction attribute value");//$NON-NLS-1$
- yybegin(ST_XML_PI_ATTRIBUTE_NAME);
- return XML_TAG_ATTRIBUTE_VALUE;
- }
- case 316: break;
- case 56:
- {
- if(Debug.debugTokenizer)
- dump("XML processing instruction '='");//$NON-NLS-1$
- yybegin(ST_XML_PI_ATTRIBUTE_VALUE);
- return XML_TAG_ATTRIBUTE_EQUALS;
- }
- case 317: break;
- case 55:
- {
- if(Debug.debugTokenizer)
- dump("XML processing instruction attribute name");//$NON-NLS-1$
- yybegin(ST_XML_PI_EQUALS);
- return XML_TAG_ATTRIBUTE_NAME;
- }
- case 318: break;
- case 51:
- case 52:
- case 53:
- {
- // block scan until close is found
- return doScan("?>", false, XML_PI_CONTENT, ST_XML_PI_TAG_CLOSE, ST_XML_PI_TAG_CLOSE);
- }
- case 319: break;
- case 50:
- {
- yybegin(ST_PI_CONTENT);
- return WHITE_SPACE;
- }
- case 320: break;
- case 46:
- case 47:
- case 48:
- case 49:
- case 129:
- case 130:
- case 131:
- case 217:
- case 239:
- case 240:
- case 252:
- case 253:
- case 262:
- case 272:
- case 280:
- case 284:
- case 287:
- case 288:
- case 289:
- case 290:
- {
- if(Debug.debugTokenizer)
- dump("processing instruction target");//$NON-NLS-1$
- yybegin(ST_PI_WS);
- return XML_TAG_NAME;
- }
- case 321: break;
- case 41:
- case 42:
- {
- if(Debug.debugTokenizer)
- dump("comment content");//$NON-NLS-1$
- return scanXMLCommentText();
- }
- case 322: break;
- case 40:
- {
- if(Debug.debugTokenizer)
- dump("LINE FEED");//$NON-NLS-1$
- return WHITE_SPACE;
- }
- case 323: break;
- case 0:
- case 31:
- case 122:
- case 124:
- case 207:
- case 208:
- case 236:
- {
- if(Debug.debugTokenizer)
- dump("\nXML content");//$NON-NLS-1$
- return XML_CONTENT;
- }
- case 324: break;
- case 5:
- case 8:
- case 9:
- case 10:
- case 12:
- case 13:
- case 14:
- case 15:
- case 17:
- case 18:
- case 19:
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 28:
- case 45:
- {
- if(Debug.debugTokenizer)
- dump("white space");//$NON-NLS-1$
- return WHITE_SPACE;
- }
- case 325: break;
- case 16:
- case 71:
- {
- if(Debug.debugTokenizer)
- dump("inappropriate tag name");//$NON-NLS-1$
- yybegin(YYINITIAL);
- return XML_CONTENT;
- }
- case 326: break;
- case 27:
- case 106:
- case 107:
- case 193:
- case 229:
- case 248:
- case 259:
- case 269:
- case 277:
- case 281:
- {
- if(Debug.debugTokenizer)
- dump("elementdecl contentspec");//$NON-NLS-1$
- return XML_ELEMENT_DECL_CONTENT;
- }
- case 327: break;
- case 29:
- case 113:
- case 114:
- case 204:
- case 233:
- case 250:
- case 260:
- case 270:
- case 278:
- case 282:
- {
- if(Debug.debugTokenizer)
- dump("attlist contentspec");//$NON-NLS-1$
- return XML_ATTLIST_DECL_CONTENT;
- }
- case 328: break;
- case 32:
- case 72:
- case 83:
- {
- if(Debug.debugTokenizer)
- dump("\nstart tag open");//$NON-NLS-1$
- yybegin(ST_XML_TAG_NAME);
- return XML_TAG_OPEN;
- }
- case 329: break;
- case 33:
- case 34:
- case 37:
- case 38:
- case 39:
- case 43:
- case 44:
- case 54:
- case 58:
- case 62:
- case 64:
- case 68:
- case 74:
- case 80:
- case 85:
- case 86:
- case 87:
- case 88:
- case 90:
- case 91:
- case 93:
- case 98:
- case 103:
- case 110:
- {
- if (Debug.debugTokenizer)
- System.out.println("!!!unexpected!!!: \"" + yytext() + "\":" + //$NON-NLS-2$//$NON-NLS-1$
- yychar + "-" + (yychar + yylength()));//$NON-NLS-1$
- return UNDEFINED;
- }
- case 330: break;
- case 35:
- case 36:
- {
- if(Debug.debugTokenizer)
- dump("CDATA text");//$NON-NLS-1$
- String blockContext = doBlockScan("]]>", XML_CDATA_TEXT, ST_CDATA_END);//$NON-NLS-1$
- if(blockContext == XML_CDATA_TEXT)
- yybegin(ST_CDATA_END);
- return blockContext;
- }
- case 331: break;
- case 65:
- {
- if(Debug.debugTokenizer)
- dump("DHTML processing instruction attribute name");//$NON-NLS-1$
- yybegin(ST_DHTML_EQUALS);
- return XML_TAG_ATTRIBUTE_NAME;
- }
- case 332: break;
- case 66:
- {
- if(Debug.debugTokenizer)
- dump("DHTML processing instruction '='");//$NON-NLS-1$
- yybegin(ST_DHTML_ATTRIBUTE_VALUE);
- return XML_TAG_ATTRIBUTE_EQUALS;
- }
- case 333: break;
- case 67:
- case 69:
- case 70:
- case 145:
- {
- if(Debug.debugTokenizer)
- dump("DHTML processing instruction attribute value");//$NON-NLS-1$
- yybegin(ST_DHTML_ATTRIBUTE_NAME);
- return XML_TAG_ATTRIBUTE_VALUE;
- }
- case 334: break;
- case 73:
- {
- if(Debug.debugTokenizer)
- dump("tag close");//$NON-NLS-1$
- if(isBlockMarker()) {
- yybegin(ST_BLOCK_TAG_SCAN);
- }
- else
- yybegin(YYINITIAL);
- return XML_TAG_CLOSE;
- }
- case 335: break;
- case 75:
- case 76:
- {
- if(Debug.debugTokenizer)
- dump("tag name");//$NON-NLS-1$
- yybegin(ST_XML_ATTRIBUTE_NAME);
- return XML_TAG_NAME;
- }
- case 336: break;
- case 77:
- {
- if(Debug.debugTokenizer)
- dump("attr name");//$NON-NLS-1$
- yybegin(ST_XML_EQUALS);
- return XML_TAG_ATTRIBUTE_NAME;
- }
- case 337: break;
- case 78:
- {
- if(Debug.debugTokenizer)
- dump("equals");//$NON-NLS-1$
- yybegin(ST_XML_ATTRIBUTE_VALUE);
- return XML_TAG_ATTRIBUTE_EQUALS;
- }
- case 338: break;
- case 79:
- case 81:
- case 82:
- case 152:
- {
- if(Debug.debugTokenizer)
- dump("attr value");//$NON-NLS-1$
- yybegin(ST_XML_ATTRIBUTE_NAME);
- return XML_TAG_ATTRIBUTE_VALUE;
- }
- case 339: break;
- case 84:
- {
- if(Debug.debugTokenizer)
- dump("declaration end");//$NON-NLS-1$
- if (Debug.debugTokenizer) {
- if(fStateStack.peek()!=YYINITIAL)
- System.out.println("end embedded region");//$NON-NLS-1$
- }
- yybegin(fStateStack.pop());
- return XML_DECLARATION_CLOSE;
- }
- case 340: break;
- case 89:
- {
- if(Debug.debugTokenizer)
- dump("doctype type");//$NON-NLS-1$
- yybegin(ST_XML_DOCTYPE_EXTERNAL_ID);
- return XML_DOCTYPE_NAME;
- }
- case 341: break;
- case 92:
- case 94:
- case 95:
- case 96:
- case 166:
- case 167:
- case 170:
- case 171:
- case 224:
- {
- if(Debug.debugTokenizer)
- dump("doctype public reference");//$NON-NLS-1$
- yybegin(ST_XML_DOCTYPE_ID_SYSTEM);
- return XML_DOCTYPE_EXTERNAL_ID_PUBREF;
- }
- case 342: break;
- case 97:
- case 99:
- case 100:
- case 101:
- case 178:
- {
- if(Debug.debugTokenizer)
- dump("doctype system reference");//$NON-NLS-1$
- yybegin(ST_XML_DECLARATION_CLOSE);
- return XML_DOCTYPE_EXTERNAL_ID_SYSREF;
- }
- case 343: break;
- case 102:
- case 104:
- case 105:
- case 186:
- case 187:
- case 190:
- case 191:
- case 227:
- {
- if(Debug.debugTokenizer)
- dump("elementdecl name");//$NON-NLS-1$
- yybegin(ST_XML_ELEMENT_DECLARATION_CONTENT);
- return XML_ELEMENT_DECL_NAME;
- }
- case 344: break;
- case 108:
- {
- if(Debug.debugTokenizer)
- dump("elementdecl close");//$NON-NLS-1$
- if (Debug.debugTokenizer) {
- if(fStateStack.peek()!=YYINITIAL)
- System.out.println("end embedded region");//$NON-NLS-1$
- }
- yybegin(fStateStack.pop());
- return XML_DECLARATION_CLOSE;
- }
- case 345: break;
- case 109:
- case 111:
- case 112:
- case 197:
- case 198:
- case 201:
- case 202:
- case 231:
- {
- if(Debug.debugTokenizer)
- dump("attlist name");//$NON-NLS-1$
- yybegin(ST_XML_ATTLIST_DECLARATION_CONTENT);
- return XML_ATTLIST_DECL_NAME;
- }
- case 346: break;
- case 115:
- {
- if(Debug.debugTokenizer)
- dump("attlist close");//$NON-NLS-1$
- if (Debug.debugTokenizer) {
- if(fStateStack.peek()!=YYINITIAL)
- System.out.println("end embedded region");//$NON-NLS-1$
- }
- yybegin(fStateStack.pop());
- return XML_DECLARATION_CLOSE;
- }
- case 347: break;
- case 118:
- {
- if(Debug.debugTokenizer)
- dump("\nend tag open");//$NON-NLS-1$
- yybegin(ST_XML_TAG_NAME);
- return XML_END_TAG_OPEN;
- }
- case 348: break;
- case 116:
- case 117:
- {
- return doBlockTagScan();
- }
- case 349: break;
- default:
- if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
- yy_atEOF = true;
- yy_do_eof();
- return null;
- }
- else {
- yy_ScanError(YY_NO_MATCH);
- }
- }
- }
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeEqualsRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeEqualsRegion.java
deleted file mode 100644
index 836dd41f5c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeEqualsRegion.java
+++ /dev/null
@@ -1,92 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-
-public class AttributeEqualsRegion implements ITextRegion {
- static private final byte fTextLength = 1;
- static private final String fType = DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS;
- private short fLength;
- private int fStart;
-
-
- public AttributeEqualsRegion() {
- super();
- }
-
- public AttributeEqualsRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fLength = (short) length;
- }
-
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
- public void adjustTextLength(int i) {
- // not supported
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = (short) region.getLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeNameRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeNameRegion.java
deleted file mode 100644
index a2c4158f80..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeNameRegion.java
+++ /dev/null
@@ -1,165 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class AttributeNameRegion implements ITextRegion {
- // specify correct type
- static private final String fType = DOMRegionContext.XML_TAG_ATTRIBUTE_NAME;
- private int fLength;
- private int fStart;
- private int fTextLength;
-
- public AttributeNameRegion() {
- super();
- }
-
- public AttributeNameRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fTextLength = textLength;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
- public void adjustTextLength(int i) {
- fTextLength += 1;
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- RegionChangedEvent result = null;
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + fType); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
- canHandle = false;
- } else {
- canHandle = true;
- }
- } else {
- if ((RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(this, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- } else {
- canHandle = false;
- }
-
- }
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- // TO_DO_FUTURE: cache value of canHandleAsWhiteSpace from above
- // If we are handling as whitespace, there is no need to increase
- // the text length, only
- // the total length is changing.
- if (!RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) {
- fTextLength += lengthDifference;
- }
- fLength += lengthDifference;
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, this, changes, requestStart, lengthToReplace);
- }
-
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeValueRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeValueRegion.java
deleted file mode 100644
index 7fbbbbf353..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/AttributeValueRegion.java
+++ /dev/null
@@ -1,162 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class AttributeValueRegion implements ITextRegion {
- // specify correct type
- static private final String fType = DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE;
- private int fLength;
- private int fStart;
- private int fTextLength;
-
- public AttributeValueRegion() {
- super();
- }
-
- public AttributeValueRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fTextLength = textLength;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
- }
-
- public void adjustStart(int i) {
- fStart += i;
- }
-
- public void adjustTextLength(int i) {
- fTextLength += 1;
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- RegionChangedEvent result = null;
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + fType); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
- canHandle = false;
- } else {
- canHandle = true;
- }
- } else {
- if ((RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(this, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- } else {
- canHandle = false;
- }
- }
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- // TO_DO_FUTURE: cache value of canHandleAsWhiteSpace from above
- // If we are handling as whitespace, there is no need to increase
- // the text length, only
- // the total length is changing.
- if (!RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) {
- fTextLength += lengthDifference;
- }
- // update length (and end) after above check for white space,
- // since
- // it looks to determine if at end of region.
- fLength += lengthDifference;
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, this, changes, requestStart, lengthToReplace);
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EmptyTagCloseRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EmptyTagCloseRegion.java
deleted file mode 100644
index 339d692f4a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EmptyTagCloseRegion.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-public class EmptyTagCloseRegion implements ITextRegion {
- private int fLength = 2;
- static private final byte fTextLength = 2;
- static private final String fType = DOMRegionContext.XML_EMPTY_TAG_CLOSE;
- private int fStart;
-
-
- public EmptyTagCloseRegion() {
- super();
- }
-
- public EmptyTagCloseRegion(int start, int textLength, int length) {
- super();
- fStart = start;
- fLength = length;
- if (fTextLength != textLength)
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- }
-
- public void adjustLength(int i) {
- fLength += i;
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
- public void adjustTextLength(int i) {
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EndTagOpenRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EndTagOpenRegion.java
deleted file mode 100644
index 1ad5549d0d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/EndTagOpenRegion.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-public class EndTagOpenRegion implements ITextRegion {
- static private final String fType = DOMRegionContext.XML_END_TAG_OPEN;
- private int fLength;
- private int fStart;
- static private final byte fTextLength = 2;
-
-
- public EndTagOpenRegion() {
- super();
- }
-
- public EndTagOpenRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- if (fTextLength != textLength)
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- fLength = length;
- }
-
- public EndTagOpenRegion(int start, int length) {
- this();
- fStart = start;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
-// fTextLength += 1;
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
-// fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/GenericTemplateRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/GenericTemplateRegion.java
deleted file mode 100644
index e6064beb1d..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/GenericTemplateRegion.java
+++ /dev/null
@@ -1,102 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-/**
- *
- * This class is not intended to be used, its just present to server as a
- * generic starting point for adding new specific region types.
- *
- */
-
-public class GenericTemplateRegion implements ITextRegion {
- // specify correct type
- static private final String fType = DOMRegionContext.UNDEFINED;
- private int fLength;
- private int fStart;
- private int fTextLength;
-
-
- public GenericTemplateRegion() {
- super();
- }
-
- public GenericTemplateRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fTextLength = textLength;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
- fTextLength += i;
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionToStringUtil.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionToStringUtil.java
deleted file mode 100644
index af783f63b0..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionToStringUtil.java
+++ /dev/null
@@ -1,29 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-
-
-public class RegionToStringUtil {
- static public String toString(ITextRegion region) {
- String className = region.getClass().getName();
- String shortClassName = className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$
- String result = shortClassName + "--> " + region.getType() + ": " + region.getStart() + "-" + region.getTextEnd() + (region.getTextEnd() != region.getEnd() ? ("/" + region.getEnd()) : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- // NOTE: if the document held by any region has been updated and the
- // region offsets have not
- // yet been updated, the output from this method invalid.
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionUpdateRule.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionUpdateRule.java
deleted file mode 100644
index 567d0937bc..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/RegionUpdateRule.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-
-
-/**
- *
- * This is a utility class to centralize 'region' update. Note: care must be
- * taken that is is not used for StructuredDocumentRegions, or container
- * regions, its only for "token regions"
- *
- */
-public class RegionUpdateRule {
-
- static public boolean allLetterOrDigit(String changes) {
- boolean result = true;
- for (int i = 0; i < changes.length(); i++) {
- // TO_DO_FUTURE: check that a Java Letter or Digit is
- // the same thing as an XML letter or digit
- if (!(Character.isLetterOrDigit(changes.charAt(i)))) {
- result = false;
- break;
- }
- }
- return result;
- }
-
- static public boolean allWhiteSpace(String changes) {
- boolean result = true;
- for (int i = 0; i < changes.length(); i++) {
- if (!Character.isWhitespace(changes.charAt(i))) {
- result = false;
- break;
- }
- }
- return result;
- }
-
- static public boolean canHandleAsLetterOrDigit(ITextRegion region, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- if (parent == null)
- return canHandleAsLetterOrDigit(region, changes, requestStart, lengthToReplace);
- boolean result = false;
- // Make sure we are in a non-white space area
- if ((requestStart <= (parent.getTextEndOffset(region))) && (allLetterOrDigit(changes))) {
- result = true;
- }
- return result;
- }
-
- static public boolean canHandleAsLetterOrDigit(ITextRegion region, String changes, int requestStart, int lengthToReplace) {
- boolean result = false;
- // Make sure we are in a non-white space area
- if ((requestStart <= (region.getTextEnd())) && (allLetterOrDigit(changes))) {
- result = true;
- }
- return result;
- }
-
- static public boolean canHandleAsWhiteSpace(ITextRegion region, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // we don't explect a null parent, but just in case!
- // (in which case, we must be dealing with regions that are
- // structuredDocumentRegions).
- if (parent == null)
- return canHandleAsWhiteSpace(region, changes, requestStart, lengthToReplace);
- boolean result = false;
- // if we are in the "white space" area of a region, then
- // we don't want to handle, a reparse is needed.
- // the white space region is consider anywhere that would
- // leave whitespace between this character and the text part.
- // and of course, we can insert whitespace in whitespace region
- //
- // if there is no whitespace in this region, no need to look further
- if (region.getEnd() > region.getTextEnd()) {
- // no need to add one to end of text, as we used to, since we
- // change definition of length to equate to offset plus one.
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105866
- // watch out for whitespace at end of text
- if (requestStart >= parent.getTextEndOffset(region)) {
- // ok, we are in the whitespace region, so we can't handle,
- // unless
- // we are just inserting whitespace.
- if (allWhiteSpace(changes)) {
- result = true;
- } else {
- result = false;
- }
- }
- }
- return result;
- }
-
- static public boolean canHandleAsWhiteSpace(ITextRegion region, String changes, int requestStart, int lengthToReplace) {
- boolean result = false;
- // if we are in the "white space" area of a region, then
- // we don't want to handle, a reparse is needed.
- // the white space region is consider anywhere that would
- // leave whitespace between this character and the text part.
- // and of course, we can insert whitespace in whitespace region
- //
- // if there is no whitespace in this region, no need to look further
- if (region.getEnd() > region.getTextEnd()) {
- // no need to add one to end of text, as we used to, since we
- // change definition of length to equate to offset plus one.
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105866
- // watch out for whitespace at end of text
- if (requestStart >= region.getTextEnd()) {
- // ok, we are in the whitespace region, so we can't handle,
- // unless
- // we are just inserting whitespace.
- if (allWhiteSpace(changes)) {
- result = true;
- } else {
- result = false;
- }
- }
- }
- return result;
- }
-
- // need an adjust text length API before this can be used
- static public StructuredDocumentEvent updateModel(ITextRegion region, Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- RegionChangedEvent result = null;
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + region.getType()); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((region.getStart() >= region.getTextEnd()) || (Math.abs(lengthToReplace) >= region.getTextEnd() - region.getStart())) {
- canHandle = false;
- } else {
- canHandle = true;
- }
- } else {
- if ((RegionUpdateRule.canHandleAsWhiteSpace(region, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(region, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- } else {
- canHandle = false;
- }
- }
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- region.adjustLength(lengthDifference);
- // TO_DO_FUTURE: cache value of canHandleAsWhiteSpace from above
- // If we are handling as whitespace, there is no need to increase
- // the text length, only
- // the total length is changing.
- if (!RegionUpdateRule.canHandleAsWhiteSpace(region, parent, changes, region.getStart(), lengthToReplace)) {
- // region.adjustTextLength(lengthDifference);
- }
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, region, changes, requestStart, lengthToReplace);
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagCloseRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagCloseRegion.java
deleted file mode 100644
index 027ae4d992..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagCloseRegion.java
+++ /dev/null
@@ -1,89 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-public class TagCloseRegion implements ITextRegion {
- static private final byte fLength = 1;
- static private final byte fTextLength = 1;
- static private final String fType = DOMRegionContext.XML_TAG_CLOSE;
- private int fStart;
-
-
- public TagCloseRegion() {
- super();
- }
-
- public TagCloseRegion(int start) {
- this();
- fStart = start;
- }
-
- public void adjustLength(int i) {
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
- public void adjustTextLength(int i) {
- // not supported
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagNameRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagNameRegion.java
deleted file mode 100644
index 38b59c4233..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagNameRegion.java
+++ /dev/null
@@ -1,93 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-public class TagNameRegion implements ITextRegion {
- static private final String fType = DOMRegionContext.XML_TAG_NAME;
- private short fLength;
- private int fStart;
- private short fTextLength;
-
-
- public TagNameRegion() {
- super();
- }
-
- public TagNameRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fTextLength = (short) textLength;
- fLength = (short) length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
- fTextLength += i;
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = (short) region.getLength();
- fTextLength = (short) region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagOpenRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagOpenRegion.java
deleted file mode 100644
index e8cb85e928..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/TagOpenRegion.java
+++ /dev/null
@@ -1,98 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-public class TagOpenRegion implements ITextRegion {
- static private final String fType = DOMRegionContext.XML_TAG_OPEN;
- private int fLength;
- private int fStart;
- static private final byte fTextLength = 1;
-
-
- public TagOpenRegion() {
- super();
- }
-
- public TagOpenRegion(int start, int textLength, int length) {
- this(start, length);
- if (fTextLength != textLength)
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- }
-
- public TagOpenRegion(int start, int length) {
- this();
- fStart = start;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
-// fTextLength += 1;
- throw new RuntimeException("invalid for this region type"); //$NON-NLS-1$
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/WhiteSpaceOnlyRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/WhiteSpaceOnlyRegion.java
deleted file mode 100644
index bc0bcc197b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/WhiteSpaceOnlyRegion.java
+++ /dev/null
@@ -1,188 +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.parser.regions;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class WhiteSpaceOnlyRegion implements ITextRegion {
- static private final byte fTextLength = 0;
-
- static private final String fType = DOMRegionContext.WHITE_SPACE;
- protected int fLength;
- protected int fStart;
-
- public WhiteSpaceOnlyRegion(int start, int length) {
- super();
- fStart = start;
- fLength = length;
- }
-
- public void adjust(int i) {
- fStart += i;
- }
-
- public void adjustLength(int i) {
- fLength += i;
- }
-
- public void adjustStart(int i) {
- fStart += i;
- }
-
-
- public void adjustTextLength(int i) {
- // not supported
-
- }
-
- public boolean contains(int position) {
-
- return fStart <= position && position < fStart + fLength;
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public void setLength(int i) {
- fLength = i;
- }
-
- public void setStart(int i) {
- fStart = i;
- }
-
- public void setTextLength(short i) {
- throw new RuntimeException("invalid call"); //$NON-NLS-1$
- }
-
- public void setType(String string) {
- throw new RuntimeException("invalid call"); //$NON-NLS-1$
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- /**
- * For this ITextRegion type, the start must in terms of what the region
- * expects ... that is, its not document offset, but start relative to
- * what ever contains it.
- */
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + fType); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
- canHandle = false;
- }
- else {
- canHandle = true;
- }
- }
- else {
- if (RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- }
- else {
- canHandle = false;
- }
-
- }
- RegionChangedEvent result = null;
-
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- fLength += lengthDifference;
-
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, this, changes, requestStart, lengthToReplace);
- }
-
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLCDataTextRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLCDataTextRegion.java
deleted file mode 100644
index 23da980cde..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLCDataTextRegion.java
+++ /dev/null
@@ -1,175 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class XMLCDataTextRegion implements ITextRegion {
- static private final String fType = DOMRegionContext.XML_CDATA_TEXT;
- private int fLength;
- private int fStart;
- private int fTextLength;
-
-
- public XMLCDataTextRegion() {
- super();
- }
-
- public XMLCDataTextRegion(int start, int textLength, int length) {
- this();
- fStart = start;
- fTextLength = textLength;
- fLength = length;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
- fTextLength += i;
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- // TODO: shouldn't cdata be like XML Content ... length and text
- // length
- // always be the same, regardless of whitespace?
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // TODO: this is a pretty lame method, since XML CData region can have
- // a much
- // better rule for region update, but this is what previous
- // (unfactored)
- // version had, so I'll carry it over, of now.
- RegionChangedEvent result = null;
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + fType); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
- canHandle = false;
- } else {
- canHandle = true;
- }
- } else {
- if ((RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(this, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- } else {
- canHandle = false;
- }
-
- }
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- // TO_DO_FUTURE: cache value of canHandleAsWhiteSpace from above
- // If we are handling as whitespace, there is no need to increase
- // the text length, only
- // the total length is changing.
- if (!RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) {
- fTextLength += lengthDifference;
- }
- fLength += lengthDifference;
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, this, changes, requestStart, lengthToReplace);
- }
-
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLContentRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLContentRegion.java
deleted file mode 100644
index e9088dbb0c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLContentRegion.java
+++ /dev/null
@@ -1,175 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.util.Debug;
-import org.eclipse.wst.sse.core.internal.util.Utilities;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-
-public class XMLContentRegion implements ITextRegion {
- static private final String fType = DOMRegionContext.XML_CONTENT;
- // length and textLength are always the same for content region
- //private int fTextLength;
- private int fLength;
- private int fStart;
-
-
- public XMLContentRegion() {
- super();
- }
-
- public XMLContentRegion(int start, int length) {
- this();
- fStart = start;
- fLength = length;
- }
-
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
- // not supported
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public int getTextEnd() {
- return fStart + fLength;
- }
-
- public int getTextLength() {
- return fLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // TODO: this is a pretty lame method, since XML Content can have a
- // much
- // better rule for region update, but this is what previous
- // (unfactored)
- // version had, so I'll carry it over, of now.
- RegionChangedEvent result = null;
- // if the region is an easy type (e.g. attribute value),
- // and the requested changes are all
- // alphanumeric, then make the change here locally.
- // (This can obviously be made more sophisticated as the need arises,
- // but should
- // always follow this pattern.)
- if (Debug.debugStructuredDocument) {
- System.out.println("\t\tContextRegion::updateModel"); //$NON-NLS-1$
- System.out.println("\t\t\tregion type is " + fType); //$NON-NLS-1$
- }
- boolean canHandle = false;
- // note: we'll always handle deletes from these
- // regions ... if its already that region,
- // deleting something from it won't change its
- // type. (remember, the calling program needs
- // to insure we are not called, if not all contained
- // on one region.
- if ((changes == null) || (changes.length() == 0)) {
- // delete case
- // We can not do the quick delete, if
- // if all the text in a region is to be deleted.
- // Or, if the delete starts in the white space region.
- // In these cases, a reparse is needed.
- // Minor note, we use textEnd-start since it always
- // less than or equal to end-start. This might
- // cause us to miss a few cases we could have handled,
- // but will prevent us from trying to handle funning cases
- // involving whitespace.
- if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
- canHandle = false;
- } else {
- canHandle = true;
- }
- } else {
- if ((RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(this, parent, changes, requestStart, lengthToReplace)) {
- canHandle = true;
- } else {
- canHandle = false;
- }
-
- }
- if (canHandle) {
- // at this point, we still have the old region. We won't create a
- // new instance, we'll just update the one we have, by changing
- // its end postion,
- // The parent flatnode, upon return, has responsibility
- // for updating sibling regions.
- // and in turn, the structuredDocument itself has responsibility
- // for
- // updating the text store and down stream flatnodes.
- if (Debug.debugStructuredDocument) {
- System.out.println("change handled by region"); //$NON-NLS-1$
- }
- int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
- // Note: we adjust both end and text end, because for any change
- // that is in only the trailing whitespace region, we should not
- // do a quick change,
- // so 'canHandle' should have been false for those case.
- fLength += lengthDifference;
- // TO_DO_FUTURE: cache value of canHandleAsWhiteSpace from above
- // If we are handling as whitespace, there is no need to increase
- // the text length, only
- // the total length is changing.
- // don't need for content region
- // if (!RegionUpdateRule.canHandleAsWhiteSpace(this, changes,
- // fStart, lengthToReplace)) {
- // fTextLength += lengthDifference;
- // }
- result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, this, changes, requestStart, lengthToReplace);
- }
-
- return result;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserFactory.java
deleted file mode 100644
index 38df3ea165..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserFactory.java
+++ /dev/null
@@ -1,25 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-
-public class XMLHeadParserFactory {
- public ITextRegion createToken(String context, int start, int textLength, int length, String text) {
- ITextRegion newRegion = null;
- // if (context == XMLRegionContext.XML_CDATA_TEXT) {
- newRegion = new XMLHeadParserRegion(context, start, textLength, length, text);
- // }
- return newRegion;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserRegion.java
deleted file mode 100644
index f3917b6338..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLHeadParserRegion.java
+++ /dev/null
@@ -1,107 +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.parser.regions;
-
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent;
-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.regions.DOMRegionContext;
-
-
-/**
- *
- * This class is not intended to be used, its just present to server as a
- * generic starting point for adding new specific region types.
- */
-
-public class XMLHeadParserRegion implements ITextRegion {
- private int fLength;
- private int fStart;
- private String fText;
- private int fTextLength;
- // specify correct type
- private String fType = DOMRegionContext.UNDEFINED;
-
- public XMLHeadParserRegion() {
- super();
- }
-
- public XMLHeadParserRegion(String context, int start, int textLength, int length, String text) {
- this();
- fType = context;
- fStart = start;
- fTextLength = textLength;
- fLength = length;
- fText = text;
- }
-
- public void adjustLength(int i) {
- fLength += i;
-
- }
-
- public void adjustStart(int i) {
- fStart += i;
-
- }
-
-
- public void adjustTextLength(int i) {
- fTextLength += 1;
-
- }
-
- public void equatePositions(ITextRegion region) {
- fStart = region.getStart();
- fLength = region.getLength();
- fTextLength = region.getTextLength();
- }
-
- public int getEnd() {
- return fStart + fLength;
- }
-
- public int getLength() {
- return fLength;
- }
-
- public int getStart() {
- return fStart;
- }
-
- public String getText() {
- return fText;
- }
-
- public int getTextEnd() {
- return fStart + fTextLength;
- }
-
- public int getTextLength() {
- return fTextLength;
- }
-
- public String getType() {
- return fType;
- }
-
- public String toString() {
- return RegionToStringUtil.toString(this);
- }
-
- public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
- // can never be updated
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLParserRegionFactory.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLParserRegionFactory.java
deleted file mode 100644
index 581f44780e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/parser/regions/XMLParserRegionFactory.java
+++ /dev/null
@@ -1,103 +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.parser.regions;
-
-
-
-import org.eclipse.wst.sse.core.internal.parser.ContextRegion;
-import org.eclipse.wst.sse.core.internal.parser.ForeignRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-/**
- *
- * This region factory is very specific to the parser output, and the specific
- * implementation classes for various regions.
- */
-
-public class XMLParserRegionFactory {
-
- public XMLParserRegionFactory() {
- super();
- }
-
- public ITextRegion createToken(ITextRegionContainer parent, String context, int start, int textLength, int length) {
- return this.createToken(parent, context, start, textLength, length, null, null);
- }
-
- public ITextRegion createToken(ITextRegionContainer parent, String context, int start, int textLength, int length, String lang, String surroundingTag) {
- ITextRegion newRegion = createToken(context, start, textLength, length);
- // DW, 4/16/2003 token regions no longer have parents
- // newRegion.setParent(parent);
- return newRegion;
- }
-
- public ITextRegion createToken(String context, int start, int textLength, int length) {
- return this.createToken(context, start, textLength, length, null, null);
- }
-
- public ITextRegion createToken(String context, int start, int textLength, int length, String lang, String surroundingTag) {
- ITextRegion newRegion = null;
- if (context == DOMRegionContext.XML_CDATA_TEXT) {
- newRegion = new XMLCDataTextRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_CONTENT) {
- newRegion = new XMLContentRegion(start, length);
- }
- else if (context == DOMRegionContext.XML_TAG_NAME) {
- newRegion = new TagNameRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
- newRegion = new AttributeNameRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
- newRegion = new AttributeEqualsRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
- newRegion = new AttributeValueRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_TAG_OPEN) {
- newRegion = new TagOpenRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_END_TAG_OPEN) {
- newRegion = new EndTagOpenRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.XML_TAG_CLOSE) {
- newRegion = new TagCloseRegion(start);
- }
- else if (context == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- newRegion = new EmptyTagCloseRegion(start, textLength, length);
- }
- else if (context == DOMRegionContext.WHITE_SPACE) {
- newRegion = new WhiteSpaceOnlyRegion(start, length);
- }
- else
- // removed this condition during transition, and implemented in
- // subclass
- // if (context == XMLJSPRegionContexts.JSP_CONTENT) {
- // newRegion = new JSPCodeRegion(context, start, textLength, length);
- // } else
- if (context == DOMRegionContext.BLOCK_TEXT) {
- newRegion = new ForeignRegion(context, start, textLength, length);
- ((ForeignRegion) newRegion).setSurroundingTag(surroundingTag);
- }
- else {
- newRegion = new ContextRegion(context, start, textLength, length);
- }
- return newRegion;
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
deleted file mode 100644
index b050f9de14..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceInitializer.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 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
- * David Carver - STAR - [205989] - [validation] validate XML after XInclude resolution
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.preferences;
-
-import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-
-/**
- * Sets default values for XML Core preferences
- */
-public class XMLCorePreferenceInitializer extends AbstractPreferenceInitializer {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
- */
- public void initializeDefaultPreferences() {
- IEclipsePreferences node = new DefaultScope().getNode(XMLCorePlugin.getDefault().getBundle().getSymbolicName());
-
- // formatting preferences
- node.putInt(XMLCorePreferenceNames.LINE_WIDTH, 72);
- node.putBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES, false);
- node.put(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.TAB);
- node.putInt(XMLCorePreferenceNames.INDENTATION_SIZE, 1);
- node.putBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS, false);
- node.putBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET, false);
- node.putBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT, false);
- node.putBoolean(XMLCorePreferenceNames.SPACE_BEFORE_EMPTY_CLOSE_TAG, true);
- node.putBoolean(XMLCorePreferenceNames.FORMAT_COMMENT_TEXT, true);
- node.putBoolean(XMLCorePreferenceNames.FORMAT_COMMENT_JOIN_LINES, true);
- // cleanup preferences
- node.putBoolean(XMLCorePreferenceNames.COMPRESS_EMPTY_ELEMENT_TAGS, true);
- node.putBoolean(XMLCorePreferenceNames.INSERT_REQUIRED_ATTRS, true);
- node.putBoolean(XMLCorePreferenceNames.INSERT_MISSING_TAGS, true);
- node.putBoolean(XMLCorePreferenceNames.QUOTE_ATTR_VALUES, true);
- node.putBoolean(XMLCorePreferenceNames.FORMAT_SOURCE, true);
- node.putBoolean(XMLCorePreferenceNames.CONVERT_EOL_CODES, false);
- node.putBoolean(XMLCorePreferenceNames.FIX_XML_DECLARATION, true);
-
- node.put(CommonEncodingPreferenceNames.INPUT_CODESET, ""); //$NON-NLS-1$
- node.put(CommonEncodingPreferenceNames.OUTPUT_CODESET, "UTF-8");//$NON-NLS-1$
- node.put(CommonEncodingPreferenceNames.END_OF_LINE_CODE, ""); //$NON-NLS-1$
-
- // this could be made smarter by actually looking up the content
- // type's valid extensions
- node.put(XMLCorePreferenceNames.DEFAULT_EXTENSION, "xml"); //$NON-NLS-1$
-
- node.putBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR, true);
- // 1 = IMarker.SEVERITY_WARNING
- node.putInt(XMLCorePreferenceNames.INDICATE_NO_GRAMMAR, 1);
- node.putBoolean(XMLCorePreferenceNames.USE_XINCLUDE, false);
- node.putBoolean(XMLCorePreferenceNames.HONOUR_ALL_SCHEMA_LOCATIONS, true);
- node.putBoolean(XMLCorePreferenceNames.CMDOCUMENT_GLOBAL_CACHE_ENABLED, true);
-
- node.putBoolean(XMLCorePreferenceNames.MARKUP_VALIDATION, false);
- node.putInt(XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE, 2);
- node.putInt(XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_START_TAG, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_END_TAG, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_TAG_NAME, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_QUOTES, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, 2);
- node.putInt(XMLCorePreferenceNames.MISSING_CLOSING_QUOTE, 2);
- node.putInt(XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET, 2);
- node.putInt(XMLCorePreferenceNames.WHITESPACE_AT_START, 2);
- node.putInt(XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME, 2);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
deleted file mode 100644
index 00f597ce05..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/preferences/XMLCorePreferenceNames.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 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
- * David Carver - STAR - [205989] - [validation] validate XML after XInclude resolution
- *******************************************************************************/
-
-package org.eclipse.wst.xml.core.internal.preferences;
-
-
-/**
- * Common preference keys used by XML core
- *
- * @plannedfor 1.0
- */
-public class XMLCorePreferenceNames {
- private XMLCorePreferenceNames() {
- // empty private constructor so users cannot instantiate class
- }
-
- /**
- * The default extension to use when none is specified in the New File
- * Wizard.
- * <p>
- * Value is of type <code>String</code>.
- * </p>
- */
- public static final String DEFAULT_EXTENSION = "defaultExtension"; //$NON-NLS-1$
-
-
- /**
- * The maximum width of a line before a line split is needed.
- * <p>
- * Value is of type <code>Integer</code>.
- * </p>
- */
- public static final String LINE_WIDTH = "lineWidth";//$NON-NLS-1$
-
- /**
- * Indicates if all blanks lines should be cleared during formatting.
- * Blank lines will be kept when false.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String CLEAR_ALL_BLANK_LINES = "clearAllBlankLines";//$NON-NLS-1$
-
- /**
- * The number of #INDENTATION_CHAR for 1 indentation.
- * <p>
- * Value is of type <code>Integer</code>.
- * </p>
- */
- public static final String INDENTATION_SIZE = "indentationSize";//$NON-NLS-1$
-
- /**
- * The character used for indentation.
- * <p>
- * Value is of type <code>String</code>.<br />
- * Possible values: {TAB, SPACE}
- * </p>
- */
- public static final String INDENTATION_CHAR = "indentationChar";//$NON-NLS-1$
-
- /**
- * Possible value for the preference #INDENTATION_CHAR. Indicates to use
- * tab character when formatting.
- *
- * @see #SPACE
- * @see #INDENTATION_CHAR
- */
- public static final String TAB = "tab"; //$NON-NLS-1$
-
- /**
- * Possible value for the preference #INDENTATION_CHAR. Indicates to use
- * space character when formatting.
- *
- * @see #TAB
- * @see #INDENTATION_CHAR
- */
- public static final String SPACE = "space"; //$NON-NLS-1$
-
- /**
- * Indicates if tags with multiple attributes should be formatted
- * (splitting each attr on a new line).
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String SPLIT_MULTI_ATTRS = "splitMultiAttrs";//$NON-NLS-1$
-
- /**
- * Indicates whether or not cleanup processor should format source.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String FORMAT_SOURCE = "formatSource";//$NON-NLS-1$
-
- /**
- * Indicates whether or not empty elements should be compressed during
- * cleanup.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String COMPRESS_EMPTY_ELEMENT_TAGS = "compressEmptyElementTags";//$NON-NLS-1$
-
- /**
- * Indicates whether or not to insert required attributes during cleanup.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String INSERT_REQUIRED_ATTRS = "insertRequiredAttrs";//$NON-NLS-1$
-
- /**
- * Indicates whether or not to insert missing tags during cleanup.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String INSERT_MISSING_TAGS = "insertMissingTags";//$NON-NLS-1$
-
- /**
- * Indicates whether or not to quote all attribute values during cleanup.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String QUOTE_ATTR_VALUES = "quoteAttrValues";//$NON-NLS-1$
-
- /**
- * Indicates whether or not to insert missing XML declarations during cleanup.
- * <p>
- * Value is of type <code>Boolean</code>
- * </p>
- */
- public static final String FIX_XML_DECLARATION = "fixXMLDeclaration"; //$NON-NLS-1$
-
- /**
- * Indicates whether or not to convert all line delimiters during cleanup.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- * @deprecated - no longer used
- */
- public static final String CONVERT_EOL_CODES = "convertEOLCodes";//$NON-NLS-1$
-
- /**
- * Indicates the line delimiter to use during cleanup if converting line
- * delimiters.
- * <p>
- * Value is of type <code>String</code>.<br />
- * Possible values: {CR, CRLF, LF, NO_TRANSLATION}
- * </p>
- *
- */
- public static final String CLEANUP_EOL_CODE = "cleanupEOLCode";//$NON-NLS-1$
-
- /**
- * Indicates whether or not a warning should be produced when validating a
- * file that specifies not grammar.
- * <p>
- * Value is of type <code>boolean</code>.<br />
- * Possible values: {TRUE, FALSE}
- * </p>
- * @deprecated
- */
- public static final String WARN_NO_GRAMMAR = "warnNoGrammar";//$NON-NLS-1$
-
- /**
- * Indicates whether or not a message should be produced when validating a
- * file that specifies not grammar.
- * <p>
- * Value is of type <code>integer</code>.<br />
- * Possible values: {0, 1, 2} (none, warning, error)
- * </p>
- */
- public static final String INDICATE_NO_GRAMMAR = "indicateNoGrammar";//$NON-NLS-1$
-
- /**
- * Indicates whether or not xincludes should be processed before
- * validation.
- * <p>
- * Value is of type <code>boolean</code>.<br />
- * Possible values: {TRUE, FALSE}
- * </p>
- *
- */
- public static final String USE_XINCLUDE = "xinclude";//$NON-NLS-1$
-
- /**
- * Indicates if all whitespace in tags with CDATA content should be
- * preserved.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String PRESERVE_CDATACONTENT = "preserveCDATAContent";//$NON-NLS-1$
-
- /**
- * Indicates if end brackets of start tags should be placed on a new line
- * if the start tag spans more than one line.
- * <p>
- * Value is of type <code>Boolean</code>.
- * </p>
- */
- public static final String ALIGN_END_BRACKET = "alignEndBracket";//$NON-NLS-1$
-
- /**
- * Indicates if an empty close tag should have a space inserted before
- * closing.
- * <p>
- * Value is of type <code>Boolean</code>
- * </p>
- */
- public static final String SPACE_BEFORE_EMPTY_CLOSE_TAG = "spaceBeforeEmptyCloseTag";//$NON-NLS-1$
-
- /**
- * Indicates whether or not all schema locations for XSD should be honoured
- * during XSD validation of XML.
- * <p>
- * Value is of type <code>boolean</code>.<br />
- * Possible values: {TRUE, FALSE}
- * </p>
- *
- */
- public static final String HONOUR_ALL_SCHEMA_LOCATIONS = "honourAllSchemaLocations";//$NON-NLS-1$
-
- /**
- * Indicates whether or not the content of comments should be formatted
- * <p>
- * Value is of type <code>boolean</code><br />
- * Possible values: {TRUE, FALSE}
- * </p>
- */
- public static final String FORMAT_COMMENT_TEXT = "formatCommentText"; //$NON-NLS-1$
-
- /**
- * Indicates whether or not the lines of comments should be joined when formatting
- * <p>
- * Value is of type <code>boolean</code>
- */
- public static final String FORMAT_COMMENT_JOIN_LINES = "formatCommentJoinLines"; //$NON-NLS-1$
-
- /**
- * Indicates whether or not CMDocuments should be globally cached
- * <p>
- * Value is of type <code>boolean</code>
- */
- public static final String CMDOCUMENT_GLOBAL_CACHE_ENABLED = "cmDocumentGlobalCacheEnabled"; //$NON-NLS-1$
-
- /**
- * Indicates whether or not MarkUpValidator should run as part of XMl Validation.
- * <p>
- * Value is of type <code>boolean</code>.<br />
- * Possible values: {TRUE, FALSE}
- * </p>
- */
- public static final String MARKUP_VALIDATION = "markupValidation"; //$NON-NLS-1$
-
- /**
- * Indicates whether or not a message should be produced when validating a
- * file that specifies following condition.
- * <p>
- * Value is of type <code>integer</code>.<br />
- * Possible values: {0, 1, 2} (none, warning, error)
- * </p>
- */
- public static final String ATTRIBUTE_HAS_NO_VALUE = "attributeHasNoValue"; //$NON-NLS-1$
- public static final String END_TAG_WITH_ATTRIBUTES = "endTagWithAttributes"; //$NON-NLS-1$
- public static final String WHITESPACE_BEFORE_TAGNAME = "whitespaceBeforeTagName"; //$NON-NLS-1$
- public static final String MISSING_CLOSING_BRACKET = "missingClosingBracket"; //$NON-NLS-1$
- public static final String MISSING_CLOSING_QUOTE = "missingClosingQuote"; //$NON-NLS-1$
- public static final String MISSING_END_TAG = "missingEndTag"; //$NON-NLS-1$
- public static final String MISSING_START_TAG = "missingStartTag"; //$NON-NLS-1$
- public static final String MISSING_QUOTES = "missingQuotes"; //$NON-NLS-1$
- public static final String NAMESPACE_IN_PI_TARGET = "namespaceInPITarget"; //$NON-NLS-1$
- public static final String MISSING_TAG_NAME = "missingTagName"; //$NON-NLS-1$
- public static final String WHITESPACE_AT_START = "whitespaceAtStart"; //$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterFactoryImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterFactoryImpl.java
deleted file mode 100644
index 7376d4ee46..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterFactoryImpl.java
+++ /dev/null
@@ -1,113 +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.propagate;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.PropagatingAdapter;
-import org.eclipse.wst.sse.core.internal.PropagatingAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-
-
-/**
- * The PropagatingAdapterFactory is part of the "adapt on create" mechanism. A
- * PropagatingAdapter, once added to a node, will cause proagating adapters to
- * be created for all child nodes. A side effect of creating a
- * PropagatingAdapter for a node is that is is also creates adapters for and
- * adapts the Node for all other registered 'create on adapt' Adapters. This
- * other adapters are registered by registering their factories via plugin
- * extension point.
- */
-public class PropagatingAdapterFactoryImpl extends AbstractAdapterFactory implements PropagatingAdapterFactory {
-
- private PropagatingAdapter fAdapterInstance;
- private List fContributedFactories = null;
-
- /**
- * PropagatingAdapterFactory constructor comment.
- */
- public PropagatingAdapterFactoryImpl() {
- this(PropagatingAdapter.class, true);
- }
-
- protected PropagatingAdapterFactoryImpl(Object adapterKey, boolean registerAdapters) { // ,
- super(adapterKey, registerAdapters);
- }
-
- public void addContributedFactories(INodeAdapterFactory factory) {
- if (fContributedFactories != null) {
- fContributedFactories.add(factory);
- }
-
- }
-
- /**
- * createAdapter method comment.
- */
- protected INodeAdapter createAdapter(INodeNotifier target) {
- // every notifier get's one of these
- // (and the same instance of it)
- return getAdapterInstance();
- }
-
- /**
- * Gets the adapterInstance.
- *
- * @return Returns a PropagatingAdapter
- */
- private PropagatingAdapter getAdapterInstance() {
- if (fAdapterInstance == null) {
- fAdapterInstance = new PropagatingAdapterImpl();
- if (fContributedFactories != null) {
- for (int i = 0; i < fContributedFactories.size(); i++)
- fAdapterInstance.addAdaptOnCreateFactory((PropagatingAdapterFactory) fContributedFactories.get(i));
- }
- }
- return fAdapterInstance;
- }
-
- public void release() {
- // give the adapter instance a chance to release its factories
- getAdapterInstance().release();
-
- }
-
- public void setContributedFactories(ArrayList list) {
- fContributedFactories = list;
-
- }
-
- public INodeAdapterFactory copy() {
- PropagatingAdapterFactory clonedInstance = new PropagatingAdapterFactoryImpl(getAdapterKey(), isShouldRegisterAdapter());
- // clone this adapters specific list of adapter factories too
- if (fContributedFactories != null) {
-
- Iterator iterator = fContributedFactories.iterator();
- clonedInstance.setContributedFactories(new ArrayList());
- while (iterator.hasNext()) {
- INodeAdapterFactory existingFactory = (INodeAdapterFactory) iterator.next();
- clonedInstance.addContributedFactories(existingFactory.copy());
- }
- }
- return clonedInstance;
- }
-
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterImpl.java
deleted file mode 100644
index f581590c35..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/propagate/PropagatingAdapterImpl.java
+++ /dev/null
@@ -1,144 +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.propagate;
-
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.wst.sse.core.internal.PropagatingAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-public class PropagatingAdapterImpl implements PropagatingAdapter {
-
- private List adaptOnCreateFactories = null;
-
- /**
- * AbstractPropagatingAdapterImpl constructor comment.
- */
- public PropagatingAdapterImpl() {
- super();
- }
-
- private void adaptOnCreate(IDOMNode node) {
- // give each of the factories a chance to adapt the node, if it
- // chooses to
- if (adaptOnCreateFactories != null) {
-
-
- synchronized (adaptOnCreateFactories) {
- int length = adaptOnCreateFactories.size();
- for (int i = 0; i < length; i++) {
- INodeAdapterFactory factory = (INodeAdapterFactory) adaptOnCreateFactories.get(i);
- factory.adapt(node);
- }
- }
-
- }
-
- }
-
- /**
- * This mechanism can be made "easier to use" later.
- */
- public void addAdaptOnCreateFactory(INodeAdapterFactory factory) {
- getAdaptOnCreateFactories().add(factory);
- }
-
- /**
- * Gets the adaptOnCreateFactories.
- *
- * @return Returns a List
- */
- public List getAdaptOnCreateFactories() {
- if (adaptOnCreateFactories == null)
- adaptOnCreateFactories = new ArrayList();
- return adaptOnCreateFactories;
- }
-
-
- /**
- * @see PropagatingAdapter#initializeForFactory(INodeAdapterFactory,
- * INodeNotifier)
- */
- public void initializeForFactory(INodeAdapterFactory factory, INodeNotifier node) {
- // ISSUE: we are a DOM specific implimentation,
- // we should not be.
- if (node instanceof IDOMNode) {
- IDOMNode xmlNode = (IDOMNode) node;
- propagateTo(xmlNode);
- }
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type allows it
- * to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return type.equals(PropagatingAdapter.class);
- }
-
- private boolean isInteresting(Object newValue) {
- return (newValue != null && (newValue instanceof Element || newValue instanceof Document || newValue instanceof DocumentType));
- }
-
- /**
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- // Issue: We only propagate to Elements ...
- // not attributes too! We should careful consider doning all when
- // when we improve "adapt on create" design.
- if (eventType == INodeNotifier.ADD && isInteresting(newValue)) {
- propagateTo((IDOMNode) newValue);
- }
- }
-
- private void propagateTo(IDOMNode node) {
- // get adapter to ensure its created
- node.getAdapterFor(PropagatingAdapter.class);
- adaptOnCreate(node);
- propagateToChildren(node);
- }
-
- private void propagateToChildren(IDOMNode parent) {
- for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
- propagateTo((IDOMNode) child);
- }
- }
-
- /**
- * @see PropagatingAdapter#release()
- */
- public void release() {
- if (adaptOnCreateFactories != null) {
-
- synchronized (adaptOnCreateFactories) {
- int length = adaptOnCreateFactories.size();
- for (int i = 0; i < length; i++) {
- INodeAdapterFactory factory = (INodeAdapterFactory) adaptOnCreateFactories.get(i);
- factory.release();
- }
- }
-
- }
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLCharEntity.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLCharEntity.java
deleted file mode 100644
index b1fb483b99..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLCharEntity.java
+++ /dev/null
@@ -1,39 +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.provisional;
-
-
-
-/**
- * XML Namespace constants
- *
- * @plannedfor 1.0
- */
-public interface IXMLCharEntity {
- static final String AMP_NAME = "amp";//$NON-NLS-1$
- static final String AMP_REF = "&amp;";//$NON-NLS-1$
- static final String AMP_VALUE = "&";//$NON-NLS-1$
- static final String APOS_NAME = "apos";//$NON-NLS-1$
- static final String APOS_REF = "&apos;";//$NON-NLS-1$
- static final String APOS_VALUE = "'";//$NON-NLS-1$
- static final String GT_NAME = "gt";//$NON-NLS-1$
- static final String GT_REF = "&gt;";//$NON-NLS-1$
- static final String GT_VALUE = ">";//$NON-NLS-1$
-
- static final String LT_NAME = "lt";//$NON-NLS-1$
- static final String LT_REF = "&lt;";//$NON-NLS-1$
- static final String LT_VALUE = "<";//$NON-NLS-1$
- static final String QUOT_NAME = "quot";//$NON-NLS-1$
- static final String QUOT_REF = "&quot;";//$NON-NLS-1$
- static final String QUOT_VALUE = "\"";//$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLNamespace.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLNamespace.java
deleted file mode 100644
index 10847db83c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLNamespace.java
+++ /dev/null
@@ -1,29 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional;
-
-
-
-/**
- * XML Namespace constants
- *
- * @plannedfor 1.0
- */
-public interface IXMLNamespace {
-
- String XMLNS = "xmlns";//$NON-NLS-1$
- String XMLNS_PREFIX = "xmlns:";//$NON-NLS-1$
- String XMLNS_URI = "http://www.w3.org/2000/xmlns/";//$NON-NLS-1$
- String XML = "xml";//$NON-NLS-1$
- String XML_PREFIX = "xml:";//$NON-NLS-1$
- String XML_URI = "http://www.w3.org/XML/1998/namespace";//$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLPreferenceNames.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLPreferenceNames.java
deleted file mode 100644
index df49d48e1b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLPreferenceNames.java
+++ /dev/null
@@ -1,55 +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.provisional;
-
-/**
- * Keys to use for preference settings.
- *
- * @plannedfor 1.0
- */
-
-public interface IXMLPreferenceNames {
- String CLEANUP_ATTR_NAME_CASE = "cleanupAttrNameCase";//$NON-NLS-1$
- String CLEANUP_EOL_CODE = "cleanupEOLCode";//$NON-NLS-1$
- // cleanup preference names
- String CLEANUP_TAG_NAME_CASE = "cleanupTagNameCase";//$NON-NLS-1$
- String CONVERT_EOL_CODES = "convertEOLCodes";//$NON-NLS-1$
- String FORMAT_SOURCE = "formatSource";//$NON-NLS-1$
- String INSERT_MISSING_TAGS = "insertMissingTags";//$NON-NLS-1$
-
- // others
- String LAST_ACTIVE_PAGE = "lastActivePage";//$NON-NLS-1$
- String QUOTE_ATTR_VALUES = "quoteAttrValues";//$NON-NLS-1$
-
- /*
- * not used for now // highlighting types String COMMENT_BORDER =
- * "commentBorder";//$NON-NLS-1$ String COMMENT_TEXT =
- * "commentText";//$NON-NLS-1$ String CDATA_BORDER =
- * "cdataBorder";//$NON-NLS-1$ String CDATA_TEXT =
- * "cdataText";//$NON-NLS-1$ String PI_BORDER = "piBorder";//$NON-NLS-1$
- * String PI_CONTENT = "piContent";//$NON-NLS-1$ String TAG_BORDER =
- * "tagBorder";//$NON-NLS-1$ String TAG_NAME = "tagName";//$NON-NLS-1$
- * String TAG_ATTRIBUTE_NAME = "tagAttributeName";//$NON-NLS-1$ String
- * TAG_ATTRIBUTE_VALUE = "tagAttributeValue";//$NON-NLS-1$ String
- * DECL_BORDER = "declBoder";//$NON-NLS-1$ String DOCTYPE_NAME =
- * "doctypeName";//$NON-NLS-1$ String DOCTYPE_EXTERNAL_ID =
- * "doctypeExternalId";//$NON-NLS-1$ String DOCTYPE_EXTERNAL_ID_PUBREF =
- * "doctypeExternalPubref";//$NON-NLS-1$ String DOCTYPE_EXTERNAL_ID_SYSREF =
- * "doctypeExtrenalSysref";//$NON-NLS-1$ String XML_CONTENT =
- * "xmlContent";//$NON-NLS-1$ // highlighting preferences String COMMA =
- * ",";//$NON-NLS-1$ String COLOR = "color";//$NON-NLS-1$ String NAME =
- * "name";//$NON-NLS-1$ String FOREGROUND = "foreground";//$NON-NLS-1$
- * String BACKGROUND = "background";//$NON-NLS-1$ String BOLD =
- * "bold";//$NON-NLS-1$ String ITALIC = "italic";//$NON-NLS-1$
- */
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/NameValidator.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/NameValidator.java
deleted file mode 100644
index 496beb7234..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/NameValidator.java
+++ /dev/null
@@ -1,63 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional;
-
-import java.io.Reader;
-
-import org.eclipse.wst.xml.core.internal.parser.XML10Names;
-
-/**
- * This class provides consistent way to pre-check if a string is a valid XML
- * name, before, for example, trying to actually create an Element with it.
- * Attempting to create an Element with an invalid name will throw the appropriate
- * DOM Exception, but often clients want to check the validiting of a name
- * such as based on some user input, long in advance of actually making
- * the DOM call. And, natually, want to give the user feedback in a more
- * timely fashion.
- *
- * ISSUE: is "endns:" really valid xml name? I think not, but this method
- * (currently) says it is.
- *
- * @plannedfor 1.0
- */
-public final class NameValidator {
-
- private static XML10Names xml10charChecker = null;
-
- /**
- * Returns true if <code>name</code> is valid XML name according to XML
- * 1.0 rules, false otherwise.
- *
- * @param name
- * name is the string to test
- * @return true if valid name according to XML 1.0 rules, false otherwise.
- */
- public synchronized static final boolean isValid(String name) {
-
- if (xml10charChecker == null) {
- xml10charChecker = inititailizeXML10Names();
- }
- return xml10charChecker.isValidXML10Name(name);
- }
-
- private static XML10Names inititailizeXML10Names() {
- return new XML10Names((Reader) null);
- }
-
- /**
- * Not intenteded to be instantiated.
- */
- private NameValidator() {
- super();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocType.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocType.java
deleted file mode 100644
index 679cefd540..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocType.java
+++ /dev/null
@@ -1,49 +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.provisional.contentmodel;
-
-
-public interface CMDocType {
- /**
- * CHTML files
- */
- public final static String CHTML_DOC_TYPE = "CHTML";//$NON-NLS-1$
- /**
- * HTML files
- */
- public final static String HTML_DOC_TYPE = "HTML";//$NON-NLS-1$
- /**
- * HTML5 files
- */
- public final static String HTML5_DOC_TYPE = "HTML5";//$NON-NLS-1$
- /**
- * JSP 1.1 files (currently includes 1.2 elements for backward behavioral compatibility)
- */
- public final static String JSP11_DOC_TYPE = "JSP11";//$NON-NLS-1$
- /**
- * JSP 1.2 files
- */
- public final static String JSP12_DOC_TYPE = "JSP12";//$NON-NLS-1$
- /**
- * JSP 2.0 JSP files
- */
- public final static String JSP20_DOC_TYPE = "JSP20";//$NON-NLS-1$
- /**
- * JSP 2.0 Tag files
- */
- public final static String TAG20_DOC_TYPE = "JSP20.TAG";//$NON-NLS-1$
- /**
- * JSP 2.1 JSP files
- */
- public final static String JSP21_DOC_TYPE = "JSP21";//$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocumentTracker.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocumentTracker.java
deleted file mode 100644
index 19baa552e9..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocumentTracker.java
+++ /dev/null
@@ -1,32 +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.provisional.contentmodel;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-
-
-/**
- * Position dependent CMDocument tracker. A tracker matches a
- * IStructuredDocumentRegion with a CMDocument that it enables allowing for
- * position-dependent content models
- */
-public interface CMDocumentTracker {
-
- CMDocument getDocument();
-
- IStructuredDocumentRegion getStructuredDocumentRegion();
-}
-
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMNodeWrapper.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMNodeWrapper.java
deleted file mode 100644
index dbe75d6799..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMNodeWrapper.java
+++ /dev/null
@@ -1,21 +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.provisional.contentmodel;
-
-
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-
-public interface CMNodeWrapper extends CMNode {
- CMNode getOriginNode();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/ContentModelAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/ContentModelAdapter.java
deleted file mode 100644
index a66811ee42..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/ContentModelAdapter.java
+++ /dev/null
@@ -1,54 +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.provisional.contentmodel;
-
-
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-
-/**
- * ContentModelAdapter interface
- */
-public interface ContentModelAdapter extends org.eclipse.wst.sse.core.internal.provisional.INodeAdapter {
-
- /**
- * getCMDocument method
- *
- * @return CMDocument
- * @param notifer
- *
- * Returns CMDocument associated to the adapting node. For exampl : HTML
- * CMDocument is associated to HTML Document node, DTD CMDocument is
- * associated to DocumentType node, DTD/Schema CMDocument is associated to
- * Element node (sometime with namespace), and taglib CMDocument is
- * associated to taglib directive Element node.
- *
- * INodeNotifier is passed for stateless (singleton) INodeAdapter
- * implementation.
- */
- CMDocument getCMDocument(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier notifier);
-
- /**
- * getDeclaration method
- *
- * @return CMNode
- * @param notifer
- *
- * Returns ElementDefinition or AttributeDefinition for the adapting node.
- *
- * INodeNotifier is passed for stateless (singleton) INodeAdapter
- * implementation.
- */
- CMNode getDeclaration(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier notifier);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/NullContentModel.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/NullContentModel.java
deleted file mode 100644
index 0b2ee6ba9b..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/NullContentModel.java
+++ /dev/null
@@ -1,101 +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.provisional.contentmodel;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-
-
-/**
- * This class can be used to intialize specific variables that need a content
- * model, until the true content model is available. This prevents having to
- * do lots of null checks.
- */
-public class NullContentModel implements CMDocument {
-
- private static class NullCMNamedNodeMap implements CMNamedNodeMap {
- public int getLength() {
- return 0;
- }
-
- public CMNode getNamedItem(String name) {
- return null;
- }
-
- public CMNode item(int index) {
- return null;
- }
-
- public Iterator iterator() {
- return new NullIterator();
- }
-
- }
-
- private static class NullIterator implements Iterator {
- public NullIterator() {
- }
-
- public boolean hasNext() {
- return false;
- }
-
- public Object next() {
- throw new NoSuchElementException();
- }
-
- public void remove() {
- throw new UnsupportedOperationException("can not remove regions via iterator"); //$NON-NLS-1$
-
- }
-
- }
-
- public NullContentModel() {
- super();
- }
-
- public CMNamedNodeMap getElements() {
- return new NullCMNamedNodeMap();
- }
-
- public CMNamedNodeMap getEntities() {
- return new NullCMNamedNodeMap();
- }
-
- public CMNamespace getNamespace() {
- return null;
- }
-
- public String getNodeName() {
- return null;
- }
-
- public int getNodeType() {
- return 0;
- }
-
- public Object getProperty(String propertyName) {
- return null;
- }
-
- public boolean supports(String propertyName) {
- return false;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contenttype/ContentTypeIdForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contenttype/ContentTypeIdForXML.java
deleted file mode 100644
index 67c3a90b03..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contenttype/ContentTypeIdForXML.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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
- *
- *******************************************************************************/
-
-package org.eclipse.wst.xml.core.internal.provisional.contenttype;
-
-/**
- * This class, with its few field, is a convience to provide compile-time
- * safety when refering to a contentType ID. The value of the contenttype id
- * field must match what is specified in plugin.xml file.
- *
- * @plannedfor 1.0
- */
-final public class ContentTypeIdForXML {
- /**
- * This content type is actually supplied by base Eclipse. Its given here
- * just as documentation for WTP based clients. Typically, clients should
- * use the values/constants supplied by base Eclipse.
- */
- public final static String ContentTypeID_XML = getConstantString2();
- /**
- * This value is public only for testing and special infrastructure. The
- * constant nor is value should not be referenced by clients.
- *
- * The value of the contenttype id field must match what is specified in
- * plugin.xml file. Note: this value is intentially set with default
- * protected method so it will not be inlined.
- */
- public final static String ContentTypeID_SSEXML = getConstantString();
-
- /**
- * Don't allow instantiation.
- */
- private ContentTypeIdForXML() {
- super();
- }
-
- static String getConstantString() {
- return "org.eclipse.wst.xml.core.xmlsource"; //$NON-NLS-1$
- }
-
- static String getConstantString2() {
- return "org.eclipse.core.runtime.xml"; //$NON-NLS-1$
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMAttr.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMAttr.java
deleted file mode 100644
index ee16e15de8..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMAttr.java
+++ /dev/null
@@ -1,128 +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.provisional.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.w3c.dom.Attr;
-
-
-/**
- * This interface provides extensions to corresponding DOM interface to enable
- * functions for source editing and incremental parsing.
- *
- * @plannedfor 1.0
- *
- */
-public interface IDOMAttr extends IDOMNode, Attr {
-
- /**
- * Get's the region in attribute representing the '=' sign. May or may not
- * have whitespace surrounding it.
- *
- * @deprecated -
- * ISSUE: need to change/remove to avoid exposing 'ITextRegion'
- * change to offset pattern, as others.
- *
- * @return ITextRegion - the region representing the equals sign, or null
- * if their is no equals sign.
- */
- ITextRegion getEqualRegion();
-
- /**
- * Gets the source location of the end of the attribute name, including
- * whitespace.
- *
- * @return int - the source location of the end of the attribute name,
- * including whitespace.
- */
- int getNameRegionEndOffset();
-
- /**
- * Gets the source location of the start of the attribute name.
- *
- * @return int - the source location of the start of the attribute name.
- */
- int getNameRegionStartOffset();
-
-
- /**
- * Gets the text associated with the attribute name.
- *
- * @return String - the text associated with the attribute name.
- */
- String getNameRegionText();
-
- /**
- * Gets the source location of the end of the attribute name, excluding
- * whitespace.
- *
- * @return int - returns the source location of the end of the attribute
- * name, excluding whitespace.
- */
- int getNameRegionTextEndOffset();
-
- /**
- * Gets the source location of the start of the attribute value.
- *
- * @return int - returns the source location of the start of the attribute
- * value.
- *
- * ISSUE: need to better spec interaction with quote marks
- */
- int getValueRegionStartOffset();
-
- /**
- * Gets the text associated with the attribute value.
- *
- * @return String - returns the text associated with the attribute value.
- */
- String getValueRegionText();
-
- /**
- * Check if Attr has a nested value (such as a JSP expression).
- *
- * @return true if contains a nested value, false otherwise.
- */
- boolean hasNestedValue();
-
- /**
- * Check if Attr has only name but not equal sign nor value.
- *
- * @return true if has only name but not equal sign nor value.
- */
- boolean hasNameOnly();
-
- /**
- * Returns true if attribute is defined globally for document. Returns
- * false if attribute is preceeded by a prefix (whether valid name space
- * or not). Returns true if its owning element is a global element.
- *
- * @return true if attribute is defined globally for document. Returns
- * false if attribute is preceeded by a prefix (whether valid name
- * space or not). Returns true if its owning element is a global
- * element.
- */
- boolean isGlobalAttr();
-
- /**
- * Returns true if is xml attr
- *
- * ISSUE: need to figure out how to specify this one in a meaningful way.
- *
- * @return boolean - returns true if is xml attr
- */
- boolean isXMLAttr();
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocument.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocument.java
deleted file mode 100644
index 4d69e58301..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocument.java
+++ /dev/null
@@ -1,100 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.document;
-
-
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * This interface enables creation of DOCTYPE declaration and some DOM Level 2
- * interfaces. May be referenced but not implemented by clients.
- *
- * @plannedfor 1.0
- */
-public interface IDOMDocument extends Node, Document, IDOMNode {
-
- /**
- * create comment element. tagName must be registered as comment element
- * name in plugin.xml
- *
- * @param tagName
- * the element name
- * @param isJSPTag
- * true if the element is JSP style comment (&lt;%-- ...
- * --%&gt;)
- * @return Element element instance
- * @throws DOMException
- * thrown if the element name is registered as comment element
- */
- Element createCommentElement(String tagName, boolean isJSPTag) throws DOMException;
-
- /**
- * Creates a DocumentType node
- *
- * ISSUE: I believe this 'name' is the one specific in doctype extension,
- * need to verify.
- *
- * @param name -
- * name of the doctype
- * @return DocumentType - returns a document type node.
- */
- DocumentType createDoctype(String name);
-
- /**
- * Returns the DocumentType ID. Unlike the standard DOM approach of
- * "getDocumentType().getPublicId()", this method returns the id even if
- * implicit.
- *
- * @return the DocumentType ID
- */
- String getDocumentTypeId();
-
- /**
- * NOT API ... needs to be removed/changed
- *
- * ISSUE: need to specify
- *
- * @deprecated
- *
- * @return true if is JSPDocument
- *
- */
- boolean isJSPDocument();
-
- /**
- * NOT API ... needs to be removed/changed
- *
- * ISSUE: need to specify
- *
- * @deprecated
- *
- */
- boolean isJSPType();
-
- /**
- * NOT API ... may removed/changed
- *
- * ISSUE: need to specify -- currently used to denote an HTML DOM document
- * is XHTML
- *
- * @deprecated
- *
- */
- boolean isXMLType();
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocumentType.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocumentType.java
deleted file mode 100644
index 602c65e07c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMDocumentType.java
+++ /dev/null
@@ -1,43 +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.provisional.document;
-
-
-
-import org.w3c.dom.DocumentType;
-
-/**
- * This interface enables setting of Public and System ID for DOCTYPE
- * declaration.
- *
- * @plannedfor 1.0
- */
-public interface IDOMDocumentType extends IDOMNode, DocumentType {
-
-
- /**
- * Sets document type's public id, as source.
- *
- * @param String -
- * the publicId
- */
- void setPublicId(String publicId);
-
- /**
- * Sets docment type's system id, as source.
- *
- * @param String -
- * the systemId
- */
- void setSystemId(String systemId);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMElement.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMElement.java
deleted file mode 100644
index fcd7763397..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMElement.java
+++ /dev/null
@@ -1,196 +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.provisional.document;
-
-
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
-
-/**
- * This interface provides extensions to corresponding DOM interface to enable
- * functions for source editing and incremental parsing.
- *
- * @plannedfor 1.0
- *
- */
-public interface IDOMElement extends IDOMNode, Element {
-
- /**
- * Retuns the start offset of the end tag.
- *
- * ISSUE: need to sort out need for this
- *
- * @return int - the start offset of the end tag.
- */
- int getEndStartOffset();
-
- /**
- * Returns the end offset of the
- *
- * ISSUE: need to sort out need for this
- *
- * @return int - the end offset of the start tag.
- */
- int getStartEndOffset();
-
- /**
- * Returns true if has an end tag.
- *
- * In our source-oriented DOM, sometimes Elements are "ended", even
- * without an explicit end tag in the source.
- *
- * @return true if has an end tag.
- */
- boolean hasEndTag();
-
- /**
- * returns true if has a start tag.
- *
- * In our source-oriented DOM, a lone end tag will cause a node to be
- * created in the tree, unlike well-formed-only DOMs.
- *
- * @return true if has a start tag.
- */
- boolean hasStartTag();
-
- /**
- * returns true if this element is a comment element
- *
- * @return true if this element is a comment element
- */
- boolean isCommentTag();
-
- /**
- * isEmptyTag method
- *
- * @return boolean - true if is empty tag, false otherwise
- */
- boolean isEmptyTag();
-
- /**
- * Returns true if floating end tag.
- *
- * @return true if floating end tag.
- */
- boolean isEndTag();
-
- /**
- * Returns true for "global tag" (basically, without prefix)
- *
- * @return true for "global tag" (basically, without prefix)
- */
- boolean isGlobalTag();
-
- /**
- * Returns true for no start and the end tags in source.
- *
- * Provided for some very special cases when, for example, and HTML tag is
- * assumed in an HTML document that does not have a literal HTML tag.
- *
- * ISSUE: check with clients to see if still needed
- *
- * @return true or no start and the end tags in source.
- */
- boolean isImplicitTag();
-
- /**
- * isJSPTag method
- *
- * @return boolean
- *
- * ISSUE: change to isContainerLanguageTag(String type);
- */
- boolean isJSPTag();
-
- /**
- * Returns true if start tag is closed.
- *
- * @return true if start tag is closed.
- */
- boolean isStartTagClosed();
-
- /**
- * returns true if is xml tag
- *
- * ISSUE: need to spec this better.
- *
- * @return true if is xml tag
- */
- boolean isXMLTag();
-
- /**
- * NOT CLIENT API
- *
- * notifyEndTagChanged
- *
- */
- void notifyEndTagChanged();
-
- /**
- * NOT CLIENT API
- *
- * notifyStartTagChanged
- *
- */
- void notifyStartTagChanged();
-
- /**
- * NOT CLIENT API
- *
- * Signify that this tag is a comment
- *
- * For use only by parsers.
- *
- */
- void setCommentTag(boolean isCommentTag);
-
- /**
- * NOT CLIENT API
- *
- * Signify that this tag is an empty tag
- *
- * For use only by parsers
- */
- void setEmptyTag(boolean isEmptyTag);
-
- /**
- * NOT CLIENT API
- *
- * Signify that this tag is a JSP tag
- *
- * For use only by parsers
- *
- * ISSUE: I have had one non-parsing client who has had to use this ...
- * need to check
- *
- */
- void setJSPTag(boolean isJSPTag);
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttribute(String name, boolean isId);
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttributeNS(String namespaceURI, String localName, boolean isId);
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation for DOM 3.
- */
- public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException;
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMEntity.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMEntity.java
deleted file mode 100644
index 3e22ec0587..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMEntity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 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
- *
- *******************************************************************************/
-
-package org.eclipse.wst.xml.core.internal.provisional.document;
-
-import org.w3c.dom.Entity;
-
-public interface IDOMEntity extends Entity {
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation of DOM 3.
- */
- public String getInputEncoding();
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation of DOM 3.
- */
- public String getXmlEncoding();
-
- /**
- * NOT IMPLEMENTED. Is defined here in preparation of DOM 3.
- */
- public String getXmlVersion();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMImplementation.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMImplementation.java
deleted file mode 100644
index da73e24db4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMImplementation.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 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
- *
- *******************************************************************************/
-
-package org.eclipse.wst.xml.core.internal.provisional.document;
-
-public interface IDOMImplementation {
-
- /**
- * NOT IMPLEMENTED. This is defined here in preparation of DOM 3.
- *
- * This method returns a specialized object which implements the
- * specialized APIs of the specified feature and version, as specified in .
- * The specialized object may also be obtained by using binding-specific
- * casting methods but is not necessarily expected to, as discussed in .
- * This method also allow the implementation to provide specialized
- * objects which do not support the <code>DOMImplementation</code>
- * interface.
- *
- * @param feature
- * The name of the feature requested. Note that any plus sign
- * "+" prepended to the name of the feature will be ignored
- * since it is not significant in the context of this method.
- * @param version
- * This is the version number of the feature to test.
- * @return Returns an object which implements the specialized APIs of the
- * specified feature and version, if any, or <code>null</code>
- * if there is no object which implements interfaces associated
- * with that feature. If the <code>DOMObject</code> returned by
- * this method implements the <code>DOMImplementation</code>
- * interface, it must delegate to the primary core
- * <code>DOMImplementation</code> and not return results
- * inconsistent with the primary core
- * <code>DOMImplementation</code> such as
- * <code>hasFeature</code>, <code>getFeature</code>, etc.
- * @see DOM Level 3
- */
- public Object getFeature(String feature, String version);
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMModel.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMModel.java
deleted file mode 100644
index 3effc7ef0f..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMModel.java
+++ /dev/null
@@ -1,59 +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.provisional.document;
-
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.document.XMLModelNotifier;
-
-/**
- * Provides means to get the XMLModel form of IStrucutredModel. Not to be
- * implemented or extended by clients.
- *
- * @plannedfor 1.0
- */
-public interface IDOMModel extends IStructuredModel {
-
- /**
- * Returns the DOM Document.
- *
- * @return the DOM Document.
- */
- IDOMDocument getDocument();
-
- /**
- *
- * Returns an source generator appropriate for this model.
- *
- * @return the source generator
- */
- ISourceGenerator getGenerator();
-
- /**
- * NOT CLIENT API
- *
- * Returns an XMLModelNotifier. Clients should not use.
- *
- * ISSUE: should be "internalized".
- *
- */
- XMLModelNotifier getModelNotifier();
-
- /**
- * NOT CLIENT API
- *
- * Sets the model notifier Clients should not use.
- *
- * ISSUE: need to review with legacy clients.
- */
- void setModelNotifier(XMLModelNotifier notifier);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMNode.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMNode.java
deleted file mode 100644
index ed8875f671..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMNode.java
+++ /dev/null
@@ -1,272 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.document;
-
-
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-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.document.InvalidCharacterException;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Node;
-
-/**
- * This interface describes the extended functionality of our source-oriented
- * DOM. First, our nodes extend the w3c Node interface, IndexedRegion, and
- * INodeNotifier. Plus, has the extra methods called out here.
- *
- * ISSUE: the 'read-only' API should be broken out in their own interface
- *
- * @plannedfor 1.0
- *
- */
-public interface IDOMNode extends IndexedRegion, INodeNotifier, Node {
-
- /**
- * Gets the last structured document region of this node.
- *
- * ISSUE: need to resolve getEnd/getLast confusion.
- *
- * @return IStructuredDocumentRegion - returns the last structured
- * document region associated with
- */
- IStructuredDocumentRegion getEndStructuredDocumentRegion();
-
- /**
- * Gets the first structured document region of this node.
- *
- * ISSUE: need to resolve getFirst/getStart confusion
- *
- * @return the first structured document region of this node.
- */
- IStructuredDocumentRegion getFirstStructuredDocumentRegion();
-
- /**
- * Gets the last structured document region of this node.
- *
- * ISSUE: need to resolve getEnd/getLast confusion.
- *
- * @return IStructuredDocumentRegion - returns the last structured
- * document region associated with
- */
- IStructuredDocumentRegion getLastStructuredDocumentRegion();
-
- /**
- * Returns the model associated with this node. Returns null if not part
- * of an active model.
- *
- * @return IDOMModel - returns the IDOMModel this node is part of.
- */
- IDOMModel getModel();
-
- /**
- * Get's the region representing the name of this node
- *
- * ISSUE: only implemented/used at attribute and DTDNodes -- should move.
- *
- * @return ITextRegion - returns the ITextRegion associated with this
- * Node.
- *
- * @deprecated
- */
- ITextRegion getNameRegion();
-
- /**
- * Returns the literal source representing this node in source document.
- *
- * ISSUE: need to fix implementation to match.
- *
- * @return the literal source representing this node in source document.
- */
- String getSource();
-
- /**
- * Gets the first structured document region of this node.
- *
- * ISSUE: need to resolve getFirst/getStart confusion
- *
- * @return the first structured document region of this node.
- */
- IStructuredDocumentRegion getStartStructuredDocumentRegion();
-
- /**
- * Returns the structured document that underlies this node's model.
- *
- * Returns null if this node is not actively part of a source document. In
- * contrast, in the pure DOM world, "owning document" is not null even
- * after a node is deleted from the DOM.
- *
- * ISSUE: we need to fix our implementation to match this spec.
- *
- * @return the structured document.
- */
- IStructuredDocument getStructuredDocument();
-
- /**
- * Get's the region representing the value of this node if only one
- * ITextRegion, null otherwise.
- *
- * ISSUE: only implemented/used at attribute level, move "down".
- *
- * @return ITextRegion - returns the ITextRegion associated with this
- * Node.
- *
- * @deprecated
- */
- ITextRegion getValueRegion();
-
- /**
- * Returns a string representing the source of this node, but with
- * character enties converted (e.g. &lt; is converted to '<').
- *
- * ISSUE: need to better spec extent of this conversion, we may not know
- * all character entities.
- *
- * ISSUE: need to fix implementation to match spec.
- *
- * @return String - get's the source of this Node.
- */
- String getValueSource();
-
- /**
- * Used to know read-only state of children.
- *
- * @return boolean Whether children of the element can be appended or
- * removed.
- */
- boolean isChildEditable();
-
- /**
- * Returns true if tag is closed in source.
- *
- * In our source orient DOM we sometimes end a Node without it being
- * explicitly closed in source.
- *
- * @return boolean - true if node is closed
- */
- boolean isClosed();
-
- /**
- * Returns true if this node can contain children.
- *
- * @return boolean - true if this node can contain children.
- */
- boolean isContainer();
-
- /**
- * Used to know read-only state of data.
- *
- */
- boolean isDataEditable();
-
- /**
- * Set's readonly state of children
- *
- */
- void setChildEditable(boolean editable);
-
- /**
- * Set's readonly state of data
- *
- */
- void setDataEditable(boolean editable);
-
- /**
- * Sets readonly state of data
- *
- * faster approach to set read-only state.
- */
- void setEditable(boolean editable, boolean deep);
-
- /**
- * Sets the specified raw source to the Text node. Throws
- * InvalidCharacterException when the specified raw source includes
- * invalid characters, such as, ' <', '>' and '&'. Valid character
- * entities, such as, "&amp;lt;", are accepted.
- */
- void setSource(String source) throws InvalidCharacterException;
-
- /**
- * Sets the specified raw source to the Text or Attr node's value. When
- * the specified raw source includes invalid characters, such as, ' <',
- * '>' and '&', converts them. Valid character entities, such as,
- * "&amp;lt;", are accepted.
- */
- void setValueSource(String source);
-
-
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public short compareDocumentPosition(Node other) throws DOMException;
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String getBaseURI();
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public Object getFeature(String feature, String version);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String getTextContent() throws DOMException;
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public Object getUserData(String key);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isDefaultNamespace(String namespaceURI);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isEqualNode(Node arg);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isSameNode(Node other);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String lookupNamespaceURI(String prefix);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public String lookupPrefix(String namespaceURI);
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public void setTextContent(String textContent) throws DOMException;
-
-
- /**
- * NOT IMPLEMENTED, is defined here in preparation of DOM Level 3
- */
- public boolean isId();
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMText.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMText.java
deleted file mode 100644
index efb3a5f0f4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/IDOMText.java
+++ /dev/null
@@ -1,129 +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.provisional.document;
-
-
-
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Text;
-
-/**
- * This interface provides extensions to corresponding DOM interface to enable
- * functions for source editing and incremental parsing.
- *
- * @plannedfor 1.0
- *
- */
-public interface IDOMText extends IDOMNode, Text {
-
- /**
- * NOT API - can be eliminated or moved to ltk level
- *
- * Appends the content of the text node
- *
- * @param text -
- * the Text to append.
- */
- void appendText(Text text);
-
- /**
- * NOT API - can be eliminated or moved to ltk level
- *
- * Returns true if is not valid.
- */
- boolean isInvalid();
-
- /**
- * Returns true if is entirely white space.
- *
- * This is intened to be better performing that all clients getting the
- * source, and checking themselves.
- *
- * ISSUE: need to clarify if implementation is pure to "white space" as
- * per DOM spec? Here is the DOM spec:
- *
- * 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
- *
- * @return true if is entirely white space.
- */
-
- public boolean isElementContentWhitespace();
-
- /**
- * NOT YET IMPLEMTENTED but exists here interface in preparation for DOM3
- *
- * Returns all text of <code>Text</code> nodes logically-adjacent text
- * nodes to this node, concatenated in document order. <br>
- * For instance, in the example below <code>wholeText</code> on the
- * <code>Text</code> node that contains "bar" returns "barfoo", while on
- * the <code>Text</code> node that contains "foo" it returns "barfoo".
- *
- * @see DOM Level 3
- *
- */
- public String getWholeText();
-
- /**
- * NOT YET IMPLEMTENTED but exists here interface in preparation for DOM3
- *
- * 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;
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/ISourceGenerator.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/ISourceGenerator.java
deleted file mode 100644
index 473048cd52..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/document/ISourceGenerator.java
+++ /dev/null
@@ -1,201 +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.provisional.document;
-
-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.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-/**
- *
- * ISourceGenerator allows DOM models to generate source appropriate for their
- * parameter, relative to the model that provides the source generator.
- *
- */
-
-public interface ISourceGenerator {
-
- /**
- * Generate attribute name.
- *
- * @param attr -
- * the Attr
- * @return String - the string generated
- */
- String generateAttrName(Attr attr);
-
- /**
- * generateAttrValue
- *
- * @param attr -
- * the Attr
- * @return String - the string generated
- */
- String generateAttrValue(Attr attr);
-
- /**
- * generateAttrValue
- *
- * @param attr -
- * the Attr
- * @param char -
- * the type of quote desired (' or ").
- * @return String - the string generated
- */
- String generateAttrValue(Attr attr, char quote);
-
- /**
- * generateAttrValue
- *
- * @param value
- * the String value
- * @param char -
- * the type of quote desired (' or ").
- * @return String - the string generated
- */
- String generateAttrValue(String value, char quote);
-
- /**
- * generateCDATASection method
- *
- * @param comment
- * CDATASection
- * @return String - the string generated
- */
- String generateCDATASection(CDATASection cdata);
-
- /**
- * generateChild method
- *
- * @return String
- * @param Node
- * @return String - the string generated
- */
- String generateChild(Node parentNode);
-
- /**
- * generateCloseTag
- *
- * @param node -
- * the Node
- * @return String - the string generated
- */
- String generateCloseTag(Node node);
-
- /**
- * generateComment method
- *
- * @param comment
- * org.w3c.dom.Comment
- * @return String - the string generated
- */
- String generateComment(Comment comment);
-
- /**
- * generateDoctype method
- *
- * @param docType
- * DocumentType
- * @return String - the string generated
- */
- String generateDoctype(DocumentType docType);
-
- /**
- * generateElement method
- *
- * @param element -
- * Element
- * @return String - the string generated
- */
- String generateElement(Element element);
-
- /**
- * generateEndTag method
- *
- * @param element -
- * Element
- * @return String - the string generated
- */
- String generateEndTag(Element element);
-
- /**
- * generateEntityRef method
- *
- * @param entityRef
- * EntityReference
- * @return String - the string generated
- */
- String generateEntityRef(EntityReference entityRef);
-
- /**
- * generatePI method
- *
- * @param pi -
- * ProcessingInstruction
- * @return String - the string generated
- */
- String generatePI(ProcessingInstruction pi);
-
- /**
- * generateSource method
- *
- * @param node -
- * the Node
- * @return String - the string generated
- */
- String generateSource(Node node);
-
- /**
- * generateStartTag method
- *
- * @param element
- * Element
- * @return String - the string generated
- */
- String generateStartTag(Element element);
-
- /**
- * Generate tag name.
- *
- * @param element -
- * element
- * @return String - the string generated
- */
- String generateTagName(Element element);
-
- /**
- * generateText method
- *
- * @param text -
- * the Text
- * @return String - the string generated
- */
- String generateText(Text text);
-
- /**
- * generate text data
- *
- * @param text -
- * the Text
- * @param data -
- * the data
- * @return String - the string generated
- */
- String generateTextData(Text text, String data);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/CommentNodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/CommentNodeFormatter.java
deleted file mode 100644
index 7fba90580a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/CommentNodeFormatter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.provisional.format;
-
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-import org.eclipse.wst.sse.core.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Node;
-
-
-public class CommentNodeFormatter extends NodeFormatter {
- static private final String CR = "\r"; //$NON-NLS-1$
- static private final String LF = "\n"; //$NON-NLS-1$
-
- protected String adjustIndentations(String aString, String lineIndent, String singleIndent) {
- String result = NodeFormatter.EMPTY_STRING;
-
- int indexOfLineDelimiter = StringUtils.indexOfLineDelimiter(aString);
- result = aString.substring(0, indexOfLineDelimiter);
- while (indexOfLineDelimiter != -1) {
- // Before find the next LineDelimiter, we have to figure out the
- // size of the current LineDelimiter
- // so we can figure out how many bytes to skip before finding the
- // next LineDelimiter.
- // Otherwise, we may treat the LF in CRLF as the next
- // LineDelimiter.
- int lineDelimiterSize = 1;
- if (aString.length() >= indexOfLineDelimiter + 2 && aString.substring(indexOfLineDelimiter, indexOfLineDelimiter + 1).compareTo(CR) == 0 && aString.substring(indexOfLineDelimiter + 1, indexOfLineDelimiter + 2).compareTo(LF) == 0)
- lineDelimiterSize = 2;
-
- int indexOfNextLineDelimiter = StringUtils.indexOfLineDelimiter(aString, indexOfLineDelimiter + lineDelimiterSize);
- int indexOfNonblank = StringUtils.indexOfNonblank(aString, indexOfLineDelimiter);
-
- if (indexOfNonblank != -1) {
- if (indexOfNextLineDelimiter == -1) {
- // last line; copy till the end
- result += lineIndent + singleIndent + aString.substring(indexOfNonblank);
- } else if (indexOfNextLineDelimiter != -1 && indexOfNextLineDelimiter < indexOfNonblank) {
- // blank line; just add a indent
- result += lineIndent + singleIndent;
- } else {
- // copy all text between indexOfNonblank and
- // indexOfNextLineDelimiter
- result += lineIndent + singleIndent + aString.substring(indexOfNonblank, indexOfNextLineDelimiter);
- }
-
- indexOfLineDelimiter = indexOfNextLineDelimiter;
- } else {
- if (indexOfNextLineDelimiter == -1) {
- result += lineIndent;
- } else {
- // blank line; just add a indent
- result += lineIndent + singleIndent;
- }
-
- indexOfLineDelimiter = indexOfNextLineDelimiter;
- }
- }
-
- return result;
- }
-
- protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- if (node != null) {
- // lineDelimiterFound means multi line comment
- String nodeValue = node.getNodeValue();
- boolean lineDelimiterFoundInComment = StringUtils.containsLineDelimiter(nodeValue);
-
- if (lineDelimiterFoundInComment) {
- // format indentation before node
- formatIndentationBeforeNode(node, formatContraints);
-
- // adjust indentations in multi line comment
- String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter();
- String lineIndent = formatContraints.getCurrentIndent();
- String singleIndent = getFormatPreferences().getIndent();
- String newNodevalue = adjustIndentations(nodeValue, lineDelimiter + lineIndent, singleIndent);
- if (nodeValue.compareTo(newNodevalue) != 0)
- node.setNodeValue(newNodevalue);
- }
-
- if (!nodeHasSiblings(node) || (node.getPreviousSibling() != null && node.getPreviousSibling().getNodeType() == Node.TEXT_NODE && !StringUtils.containsLineDelimiter(node.getPreviousSibling().getNodeValue()) && node.getNextSibling() == null)) {
- // single child
- // or inline comment after text
- // do nothing
- } else
- // format indentation after node
- formatIndentationAfterNode(node, formatContraints);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/DocumentNodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/DocumentNodeFormatter.java
deleted file mode 100644
index 297df28a1f..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/DocumentNodeFormatter.java
+++ /dev/null
@@ -1,55 +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
- * Jesper Steen Møller - xml:space='preserve' support
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.format;
-
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-
-
-public class DocumentNodeFormatter extends NodeFormatter {
- protected void formatChildren(IDOMNode node, IStructuredFormatContraints formatContraints) {
- String singleIndent = getFormatPreferences().getIndent();
- String lineIndent = formatContraints.getCurrentIndent();
-
- if (node != null && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) {
- // normalize node first to combine adjacent text nodes
- node.normalize();
-
- IDOMNode nextChild = (IDOMNode) node.getFirstChild();
- while (nextChild != null) {
- IDOMNode eachChildNode = nextChild;
- nextChild = (IDOMNode) eachChildNode.getNextSibling();
- IStructuredFormatter formatter = getFormatter(eachChildNode);
- IStructuredFormatContraints childFormatContraints = formatter.getFormatContraints();
- String childIndent = lineIndent + singleIndent;
- childFormatContraints.setCurrentIndent(childIndent);
- childFormatContraints.setClearAllBlankLines(formatContraints.getClearAllBlankLines());
- childFormatContraints.setInPreserveSpaceElement(formatContraints.getInPreserveSpaceElement());
-
- // format each child
- formatter.format(eachChildNode, childFormatContraints);
-
- if (nextChild != null && nextChild.getParentNode() == null)
- // nextNode is deleted during format
- nextChild = (IDOMNode) eachChildNode.getNextSibling();
- }
- }
- }
-
- protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- if (node != null)
- formatChildren(node, formatContraints);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/ElementNodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/ElementNodeFormatter.java
deleted file mode 100644
index 6baf55b456..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/ElementNodeFormatter.java
+++ /dev/null
@@ -1,425 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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
- * Jesper Steen Møller - xml:space='preserve' support
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.format;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-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.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.Logger;
-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.document.AttrImpl;
-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.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-
-public class ElementNodeFormatter extends DocumentNodeFormatter {
- static private final char DOUBLE_QUOTE = '"';//$NON-NLS-1$
- static private final String DOUBLE_QUOTES = "\"\"";//$NON-NLS-1$
- static private final char EQUAL_CHAR = '='; // equal sign$NON-NLS-1$
- static private final String PRESERVE = "preserve";//$NON-NLS-1$
- static private final String PRESERVE_QUOTED = "\"preserve\"";//$NON-NLS-1$
- static private final char SINGLE_QUOTE = '\'';//$NON-NLS-1$
- static private final String XML_SPACE = "xml:space";//$NON-NLS-1$
- static private final char SPACE_CHAR = ' '; //$NON-NLS-1$
- static private final String XSL_NAMESPACE = "http://www.w3.org/1999/XSL/Transform"; //$NON-NLS-1$
- static private final String XSL_ATTRIBUTE = "attribute"; //$NON-NLS-1$
- static private final String XSL_TEXT = "text"; //$NON-NLS-1$
-
- protected void formatEndTag(IDOMNode node, IStructuredFormatContraints formatContraints) {
- if (!isEndTagMissing(node)) {
- // end tag exists
-
- IStructuredDocument structuredDocument = node.getModel().getStructuredDocument();
- String lineDelimiter = structuredDocument.getLineDelimiter();
- String nodeIndentation = getNodeIndent(node);
- IDOMNode lastChild = (IDOMNode) node.getLastChild();
- if (lastChild != null && lastChild.getNodeType() != Node.TEXT_NODE) {
- if (isEndTagMissing(lastChild)) {
- // find deepest child
- IDOMNode deepestChild = (IDOMNode) lastChild.getLastChild();
- while (deepestChild != null && deepestChild.getLastChild() != null && isEndTagMissing(deepestChild)) {
- lastChild = deepestChild;
- deepestChild = (IDOMNode) deepestChild.getLastChild();
- }
-
- if (deepestChild != null) {
- if (deepestChild.getNodeType() == Node.TEXT_NODE) {
- // Special indentation handling if lastChild's end
- // tag is missing and deepestChild is a text node.
- String nodeText = deepestChild.getNodeValue();
-
- if (!nodeText.endsWith(lineDelimiter + nodeIndentation)) {
- nodeText = StringUtils.appendIfNotEndWith(nodeText, lineDelimiter);
- nodeText = StringUtils.appendIfNotEndWith(nodeText, nodeIndentation);
- }
-
- replaceNodeValue(deepestChild, nodeText);
- }
- else
- insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
- }
- }
- else
- // indent end tag
- insertAfterNode(lastChild, lineDelimiter + nodeIndentation);
- }
- else if (lastChild == null && firstStructuredDocumentRegionContainsLineDelimiters(node)) {
- // BUG174243 do not indent end tag if node has empty content
- // (otherwise new text node would be introduced)
- ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
- CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
- if ((elementDeclaration == null) || (elementDeclaration.getContentType() != CMElementDeclaration.EMPTY)) {
- // indent end tag
- replace(structuredDocument, node.getFirstStructuredDocumentRegion().getEndOffset(), 0, lineDelimiter + nodeIndentation);
- }
- }
-
- // format end tag name
- IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getLastStructuredDocumentRegion();
- if (endTagStructuredDocumentRegion.getRegions().size() >= 3) {
- ITextRegion endTagNameRegion = endTagStructuredDocumentRegion.getRegions().get(1);
- removeRegionSpaces(node, endTagStructuredDocumentRegion, endTagNameRegion);
- }
- }
- }
-
- protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- if (node != null) {
- // format indentation before node
- formatIndentationBeforeNode(node, formatContraints);
-
- // format start tag
- IDOMNode newNode = node;
- int startTagStartOffset = node.getStartOffset();
- IDOMModel structuredModel = node.getModel();
-
- boolean currentlyInXmlSpacePreserve = formatContraints.getInPreserveSpaceElement();
- formatStartTag(node, formatContraints);
- // save new node
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
-
- IStructuredDocumentRegion flatNode = newNode.getFirstStructuredDocumentRegion();
- if (flatNode != null) {
- ITextRegionList regions = flatNode.getRegions();
- ITextRegion lastRegion = regions.get(regions.size() - 1);
- // format children and end tag if not empty start tag
- if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- // format children
- formatChildren(newNode, formatContraints);
-
- // save new node
- newNode = (IDOMNode) structuredModel.getIndexedRegion(startTagStartOffset);
-
- // format end tag
- formatEndTag(newNode, formatContraints);
- }
- }
-
- formatContraints.setInPreserveSpaceElement(currentlyInXmlSpacePreserve);
- // only indent if not at last node
- if (newNode != null && newNode.getNextSibling() != null)
- // format indentation after node
- formatIndentationAfterNode(newNode, formatContraints);
- }
- }
-
- /**
- * This method formats the start tag name, and formats the attributes if
- * available.
- */
- protected void formatStartTag(IDOMNode node, IStructuredFormatContraints formatContraints) {
- StructuredFormatPreferencesXML preferences = (StructuredFormatPreferencesXML) getFormatPreferences();
- String singleIndent = preferences.getIndent();
- String lineIndent = formatContraints.getCurrentIndent();
- String attrIndent = lineIndent + singleIndent;
- boolean splitMultiAttrs = preferences.getSplitMultiAttrs();
- boolean alignEndBracket = preferences.isAlignEndBracket();
- boolean sawXmlSpace = false;
-
- IStructuredDocumentRegion flatNode = node.getFirstStructuredDocumentRegion();
- NamedNodeMap attributes = node.getAttributes();
-
- // Note: attributes should not be null even if the node has no
- // attributes. However, attributes.getLength() will be 0. But, check
- // for null just in case.
- if (attributes != null) {
- // compute current available line width
- int currentAvailableLineWidth = 0;
- try {
- // 1 is for "<"
- int nodeNameOffset = node.getStartOffset() + 1 + node.getNodeName().length();
- int lineOffset = node.getStructuredDocument().getLineInformationOfOffset(nodeNameOffset).getOffset();
- String text = node.getStructuredDocument().get(lineOffset, nodeNameOffset - lineOffset);
- int usedWidth = getIndentationLength(text);
- currentAvailableLineWidth = preferences.getLineWidth() - usedWidth;
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
-
- StringBuffer stringBuffer = new StringBuffer();
- String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter();
- int attrLength = attributes.getLength();
- int lastUndefinedRegionOffset = 0;
- boolean startTagSpansOver1Line = false;
-
- for (int i = 0; i < attrLength; i++) {
- AttrImpl attr = (AttrImpl) attributes.item(i);
- ITextRegion nameRegion = attr.getNameRegion();
- ITextRegion equalRegion = attr.getEqualRegion();
- ITextRegion valueRegion = attr.getValueRegion();
-
- // append undefined regions
- String undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, attr.getStartOffset() - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
- lastUndefinedRegionOffset = attr.getStartOffset();
-
- // check for xml:space attribute
- if (flatNode.getText(nameRegion).compareTo(XML_SPACE) == 0) {
- if (valueRegion == null) {
- // [111674] If nothing has been written yet, treat as
- // preserve, but only as hint
- formatContraints.setInPreserveSpaceElement(true);
- // Note we don't set 'sawXmlSpace', so that default or
- // fixed DTD/XSD values may override.
- }
- else {
- ISourceGenerator generator = node.getModel().getGenerator();
- String newAttrValue = generator.generateAttrValue(attr);
-
- // There is a problem in
- // StructuredDocumentRegionUtil.getAttrValue(ITextRegion)
- // when the region is instanceof ContextRegion.
- // Workaround for now.
- if (flatNode.getText(valueRegion).length() == 1) {
- char firstChar = flatNode.getText(valueRegion).charAt(0);
- if ((firstChar == DOUBLE_QUOTE) || (firstChar == SINGLE_QUOTE))
- newAttrValue = DOUBLE_QUOTES;
- }
-
- if (newAttrValue.compareTo(PRESERVE_QUOTED) == 0)
- formatContraints.setInPreserveSpaceElement(true);
- else
- formatContraints.setInPreserveSpaceElement(false);
- sawXmlSpace = true;
- }
- }
-
- if (splitMultiAttrs && attrLength > 1) {
- stringBuffer.append(lineDelimiter + attrIndent);
- stringBuffer.append(flatNode.getText(nameRegion));
- startTagSpansOver1Line = true;
- if (valueRegion != null) {
- // append undefined regions
- undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, flatNode.getStartOffset(equalRegion) - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
- lastUndefinedRegionOffset = flatNode.getStartOffset(equalRegion);
-
- stringBuffer.append(EQUAL_CHAR);
-
- // append undefined regions
- undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, flatNode.getStartOffset(valueRegion) - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
- lastUndefinedRegionOffset = flatNode.getStartOffset(valueRegion);
-
- // Note: trim() should not be needed for
- // valueRegion.getText(). Just a workaround for a
- // problem found in valueRegion for now.
- stringBuffer.append(flatNode.getText(valueRegion).trim());
- }
- }
- else {
- if (valueRegion != null) {
- int textLength = 1 + flatNode.getText(nameRegion).length() + 1 + flatNode.getText(valueRegion).length();
- if (i == attrLength - 1) {
- if (flatNode != null) {
- ITextRegionList regions = flatNode.getRegions();
- ITextRegion lastRegion = regions.get(regions.size() - 1);
- if (lastRegion.getType() != DOMRegionContext.XML_EMPTY_TAG_CLOSE)
- // 3 is for " />"
- textLength += 3;
- else
- // 1 is for ">"
- textLength++;
- }
- }
-
- if (currentAvailableLineWidth >= textLength) {
- stringBuffer.append(SPACE_CHAR);
- currentAvailableLineWidth--;
- }
- else {
- stringBuffer.append(lineDelimiter + attrIndent);
- startTagSpansOver1Line = true;
- currentAvailableLineWidth = preferences.getLineWidth() - attrIndent.length();
- }
-
- stringBuffer.append(flatNode.getText(nameRegion));
-
- // append undefined regions
- undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, flatNode.getStartOffset(equalRegion) - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
- lastUndefinedRegionOffset = flatNode.getStartOffset(equalRegion);
-
- stringBuffer.append(EQUAL_CHAR);
-
- // append undefined regions
- undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, flatNode.getStartOffset(valueRegion) - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
- lastUndefinedRegionOffset = flatNode.getStartOffset(valueRegion);
-
- // Note: trim() should not be needed for
- // valueRegion.getText(). Just a workaround for a
- // problem found in valueRegion for now.
- stringBuffer.append(flatNode.getText(valueRegion).trim());
-
- currentAvailableLineWidth -= flatNode.getText(nameRegion).length();
- currentAvailableLineWidth--;
- currentAvailableLineWidth -= flatNode.getText(valueRegion).trim().length();
- }
- else {
- if (currentAvailableLineWidth >= 1 + flatNode.getText(nameRegion).length()) {
- stringBuffer.append(SPACE_CHAR);
- currentAvailableLineWidth--;
- }
- else {
- stringBuffer.append(lineDelimiter + attrIndent);
- startTagSpansOver1Line = true;
- currentAvailableLineWidth = preferences.getLineWidth() - attrIndent.length();
- }
-
- stringBuffer.append(flatNode.getText(nameRegion));
-
- currentAvailableLineWidth -= flatNode.getText(nameRegion).length();
- }
- }
- }
-
- // append undefined regions
- String undefinedRegion = getUndefinedRegions(node, lastUndefinedRegionOffset, node.getEndOffset() - lastUndefinedRegionOffset);
- stringBuffer.append(undefinedRegion);
-
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- // 1 is for "<"
- int offset = node.getStartOffset() + 1 + node.getNodeName().length();
- // 1 is for "<"
- int length = node.getFirstStructuredDocumentRegion().getTextLength() - 1 - node.getNodeName().length();
-
- if (flatNode != null) {
- ITextRegionList regions = flatNode.getRegions();
- ITextRegion firstRegion = regions.get(0);
- ITextRegion lastRegion = regions.get(regions.size() - 1);
-
- if (firstRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN)
- // skip formatting for end tags in this format: </tagName>
- return;
- else {
- if (lastRegion.getType() == DOMRegionContext.XML_TAG_CLOSE || lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE)
- length = length - lastRegion.getLength();
-
- if (lastRegion.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
- // leave space before XML_EMPTY_TAG_CLOSE: <tagName />
- // unless already going to move end bracket
- if (!startTagSpansOver1Line || !alignEndBracket)
- stringBuffer.append(SPACE_CHAR);
- }
- }
- }
-
- if (startTagSpansOver1Line && alignEndBracket) {
- stringBuffer.append(lineDelimiter).append(lineIndent);
- }
-
- replace(structuredDocument, offset, length, stringBuffer.toString());
-
- // BUG108074 & BUG84688 - preserve whitespace in xsl:text &
- // xsl:attribute
- String nodeNamespaceURI = node.getNamespaceURI();
- if (XSL_NAMESPACE.equals(nodeNamespaceURI)) {
- String nodeName = ((Element) node).getLocalName();
- if (XSL_ATTRIBUTE.equals(nodeName) || XSL_TEXT.equals(nodeName)) {
- sawXmlSpace = true;
- formatContraints.setInPreserveSpaceElement(true);
- }
- }
-
- // If we didn't see a xml:space attribute above, we'll look for
- // one in the DTD.
- // We do not check for a conflict between a DTD's 'fixed' value
- // and the attribute value found in the instance document, we
- // leave that to the validator.
- if (!sawXmlSpace) {
- ModelQueryAdapter adapter = (ModelQueryAdapter) ((IDOMDocument) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class);
- CMElementDeclaration elementDeclaration = (CMElementDeclaration) adapter.getModelQuery().getCMNode(node);
- if (elementDeclaration != null) {
- int contentType = elementDeclaration.getContentType();
- if (preferences.isPreservePCDATAContent() && contentType == CMElementDeclaration.PCDATA) {
- formatContraints.setInPreserveSpaceElement(true);
- }
- else {
- CMNamedNodeMap cmAttributes = elementDeclaration.getAttributes();
- // Check implied values from the DTD way.
- CMAttributeDeclaration attributeDeclaration = (CMAttributeDeclaration) cmAttributes.getNamedItem(XML_SPACE);
- if (attributeDeclaration != null) {
- // CMAttributeDeclaration found, check it out.
- String defaultValue = attributeDeclaration.getAttrType().getImpliedValue();
-
- // xml:space="preserve" means preserve space,
- // everything else means back to default.
- if (PRESERVE.compareTo(defaultValue) == 0)
- formatContraints.setInPreserveSpaceElement(true);
- else
- formatContraints.setInPreserveSpaceElement(false);
- }
- }
- }
- }
- }
- }
-
- protected String getUndefinedRegions(IDOMNode node, int startOffset, int length) {
- String result = NodeFormatter.EMPTY_STRING;
-
- IStructuredDocumentRegion flatNode = node.getFirstStructuredDocumentRegion();
- ITextRegionList regions = flatNode.getRegions();
- for (int i = 0; i < regions.size(); i++) {
- ITextRegion region = regions.get(i);
- String regionType = region.getType();
- int regionStartOffset = flatNode.getStartOffset(region);
-
- if (regionType.compareTo(DOMRegionContext.UNDEFINED) == 0 && regionStartOffset >= startOffset && regionStartOffset < startOffset + length)
- result = result + flatNode.getFullText(region);
- }
-
- if (result.length() > 0)
- return SPACE_CHAR + result.trim();
- else
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java
deleted file mode 100644
index a798dbdbda..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/FormatProcessorXML.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.provisional.format;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.wst.sse.core.internal.format.AbstractStructuredFormatProcessor;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatter;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-import org.w3c.dom.Node;
-
-public class FormatProcessorXML extends AbstractStructuredFormatProcessor {
- protected IStructuredFormatPreferences fFormatPreferences = null;
-
- protected String getFileExtension() {
- return "xml"; //$NON-NLS-1$
- }
-
- public IStructuredFormatPreferences getFormatPreferences() {
- if (fFormatPreferences == null) {
- fFormatPreferences = new StructuredFormatPreferencesXML();
-
- Preferences preferences = getModelPreferences();
- if (preferences != null) {
- fFormatPreferences.setLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setAlignEndBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setPreservePCDATAContent(preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
- fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
-
- char indentChar = ' ';
- String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
- if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
- indentChar = '\t';
- }
- int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
-
- StringBuffer indent = new StringBuffer();
- for (int i = 0; i < indentationWidth; i++) {
- indent.append(indentChar);
- }
- fFormatPreferences.setIndent(indent.toString());
- }
- }
-
- return fFormatPreferences;
- }
-
- protected IStructuredFormatter getFormatter(Node node) {
- // 262135 - NPE during format of empty document
- if (node == null)
- return null;
-
- short nodeType = node.getNodeType();
- IStructuredFormatter formatter = null;
- switch (nodeType) {
- case Node.ELEMENT_NODE : {
- formatter = new ElementNodeFormatter();
- break;
- }
- case Node.TEXT_NODE : {
- formatter = new TextNodeFormatter();
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- formatter = new NoMoveFormatter();
- break;
- }
- case Node.COMMENT_NODE : {
- formatter = new CommentNodeFormatter();
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- formatter = new NodeFormatter();
- break;
- }
- case Node.DOCUMENT_NODE : {
- formatter = new DocumentNodeFormatter();
- break;
- }
- case Node.ENTITY_REFERENCE_NODE : {
- formatter = new NoMoveFormatter();
- break;
- }
- default : {
- formatter = new NodeFormatter();
- }
- }
-
- // init fomatter
- formatter.setFormatPreferences(getFormatPreferences());
- formatter.setProgressMonitor(fProgressMonitor);
-
- return formatter;
- }
-
- protected Preferences getModelPreferences() {
- return XMLCorePlugin.getDefault().getPluginPreferences();
- }
-
- protected void refreshFormatPreferences() {
- fFormatPreferences = null;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java
deleted file mode 100644
index 7b68ece73e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NoMoveFormatter.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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.provisional.format;
-
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-
-/**
- * Formats entities which really need no formatting. They are just like text
- * nodes.
- */
-class NoMoveFormatter extends NodeFormatter {
- protected void formatIndentationBeforeNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // node nothing
- }
-
- protected void formatIndentationAfterNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // still do nothing
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java
deleted file mode 100644
index f48ed184bf..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/NodeFormatter.java
+++ /dev/null
@@ -1,753 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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
- * Jesper Steen Møller - xml:space='preserve' support
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.format;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatter;
-import org.eclipse.wst.sse.core.internal.format.StructuredFormatContraints;
-import org.eclipse.wst.sse.core.internal.parser.ContextRegion;
-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.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
-import org.eclipse.wst.xml.core.internal.document.CDATASectionImpl;
-import org.eclipse.wst.xml.core.internal.document.CharacterDataImpl;
-import org.eclipse.wst.xml.core.internal.document.CommentImpl;
-import org.eclipse.wst.xml.core.internal.parser.regions.TagNameRegion;
-import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames;
-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.Node;
-
-public class NodeFormatter implements IStructuredFormatter {
- static protected final String EMPTY_STRING = ""; //$NON-NLS-1$
- static private final char SPACE_CHAR = ' '; //$NON-NLS-1$
- static private final char TAB_CHAR = '\t'; //$NON-NLS-1$
- static private final String TAB = "\t"; //$NON-NLS-1$
- protected IStructuredFormatContraints fFormatContraints = null;
- protected IStructuredFormatPreferences fFormatPreferences = null;
- protected IProgressMonitor fProgressMonitor = null;
-
- protected boolean firstStructuredDocumentRegionContainsLineDelimiters(IDOMNode node) {
- boolean result = false;
-
- if (node != null) {
- IStructuredDocumentRegion firstStructuredDocumentRegion = node.getFirstStructuredDocumentRegion();
- if (firstStructuredDocumentRegion != null) {
- String firstStructuredDocumentRegionText = firstStructuredDocumentRegion.getText();
- result = StringUtils.containsLineDelimiter(firstStructuredDocumentRegionText);
- }
- }
-
- return result;
- }
-
- public void format(Node node) {
- IStructuredFormatContraints formatContraints = getFormatContraints();
-
- format(node, formatContraints);
- }
-
- public void format(Node node, IStructuredFormatContraints formatContraints) {
- if (formatContraints.getFormatWithSiblingIndent())
- formatContraints.setCurrentIndent(getSiblingIndent(node));
-
- if (node instanceof IDOMNode)
- formatNode((IDOMNode) node, formatContraints);
- }
-
- protected void formatIndentationAfterNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // [111674] If inside xml:space="preserve" element, we bail
- if (formatContraints.getInPreserveSpaceElement())
- return;
- if (node != null) {
- IDOMNode nextSibling = (IDOMNode) node.getNextSibling();
- IStructuredDocument doc = node.getModel().getStructuredDocument();
- String lineDelimiter = getLineDelimiter(node, doc);
-
- if (node.getParentNode() != null) {
- if (node.getParentNode().getNodeType() == Node.DOCUMENT_NODE)
- if (nextSibling != null)
- if (nextSibling.getNodeType() == Node.TEXT_NODE)
- getFormatter(nextSibling).format(nextSibling, formatContraints);
- else if (nextSibling.getNodeType() == Node.COMMENT_NODE) {
- // do nothing
- }
- else {
- String lineIndent = formatContraints.getCurrentIndent();
- insertAfterNode(node, lineDelimiter + lineIndent);
- }
- else {
- }
-
- else if (nextSibling != null)
- if (nextSibling.getNodeType() == Node.TEXT_NODE)
- getFormatter(nextSibling).format(nextSibling, formatContraints);
- else if (nextSibling.getNodeType() == Node.COMMENT_NODE) {
- // do nothing
- }
- else {
- String lineIndent = formatContraints.getCurrentIndent();
- insertAfterNode(node, lineDelimiter + lineIndent);
- }
- else {
- IDOMNode indentNode = getParentIndentNode(node);
- String lineIndent = getNodeIndent(indentNode);
- IDOMNode lastChild = getDeepestChildNode(node);
- boolean clearAllBlankLines = formatContraints.getClearAllBlankLines();
-
- if (lastChild != null) {
- if ((lastChild.getNodeType() == Node.TEXT_NODE) && (lastChild.getNodeValue().endsWith(lineDelimiter + lineIndent))) {
- // this text node already ends with the requested
- // indentation
- }
-
- else if ((lastChild.getNodeType() == Node.TEXT_NODE) && (lastChild.getNodeValue() != null && lastChild.getNodeValue().endsWith(lineDelimiter)))
- if (clearAllBlankLines) {
- replaceNodeValue(lastChild, lineDelimiter + lineIndent);
- }
- else {
- // append indentation
- insertAfterNode(lastChild, lineIndent);
- }
- else if (lastChild.getNodeType() == Node.TEXT_NODE)
- if (lastChild.getNodeValue().length() == 0) {
- // replace
- replaceNodeValue(lastChild, lineDelimiter + lineIndent);
- }
- else {
- // append indentation
- insertAfterNode(lastChild, lineDelimiter + lineIndent);
- }
- else {
- // as long as not at the end of the document
- IStructuredDocumentRegion endRegion = node.getLastStructuredDocumentRegion();
- if (endRegion != null && endRegion.getNext() != null)
- // append indentation
- insertAfterNode(lastChild, lineDelimiter + lineIndent);
- }
- }
- }
- }
- }
- }
-
- protected void formatIndentationBeforeNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // [111674] If inside xml:space="preserve" element, we bail
- if (formatContraints.getInPreserveSpaceElement())
- return;
- if (node != null) {
- IDOMNode previousSibling = (IDOMNode) node.getPreviousSibling();
- IStructuredDocument doc = node.getModel().getStructuredDocument();
- String lineDelimiter = getLineDelimiter(node, doc);
-
- String lineIndent = formatContraints.getCurrentIndent();
-
- if (node.getParentNode() != null) {
- if (node.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
- if (previousSibling != null)
- if (previousSibling.getNodeType() == Node.TEXT_NODE)
- getFormatter(previousSibling).format(previousSibling, formatContraints);
- else {
- insertBeforeNode(node, lineDelimiter + lineIndent);
- }
- }
- else {
- if (previousSibling == null || previousSibling.getNodeType() != Node.TEXT_NODE) {
- // 261968 - formatting tag without closing bracket:
- // <t1><t1
- // 265673 - Null ptr in formatIndentationBeforeNode
- int prevEndNodeOffset = -1;
- int prevEndRegionOffset = -1;
- if (previousSibling != null) {
- prevEndNodeOffset = previousSibling.getEndOffset();
- IStructuredDocumentRegion endRegion = previousSibling.getEndStructuredDocumentRegion();
- if (endRegion != null) {
- prevEndRegionOffset = endRegion.getTextEndOffset();
- }
- }
- if ((previousSibling == null) || (prevEndNodeOffset != -1 && prevEndNodeOffset == prevEndRegionOffset)) {
- insertBeforeNode(node, lineDelimiter + lineIndent);
- }
-
- }
- else {
- if (previousSibling.getNodeValue().length() == 0) {
- // replace
- replaceNodeValue(previousSibling, lineDelimiter + lineIndent);
- }
- else {
- // append indentation
- if (!previousSibling.getNodeValue().endsWith(lineDelimiter + lineIndent)) {
- if (previousSibling.getNodeValue().endsWith(lineDelimiter)) {
- insertAfterNode(previousSibling, lineIndent);
- }
- else
- getFormatter(previousSibling).format(previousSibling, formatContraints);
- }
- }
- }
- }
- }
- }
- }
-
- private String getLineDelimiter(IDOMNode node, IStructuredDocument doc) {
- int line = doc.getLineOfOffset(node.getStartOffset());
- String lineDelimiter = doc.getLineDelimiter();
- try {
- if (line > 0) {
- lineDelimiter = doc.getLineDelimiter(line - 1);
- }
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- // BUG115716: if cannot get line delimiter from current line, just
- // use default line delimiter
- if (lineDelimiter == null)
- lineDelimiter = doc.getLineDelimiter();
- return lineDelimiter;
- }
-
- protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- if (node != null && (fProgressMonitor == null || !fProgressMonitor.isCanceled())) {
- // format indentation before node
- formatIndentationBeforeNode(node, formatContraints);
-
- // format indentation after node
- formatIndentationAfterNode(node, formatContraints);
- }
- }
-
- /**
- * This method will compute the correct indentation after this node
- * depending on the indentations of its sibling nodes and parent node. Not
- * needed anymore?
- */
- protected void formatTrailingText(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // [111674] If inside xml:space="preserve" element, we bail
- if (formatContraints.getInPreserveSpaceElement())
- return;
-
- String lineDelimiter = node.getModel().getStructuredDocument().getLineDelimiter();
- String lineIndent = formatContraints.getCurrentIndent();
- String parentLineIndent = getNodeIndent(node.getParentNode());
- boolean clearAllBlankLines = formatContraints.getClearAllBlankLines();
-
- if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE)) {
- IDOMNode nextSibling = (IDOMNode) node.getNextSibling();
- if ((nextSibling != null) && (nextSibling.getNodeType() == Node.TEXT_NODE)) {
- String nextSiblingText = nextSibling.getNodeValue();
- if (nextSibling.getNextSibling() == null)
- if ((nextSibling.getParentNode().getNodeType() == Node.DOCUMENT_NODE) && (nextSiblingText.trim().length() == 0))
- // delete spaces at the end of the document
- replaceNodeValue(nextSibling, EMPTY_STRING);
- else
- // replace the text node with parent indentation
- replaceNodeValue(nextSibling, lineDelimiter + parentLineIndent);
- else
- // replace the text node with indentation
- replaceNodeValue(nextSibling, lineDelimiter + lineIndent);
- }
- else {
- if (nextSibling == null) {
- lineIndent = parentLineIndent;
-
- if (node.getParentNode().getNodeType() != Node.DOCUMENT_NODE)
- if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().endsWith(lineDelimiter + lineIndent))) {
- // this text node already ends with the requested
- // indentation
- }
-
- else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().endsWith(lineDelimiter)))
- if (clearAllBlankLines)
- replaceNodeValue(node, lineDelimiter + lineIndent);
- else
- // append indentation
- insertAfterNode(node, lineIndent);
- else if (node.getNodeType() == Node.TEXT_NODE)
- if (node.getNodeValue().length() == 0)
- // replace
- replaceNodeValue(node, lineDelimiter + lineIndent);
- else
- // append indentation
- if (!node.getNodeValue().endsWith(lineDelimiter + lineIndent))
- if (node.getNodeValue().endsWith(lineDelimiter))
- insertAfterNode(node, lineIndent);
- else
- insertAfterNode(node, lineDelimiter + lineIndent);
- else
- replaceNodeValue(node, lineDelimiter + lineIndent);
- }
- else {
- if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().endsWith(lineDelimiter + lineIndent))) {
- // this text node already ends with the requested
- // indentation
- }
-
- else if ((node.getNodeType() == Node.TEXT_NODE) && (node.getNodeValue().endsWith(lineDelimiter)))
- if (clearAllBlankLines)
- replaceNodeValue(node, lineDelimiter + lineIndent);
- else
- // append indentation
- insertAfterNode(node, lineIndent);
- else if (node.getNodeType() == Node.TEXT_NODE)
- if (node.getNodeValue().length() == 0)
- // replace
- replaceNodeValue(node, lineDelimiter + lineIndent);
- else
- // append indentation
- insertAfterNode(node, lineDelimiter + lineIndent);
- else
- // append indentation
- insertAfterNode(node, lineDelimiter + lineIndent);
- }
- }
- }
- }
-
- protected IDOMNode getDeepestChildNode(IDOMNode node) {
- IDOMNode result = null;
- IDOMNode lastChild = (IDOMNode) node.getLastChild();
-
- if (lastChild == null)
- result = node;
- else {
- result = getDeepestChildNode(lastChild);
-
- if ((result.getNodeType() == Node.TEXT_NODE || result.getNodeType() == Node.COMMENT_NODE) && !isEndTagMissing(node))
- result = node;
- }
-
- return result;
- }
-
- public IStructuredFormatContraints getFormatContraints() {
- if (fFormatContraints == null) {
- fFormatContraints = new StructuredFormatContraints();
-
- fFormatContraints.setClearAllBlankLines(getFormatPreferences().getClearAllBlankLines());
- }
-
- return fFormatContraints;
- }
-
- public IStructuredFormatPreferences getFormatPreferences() {
- if (fFormatPreferences == null) {
- fFormatPreferences = new StructuredFormatPreferencesXML();
-
- Preferences preferences = getModelPreferences();
- if (preferences != null) {
- fFormatPreferences.setLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setAlignEndBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
- ((StructuredFormatPreferencesXML) fFormatPreferences).setPreservePCDATAContent(preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
- fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
-
- char indentChar = ' ';
- String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
- if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
- indentChar = '\t';
- }
- int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
-
- StringBuffer indent = new StringBuffer();
- for (int i = 0; i < indentationWidth; i++) {
- indent.append(indentChar);
- }
- fFormatPreferences.setIndent(indent.toString());
- }
- }
-
- return fFormatPreferences;
- }
-
- protected IStructuredFormatter getFormatter(IDOMNode node) {
- // 262135 - NPE during format of empty document
- if (node == null)
- return null;
-
- short nodeType = ((Node) node).getNodeType();
- IStructuredFormatter formatter = null;
- switch (nodeType) {
- case Node.ELEMENT_NODE : {
- formatter = new ElementNodeFormatter();
- break;
- }
- case Node.TEXT_NODE : {
- formatter = new TextNodeFormatter();
- break;
- }
- case Node.CDATA_SECTION_NODE : {
- formatter = new NoMoveFormatter();
- break;
- }
- case Node.COMMENT_NODE : {
- formatter = new CommentNodeFormatter();
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE : {
- formatter = new NodeFormatter();
- break;
- }
- case Node.DOCUMENT_NODE : {
- formatter = new DocumentNodeFormatter();
- break;
- }
- case Node.ENTITY_REFERENCE_NODE : {
- formatter = new NoMoveFormatter();
- break;
- }
- default : {
- formatter = new NodeFormatter();
- }
- }
-
- // init fomatter
- formatter.setFormatPreferences(getFormatPreferences());
- formatter.setProgressMonitor(fProgressMonitor);
-
- return formatter;
- }
-
- protected int getIndentationLength(String indent) {
- // TODO Kit : The calculation of IndentationLength is not correct
- // here.
- // nodeIndentation may contain tabs. Multiply by 4 temporarily to get
- // approx. width.
- // Need to re-work.
-
- int indentationLength = 0;
-
- for (int i = 0; i < indent.length(); i++) {
- if (indent.substring(i, i + 1).compareTo(TAB) == 0)
- indentationLength += 4;
- else
- indentationLength++;
- }
-
- return indentationLength;
- }
-
- protected Preferences getModelPreferences() {
- return XMLCorePlugin.getDefault().getPluginPreferences();
- }
-
- /**
- * This method will find the indentation for this node. It will search
- * backwards starting from the beginning of the node until a character
- * other than a space or a tab is found. If this node is null or it's a
- * document node or it's a first level node (node's parent is a document
- * node) the default empty string will be returned as the indentation.
- */
- protected String getNodeIndent(Node node) {
- String result = EMPTY_STRING;
-
- if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && (node.getParentNode() != null) && (node.getParentNode().getNodeType() != Node.DOCUMENT_NODE)) {
- IDOMNode siblingTextNode = (IDOMNode) node.getPreviousSibling();
- if ((siblingTextNode != null) && (siblingTextNode.getNodeType() == Node.TEXT_NODE)) {
- // find the indentation
- String siblingText = siblingTextNode.getNodeValue();
- int siblingTextLength = siblingText.length();
- if ((siblingText != null) && (siblingTextLength > 0) && ((siblingText.charAt(siblingTextLength - 1) == SPACE_CHAR) || (siblingText.charAt(siblingTextLength - 1) == TAB_CHAR))) {
- int searchIndex = siblingTextLength - 1;
- while ((searchIndex >= 0) && ((siblingText.charAt(searchIndex) == SPACE_CHAR) || (siblingText.charAt(searchIndex) == TAB_CHAR)))
- searchIndex--;
-
- if (searchIndex < siblingTextLength)
- result = siblingText.substring(searchIndex + 1, siblingTextLength);
- }
- }
- }
-
- return result;
- }
-
- protected String getNodeName(IDOMNode node) {
- return node.getNodeName();
- }
-
- protected String getNodeText(IDOMNode node) {
- String text = null;
-
- if ((node instanceof CharacterDataImpl) && !(node instanceof CommentImpl) && !(node instanceof CDATASectionImpl) && !isJSPTag(node))
- text = ((CharacterDataImpl) node).getSource();
- else
- text = node.getFirstStructuredDocumentRegion().getText();
-
- return text;
- }
-
- protected IDOMNode getParentIndentNode(IDOMNode node) {
- IDOMNode result = null;
- IDOMNode parentNode = (IDOMNode) node.getParentNode();
-
- if (parentNode.getNodeType() == Node.DOCUMENT_NODE)
- result = parentNode;
- else {
- ITextRegion region = parentNode.getLastStructuredDocumentRegion().getFirstRegion();
- if (region.getType() == DOMRegionContext.XML_END_TAG_OPEN)
- result = parentNode;
- else
- result = getParentIndentNode(parentNode);
- }
-
- return result;
- }
-
- /**
- * This method will find the indentation for a node sibling to this node.
- * It will try to find a sibling node before this node first. If there is
- * no sibling node before this node, it will try to find a sibling node
- * after this node. If still not found, we will check if this node is
- * already indented from its parent. If yes, this node's indentation will
- * be used. Otherwise, the parent node's indentation plus one indentation
- * will be used. If this node is null or it's a document node or it's a
- * first level node (node's parent is a document node) the default empty
- * string will be returned as the indentation.
- */
- protected String getSiblingIndent(Node node) {
- String result = EMPTY_STRING;
-
- if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && (node.getParentNode() != null) && (node.getParentNode().getNodeType() != Node.DOCUMENT_NODE)) {
- // find the text node before the previous non-text sibling
- // if that's not found, we will try the text node before the next
- // non-text sibling
- IDOMNode sibling = (IDOMNode) node.getPreviousSibling();
- while ((sibling != null) && (sibling.getNodeType() == Node.TEXT_NODE || sibling.getNodeType() == Node.COMMENT_NODE)) {
- if (sibling.getNodeType() == Node.COMMENT_NODE && sibling.getPreviousSibling() != null && sibling.getPreviousSibling().getNodeType() == Node.TEXT_NODE && StringUtils.containsLineDelimiter(sibling.getPreviousSibling().getNodeValue()))
- break;
- sibling = (IDOMNode) sibling.getPreviousSibling();
- }
- if (sibling == null) {
- sibling = (IDOMNode) node.getNextSibling();
- while ((sibling != null) && (sibling.getNodeType() == Node.TEXT_NODE))
- sibling = (IDOMNode) sibling.getNextSibling();
- }
- String singleIndent = getFormatPreferences().getIndent();
- String parentLineIndent = getNodeIndent(node.getParentNode());
-
- if (sibling != null) {
- String siblingIndent = getNodeIndent(sibling);
- if (siblingIndent.length() > 0)
- result = siblingIndent;
- else {
- String nodeIndent = getNodeIndent(node);
- if (nodeIndent.length() > parentLineIndent.length())
- // this node is indented from its parent, its
- // indentation will be used
- result = nodeIndent;
- else
- result = parentLineIndent + singleIndent;
- }
- }
- else {
- String nodeIndent = getNodeIndent(node);
- if (nodeIndent.length() > parentLineIndent.length())
- // this node is indented from its parent, its indentation
- // will be used
- result = nodeIndent;
- else
- result = parentLineIndent + singleIndent;
- }
- }
-
- return result;
- }
-
- protected void insertAfterNode(IDOMNode node, String string) {
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
-
- int offset = node.getEndOffset();
- int length = 0;
-
- // 261968 - formatting tag without closing bracket: <t1><t1
- if (node.getEndStructuredDocumentRegion() != null) {
- offset = node.getEndStructuredDocumentRegion().getTextEndOffset();
- length = node.getEndOffset() - offset;
- }
- replace(structuredDocument, offset, length, string);
- }
-
- protected void insertBeforeNode(IDOMNode node, String string) {
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
-
- replace(structuredDocument, node.getStartOffset(), 0, string);
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type allows it
- * to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return type.equals(IStructuredFormatter.class);
- }
-
- protected boolean isEndTagMissing(IDOMNode node) {
- boolean result = false;
-
- if ((node != null) && (node.getNodeType() != Node.DOCUMENT_NODE) && !isJSPTag(node)) {
- IStructuredDocumentRegion startTagStructuredDocumentRegion = node.getFirstStructuredDocumentRegion();
- IStructuredDocumentRegion endTagStructuredDocumentRegion = node.getLastStructuredDocumentRegion();
-
- ITextRegion startTagNameRegion = null;
- if (startTagStructuredDocumentRegion.getRegions().size() > 1)
- startTagNameRegion = startTagStructuredDocumentRegion.getRegions().get(1);
- ITextRegion endTagNameRegion = null;
- if (endTagStructuredDocumentRegion.getRegions().size() > 1)
- endTagNameRegion = endTagStructuredDocumentRegion.getRegions().get(1);
-
- ITextRegionList startTagRegions = startTagStructuredDocumentRegion.getRegions();
- if (startTagNameRegion == endTagNameRegion && startTagNameRegion != null && (startTagRegions.get(0)).getType() != DOMRegionContext.XML_END_TAG_OPEN && (startTagRegions.get(startTagRegions.size() - 1).getType()) != DOMRegionContext.XML_EMPTY_TAG_CLOSE)
- // end tag missing
- result = true;
- }
-
- return result;
- }
-
- protected boolean nodeHasSiblings(IDOMNode node) {
- return (node.getPreviousSibling() != null) || (node.getNextSibling() != null);
- }
-
- /**
- * Node changed. No format should be performed automatically.
- */
- public void notifyChanged(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- }
-
- protected void removeRegionSpaces(IDOMNode node, IStructuredDocumentRegion flatNode, ITextRegion region) {
- if ((region != null) && (region instanceof ContextRegion || region instanceof TagNameRegion) && (flatNode.getEndOffset(region) > flatNode.getTextEndOffset(region))) {
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
-
- replace(structuredDocument, flatNode.getTextEndOffset(region), flatNode.getEndOffset(region) - flatNode.getTextEndOffset(region), EMPTY_STRING);
- }
- }
-
- /**
- * This method will replace the string at offset and length with a new
- * string. If the string to be replaced is the same as the new string, the
- * string will not be replaced.
- */
- protected void replace(IStructuredDocument structuredDocument, int offset, int length, String string) {
- try {
- String structuredDocumentString = structuredDocument.get(offset, length);
- if (structuredDocumentString.compareTo(string) != 0)
- structuredDocument.replaceText(structuredDocument, offset, length, string);
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- }
-
- /**
- * This method will replace the node value with a new string. If the node
- * value to be replaced is the same as the new string, the node value will
- * not be replaced.
- */
- protected void replaceNodeValue(IDOMNode node, String string) {
- IDOMModel structuredModel = node.getModel();
- IStructuredDocument structuredDocument = structuredModel.getStructuredDocument();
- int offset = node.getStartOffset();
- int length = node.getEndOffset() - node.getStartOffset();
-
- try {
- String structuredDocumentString = structuredDocument.get(offset, length);
- if (structuredDocumentString.compareTo(string) != 0)
- replace(structuredDocument, offset, length, string);
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- }
-
- public void setFormatPreferences(IStructuredFormatPreferences formatPreferences) {
- fFormatPreferences = formatPreferences;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.core.format.IStructuredFormatter#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor = monitor;
- }
-
- /**
- * ISSUE: this is a bit of hidden JSP knowledge that was implemented this
- * way for expedency. Should be evolved in future to depend on
- * "nestedContext".
- */
- private boolean isJSPTag(Node node) {
-
- final String JSP_CLOSE = "JSP_CLOSE"; //$NON-NLS-1$
- // final String JSP_COMMENT_CLOSE = "JSP_COMMENT_CLOSE"; //$NON-NLS-1$
-
- // final String JSP_COMMENT_OPEN = "JSP_COMMENT_OPEN"; //$NON-NLS-1$
- // final String JSP_COMMENT_TEXT = "JSP_COMMENT_TEXT"; //$NON-NLS-1$
-
- final String JSP_CONTENT = "JSP_CONTENT"; //$NON-NLS-1$
- final String JSP_DECLARATION_OPEN = "JSP_DECLARATION_OPEN"; //$NON-NLS-1$
- final String JSP_DIRECTIVE_CLOSE = "JSP_DIRECTIVE_CLOSE"; //$NON-NLS-1$
- final String JSP_DIRECTIVE_NAME = "JSP_DIRECTIVE_NAME"; //$NON-NLS-1$
-
- final String JSP_DIRECTIVE_OPEN = "JSP_DIRECTIVE_OPEN"; //$NON-NLS-1$
- final String JSP_EXPRESSION_OPEN = "JSP_EXPRESSION_OPEN"; //$NON-NLS-1$
-
- // final String JSP_ROOT_TAG_NAME = "JSP_ROOT_TAG_NAME"; //$NON-NLS-1$
-
- final String JSP_SCRIPTLET_OPEN = "JSP_SCRIPTLET_OPEN"; //$NON-NLS-1$
-
- boolean result = false;
-
- if (node instanceof IDOMNode) {
- IStructuredDocumentRegion flatNode = ((IDOMNode) node).getFirstStructuredDocumentRegion();
- // in some cases, the nodes exists, but hasn't been associated
- // with
- // a flatnode yet (the screen updates can be initiated on a
- // different thread,
- // so the request for a flatnode can come in before the node is
- // fully formed.
- // if the flatnode is null, we'll just allow the defaults to
- // apply.
- if (flatNode != null) {
- String flatNodeType = flatNode.getType();
- // should not be null, but just to be sure
- if (flatNodeType != null) {
- if ((flatNodeType.equals(JSP_CONTENT)) || (flatNodeType.equals(JSP_EXPRESSION_OPEN)) || (flatNodeType.equals(JSP_SCRIPTLET_OPEN)) || (flatNodeType.equals(JSP_DECLARATION_OPEN)) || (flatNodeType.equals(JSP_DIRECTIVE_CLOSE)) || (flatNodeType.equals(JSP_DIRECTIVE_NAME)) || (flatNodeType.equals(JSP_DIRECTIVE_OPEN)) || (flatNodeType.equals(JSP_CLOSE))) {
- result = true;
- }
- }
- }
- }
-
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/StructuredFormatPreferencesXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/StructuredFormatPreferencesXML.java
deleted file mode 100644
index 07024eb3f5..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/StructuredFormatPreferencesXML.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.provisional.format;
-
-import org.eclipse.wst.sse.core.internal.format.StructuredFormatPreferences;
-
-public class StructuredFormatPreferencesXML extends StructuredFormatPreferences {
- private boolean fSplitMultiAttrs = false;
- private boolean fPreservePCDATAContent = false;
- private boolean fAlignEndBracket = false;
-
- /**
- * True if formatter should split elements with multiple attributes onto
- * new lines.
- *
- * @return boolean
- */
- public boolean getSplitMultiAttrs() {
- return fSplitMultiAttrs;
- }
-
- /**
- * Sets whether or not formatter should split elements with multiple
- * attributes onto new lines.
- *
- * @param splitMultiAttrs
- */
- public void setSplitMultiAttrs(boolean splitMultiAttrs) {
- fSplitMultiAttrs = splitMultiAttrs;
- }
-
- /**
- * True if tags with PCDATA content should not have their whitespace
- * messed with when formatting.
- *
- * @return boolean
- */
- public boolean isPreservePCDATAContent() {
- return fPreservePCDATAContent;
- }
-
- /**
- * Sets whether or not formatter should preserve whitespace in tags with
- * PCDATA content.
- *
- * @param preservePCDATAContent
- */
- public void setPreservePCDATAContent(boolean preservePCDATAContent) {
- fPreservePCDATAContent = preservePCDATAContent;
- }
-
- /**
- * True if end brackets of start tags should be placed on a new line if
- * the start tag spans more than one line.
- *
- * @return
- */
- public boolean isAlignEndBracket() {
- return fAlignEndBracket;
- }
-
- /**
- * Sets whether or not formatter should align the end bracket of a start
- * tag on a new line if the start tag spans more than one line.
- *
- * @param alignEndBracket
- */
- public void setAlignEndBracket(boolean alignEndBracket) {
- fAlignEndBracket = alignEndBracket;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java
deleted file mode 100644
index 873ab766e4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/format/TextNodeFormatter.java
+++ /dev/null
@@ -1,385 +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
- * Jesper Steen Møller - xml:space='preserve' support
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.format;
-
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.wst.sse.core.internal.format.IStructuredFormatContraints;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.utils.StringUtils;
-import org.eclipse.wst.xml.core.internal.Logger;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Node;
-
-
-public class TextNodeFormatter extends NodeFormatter {
- static private final String CR = "\r"; //$NON-NLS-1$
- static private final String DELIMITERS = " \t\n\r\f"; //$NON-NLS-1$
- static private final String EMPTY_STRING = ""; //$NON-NLS-1$
- static private final String FF = "\f"; //$NON-NLS-1$
- static private final String LF = "\n"; //$NON-NLS-1$
- static private final String SPACE = " "; //$NON-NLS-1$
- static private final String TAB = "\t"; //$NON-NLS-1$
-
- private String compressSpaces(String string, IStructuredFormatContraints formatContraints) {
- /*
- * Note that the StructuredTextEditor supports mixed new line
- * characters (CR, LF, CRLF) in one file. We have to handle that when
- * we try to preserve blank lines.
- */
- String[] stringArray = null;
- boolean clearAllBlankLines = formatContraints.getClearAllBlankLines();
-
- if (clearAllBlankLines)
- stringArray = StringUtils.asArray(string);
- else
- stringArray = StringUtils.asArray(string, DELIMITERS, true);
-
- StringBuffer compressedString = new StringBuffer();
- if (stringArray.length > 0) {
- boolean cr = false, lf = false, cr2 = false, nonSpace = true;
-
- if (stringArray[0].compareTo(CR) == 0)
- cr = true;
- else if (stringArray[0].compareTo(LF) == 0)
- lf = true;
- else if ((stringArray[0].compareTo(SPACE) != 0) && (stringArray[0].compareTo(TAB) != 0) && (stringArray[0].compareTo(FF) != 0)) {
- compressedString.append(stringArray[0]);
- nonSpace = true;
- }
-
- for (int i = 1; i < stringArray.length; i++) {
- if (stringArray[i].compareTo(CR) == 0) {
- if (cr && lf) {
- if (nonSpace) {
- compressedString.append(CR + LF);
- nonSpace = false;
- }
- compressedString.append(stringArray[i]);
- cr2 = true;
- }
- else if (cr) {
- if (nonSpace) {
- compressedString.append(CR);
- nonSpace = false;
- }
- compressedString.append(stringArray[i]);
- cr2 = true;
- }
- else
- cr = true;
- }
- else if (stringArray[i].compareTo(LF) == 0) {
- if (cr && lf && cr2) {
- compressedString.append(stringArray[i]);
- }
- else if (lf) {
- if (nonSpace) {
- compressedString.append(LF);
- nonSpace = false;
- }
- compressedString.append(stringArray[i]);
- }
- else
- lf = true;
- }
- else if ((stringArray[i].compareTo(SPACE) != 0) && (stringArray[i].compareTo(TAB) != 0) && (stringArray[i].compareTo(FF) != 0)) {
- if (compressedString.length() > 0)
- compressedString.append(SPACE);
- compressedString.append(stringArray[i]);
-
- cr = false;
- lf = false;
- cr2 = false;
- nonSpace = true;
- }
- }
- }
-
- return compressedString.toString();
- }
-
- protected void formatNode(IDOMNode node, IStructuredFormatContraints formatContraints) {
- // [111674] If inside xml:space="preserve" element, we bail
- if (formatContraints.getInPreserveSpaceElement())
- return;
- if (node != null) {
- IStructuredDocument doc = node.getStructuredDocument();
-
- int lineWidth = getFormatPreferences().getLineWidth();
- int currentAvailableLineWidth = computeAvailableLineWidth(doc, node.getStartOffset(), lineWidth);
-
- String nodeText = getNodeText(node);
- String compressedText = compressSpaces(nodeText, formatContraints);
-
- IDOMNode parentNode = (IDOMNode) node.getParentNode();
-
- if (((enoughSpace(parentNode, currentAvailableLineWidth, compressedText)) && (noSiblingsAndNoFollowingComment(node)) && !firstStructuredDocumentRegionContainsLineDelimiters(parentNode)) || node.getStartOffset() == 0) {
- handleNoReflow(node, doc, compressedText, parentNode);
- }
- else {
- // not enough space, need to reflow text
- String nodeIndentation = formatContraints.getCurrentIndent();
- currentAvailableLineWidth = lineWidth - getIndentationLength(nodeIndentation);
- List vector = reflowText(compressedText, currentAvailableLineWidth);
- int vectorSize = vector.size();
- StringBuffer reflowedTextBuffer = new StringBuffer();
- String lineDelimiter = getLineDelimiter(doc, node.getStartOffset());
- // handle first line specially to check for allowWhitespace
- if (vectorSize > 0) {
- // determines whether or not to allow whitespace if there
- // is an entity or cdata before it
- boolean allowWhitespace = true;
- // [206072] StringIndexOutOfBoundsException
- if (nodeText.length() == 0 || !Character.isWhitespace(nodeText.charAt(0))) {
- Node previousSibling = node.getPreviousSibling();
- if (previousSibling != null && (previousSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE || previousSibling.getNodeType() == Node.CDATA_SECTION_NODE))
- allowWhitespace = false;
- }
- String theString = (String) vector.get(0);
- if (allowWhitespace) {
- reflowedTextBuffer.append(lineDelimiter);
- if (theString.trim().length() > 0)
- reflowedTextBuffer.append(nodeIndentation).append(theString);
- }
- else {
- reflowedTextBuffer.append(theString);
- }
- }
- // do the rest of the lines
- for (int i = 1; i < vectorSize; i++) {
- String theString = (String) vector.get(i);
- if (theString.trim().length() > 0)
- reflowedTextBuffer.append(lineDelimiter).append(nodeIndentation).append(theString);
- else
- reflowedTextBuffer.append(lineDelimiter);
- }
- String reflowedText = reflowedTextBuffer.toString();
- if (node.getNextSibling() == null) {
- if (isEndTagMissing(parentNode)) {
- // don't add indentation to end if parent end tag is
- // missing
- }
-
- else {
- // add parent's indentation to end
- nodeIndentation = getNodeIndent(parentNode);
- if (!reflowedText.endsWith(lineDelimiter + nodeIndentation)) {
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, lineDelimiter);
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, nodeIndentation);
- }
- }
- }
- else {
- if (!reflowedText.endsWith(lineDelimiter + nodeIndentation)) {
- // not already ended with the expected indentation
- Node nextSibling = node.getNextSibling();
- if (nextSibling.getNodeType() == Node.COMMENT_NODE) {
- // add indentation to end if
- // currentTextEndsWithLineDelimiter
- // or followed by multiLineComment
-
- int indexOfLastLineDelimiter = StringUtils.indexOfLastLineDelimiter(nodeText);
- boolean currentTextEndsWithLineDelimiter = indexOfLastLineDelimiter != -1;
- if (currentTextEndsWithLineDelimiter) {
- // no more non blank character after the last
- // line delimiter
- currentTextEndsWithLineDelimiter = StringUtils.indexOfNonblank(nodeText, indexOfLastLineDelimiter) == -1;
- }
-
- String nodeValue = nextSibling.getNodeValue();
- boolean multiLineComment = StringUtils.containsLineDelimiter(nodeValue);
-
- if (currentTextEndsWithLineDelimiter || multiLineComment) {
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, lineDelimiter);
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, nodeIndentation);
- }
- }
- else if (nextSibling.getNodeType() == Node.ENTITY_REFERENCE_NODE || nextSibling.getNodeType() == Node.CDATA_SECTION_NODE) {
- int textLength = nodeText.length();
- if (textLength > 0 && Character.isWhitespace(nodeText.charAt(textLength - 1))) {
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, lineDelimiter);
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, nodeIndentation);
- }
- }
- else {
- // not a comment, just add add indentation to end
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, lineDelimiter);
- reflowedText = StringUtils.appendIfNotEndWith(reflowedText, nodeIndentation);
- }
- }
- }
-
- replaceNodeValue(node, reflowedText);
- }
- }
- }
-
- /**
- * Keeps text inline with its parent (no reflow necessary)
- *
- * @param node
- * @param doc
- * @param compressedText
- * @param parentNode
- */
- private void handleNoReflow(IDOMNode node, IStructuredDocument doc, String compressedText, IDOMNode parentNode) {
- String nodeIndentation;
- // enough space and text has no line delimiters and (node has no
- // siblings or followed by inline comment) and
- // parentFirstStructuredDocumentRegionContainsLineDelimiters
-
- if (isEndTagMissing(parentNode)) {
- parentNode = (IDOMNode) parentNode.getParentNode();
- while (isEndTagMissing(parentNode))
- parentNode = (IDOMNode) parentNode.getParentNode();
-
- // add parent's indentation to end
- nodeIndentation = getNodeIndent(parentNode);
- String lineDelimiter = getLineDelimiter(doc, node.getStartOffset());
- if (!compressedText.endsWith(lineDelimiter + nodeIndentation)) {
- compressedText = StringUtils.appendIfNotEndWith(compressedText, lineDelimiter);
- compressedText = StringUtils.appendIfNotEndWith(compressedText, nodeIndentation);
- }
- }
-
- if ((parentNode != null) && (parentNode.getNodeType() == Node.DOCUMENT_NODE) && (node.getNodeValue().length() > 0) && (node.getNodeValue().trim().length() == 0) && ((node.getPreviousSibling() == null) || (node.getNextSibling() == null)))
- // delete spaces at the beginning or end of the document
- compressedText = EMPTY_STRING;
-
- replaceNodeValue(node, compressedText);
- }
-
- private boolean noSiblingsAndNoFollowingComment(IDOMNode node) {
- IDOMNode nextSibling = (IDOMNode) node.getNextSibling();
- return !nodeHasSiblings(node) || (noLineDelimiter(node) && isComment(nextSibling) && noLineDelimiter(nextSibling));
- }
-
- private boolean isComment(IDOMNode node) {
- boolean result = false;
- if (node != null) {
- result = node.getNodeType() == Node.COMMENT_NODE;
- }
- return result;
- }
-
- private boolean noLineDelimiter(IDOMNode node) {
- boolean result = false;
- if (node != null) {
- result = !StringUtils.containsLineDelimiter(node.getNodeValue());
- }
- return result;
- }
-
- /**
- * Calculates if there is enough space on the current line for
- * compressedText (and for its parent end tag)
- *
- * @param parentNode
- * @param currentAvailableLineWidth
- * @param compressedText
- * @return
- */
- private boolean enoughSpace(IDOMNode parentNode, int currentAvailableLineWidth, String compressedText) {
- int parentEndTagLength = parentNode.getNodeName().length() + 3;
- return compressedText.length() <= (currentAvailableLineWidth - parentEndTagLength) && !StringUtils.containsLineDelimiter(compressedText);
- }
-
- protected Vector reflowText(String text, int availableWidth) {
- String[] stringArray = null;
- boolean clearAllBlankLines = getFormatPreferences().getClearAllBlankLines();
-
- if (clearAllBlankLines)
- stringArray = StringUtils.asArray(text);
- else
- stringArray = StringUtils.asArray(text, DELIMITERS, true);
-
- Vector output = new Vector();
- if ((stringArray != null) && (stringArray.length > 0)) {
- StringBuffer buffer = new StringBuffer();
- if (stringArray[0].compareTo(CR) != 0)
- buffer.append(stringArray[0]);
- int bufferLength = stringArray[0].toString().length();
- boolean cr = stringArray[0].compareTo(CR) == 0;
-
- for (int i = 1; i < stringArray.length; i++) {
- String eachString = stringArray[i];
- if ((eachString.compareTo(SPACE) != 0) && (eachString.compareTo(TAB) != 0) && (eachString.compareTo(FF) != 0)) {
- if ((bufferLength + 1 + eachString.length() > availableWidth) || (eachString.compareTo(CR) == 0) || (eachString.compareTo(LF) == 0)) {
- if ((eachString.compareTo(LF) == 0) && cr) {
- // do nothing
- }
- else {
- output.add(buffer.toString());
- buffer = new StringBuffer();
- bufferLength = 0;
- }
- cr = eachString.compareTo(CR) == 0;
- }
- else if (buffer.toString().trim().length() > 0) {
- buffer.append(SPACE);
- bufferLength++;
- }
- if ((eachString.compareTo(CR) != 0) && (eachString.compareTo(LF) != 0)) {
- buffer.append(eachString);
- bufferLength = bufferLength + eachString.length();
- }
- }
- }
- output.add(buffer.toString());
- }
- else
- output.add(text);
-
- return output;
- }
-
- private String getLineDelimiter(IStructuredDocument doc, int nodeOffset) {
- int line = doc.getLineOfOffset(nodeOffset);
- String lineDelimiter = doc.getLineDelimiter();
- try {
- if (line > 0) {
- lineDelimiter = doc.getLineDelimiter(line - 1);
- }
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- // BUG115716: if cannot get line delimiter from current line, just
- // use default line delimiter
- if (lineDelimiter == null)
- lineDelimiter = doc.getLineDelimiter();
- return lineDelimiter;
- }
-
- private int computeAvailableLineWidth(IStructuredDocument doc, int nodeOffset, int lineWidth) {
- // compute current available line width
- int currentAvailableLineWidth = 0;
- try {
- int lineOffset = doc.getLineInformationOfOffset(nodeOffset).getOffset();
- String text = doc.get(lineOffset, nodeOffset - lineOffset);
- int usedWidth = getIndentationLength(text);
- currentAvailableLineWidth = lineWidth - usedWidth;
- }
- catch (BadLocationException e) {
- // log for now, unless we find reason not to
- Logger.log(Logger.INFO, e.getMessage());
- }
- return currentAvailableLineWidth;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/text/IXMLPartitions.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/text/IXMLPartitions.java
deleted file mode 100644
index 5d36751dca..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/text/IXMLPartitions.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 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
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.provisional.text;
-
-
-
-/**
- * This interface is not intended to be implemented.
- * It defines the partition types for XML.
- * Clients should reference the partition type Strings defined here directly.
- *
- * @deprecated use org.eclipse.wst.xml.core.text
- */
-public interface IXMLPartitions {
-
- String XML_DEFAULT = "org.eclipse.wst.xml.XML_DEFAULT"; //$NON-NLS-1$
- String XML_CDATA = "org.eclipse.wst.xml.XML_CDATA"; //$NON-NLS-1$
- String XML_PI = "org.eclipse.wst.xml.XML_PI"; //$NON-NLS-1$
- String XML_DECLARATION = "org.eclipse.wst.xml.XML_DECL"; //$NON-NLS-1$
- String XML_COMMENT = "org.eclipse.wst.xml.XML_COMMENT"; //$NON-NLS-1$
-
- /*
- * This value is used as a prefix to any unknown processing instructions
- * we find. The processor target name is converted to uppercase and
- * appended to the prefix to create a unique partition type.
- */
- String PROCESSING_INSTRUCTION_PREFIX = "org.eclipse.wst.xml.PROCESSING_INSTRUCTION:"; //$NON-NLS-1$
-
- /**
- * Should match
- * org.eclipse.wst.sse.core.dtd.partitioning.StructuredTextPartitionerForDTD.ST_DTD_SUBSET
- */
- String DTD_SUBSET = "org.eclipse.wst.xml.dtd.internal_subset"; //$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/regions/DOMRegionContext.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/regions/DOMRegionContext.java
deleted file mode 100644
index 4a73d8d431..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/regions/DOMRegionContext.java
+++ /dev/null
@@ -1,69 +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.regions;
-
-public interface DOMRegionContext {
-
- public static final String BLOCK_TEXT = "BLOCK_TEXT"; //$NON-NLS-1$
-
- public static final String UNDEFINED = "UNDEFINED"; //$NON-NLS-1$
-
- public static final String WHITE_SPACE = "WHITE_SPACE"; //$NON-NLS-1$
- public static final String XML_ATTLIST_DECL_CLOSE = "XML_ATTLIST_DECL_CLOSE"; //$NON-NLS-1$
- public static final String XML_ATTLIST_DECL_CONTENT = "XML_ATTLIST_DECL_CONTENT"; //$NON-NLS-1$
- public static final String XML_ATTLIST_DECL_NAME = "XML_ATTLIST_DECL_NAME"; //$NON-NLS-1$
-
- public static final String XML_ATTLIST_DECLARATION = "XML_ATTLIST_DECLARATION"; //$NON-NLS-1$
- public static final String XML_CDATA_CLOSE = "XML_CDATA_CLOSE"; //$NON-NLS-1$
- public static final String XML_CDATA_OPEN = "XML_CDATA_OPEN"; //$NON-NLS-1$
- public static final String XML_CDATA_TEXT = "XML_CDATA_TEXT"; //$NON-NLS-1$
- public static final String XML_CHAR_REFERENCE = "XML_CHAR_REFERENCE"; //$NON-NLS-1$
- public static final String XML_COMMENT_CLOSE = "XML_COMMENT_CLOSE"; //$NON-NLS-1$
-
- public static final String XML_COMMENT_OPEN = "XML_COMMENT_OPEN"; //$NON-NLS-1$
- public static final String XML_COMMENT_TEXT = "XML_COMMENT_TEXT"; //$NON-NLS-1$
-
- public static final String XML_CONTENT = "XML_CONTENT"; //$NON-NLS-1$
- public static final String XML_DECLARATION_CLOSE = "XML_DECLARATION_CLOSE"; //$NON-NLS-1$
-
- public static final String XML_DECLARATION_OPEN = "XML_DECLARATION_OPEN"; //$NON-NLS-1$
-
- public static final String XML_DOCTYPE_DECLARATION = "XML_DOCTYPE_DECLARATION"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_DECLARATION_CLOSE = "XML_DOCTYPE_DECLARATION_CLOSE"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_EXTERNAL_ID_PUBLIC = "XML_DOCTYPE_EXTERNAL_ID_PUBLIC"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_EXTERNAL_ID_PUBREF = "XML_DOCTYPE_EXTERNAL_ID_PUBREF"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_EXTERNAL_ID_SYSREF = "XML_DOCTYPE_EXTERNAL_ID_SYSREF"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_EXTERNAL_ID_SYSTEM = "XML_DOCTYPE_EXTERNAL_ID_SYSTEM"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_INTERNAL_SUBSET = "XML_DOCTYPE_INTERNAL_SUBSET"; //$NON-NLS-1$
- public static final String XML_DOCTYPE_NAME = "XML_DOCTYPE_NAME"; //$NON-NLS-1$
- public static final String XML_ELEMENT_DECL_CLOSE = "XML_ELEMENT_DECL_CLOSE"; //$NON-NLS-1$
- public static final String XML_ELEMENT_DECL_CONTENT = "XML_ELEMENT_DECL_CONTENT"; //$NON-NLS-1$
- public static final String XML_ELEMENT_DECL_NAME = "XML_ELEMENT_DECL_NAME"; //$NON-NLS-1$
-
- public static final String XML_ELEMENT_DECLARATION = "XML_ELEMENT_DECLARATION"; //$NON-NLS-1$
- public static final String XML_EMPTY_TAG_CLOSE = "XML_EMPTY_TAG_CLOSE"; //$NON-NLS-1$
- public static final String XML_END_TAG_OPEN = "XML_END_TAG_OPEN"; //$NON-NLS-1$
- public static final String XML_ENTITY_REFERENCE = "XML_ENTITY_REFERENCE"; //$NON-NLS-1$
-
- public static final String XML_PE_REFERENCE = "XML_PE_REFERENCE"; //$NON-NLS-1$
- public static final String XML_PI_CLOSE = "XML_PI_CLOSE"; //$NON-NLS-1$
- public static final String XML_PI_CONTENT = "XML_PI_CONTENT"; //$NON-NLS-1$
- public static final String XML_PI_OPEN = "XML_PI_OPEN"; //$NON-NLS-1$
- public static final String XML_TAG_ATTRIBUTE_EQUALS = "XML_TAG_ATTRIBUTE_EQUALS"; //$NON-NLS-1$
- public static final String XML_TAG_ATTRIBUTE_NAME = "XML_TAG_ATTRIBUTE_NAME"; //$NON-NLS-1$
- public static final String XML_TAG_ATTRIBUTE_VALUE = "XML_TAG_ATTRIBUTE_VALUE"; //$NON-NLS-1$
- public static final String XML_TAG_CLOSE = "XML_TAG_CLOSE"; //$NON-NLS-1$
- public static final String XML_TAG_NAME = "XML_TAG_NAME"; //$NON-NLS-1$
-
- public static final String XML_TAG_OPEN = "XML_TAG_OPEN"; //$NON-NLS-1$
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapter.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapter.java
deleted file mode 100644
index 74ad2a1a4a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapter.java
+++ /dev/null
@@ -1,31 +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.ssemodelquery;
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-
-public interface ModelQueryAdapter extends INodeAdapter {
-
- public CMDocumentCache getCMDocumentCache();
-
- public URIResolver getIdResolver();
-
- public ModelQuery getModelQuery();
-
- void release();
-
- void setIdResolver(URIResolver newIdResolver);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapterImpl.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapterImpl.java
deleted file mode 100644
index a68e672920..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/ModelQueryAdapterImpl.java
+++ /dev/null
@@ -1,76 +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.ssemodelquery;
-
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-
-
-public class ModelQueryAdapterImpl implements ModelQueryAdapter {
- protected CMDocumentCache cmDocumentCache;
- protected URIResolver idResolver;
-
- protected ModelQuery modelQuery;
-
- public ModelQueryAdapterImpl(CMDocumentCache cmDocumentCache, ModelQuery modelQuery, URIResolver idResolver) {
- this.cmDocumentCache = cmDocumentCache;
- this.modelQuery = modelQuery;
- this.idResolver = idResolver;
- }
-
- public CMDocumentCache getCMDocumentCache() {
- return cmDocumentCache;
- }
-
- public URIResolver getIdResolver() {
- return idResolver;
- }
-
- public ModelQuery getModelQuery() {
- return modelQuery;
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type allows it
- * to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return type.equals(ModelQueryAdapter.class);
- }
-
- /**
- */
-
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- }
-
- /**
- * @see ModelQueryAdapter#release()
- */
- public void release() {
- }
-
- /**
- * @see ModelQueryAdapter#setIdResolver(URIResolver)
- */
-
- public void setIdResolver(URIResolver newIdResolver) {
- idResolver = newIdResolver;
- if (modelQuery instanceof MovableModelQuery)
- ((MovableModelQuery) modelQuery).setIdResolver(newIdResolver);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/MovableModelQuery.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/MovableModelQuery.java
deleted file mode 100644
index 49d733960f..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/ssemodelquery/MovableModelQuery.java
+++ /dev/null
@@ -1,23 +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.ssemodelquery;
-
-
-
-import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-
-public interface MovableModelQuery extends ModelQuery {
-
- void setIdResolver(URIResolver newURIResolver);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/tasks/XMLFileTaskScanner.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/tasks/XMLFileTaskScanner.java
deleted file mode 100644
index 94b81555bc..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/tasks/XMLFileTaskScanner.java
+++ /dev/null
@@ -1,28 +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.tasks;
-
-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.tasks.StructuredFileTaskScanner;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-public class XMLFileTaskScanner extends StructuredFileTaskScanner {
- public XMLFileTaskScanner() {
- super();
- }
-
- protected boolean isCommentRegion(IStructuredDocumentRegion region, ITextRegion textRegion) {
- return textRegion.getType().equals(DOMRegionContext.XML_COMMENT_TEXT);
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/XMLStructuredDocumentRegion.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/XMLStructuredDocumentRegion.java
deleted file mode 100644
index e26bf08551..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/XMLStructuredDocumentRegion.java
+++ /dev/null
@@ -1,36 +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.text;
-
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-
-
-public class XMLStructuredDocumentRegion extends BasicStructuredDocumentRegion implements IStructuredDocumentRegion {
-
- public XMLStructuredDocumentRegion() {
- super();
- }
-
- public String getType() {
- String result = super.getType();
- // normally, we want the second region as the flatnode type ... since
- // the
- // first one is usually just "open tag".
- if ((result != DOMRegionContext.XML_PI_OPEN) && (getRegions().size() > 1)) {
- result = getRegions().get(1).getType();
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/rules/StructuredTextPartitionerForXML.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/rules/StructuredTextPartitionerForXML.java
deleted file mode 100644
index 8b73869003..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/text/rules/StructuredTextPartitionerForXML.java
+++ /dev/null
@@ -1,132 +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
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.text.rules;
-
-import java.util.Locale;
-
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.wst.sse.core.internal.parser.ForeignRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner;
-import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
-import org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner;
-import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
-import org.eclipse.wst.xml.core.text.IXMLPartitions;
-
-public class StructuredTextPartitionerForXML extends StructuredTextPartitioner implements IStructuredTextPartitioner {
-
- private final static String[] configuredContentTypes = new String[]{IXMLPartitions.XML_DEFAULT, IXMLPartitions.XML_CDATA, IXMLPartitions.XML_PI, IXMLPartitions.XML_DECLARATION, IXMLPartitions.XML_COMMENT, IXMLPartitions.DTD_SUBSET};
-
- public StructuredTextPartitionerForXML() {
- super();
- }
-
- protected void setInternalPartition(int offset, int length, String type) {
- super.setInternalPartition(offset, length, type);
- }
-
- protected void initLegalContentTypes() {
- fSupportedTypes = configuredContentTypes;
- }
-
- public String getPartitionType(ITextRegion region, int offset) {
- String result = null;
- if (region.getType() == DOMRegionContext.XML_COMMENT_TEXT)
- result = IXMLPartitions.XML_COMMENT;
- else if (region.getType() == DOMRegionContext.XML_CDATA_TEXT)
- result = IXMLPartitions.XML_CDATA;
- else if (region.getType() == DOMRegionContext.XML_PI_CONTENT) {
- /**
- * Grammatically, it's impossible to get a PI_CONTENT region
- * without a preceding XML_TAG_NAME region. Relying on this,
- * extract the target processor name and create a partition type
- * dynamically.
- */
- IStructuredDocumentRegion docRegion = fStructuredDocument.getRegionAtCharacterOffset(offset);
- ITextRegion name = docRegion.getRegionAtCharacterOffset(docRegion.getStartOffset() + region.getStart() - 1);
- result = IXMLPartitions.PROCESSING_INSTRUCTION_PREFIX + docRegion.getText(name).toUpperCase(Locale.ENGLISH);
- }
- else if (region.getType() == DOMRegionContext.XML_PI_OPEN)
- result = IXMLPartitions.XML_PI;
- else if (region.getType() == DOMRegionContext.XML_DOCTYPE_DECLARATION)
- result = IXMLPartitions.XML_DECLARATION;
- else if (region.getType() == DOMRegionContext.XML_DOCTYPE_INTERNAL_SUBSET)
- result = IXMLPartitions.DTD_SUBSET;
- else
- result = super.getPartitionType(region, offset);
- return result;
- }
-
- protected String getPartitionType(ForeignRegion region, int offset) {
- // temp added just to dis-ambiguate call from subclass
- return super.getPartitionType(region, offset);
- }
-
- public String getPartitionTypeBetween(IStructuredDocumentRegion previousNode, IStructuredDocumentRegion nextNode) {
- return super.getPartitionTypeBetween(previousNode, nextNode);
- }
-
- public String getDefaultPartitionType() {
- return IXMLPartitions.XML_DEFAULT;
- }
-
- public IDocumentPartitioner newInstance() {
- StructuredTextPartitionerForXML instance = new StructuredTextPartitionerForXML();
- return instance;
- }
-
- /**
- * @return
- */
- public static String[] getConfiguredContentTypes() {
- return configuredContentTypes;
- }
-
- protected String getPartitionFromBlockedText(ITextRegion region, int offset, String result) {
- // was moved to subclass for quick transition
- String newResult = result;
- // nsd_TODO: David and I need to discuss, design, and implement this
- // for all block tags and comments
- // and make sure is part of "extensible" design of block tags
- if (region.getType() == DOMRegionContext.BLOCK_TEXT) {
- // for code safety, we'll always check instanceof, but I think
- // always true.
- if (region instanceof ForeignRegion) {
- // super is used below so won't be ambiguous
- newResult = getPartitionType((ForeignRegion) region, offset);
- }
- else if (region instanceof ForeignRegion) {
- newResult = getPartitionType((ForeignRegion) region, offset);
- }
- else {
- newResult = getUnknown();
- }
- }
- return newResult;
- }
-
- protected boolean doParserSpecificCheck(int offset, boolean partitionFound, IStructuredDocumentRegion sdRegion, IStructuredDocumentRegion previousStructuredDocumentRegion, ITextRegion next, ITextRegion previousStart) {
- // this was moved down to subclass of StructuredTextPartioner
- // for quick fix to transition problems. Heirarchy needs lots of
- // cleanup.
- if (previousStart != null && previousStart.getType() == DOMRegionContext.XML_TAG_OPEN && next.getType() == DOMRegionContext.XML_END_TAG_OPEN) {
- ITextRegion previousName = previousStructuredDocumentRegion.getRegionAtCharacterOffset(previousStructuredDocumentRegion.getEndOffset(previousStart));
- ITextRegion nextName = sdRegion.getRegionAtCharacterOffset(sdRegion.getEndOffset(next));
- if (previousName != null && nextName != null && previousName.getType() == DOMRegionContext.XML_TAG_NAME && nextName.getType() == DOMRegionContext.XML_TAG_NAME) {
- setInternalPartition(offset, 0, getPartitionTypeBetween(previousStructuredDocumentRegion, sdRegion));
- partitionFound = true;
- }
- }
- return partitionFound;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/AbstractPropagatingValidator.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/AbstractPropagatingValidator.java
deleted file mode 100644
index 3fddda363a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/AbstractPropagatingValidator.java
+++ /dev/null
@@ -1,66 +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.validate;
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter;
-import org.w3c.dom.Node;
-
-
-public abstract class AbstractPropagatingValidator extends ValidationComponent {
-
- /**
- * Constructor for AbstractPropagatingValidator.
- */
- public AbstractPropagatingValidator() {
- super();
- }
-
- protected abstract ValidationComponent getPropagatee();
-
- protected abstract ValidationAdapter getValidator();
-
-
- public void validate(IndexedRegion node) {
- if (node == null)
- return;
- getValidator().validate(node);
-
- propagateToChildElements(getPropagatee(), (Node) node);
- }
-
- private void propagateToChildElements(ValidationComponent validator, Node parent) {
- if (parent == null)
- return;
- Class clazz = validator.getClass();
-
- Node child = parent.getFirstChild();
- while (child != null) {
- if (child.getNodeType() == Node.ELEMENT_NODE) {
- INodeNotifier notifier = (INodeNotifier) child;
- ValidationAdapter va = (ValidationAdapter) notifier.getExistingAdapter(clazz);
- if (va == null) {
- notifier.addAdapter(validator);
- va = validator;
- }
- // bug 143213 - Can't batch validate open HTML files when
- // as-you-type validation is enabled
- va.setReporter(validator.getReporter());
- va.validate((IndexedRegion) child);
- }
- child = child.getNextSibling();
- }
- }
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/Propagator.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/Propagator.java
deleted file mode 100644
index 3ce6569ccd..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/Propagator.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.validate;
-
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @deprecated since 2.0 M5 - if propogateToChildElement is needed, just copy
- * method to your own class
- */
-public class Propagator {
-
- public static void propagateToChildElements(ValidationComponent validator, Node parent) {
- if (parent == null)
- return;
- Class clazz = validator.getClass();
-
- NodeList children = parent.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- if (child == null || child.getNodeType() != Node.ELEMENT_NODE)
- continue;
-
- INodeNotifier notifier = (INodeNotifier) child;
- ValidationAdapter va = (ValidationAdapter) notifier.getExistingAdapter(clazz);
- if (va == null) {
- notifier.addAdapter(validator);
- va = validator;
- }
- va.validate((IndexedRegion) child);
- }
- }
-
- /**
- * Propagator is just a placeholder of utilities. Don't instantiate.
- */
- private Propagator() {
- super();
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/ValidationComponent.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/ValidationComponent.java
deleted file mode 100644
index dfd921f58c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/validate/ValidationComponent.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 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.validate;
-
-
-
-import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter;
-import org.eclipse.wst.sse.core.internal.validate.ValidationReporter;
-
-public abstract class ValidationComponent implements ValidationAdapter {
-
- protected ValidationReporter reporter = null;
-
- /**
- * ValidationComponent constructor comment.
- */
- public ValidationComponent() {
- super();
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type allows it
- * to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return (type == ValidationAdapter.class);
- }
-
- /**
- */
- public void notifyChanged(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- // This method will be implemented in the V2.
- }
-
- /**
- */
- public void setReporter(ValidationReporter reporter) {
- this.reporter = reporter;
- }
-
- ValidationReporter getReporter() {
- return this.reporter;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/text/IXMLPartitions.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/text/IXMLPartitions.java
deleted file mode 100644
index d8da7868a3..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/text/IXMLPartitions.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 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
- *******************************************************************************/
-package org.eclipse.wst.xml.core.text;
-
-
-
-/**
- * This interface is not intended to be implemented.
- * It defines the partition types for XML.
- * Clients should reference the partition type Strings defined here directly.
- *
- * @since 1.1
- */
-public interface IXMLPartitions {
-
- String XML_DEFAULT = "org.eclipse.wst.xml.XML_DEFAULT"; //$NON-NLS-1$
- String XML_CDATA = "org.eclipse.wst.xml.XML_CDATA"; //$NON-NLS-1$
- String XML_PI = "org.eclipse.wst.xml.XML_PI"; //$NON-NLS-1$
- String XML_DECLARATION = "org.eclipse.wst.xml.XML_DECL"; //$NON-NLS-1$
- String XML_COMMENT = "org.eclipse.wst.xml.XML_COMMENT"; //$NON-NLS-1$
-
- /*
- * This value is used as a prefix to any unknown processing instructions
- * we find. The processor target name is converted to uppercase and
- * appended to the prefix to create a unique partition type.
- */
- String PROCESSING_INSTRUCTION_PREFIX = "org.eclipse.wst.xml.PROCESSING_INSTRUCTION:"; //$NON-NLS-1$
-
- /**
- * Should match
- * org.eclipse.wst.sse.core.dtd.partitioning.StructuredTextPartitionerForDTD.ST_DTD_SUBSET
- */
- String DTD_SUBSET = "org.eclipse.wst.xml.dtd.internal_subset"; //$NON-NLS-1$
-}

Back to the top