diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional')
29 files changed, 0 insertions, 3680 deletions
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 = "&";//$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 = "'";//$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 = ">";//$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 = "<";//$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 = """;//$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 8cb2260a43..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/IXMLNamespace.java +++ /dev/null @@ -1,26 +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 - * - *******************************************************************************/ -package org.eclipse.wst.xml.core.internal.provisional; - - - -/** - * XML Namespace constants - * - * @plannedfor 1.0 - */ -public interface IXMLNamespace { - - static final String XMLNS = "xmlns";//$NON-NLS-1$ - static final String XMLNS_PREFIX = "xmlns:";//$NON-NLS-1$ - static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";//$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 7a3d95fe68..0000000000 --- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/provisional/contentmodel/CMDocType.java +++ /dev/null @@ -1,41 +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.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$ - /** - * 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$ -} 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 (<%-- ... - * --%>) - * @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. < 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, "&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, - * "&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 f30ed3a16c..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 - * - *******************************************************************************/ -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 = new 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 beed8f4d49..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 = new 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$ -} |