Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util')
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java140
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java203
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java33
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java135
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java171
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java53
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java602
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java198
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java225
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java133
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java411
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java30
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java110
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java83
-rw-r--r--bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java253
15 files changed, 0 insertions, 2780 deletions
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java
deleted file mode 100644
index a82ab1c9be..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDescriptionBuilder.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contentmodel.util;
-
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-
-public class CMDescriptionBuilder extends CMVisitor
-{
- protected StringBuffer sb;
- protected CMNode root;
- protected boolean isRootVisited;
- public String buildDescription(CMNode node)
- {
- sb = new StringBuffer();
- root = node;
- isRootVisited = false;
- visitCMNode(node);
- return sb.toString();
- }
-
- public void visitCMAnyElement(CMAnyElement anyElement)
- {
- sb.append("namespace:uri=\"" + anyElement.getNamespaceURI() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void visitCMDataType(CMDataType dataType)
- {
- sb.append("#PCDATA"); //$NON-NLS-1$
- }
-
- public void visitCMDocument(CMDocument document)
- {
- CMNamedNodeMap map = document.getElements();
- int size = map.getLength();
- for (int i = 0; i < size; i++)
- {
- visitCMNode(map.item(i));
- }
- }
-
- public void visitCMGroup(CMGroup group)
- {
- int op = group.getOperator();
- if (op == CMGroup.ALL)
- {
- sb.append("all"); //$NON-NLS-1$
- }
-
- sb.append("("); //$NON-NLS-1$
-
- String separator = ", "; //$NON-NLS-1$
-
- if (op == CMGroup.CHOICE)
- {
- separator = " | "; //$NON-NLS-1$
- }
-
-
- CMNodeList nodeList = group.getChildNodes();
- int size = nodeList.getLength();
- for (int i = 0; i < size; i++)
- {
- visitCMNode(nodeList.item(i));
- if (i < size - 1)
- {
- sb.append(separator);
- }
- }
-
- sb.append(")"); //$NON-NLS-1$
- addOccurenceSymbol(group);
- }
-
- public void visitCMElementDeclaration(CMElementDeclaration ed)
- {
- if (ed == root && !isRootVisited)
- {
- isRootVisited = true;
- CMContent content = ed.getContent();
- if (content != null)
- {
- if (content.getNodeType() != CMNode.GROUP)
- {
- sb.append("("); //$NON-NLS-1$
- visitCMNode(content);
- sb.append(")"); //$NON-NLS-1$
- }
- else
- {
- visitCMNode(content);
- }
- }
- }
- else
- {
- sb.append(ed.getElementName());
- addOccurenceSymbol(ed);
- }
- }
-
- public void addOccurenceSymbol(CMContent content)
- {
- int min = content.getMinOccur();
- int max = content.getMaxOccur();
- if (min == 0)
- {
- if (max > 1 || max == -1)
- {
- sb.append("*"); //$NON-NLS-1$
- }
- else
- {
- sb.append("?"); //$NON-NLS-1$
- }
- }
- else if (max > 1 || max == -1)
- {
- sb.append("+"); //$NON-NLS-1$
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java
deleted file mode 100644
index 670ff531b4..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCache.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-
-
-
-/**
- *
- */
-public class CMDocumentCache
-{
- public static final int STATUS_NOT_LOADED = 0;
- public static final int STATUS_LOADING = 2;
- public static final int STATUS_LOADED = 3;
- public static final int STATUS_ERROR = 4;
-
- protected class Entry
- {
- public String uri;
- public int status = STATUS_NOT_LOADED;
- public float progress;
- public CMDocument cmDocument;
-
- public Entry(String uri)
- {
- this.uri = uri;
- }
-
- public Entry(String uri, int status, CMDocument cmDocument)
- {
- this.uri = uri;
- this.status = status;
- this.cmDocument = cmDocument;
- }
- }
-
- protected Hashtable hashtable;
- protected List listenerList = new Vector();
-
-
- /**
- * temporarily public until caching problem is solved
- */
- public CMDocumentCache()
- {
- hashtable = new Hashtable();
- }
-
- public void addListener(CMDocumentCacheListener listener)
- {
- listenerList.add(listener);
- }
-
- public void removeListener(CMDocumentCacheListener listener)
- {
- listenerList.remove(listener);
- }
-
- /**
- *
- */
- public CMDocument getCMDocument(String grammarURI)
- {
- CMDocument result = null;
- if (grammarURI != null)
- {
- Entry entry = (Entry)hashtable.get(grammarURI);
- if (entry != null)
- {
- result = entry.cmDocument;
- }
- }
- return result;
- }
-
- /**
- *
- */
- public int getStatus(String grammarURI)
- {
- int result = STATUS_NOT_LOADED;
- if (grammarURI != null)
- {
- Entry entry = (Entry)hashtable.get(grammarURI);
- if (entry != null)
- {
- result = entry.status;
- }
-
- }
- return result;
- }
-
- /**
- *
- */
- protected Entry lookupOrCreate(String grammarURI)
- {
- Entry entry = (Entry)hashtable.get(grammarURI);
- if (entry == null)
- {
- entry = new Entry(grammarURI);
- hashtable.put(grammarURI, entry);
- }
- return entry;
- }
-
-
- /**
- *
- */
- public void putCMDocument(String grammarURI, CMDocument cmDocument)
- {
- if (grammarURI != null && cmDocument != null)
- {
- Entry entry = lookupOrCreate(grammarURI);
- int oldStatus = entry.status;
- entry.status = STATUS_LOADED;
- entry.cmDocument = cmDocument;
- notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument);
- }
- }
-
- /**
- *
- */
- public void setStatus(String grammarURI, int status)
- {
- if (grammarURI != null)
- {
- Entry entry = lookupOrCreate(grammarURI);
- int oldStatus = entry.status;
- entry.status = status;
- notifyCacheUpdated(grammarURI, oldStatus, entry.status, entry.cmDocument);
- }
- }
-
- /**
- *
- */
- public void clear()
- {
- hashtable.clear();
- notifyCacheCleared();
- }
-
- /**
- *
- */
- protected void notifyCacheUpdated(String uri, int oldStatus, int newStatus, CMDocument cmDocument)
- {
- List list = new Vector();
- list.addAll(listenerList);
- for (Iterator i = list.iterator(); i.hasNext(); )
- {
- CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next();
- listener.cacheUpdated(this, uri, oldStatus, newStatus, cmDocument);
- }
- }
-
- /**
- *
- */
- protected void notifyCacheCleared()
- {
- List list = new Vector();
- list.addAll(listenerList);
- for (Iterator i = list.iterator(); i.hasNext(); )
- {
- CMDocumentCacheListener listener = (CMDocumentCacheListener)i.next();
- listener.cacheCleared(this);
- }
- }
-
- public List getCMDocuments()
- {
- List list = new ArrayList();
- for (Iterator i = hashtable.values().iterator(); i.hasNext(); )
- {
- Entry entry = (Entry)i.next();
- list.add(entry.cmDocument);
- }
- return list;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java
deleted file mode 100644
index d9f6dcdece..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMDocumentCacheListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-
-
-/**
- * todo... add more interface methods
- */
-public interface CMDocumentCacheListener
-{
- /** Tells the client that the cache has been cleared.
- * This gives clients an opportunity to flush any state that depends on the CMDocument
- * since this CMDocument will be recomputed on a subsequent 'lookup' request
- */
- public void cacheCleared(CMDocumentCache cache);
-
- /**
- * Tells the client that the cache has been updated.
- */
- public void cacheUpdated(CMDocumentCache cache, String uri, int oldStatus, int newStatus, CMDocument cmDocument);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java
deleted file mode 100644
index 89bb9d6a9a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/CMVisitor.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contentmodel.util;
-
-import java.util.Stack;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-
-public class CMVisitor
-{
- protected int indent = 0;
- protected Stack visitedCMGroupStack = new Stack();
-
- public void visitCMNode(CMNode node)
- {
- if (node != null)
- {
- //ContentModelManager.printlnIndented("visitCMNode : " + node.getNodeName() + " " + node);
- indent += 2;
- int nodeType = node.getNodeType();
- switch (nodeType)
- {
- case CMNode.ANY_ELEMENT :
- {
- visitCMAnyElement((CMAnyElement)node);
- break;
- }
- case CMNode.ATTRIBUTE_DECLARATION :
- {
- visitCMAttributeDeclaration((CMAttributeDeclaration)node);
- break;
- }
- case CMNode.DATA_TYPE :
- {
- visitCMDataType((CMDataType)node);
- break;
- }
- case CMNode.DOCUMENT :
- {
- visitCMDocument((CMDocument)node);
- break;
- }
- case CMNode.ELEMENT_DECLARATION :
- {
- visitCMElementDeclaration((CMElementDeclaration)node);
- break;
- }
- case CMNode.GROUP :
- {
- CMGroup group = (CMGroup)node;
-
- // This is to prevent recursion.
- if (visitedCMGroupStack.contains(group))
- {
- break;
- }
-
- // Push the current group to check later to avoid potential recursion
- visitedCMGroupStack.push(group);
-
- visitCMGroup(group);
-
- // Pop the current group
- visitedCMGroupStack.pop();
- break;
- }
- }
- indent -= 2;
- }
- }
-
- public void visitCMAnyElement(CMAnyElement anyElement)
- {
- }
-
- public void visitCMAttributeDeclaration(CMAttributeDeclaration ad)
- {
- }
-
- public void visitCMDataType(CMDataType dataType)
- {
- }
-
- public void visitCMDocument(CMDocument document)
- {
- CMNamedNodeMap map = document.getElements();
- int size = map.getLength();
- for (int i = 0; i < size; i++)
- {
- visitCMNode(map.item(i));
- }
- }
-
- public void visitCMGroup(CMGroup group)
- {
- CMNodeList nodeList = group.getChildNodes();
- int size = nodeList.getLength();
- for (int i = 0; i < size; i++)
- {
- visitCMNode(nodeList.item(i));
- }
- }
-
- public void visitCMElementDeclaration(CMElementDeclaration ed)
- {
- CMNamedNodeMap nodeMap = ed.getAttributes();
- int size = nodeMap.getLength();
- for (int i = 0; i < size; i++)
- {
- visitCMNode(nodeMap.item(i));
- }
-
- visitCMNode(ed.getContent());
-
- visitCMDataType(ed.getDataType());
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java
deleted file mode 100644
index 14d02b1879..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/ContentBuilder.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.Vector;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-
-
-/**
- * This class lets you traverse a 'CM' model providing callbacks to build content.
- */
-public class ContentBuilder extends CMVisitor
-{
- public static final int BUILD_ALL_CONTENT = 1;
- public static final int BUILD_ONLY_REQUIRED_CONTENT = 2;
- protected int buildPolicy = BUILD_ALL_CONTENT;
-
- protected boolean alwaysVisit;
- protected Vector visitedCMElementDeclarationList = new Vector();
-
- public ContentBuilder()
- {
- }
-
- public void setBuildPolicy(int buildPolicy)
- {
- this.buildPolicy = buildPolicy;
- }
-
- public int getBuildPolicy()
- {
- return buildPolicy;
- }
-
- protected void createAnyElementNode(CMAnyElement anyElement)
- {
- }
-
- protected void createElementNodeStart(CMElementDeclaration ed)
- {
- }
-
- protected void createElementNodeEnd(CMElementDeclaration ed)
- {
- }
-
- protected void createTextNode(CMDataType dataType)
- {
- }
-
- protected void createAttributeNode(CMAttributeDeclaration attribute)
- {
- }
-
- public void visitCMElementDeclaration(CMElementDeclaration ed)
- {
- int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
- int min = Math.max(ed.getMinOccur(), forcedMin);
- alwaysVisit = false;
-
- if (min > 0 && !visitedCMElementDeclarationList.contains(ed))
- {
- visitedCMElementDeclarationList.add(ed);
- for (int i = 1; i <= min; i++)
- {
- createElementNodeStart(ed);
-
- // instead of calling super.visitCMElementDeclaration()
- // we duplicate the code with some minor modifications
- CMNamedNodeMap nodeMap = ed.getAttributes();
- int size = nodeMap.getLength();
- for (int j = 0; j < size; j++)
- {
- visitCMNode(nodeMap.item(j));
- }
-
- CMContent content = ed.getContent();
- if (content != null)
- {
- visitCMNode(content);
- }
-
- if (ed.getContentType() == CMElementDeclaration.PCDATA)
- {
- CMDataType dataType = ed.getDataType();
- if (dataType != null)
- {
- visitCMDataType(dataType);
- }
- }
- // end duplication
- createElementNodeEnd(ed);
- }
- int size = visitedCMElementDeclarationList.size();
- visitedCMElementDeclarationList.remove(size - 1);
- }
- }
-
-
- public void visitCMDataType(CMDataType dataType)
- {
- createTextNode(dataType);
- }
-
-
- public void visitCMGroup(CMGroup e)
- {
- int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
- int min = Math.max(e.getMinOccur(), forcedMin);
- alwaysVisit = false;
-
- for (int i = 1; i <= min; i++)
- {
- if (e.getOperator() == CMGroup.CHOICE)
- {
- // add only 1 element from the group
- // todo... perhaps add something other than the first one
- CMNodeList nodeList = e.getChildNodes();
- if (nodeList.getLength() > 0)
- {
- visitCMNode(nodeList.item(0));
- }
- }
- else // SEQUENCE, ALL
- {
- // visit all of the content
- super.visitCMGroup(e);
- }
- }
- }
-
- public void visitCMAttributeDeclaration(CMAttributeDeclaration ad)
- {
- if (alwaysVisit ||
- buildPolicy == BUILD_ALL_CONTENT ||
- ad.getUsage() == CMAttributeDeclaration.REQUIRED)
- {
- createAttributeNode(ad);
- }
- }
-
-
- public void visitCMAnyElement(CMAnyElement anyElement)
- {
- int forcedMin = (buildPolicy == BUILD_ALL_CONTENT || alwaysVisit) ? 1 : 0;
- alwaysVisit = false;
- int min = Math.max(anyElement.getMinOccur(), forcedMin);
- for (int i = 1; i <= min; i++)
- {
- createAnyElementNode(anyElement);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java
deleted file mode 100644
index 9d23576155..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.List;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.w3c.dom.Node;
-
-
-public interface DOMContentBuilder
-{
- public static final int BUILD_OPTIONAL_ATTRIBUTES = 1;
- public static final int BUILD_OPTIONAL_ELEMENTS = 1<<1;
- public static final int BUILD_FIRST_CHOICE = 1<<2;
- public static final int BUILD_TEXT_NODES = 1<<3;
- public static final int BUILD_FIRST_SUBSTITUTION = 1<<4;
-
- public static final int
- BUILD_ONLY_REQUIRED_CONTENT =
- BUILD_FIRST_CHOICE
- | BUILD_TEXT_NODES;
- public static final int
- BUILD_ALL_CONTENT =
- BUILD_OPTIONAL_ATTRIBUTES
- | BUILD_OPTIONAL_ELEMENTS
- | BUILD_FIRST_CHOICE
- | BUILD_TEXT_NODES;
-
- public static final String PROPERTY_BUILD_BLANK_TEXT_NODES = "buildBlankTextNodes"; //$NON-NLS-1$
-
- public void setBuildPolicy(int buildPolicy);
- public int getBuildPolicy();
- public void setProperty(String propertyName, Object value);
- public Object getProperty(String propertyName);
- public List getResult();
- public void build(Node parent, CMNode child);
- public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration) throws Exception;
- public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration, List namespaceInfoList) throws Exception;
- public void createDefaultContent(Node parent, CMElementDeclaration ed) throws Exception;
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java
deleted file mode 100644
index 532a484304..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMContentBuilderImpl.java
+++ /dev/null
@@ -1,602 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Stack;
-import java.util.Vector;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMContent;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMGroup;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList;
-import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager;
-import org.eclipse.wst.xml.core.internal.contentmodel.internal.util.CMDataTypeValueHelper;
-import org.w3c.dom.Attr;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-
-/**
- * todo... common up this code with 'ContentBuilder'
- */
-public class DOMContentBuilderImpl extends CMVisitor implements DOMContentBuilder {
- protected int buildPolicy = BUILD_ALL_CONTENT;
- protected Hashtable propertyTable = new Hashtable();
-
- protected boolean alwaysVisit = false;
- protected List resultList;
- protected Document document;
- protected Node currentParent;
- protected Node topParent;
- protected Vector visitedCMElementDeclarationList = new Vector();
- protected boolean attachNodesToParent = true;
- protected NamespaceTable namespaceTable;
-
- protected List namespaceInfoList;
- protected Element rootElement; // this is used only teporarily via
- // createDefaultRootContent
- protected ExternalCMDocumentSupport externalCMDocumentSupport;
-
- public boolean supressCreationOfDoctypeAndXMLDeclaration;
-
- protected CMDataTypeValueHelper valueHelper = new CMDataTypeValueHelper();
-
- protected int numOfRepeatableElements = 1;
- protected Stack cmGroupStack = new Stack();
-
- public interface ExternalCMDocumentSupport {
- public CMDocument getCMDocument(Element element, String uri);
- }
-
- public void setExternalCMDocumentSupport(ExternalCMDocumentSupport externalCMDocumentSupport) {
- this.externalCMDocumentSupport = externalCMDocumentSupport;
- }
-
- public DOMContentBuilderImpl(Document document) {
- this.document = document;
- namespaceTable = new NamespaceTable(document);
- }
-
- public void setBuildPolicy(int buildPolicy) {
- this.buildPolicy = buildPolicy;
- }
-
- public int getBuildPolicy() {
- return buildPolicy;
- }
-
- protected boolean buildAllContent(int policy) {
- return (policy & BUILD_ALL_CONTENT) == BUILD_ALL_CONTENT;
- }
-
- protected boolean buildOptionalElements(int policy) {
- return (policy & BUILD_OPTIONAL_ELEMENTS) == BUILD_OPTIONAL_ELEMENTS;
- }
-
- protected boolean buildOptionalAttributes(int policy) {
- return (policy & BUILD_OPTIONAL_ATTRIBUTES) == BUILD_OPTIONAL_ATTRIBUTES;
- }
-
- protected boolean buildFirstChoice(int policy) {
- return (policy & BUILD_FIRST_CHOICE) == BUILD_FIRST_CHOICE;
- }
-
- protected boolean buildTextNodes(int policy) {
- return (policy & BUILD_TEXT_NODES) == BUILD_TEXT_NODES;
- }
-
- protected boolean buildFirstSubstitution(int policy) {
- return (policy & BUILD_FIRST_SUBSTITUTION) == BUILD_FIRST_SUBSTITUTION;
- }
-
- public List getResult() {
- return resultList;
- }
-
- public void setProperty(String propertyName, Object value) {
- propertyTable.put(propertyName, value);
- }
-
- public Object getProperty(String propertyName) {
- return propertyTable.get(propertyName);
- }
-
- public void build(Node parent, CMNode child) {
- resultList = new Vector();
- topParent = parent;
- currentParent = parent;
- if (parent instanceof Element) {
- namespaceTable.addElementLineage((Element) parent);
- }
- attachNodesToParent = false;
- alwaysVisit = true;
- visitCMNode(child);
- }
-
- public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration, List namespaceInfoList) throws Exception {
- this.namespaceInfoList = namespaceInfoList;
- createDefaultRootContent(cmDocument, rootCMElementDeclaration);
- }
-
- public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration) throws Exception {
- String grammarFileName = cmDocument.getNodeName();
- if (!supressCreationOfDoctypeAndXMLDeclaration) {
- // TODO cs... investigate to see if this code path is ever used,
- // doesn't seem to be
- // for now I'm setting the encoding to UTF-8 just incase this code
- // path is used somewhere
- //
- String piValue = "version=\"1.0\""; //$NON-NLS-1$
- String encoding = "UTF-8"; //$NON-NLS-1$
- piValue += " encoding=\"" + encoding + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- ProcessingInstruction pi = document.createProcessingInstruction("xml", piValue); //$NON-NLS-1$
- document.appendChild(pi);
-
- // if we have a 'dtd' then add a DOCTYPE tag
- //
- if (grammarFileName != null && grammarFileName.endsWith("dtd")) //$NON-NLS-1$
- {
- DOMImplementation domImpl = document.getImplementation();
- DocumentType documentType = domImpl.createDocumentType(rootCMElementDeclaration.getElementName(), grammarFileName, grammarFileName);
- document.appendChild(documentType);
- }
- }
-
- // if we have a schema add an xsi:schemaLocation attribute
- //
- if (grammarFileName != null && grammarFileName.endsWith("xsd") && namespaceInfoList != null) //$NON-NLS-1$
- {
- DOMNamespaceInfoManager manager = new DOMNamespaceInfoManager();
- String name = rootCMElementDeclaration.getNodeName();
- if (namespaceInfoList.size() > 0) {
- NamespaceInfo info = (NamespaceInfo) namespaceInfoList.get(0);
- if (info.prefix != null && info.prefix.length() > 0) {
- name = info.prefix + ":" + name; //$NON-NLS-1$
- }
- }
- rootElement = createElement(rootCMElementDeclaration, name, document);
- manager.addNamespaceInfo(rootElement, namespaceInfoList, true);
- }
- createDefaultContent(document, rootCMElementDeclaration);
- }
-
- public void createDefaultContent(Node parent, CMElementDeclaration ed) {
- currentParent = parent;
- alwaysVisit = true;
- visitCMElementDeclaration(ed);
- }
-
- public String computeName(CMNode cmNode, Node parent) {
- String prefix = null;
- return DOMNamespaceHelper.computeName(cmNode, parent, prefix, namespaceTable);
- }
-
- // overide the following 'create' methods to control how nodes are created
- //
- protected Element createElement(CMElementDeclaration ed, String name, Node parent) {
- return document.createElement(name);
- }
-
- protected Attr createAttribute(CMAttributeDeclaration ad, String name, Node parent) {
- return document.createAttribute(name);
- }
-
- protected Text createTextNode(CMDataType dataType, String value, Node parent) {
- return document.createTextNode(value);
- }
-
- protected void handlePushParent(Element parent, CMElementDeclaration ed) {
- }
-
- protected void handlePopParent(Element element, CMElementDeclaration ed) {
- }
-
- // The range must be between 1 and 99.
- public void setNumOfRepeatableElements(int i) {
- numOfRepeatableElements = i;
- }
-
- protected int getNumOfRepeatableElements() {
- return numOfRepeatableElements;
- }
-
- public void visitCMElementDeclaration(CMElementDeclaration ed) {
- int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
- int min = Math.max(ed.getMinOccur(), forcedMin);
-
- // Correct the min value if the element is contained in
- // a group.
- if (!cmGroupStack.isEmpty()) {
- CMGroup group = (CMGroup) cmGroupStack.peek();
- int gmin = group.getMinOccur();
- if (gmin == 0)
- if (buildOptionalElements(buildPolicy)) {
- /* do nothing: min = min */
- }
- else {
- min = min * gmin; // min = 0
- }
- else {
- min = min * gmin;
- }
- }
-
- int max = Math.min(ed.getMaxOccur(), getNumOfRepeatableElements());
- if (max < min)
- max = min;
-
- alwaysVisit = false;
-
- // Note - ed may not be abstract but has substitutionGroups
- // involved.
- if (buildFirstSubstitution(buildPolicy) || isAbstract(ed)) // leave
- // this
- // for
- // backward
- // compatibility
- // for now
- {
- // Note - To change so that if ed is optional, we do not
- // generate anything here.
- ed = getSubstitution(ed);
-
- // Note - the returned ed may be an abstract element in
- // which case the xml will be invalid.
- }
-
- if (min > 0 && !visitedCMElementDeclarationList.contains(ed)) {
- visitedCMElementDeclarationList.add(ed);
- for (int i = 1; i <= max; i++) {
- // create an Element for each
- Element element = null;
- if (rootElement != null) {
- element = rootElement;
- rootElement = null;
- }
- else {
- element = createElement(ed, computeName(ed, currentParent), currentParent);
- }
-
- // visit the children of the GrammarElement
- Node oldParent = currentParent;
- currentParent = element;
- handlePushParent(element, ed);
-
- namespaceTable.addElement(element);
-
- boolean oldAttachNodesToParent = attachNodesToParent;
- attachNodesToParent = true;
-
- // instead of calling super.visitCMElementDeclaration()
- // we duplicate the code with some minor modifications
- CMNamedNodeMap nodeMap = ed.getAttributes();
- int size = nodeMap.getLength();
- for (int j = 0; j < size; j++) {
- visitCMNode(nodeMap.item(j));
- }
-
- CMContent content = ed.getContent();
- if (content != null) {
- visitCMNode(content);
- }
-
- if (ed.getContentType() == CMElementDeclaration.PCDATA) {
- CMDataType dataType = ed.getDataType();
- if (dataType != null) {
- visitCMDataType(dataType);
- }
- }
- // end duplication
- attachNodesToParent = oldAttachNodesToParent;
- handlePopParent(element, ed);
- currentParent = oldParent;
- linkNode(element);
- }
- int size = visitedCMElementDeclarationList.size();
- visitedCMElementDeclarationList.remove(size - 1);
- }
- }
-
-
- public void visitCMDataType(CMDataType dataType) {
- Text text = null;
- String value = null;
-
- // For backward compatibility:
- // Previous code uses a property value but new one uses
- // buildPolicy.
- if (getProperty(PROPERTY_BUILD_BLANK_TEXT_NODES) != null && getProperty(PROPERTY_BUILD_BLANK_TEXT_NODES).equals("true")) //$NON-NLS-1$
- buildPolicy = buildPolicy ^ BUILD_TEXT_NODES;
-
- if (buildTextNodes(buildPolicy)) {
- value = valueHelper.getValue(dataType);
- if (value == null) {
- if (currentParent != null && currentParent.getNodeType() == Node.ELEMENT_NODE) {
- value = currentParent.getNodeName();
- }
- else {
- value = "pcdata"; //$NON-NLS-1$
- }
- }
- }
- else {
- value = ""; //$NON-NLS-1$
- }
- text = createTextNode(dataType, value, currentParent);
- linkNode(text);
- }
-
-
- public void visitCMGroup(CMGroup e) {
- cmGroupStack.push(e);
-
- int forcedMin = (buildOptionalElements(buildPolicy) || alwaysVisit) ? 1 : 0;
- int min = Math.max(e.getMinOccur(), forcedMin);
-
- int max = 0;
- if (e.getMaxOccur() == -1) // unbounded
- max = getNumOfRepeatableElements();
- else
- max = Math.min(e.getMaxOccur(), getNumOfRepeatableElements());
-
- if (max < min)
- max = min;
-
- alwaysVisit = false;
-
- for (int i = 1; i <= max; i++) {
- if (e.getOperator() == CMGroup.CHOICE && buildFirstChoice(buildPolicy)) {
- CMNode hintNode = null;
-
- // todo... the CMGroup should specify the hint... but it seems
- // as though
- // the Yamato guys are making the CMElement specify the hint.
- // I do it that way for now until... we should fix this post
- // GA
- //
- int listSize = visitedCMElementDeclarationList.size();
- if (listSize > 0) {
- CMElementDeclaration ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
- Object contentHint = ed.getProperty("contentHint"); //$NON-NLS-1$
- if (contentHint instanceof CMNode) {
- hintNode = (CMNode) contentHint;
- }
- }
-
- // see if this hint corresponds to a valid choice
- //
- CMNode cmNode = null;
-
- if (hintNode != null) {
- CMNodeList nodeList = e.getChildNodes();
- int nodeListLength = nodeList.getLength();
- for (int j = 0; j < nodeListLength; j++) {
- if (hintNode == nodeList.item(j)) {
- cmNode = hintNode;
- }
- }
- }
-
- // if no cmNode has been determined from the hint, just use
- // the first choice
- //
- if (cmNode == null) {
- CMNodeList nodeList = e.getChildNodes();
- if (nodeList.getLength() > 0) {
- cmNode = nodeList.item(0);
- }
- }
-
- if (cmNode != null) {
- visitCMNode(cmNode);
- }
- }
- else if (e.getOperator() == CMGroup.ALL // ALL
- || e.getOperator() == CMGroup.SEQUENCE) // SEQUENCE
- {
- // visit all of the content
- super.visitCMGroup(e);
- }
- }
-
- cmGroupStack.pop();
- }
-
- static int count = 0;
-
- public void visitCMAttributeDeclaration(CMAttributeDeclaration ad) {
- if (alwaysVisit || buildOptionalAttributes(buildPolicy) || ad.getUsage() == CMAttributeDeclaration.REQUIRED) {
- alwaysVisit = false;
- String name = computeName(ad, currentParent);
- String value = valueHelper.getValue(ad, namespaceTable);
- Attr attr = createAttribute(ad, name, currentParent);
- attr.setValue(value != null ? value : ""); //$NON-NLS-1$
- linkNode(attr);
- }
- }
-
- protected boolean isAbstract(CMNode ed) {
- boolean result = false;
- if (ed != null) {
- Object value = ed.getProperty("Abstract"); //$NON-NLS-1$
- result = (value == Boolean.TRUE);
- }
- return result;
- }
-
- protected CMElementDeclaration getSubstitution(CMElementDeclaration ed) {
- CMElementDeclaration result = ed;
- CMNodeList l = (CMNodeList) ed.getProperty("SubstitutionGroup"); //$NON-NLS-1$
- if (l != null) {
- for (int i = 0; i < l.getLength(); i++) {
- CMNode candidate = l.item(i);
- if (!isAbstract(candidate) && (candidate instanceof CMElementDeclaration)) {
- result = (CMElementDeclaration) candidate;
- break;
- }
- }
- }
- return result;
- }
-
- protected CMElementDeclaration getParentCMElementDeclaration() {
- CMElementDeclaration ed = null;
- int listSize = visitedCMElementDeclarationList.size();
- if (listSize > 0) {
- ed = (CMElementDeclaration) visitedCMElementDeclarationList.get(listSize - 1);
- }
- return ed;
- }
-
- public void visitCMAnyElement(CMAnyElement anyElement) {
- // ingnore buildPolicy for ANY elements... only create elements if
- // absolutely needed
- //
- int forcedMin = alwaysVisit ? 1 : 0;
- int min = Math.max(anyElement.getMinOccur(), forcedMin);
- alwaysVisit = false;
-
- String uri = anyElement.getNamespaceURI();
- String targetNSProperty = "http://org.eclipse.wst/cm/properties/targetNamespaceURI"; //$NON-NLS-1$
- CMDocument parentCMDocument = (CMDocument) anyElement.getProperty("CMDocument"); //$NON-NLS-1$
- CMElementDeclaration ed = null;
-
- // System.out.println("parentCMDocument = " + parentCMDocument);
- // //$NON-NLS-1$
- if (parentCMDocument != null) {
- if (uri == null || uri.startsWith("##") || uri.equals(parentCMDocument.getProperty(targetNSProperty))) //$NON-NLS-1$
- {
- ed = getSuitableElement(getParentCMElementDeclaration(), parentCMDocument);
- }
- }
-
-
- if (ed == null && externalCMDocumentSupport != null && uri != null && !uri.startsWith("##") && currentParent instanceof Element) //$NON-NLS-1$
- {
- CMDocument externalCMDocument = externalCMDocumentSupport.getCMDocument((Element) currentParent, uri);
- if (externalCMDocument != null) {
- ed = getSuitableElement(null, externalCMDocument);
- }
- }
-
- for (int i = 1; i <= min; i++) {
- if (ed != null) {
- visitCMElementDeclaration(ed);
- }
- else {
- Element element = document.createElement("ANY-ELEMENT"); //$NON-NLS-1$
- linkNode(element);
- }
- }
- }
-
- protected CMElementDeclaration getSuitableElement(CMNamedNodeMap nameNodeMap) {
- CMElementDeclaration result = null;
- int size = nameNodeMap.getLength();
- for (int i = 0; i < size; i++) {
- CMElementDeclaration candidate = (CMElementDeclaration) nameNodeMap.item(i);
- if (!visitedCMElementDeclarationList.contains(candidate)) {
- result = candidate;
- break;
- }
- }
- return result;
- }
-
- protected CMElementDeclaration getSuitableElement(CMElementDeclaration ed, CMDocument cmDocument) {
- CMElementDeclaration result = null;
-
- if (ed != null) {
- result = getSuitableElement(ed.getLocalElements());
- }
-
- if (result == null && cmDocument != null) {
- result = getSuitableElement(cmDocument.getElements());
- }
-
- return result;
- }
-
-
- public void linkNode(Node node) {
- if (attachNodesToParent && currentParent != null) {
- if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
- ((Element) currentParent).setAttributeNode((Attr) node);
- }
- else {
- currentParent.appendChild(node);
- }
- }
- else if (resultList != null) {
- resultList.add(node);
- }
- }
-
- public static void testPopulateDocumentFromGrammarFile(Document document, String grammarFileName, String rootElementName, boolean hack) {
- try {
- CMDocument cmDocument = ContentModelManager.getInstance().createCMDocument(grammarFileName, null);
- CMNamedNodeMap elementMap = cmDocument.getElements();
- CMElementDeclaration element = (CMElementDeclaration) elementMap.getNamedItem(rootElementName);
-
- DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(document);
- contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = hack;
- contentBuilder.createDefaultRootContent(cmDocument, element);
-
- System.out.println();
- System.out.println("-----------------------------"); //$NON-NLS-1$
- DOMWriter writer = new DOMWriter();
- if (hack) {
- writer.print(document, grammarFileName);
- }
- else {
- writer.print(document);
- }
- System.out.println("-----------------------------"); //$NON-NLS-1$
- }
- catch (Exception e) {
- System.out.println("Error: " + e); //$NON-NLS-1$
- e.printStackTrace();
- }
- }
-
- // test
- //
- /*
- * public static void main(String arg[]) { if (arg.length >= 2) { try {
- * CMDocumentFactoryRegistry.getInstance().registerCMDocumentBuilderWithClassName("org.eclipse.wst.xml.core.internal.contentmodel.mofimpl.CMDocumentBuilderImpl");
- *
- * String grammarFileName = arg[0]; String rootElementName = arg[1];
- *
- * Document document =
- * (Document)Class.forName("org.apache.xerces.dom.DocumentImpl").newInstance();
- * testPopulateDocumentFromGrammarFile(document, grammarFileName,
- * rootElementName, true); } catch (Exception e) {
- * System.out.println("DOMContentBuilderImpl error"); e.printStackTrace(); } }
- * else { System.out.println("Usage : java
- * org.eclipse.wst.xml.util.DOMContentBuildingCMVisitor grammarFileName
- * rootElementName"); } }
- */
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java
deleted file mode 100644
index 049d44585c..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceHelper.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-public class DOMNamespaceHelper
-{
- protected static String getURIForPrefix(Element element, String prefix)
- {
- String result = null;
- String nsAttrName = null;
- if (prefix != null && prefix.length() > 0)
- {
- nsAttrName = "xmlns:" + prefix; //$NON-NLS-1$
- }
- else
- {
- nsAttrName = "xmlns"; //$NON-NLS-1$
- }
-
- // assume the node is qualified... look up the URI base on the prefix
- //
- for (Node node = element; node != null; node = node.getParentNode())
- {
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element theElement = (Element)node;
- Attr attr = theElement.getAttributeNode(nsAttrName);
- if (attr != null)
- {
- result = attr.getValue();
- }
- }
- else
- {
- break;
- }
- }
-
- // see if we can find some info from an 'implicit' namespace
- //
- if (result == null)
- {
- NamespaceTable table = new NamespaceTable(element.getOwnerDocument());
- result = table.getURIForPrefix(prefix);
- }
- return result;
- }
-
- public static String getNamespaceURI(Node node)
- {
- String result = null;
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element element = (Element)node;
- String prefix = element.getPrefix();
- result = getURIForPrefix(element, prefix);
- }
- else if (node.getNodeType() == Node.ATTRIBUTE_NODE)
- {
- Attr attr = (Attr)node;
- String prefix = attr.getPrefix();
- result = getURIForPrefix(attr.getOwnerElement(), prefix);
- }
- return result;
- }
-
- // todo... this is an ugly hack... needs to be fixed
- //
- public static String computePrefix(CMNode cmNode, Node parentNode)
- {
- String result = null;
- for (Node node = parentNode; node != null; node = node.getParentNode())
- {
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- result = getPrefix(node.getNodeName());
- if (result != null)
- {
- break;
- }
- }
- }
- return result;
- }
-
-
- public static String getPrefix(String name)
- {
- String prefix = null;
- int index = name.indexOf(":"); //$NON-NLS-1$
- if (index != -1)
- {
- prefix = name.substring(0, index);
- }
- return prefix;
- }
-
-
- public static String getUnprefixedName(String name)
- {
- int index = name.indexOf(":"); //$NON-NLS-1$
- if (index != -1)
- {
- name = name.substring(index + 1);
- }
- return name;
- }
-
-
- public static String computeName(CMNode cmNode, Node parent, String prefix)
- {
- return computeName(cmNode, parent, prefix, null);
- }
-
-
- public static String computeName(CMNode cmNode, Node parent, String prefix, NamespaceTable namespaceTable)
- {
- String result = cmNode.getNodeName();
-
- // if the cmNode has a hard coded prefix then we don't need to do anything
- //
- if (getPrefix(result) == null)
- {
- String qualification = (String)cmNode.getProperty("http://org.eclipse.wst/cm/properties/nsPrefixQualification"); //$NON-NLS-1$
- // see if we need a namespace prefix
- //
- if (qualification != null && qualification.equals("qualified")) //$NON-NLS-1$
- {
- if (prefix == null)
- {
- // todo... add getCMDocument() method to CMNode
- // for now use this getProperty() hack
- CMDocument cmDocument = (CMDocument)cmNode.getProperty("CMDocument"); //$NON-NLS-1$
- if (cmDocument != null)
- {
- String namespaceURI = (String)cmDocument.getProperty("http://org.eclipse.wst/cm/properties/targetNamespaceURI"); //$NON-NLS-1$
- if (namespaceURI != null)
- {
- // use the NamespaceTable to figure out the correct prefix for this namespace uri
- //
- if (namespaceTable == null)
- {
- Document document = parent.getNodeType() == Node.DOCUMENT_NODE ? (Document)parent : parent.getOwnerDocument();
- namespaceTable = new NamespaceTable(document);
- if (parent instanceof Element)
- {
- namespaceTable.addElementLineage((Element)parent);
- }
- }
- prefix = namespaceTable.getPrefixForURI(namespaceURI);
- }
- }
- }
- if (prefix != null && prefix.length() > 0)
- {
- result = prefix + ":" + result; //$NON-NLS-1$
- }
- }
- }
- return result;
- }
-
-
- public static String[] getURIQualifiedNameComponents(String uriQualifiedName)
- {
- String[] result = new String[2];
- int firstIndex = uriQualifiedName.indexOf("["); //$NON-NLS-1$
- int lastIndex = uriQualifiedName.indexOf("]"); //$NON-NLS-1$
- if (firstIndex != -1 && lastIndex > firstIndex)
- {
- result[0] = uriQualifiedName.substring(firstIndex + 1, lastIndex);
- result[1] = uriQualifiedName.substring(lastIndex + 1);
- }
- else
- {
- result[1] = uriQualifiedName;
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java
deleted file mode 100644
index 747efbc2af..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMNamespaceInfoManager.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-/**
- * DOMNamespaceInfoManager
- *
- *
- */
-public class DOMNamespaceInfoManager
-{
- public static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$
-
- public DOMNamespaceInfoManager()
- {
- }
-
- public List getNamespaceInfoList(Element element)
- {
- NamespaceInfoReader reader = new NamespaceInfoReader();
- return reader.getNamespaceInfoList(element);
- }
-
- public void removeNamespaceInfo(Element element)
- {
- NamespaceInfoRemover remover = new NamespaceInfoRemover();
- remover.removeNamespaceInfo(element);
- }
-
- public void addNamespaceInfo(Element element, List namespaceInfoList, boolean needsXSI)
- {
- // first we create an xmlns attribute for each namespace
- //
- Document document = element.getOwnerDocument();
-
- String schemaLocationValue = ""; //$NON-NLS-1$
-
- for (Iterator iterator = namespaceInfoList.iterator(); iterator.hasNext(); )
- {
- NamespaceInfo nsInfo = (NamespaceInfo)iterator.next();
- nsInfo.normalize();
-
- if (nsInfo.uri != null)
- {
- String attrName = nsInfo.prefix != null ? "xmlns:" + nsInfo.prefix : "xmlns"; //$NON-NLS-1$ //$NON-NLS-2$
- Attr namespaceAttr = document.createAttribute(attrName);
- namespaceAttr.setValue(nsInfo.uri);
- element.setAttributeNode(namespaceAttr);
-
- // in this case we use the attribute "xsi:schemaLocation"
- // here we build up its value
- //
- if (nsInfo.locationHint != null)
- {
- schemaLocationValue += nsInfo.uri;
- schemaLocationValue += " "; //$NON-NLS-1$
- schemaLocationValue += nsInfo.locationHint;
- schemaLocationValue += " "; //$NON-NLS-1$
- }
-
- if (nsInfo.uri.equals(XSI_URI))
- {
- needsXSI = false;
- }
- }
- else if (nsInfo.locationHint != null)
- {
- // in this case we use the attribute "xsi:noNamespaceSchemaLocation"
- //
- Attr attr = document.createAttribute("xsi:noNamespaceSchemaLocation"); //$NON-NLS-1$
- attr.setValue(nsInfo.locationHint);
- element.setAttributeNode(attr);
- }
- }
-
- if (needsXSI)
- {
- // we add an xmlns:xsi attribute to define 'xsi:schemaLocation' attribute
- //
- Attr attr = document.createAttribute("xmlns:xsi"); //$NON-NLS-1$
- attr.setValue(XSI_URI);
- element.setAttributeNode(attr);
- }
-
- if (schemaLocationValue.length() > 0)
- {
- // create the "xsi:schemaLocation" attribute
- //
- Attr attr = document.createAttribute("xsi:schemaLocation"); //$NON-NLS-1$
- attr.setValue(schemaLocationValue);
- element.setAttributeNode(attr);
- }
- }
-
- /**
- *
- */
- protected static class NamespaceInfoReader extends NamespaceAttributeVisitor
- {
- protected List namespaceInfoList = new Vector();
-
- public List getNamespaceInfoList(Element element)
- {
- visitElement(element);
- return namespaceInfoList;
- }
-
-
- public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value)
- {
- NamespaceInfo info = createNamespaceInfo();
- info.locationHint = value;
- }
-
- public void visitXMLNamespaceAttribute(Attr attr, String prefix, String uri)
- {
- NamespaceInfo info = createNamespaceInfo();
- info.uri = uri;
- info.prefix = prefix;
- super.visitXMLNamespaceAttribute(attr, prefix, uri);
- }
-
- public void visitXSISchemaLocationValuePair(String uri, String locationHint)
- {
- NamespaceInfo info = getNamespaceInfoForURI(uri);
- if (info != null)
- {
- info.locationHint = locationHint;
- }
- else
- {
- info = createNamespaceInfo();
- info.uri = uri;
- info.locationHint = locationHint;
- }
- }
-
- protected NamespaceInfo getNamespaceInfoForURI(String uri)
- {
- NamespaceInfo result = null;
- for (Iterator i = namespaceInfoList.iterator(); i.hasNext(); )
- {
- NamespaceInfo info = (NamespaceInfo)i.next();
- if (info.uri != null && info.uri.equals(uri))
- {
- result = info;
- break;
- }
- }
- return result;
- }
-
- protected NamespaceInfo createNamespaceInfo()
- {
- NamespaceInfo info = new NamespaceInfo();
- namespaceInfoList.add(info);
- return info;
- }
- }
-
-
- /**
- *
- */
- protected static class NamespaceInfoRemover extends NamespaceAttributeVisitor
- {
- protected List attributesToRemove = new Vector();
-
- public void removeNamespaceInfo(Element element)
- {
- visitElement(element);
- removeAttributes();
- }
-
- public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value)
- {
- attributesToRemove.add(attr);
- }
-
- public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI)
- {
- attributesToRemove.add(attr);
- super.visitXMLNamespaceAttribute(attr, namespacePrefix, namespaceURI);
- }
-
- public void visitXSISchemaLocationAttribute(Attr attr, String value)
- {
- attributesToRemove.add(attr);
- }
-
- public void removeAttributes()
- {
- for (Iterator i = attributesToRemove.iterator(); i.hasNext(); )
- {
- Attr attr = (Attr)i.next();
- Element element = attr.getOwnerElement();
- if (element != null)
- {
- element.removeAttributeNode(attr);
- }
- }
- }
- }
-
-
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java
deleted file mode 100644
index 0742f7bd8a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMVisitor.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-// todo.. move this class to another package (perhaps xmlutility)
-//
-public class DOMVisitor
-{
- public void visitNode(Node node)
- {
- switch (node.getNodeType())
- {
- case Node.ATTRIBUTE_NODE :
- {
- visitAttr((Attr)node);
- break;
- }
- case Node.CDATA_SECTION_NODE :
- {
- visitCDATASection((CDATASection)node);
- break;
- }
- case Node.COMMENT_NODE :
- {
- visitComment((Comment)node);
- break;
- }
- case Node.DOCUMENT_NODE :
- {
- visitDocument((Document)node);
- break;
- }
- case Node.DOCUMENT_TYPE_NODE :
- {
- visitDocumentType((DocumentType)node);
- break;
- }
- case Node.ELEMENT_NODE :
- {
- visitElement((Element)node);
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE :
- {
- visitProcessingInstruction((ProcessingInstruction)node);
- break;
- }
- case Node.TEXT_NODE :
- {
- visitText((Text)node);
- break;
- }
- }
- }
-
- protected void visitDocument(Document document)
- {
- visitChildNodesHelper(document);
- }
-
- protected void visitDocumentType(DocumentType doctype)
- {
-
- }
-
- protected void visitElement(Element element)
- {
- visitAttributesHelper(element);
- visitChildNodesHelper(element);
- }
-
-
- public void visitAttr(Attr attr)
- {
- }
-
- protected void visitText(Text text)
- {
- }
-
- protected void visitCDATASection(CDATASection cdataSection)
- {
- }
-
- protected void visitComment(Comment comment)
- {
- }
-
- protected void visitProcessingInstruction(ProcessingInstruction pi)
- {
- }
-
-
- protected void visitChildNodesHelper(Node node)
- {
- NodeList children = node.getChildNodes();
- for (int i = 0; i < children.getLength(); i++)
- {
- visitNode(children.item(i));
- }
- }
-
- protected void visitAttributesHelper(Node node)
- {
- NamedNodeMap map = node.getAttributes();
- for (int i = 0; i < map.getLength(); i++ )
- {
- visitNode(map.item(i));
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java
deleted file mode 100644
index d5a115010e..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/DOMWriter.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentType;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-import org.w3c.dom.Text;
-
-
-/**
- * This is a hacked up dom writer stolen from a Xerces sample.
- * I'd like to use an exisitng 'generic DOM' writer
- * If anyone can find such a thing then please go ahead and junk this.
- *
- * @version
- */
-public class DOMWriter
-{
- protected boolean formattingEnabled = true;
- protected boolean outputDoctypeEnabled = true;
- protected PrintWriter out;
- protected int indent = 0;
-
- public DOMWriter() throws UnsupportedEncodingException
- {
- this(System.out);
- }
-
- public DOMWriter(OutputStream outputSteam)
- {
- out = new PrintWriter(outputSteam);
- }
-
- public DOMWriter(Writer writer)
- {
- out = new PrintWriter(writer);
- }
-
- public void setFormattingEnabled(boolean enabled)
- {
- formattingEnabled = enabled;
- }
-
- public boolean getFormattingEnabled()
- {
- return formattingEnabled;
- }
-
- public void setOutputDoctypeEnabled(boolean enabled)
- {
- outputDoctypeEnabled = enabled;
- }
-
- public class XMLVisitor
- {
- protected boolean currentElementHasChildElements = false;
-
- public void visitNode(Node node)
- {
- switch (node.getNodeType())
- {
- case Node.ATTRIBUTE_NODE :
- {
- visitAttr((Attr)node);
- break;
- }
- case Node.CDATA_SECTION_NODE :
- {
- visitCDATASection((CDATASection)node);
- break;
- }
- case Node.COMMENT_NODE :
- {
- visitComment((Comment)node);
- break;
- }
- case Node.DOCUMENT_NODE :
- {
- visitDocument((Document)node);
- break;
- }
- case Node.DOCUMENT_TYPE_NODE :
- {
- visitDocumentType((DocumentType)node);
- break;
- }
- case Node.ELEMENT_NODE :
- {
- visitElement((Element)node);
- break;
- }
- case Node.PROCESSING_INSTRUCTION_NODE :
- {
- visitProcessingInstruction((ProcessingInstruction)node);
- break;
- }
- case Node.TEXT_NODE :
- {
- visitText((Text)node);
- break;
- }
- }
- }
-
- public void visitDocument(Document document)
- {
- visitChildNodesHelper(document);
- }
-
- public void visitDocumentType(DocumentType doctype)
- {
- if (outputDoctypeEnabled)
- {
- String data = getDocumentTypeData(doctype);
- print("<!DOCTYPE " + data + ">"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public void visitElement(Element element)
- {
- if (!doShow(element))
- return;
-
- boolean parentElementHasChildNodes = currentElementHasChildElements;
- currentElementHasChildElements = hasChildElements(element);
-
- printIndent();
- print("<"); //$NON-NLS-1$
- print(element.getNodeName());
- visitAttributesHelper(element);
-
- boolean hasChildNodes = element.getChildNodes().getLength() > 0;
- boolean isRootElement = element.getParentNode().getNodeType() == Node.DOCUMENT_NODE;
- if (hasChildNodes || isRootElement)
- {
- if (currentElementHasChildElements || isRootElement)
- {
- println(">"); //$NON-NLS-1$
- }
- else
- {
- print(">"); //$NON-NLS-1$
- }
- indent += 2;
- visitChildNodesHelper(element);
- indent -= 2;
-
- if (currentElementHasChildElements || isRootElement)
- {
- printIndent();
- }
- print("</"); //$NON-NLS-1$
- print(element.getNodeName());
- println(">"); //$NON-NLS-1$
- }
- else
- {
- println("/>"); //$NON-NLS-1$
- }
-
- currentElementHasChildElements = parentElementHasChildNodes;
- }
-
- public void visitAttr(Attr attr)
- {
- print(" "); //$NON-NLS-1$
- print(attr.getNodeName());
- print("=\""); //$NON-NLS-1$
- print(createPrintableCharacterData(attr.getValue()));
- print("\""); //$NON-NLS-1$
- }
-
- public void visitText(Text text)
- {
- if (currentElementHasChildElements)
- {
- printIndent();
- print(createPrintableCharacterData(text.getNodeValue()));
- println();
- }
- else
- {
- print(createPrintableCharacterData(text.getNodeValue()));
- }
- }
-
- public void visitCDATASection(CDATASection cdataSection)
- {
- }
-
- public void visitComment(Comment comment)
- {
- printIndent();
- print("<!--"); //$NON-NLS-1$
- print(comment.getNodeValue());
- println("-->"); //$NON-NLS-1$
- }
-
- public void visitProcessingInstruction(ProcessingInstruction pi)
- {
- printIndent();
- print("<?"); //$NON-NLS-1$
- print(pi.getNodeName());
- print(" "); //$NON-NLS-1$
- print(pi.getNodeValue());
- println("?>"); //$NON-NLS-1$
- }
-
-
- public boolean hasChildElements(Node node)
- {
- boolean result = false;
- NodeList children = node.getChildNodes();
- for (int i = 0; i < children.getLength(); i++)
- {
- if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
- {
- result = true;
- break;
- }
- }
- return result;
- }
-
- public void visitChildNodesHelper(Node node)
- {
- NodeList children = node.getChildNodes();
- for (int i = 0; i < children.getLength(); i++)
- {
- visitNode(children.item(i));
- }
- }
-
- public void visitAttributesHelper(Node node)
- {
- NamedNodeMap map = node.getAttributes();
- for (int i = 0; i < map.getLength(); i++ )
- {
- visitNode(map.item(i));
- }
- }
- }
-
- /** an ugly hack until I restruct this code a little
- *
- */
- protected boolean doShow(Element element)
- {
- return true;
- }
-
- /** converts DOM text values to 'printable' values
- * - converts '&' to '&amp;'
- */
- protected String createPrintableCharacterData(String string)
- {
- String result = ""; //$NON-NLS-1$
- int index = 0;
- while (true)
- {
- int ampersandIndex = string.indexOf("&", index); //$NON-NLS-1$
- if (ampersandIndex != -1)
- {
- result += string.substring(index, ampersandIndex);
- result += "&amp;"; //$NON-NLS-1$
- index = ampersandIndex + 1;
- }
- else
- {
- break;
- }
- }
- result += string.substring(index);
- return result;
- }
-
-
- /** Prints the specified node, recursively. */
- public void print(Node node)
- {
- // is there anything to do?
- if (node != null)
- {
- XMLVisitor visitor = new XMLVisitor();
- visitor.visitNode(node);
- }
- out.flush();
- }
-
- /** a temporary hack to workaround our inability to create a DocumentType tag*/
- public void print(Document document, String grammarURL)
- {
- String systemId = null;
- if (grammarURL.endsWith("dtd")) //$NON-NLS-1$
- {
- int lastSlashIndex = Math.max(grammarURL.lastIndexOf("/"), grammarURL.lastIndexOf("\\")); //$NON-NLS-1$ //$NON-NLS-2$
- if (lastSlashIndex != -1)
- {
- systemId = grammarURL.substring(lastSlashIndex + 1);
- }
- }
- print(document, "UTF-8", grammarURL, null, systemId); //$NON-NLS-1$
-
- }
-
- /** a temporary hack to workaround our inability to create a DocumentType tag*/
- public void print(Document document, String encoding, String grammarFileName, String publicId, String systemId)
- {
- out.println("<?xml version=\"1.0\"" + " encoding=\"" + encoding + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (grammarFileName.endsWith(".dtd")) //$NON-NLS-1$
- {
- String docTypeLine = "<!DOCTYPE " + document.getDocumentElement().getNodeName() + " "; //$NON-NLS-1$ //$NON-NLS-2$
- if (publicId != null)
- {
- docTypeLine += "PUBLIC \"" + publicId + "\" "; //$NON-NLS-1$ //$NON-NLS-2$
- if (systemId != null)
- {
- docTypeLine += "\"" + systemId + "\" "; //$NON-NLS-1$ //$NON-NLS-2$
- }
- docTypeLine += ">"; //$NON-NLS-1$
- out.println(docTypeLine);
- }
- else if (systemId != null)
- {
- docTypeLine += "SYSTEM \"" + systemId + "\" >"; //$NON-NLS-1$ //$NON-NLS-2$
- out.println(docTypeLine);
- }
- }
- print(document);
- }
-
- public static String getDocumentTypeData(DocumentType doctype)
- {
- String data = doctype.getName();
- if (doctype.getPublicId() != null)
- {
- data += " PUBLIC \"" + doctype.getPublicId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- String systemId = doctype.getSystemId();
- if (systemId == null)
- {
- systemId = ""; //$NON-NLS-1$
- }
- data += " \"" + systemId + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- }
- else
- {
- data += " SYSTEM \"" + doctype.getSystemId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- }
- return data;
- }
-
- public void println()
- {
- if (formattingEnabled)
- {
- out.println();
- }
- }
-
- public void println(String string)
- {
- if (formattingEnabled)
- {
- out.println(string);
- }
- else
- {
- out.print(string);
- }
- }
-
- public void printIndent()
- {
- if (formattingEnabled)
- {
- for (int i = 0; i < indent; i++)
- {
- out.print(" "); //$NON-NLS-1$
- }
- }
- }
-
- public void print(String string)
- {
- out.print(string);
- }
-}
-
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java
deleted file mode 100644
index d4a3c40384..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/InferredGrammarFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.Collection;
-
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.w3c.dom.Element;
-
-
-// this interface is used to build a grammar document given a local file name
-//
-public interface InferredGrammarFactory
-{
- public CMDocument createCMDocument(String uri);
- public CMElementDeclaration createCMElementDeclaration(CMDocument cmDocument, Element element, boolean isLocal);
- public void createCMContent(CMDocument parentCMDocument, CMElementDeclaration parentEd, CMDocument childCMDocument, CMElementDeclaration childEd, boolean isLocal, String uri);
- public void debugPrint(Collection collection);
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java
deleted file mode 100644
index 58d193d3d9..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceAttributeVisitor.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- * David Carver - STAR - bug 198807 - attribute order dependancy.
- *******************************************************************************/
-package org.eclipse.wst.xml.core.internal.contentmodel.util;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-
-import com.ibm.icu.util.StringTokenizer;
-
-
-public class NamespaceAttributeVisitor
-{
- public static final String XML_SCHEMA_INSTANCE_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$
- public String xsiPrefix = "xsi"; //$NON-NLS-1$
-
- public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI)
- {
- if (namespaceURI.equals(XML_SCHEMA_INSTANCE_URI))
- {
- xsiPrefix = namespacePrefix;
- }
- }
-
- public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String value)
- {
- }
-
- public void visitXSISchemaLocationAttribute(Attr attr, String value)
- {
- StringTokenizer st = new StringTokenizer(value);
- while (true)
- {
- String nsURI = st.hasMoreTokens() ? st.nextToken() : null;
- String locationHint = st.hasMoreTokens() ? st.nextToken() : null;
- if (nsURI != null && locationHint != null)
- {
- visitXSISchemaLocationValuePair(nsURI, locationHint);
- }
- else
- {
- break;
- }
- }
- }
-
- public void visitXSISchemaLocationValuePair(String uri, String locationHint)
- {
- }
-
- public void visitElement(Element element)
- {
- NamedNodeMap map = element.getAttributes();
- int mapLength = map.getLength();
-
- // First retrieve all the namespaces so that they are loaded before
- // doing any special prefix handling. This allows the attributes to be
- // defined in any order, but the namespaces have to be retrieved first.
-
- for (int i = 0; i < mapLength; i++)
- {
- Attr attr = (Attr)map.item(i);
- String prefix = DOMNamespaceHelper.getPrefix(attr.getName());
- String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attr.getName());
- if (prefix != null && unprefixedName != null)
- {
- if (prefix.equals("xmlns")) //$NON-NLS-1$
- {
- visitXMLNamespaceAttribute(attr, unprefixedName, attr.getValue());
- }
- }
- else if (unprefixedName != null)
- {
- if (unprefixedName.equals("xmlns")) //$NON-NLS-1$
- {
- visitXMLNamespaceAttribute(attr, "", attr.getValue()); //$NON-NLS-1$
- }
- }
-
- }
-
- for (int i = 0; i < mapLength; i++)
- {
- Attr attr = (Attr)map.item(i);
- String prefix = DOMNamespaceHelper.getPrefix(attr.getName());
- String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attr.getName());
- if (prefix != null && unprefixedName != null)
- {
- if (prefix.equals(xsiPrefix) && unprefixedName.equals("schemaLocation")) //$NON-NLS-1$
- {
- visitXSISchemaLocationAttribute(attr, attr.getValue());
- }
- else if (prefix.equals(xsiPrefix) && unprefixedName.equals("noNamespaceSchemaLocation")) //$NON-NLS-1$
- {
- visitXSINoNamespaceSchemaLocationAttribute(attr, attr.getValue());
- }
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java
deleted file mode 100644
index 56af91b55a..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceInfo.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-public class NamespaceInfo
-{
- public String uri;
- public String prefix;
- public String locationHint;
- public boolean isPrefixRequired;
- protected Hashtable hashtable;
-
- public NamespaceInfo()
- {
- }
-
- public NamespaceInfo(String uri, String prefix, String locationHint)
- {
- this.uri = uri;
- this.prefix = prefix;
- this.locationHint = locationHint;
- }
-
- public NamespaceInfo(NamespaceInfo that)
- {
- this.uri = that.uri;
- this.prefix = that.prefix;
- this.locationHint = that.locationHint;
- // todo... see if we need to clone the hastable
- }
-
- public void normalize()
- {
- uri = getNormalizedValue(uri);
- prefix = getNormalizedValue(prefix);
- locationHint= getNormalizedValue(locationHint);
- }
-
- protected String getNormalizedValue(String string)
- {
- return (string != null && string.trim().length() == 0) ? null : string;
- }
-
- public void setProperty(String property, Object value)
- {
- if (hashtable == null)
- {
- hashtable = new Hashtable();
- }
- hashtable.put(property, value);
- }
-
- public Object getProperty(String property)
- {
- return (hashtable != null) ? hashtable.get(property) : null;
- }
-
- public static List cloneNamespaceInfoList(List oldList)
- {
- List newList = new Vector(oldList.size());
- for (Iterator i = oldList.iterator(); i.hasNext(); )
- {
- NamespaceInfo oldInfo = (NamespaceInfo)i.next();
- newList.add(new NamespaceInfo(oldInfo));
- }
- return newList;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java b/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java
deleted file mode 100644
index 18a25419cb..0000000000
--- a/bundles/org.eclipse.wst.xml.core/src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/util/NamespaceTable.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 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.contentmodel.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-
-public class NamespaceTable extends NamespaceAttributeVisitor
-{
- public Hashtable hashtable = new Hashtable();
-
- public NamespaceTable(Document document)
- {
- this();
- //DOMExtension domExtension = DOMExtensionProviderRegistry.getInstance().getDOMExtension(document);
- //if (domExtension != null)
- //{
- // addNamespaceInfoList(domExtension.getImplictNamespaceInfoList(), true);
- // }
- }
-
- private NamespaceTable()
- {
- super();
- }
-
- public boolean isNamespaceEncountered()
- {
- return hashtable.values().size() > 0;
- }
-
- public String getPrefixForURI(String uri)
- {
- String result = null;
- NamespaceInfo entry = getNamespaceInfoForURI(uri, true);
- if (entry != null)
- {
- result = entry.prefix;
- }
- return result;
- }
-
-
- public String getURIForPrefix(String prefix)
- {
- String result = null;
- NamespaceInfo info = getNamespaceInfoForPrefix(prefix);
- if (info != null)
- {
- result = info.uri;
- }
- return result;
- }
-
-
- protected boolean isMatchingString(String a, String b)
- {
- return ((a == null && b == null) || (a != null && b != null && a.equals(b)));
- }
-
-
- public NamespaceInfo getNamespaceInfoForURI(String uri)
- {
- return getNamespaceInfoForURI(uri, false);
- }
-
-
- public NamespaceInfo getNamespaceInfoForURI(String uri, boolean testImplied)
- {
- NamespaceInfo result = null;
- for (Iterator i = hashtable.values().iterator(); i.hasNext(); )
- {
- NamespaceInfo nsInfo = (NamespaceInfo)i.next();
- if (isMatchingString(nsInfo.uri, uri))
- {
- result = nsInfo;
- if (testImplied && nsInfo.getProperty("isImplied") != null) //$NON-NLS-1$
- {
- // continue
- }
- else
- {
- break;
- }
- }
- }
- return result;
- }
-
-
- public void setLocationHintForURI(String uri, String locationHint)
- {
- // List list = new Vector();
- for (Iterator i = hashtable.values().iterator(); i.hasNext(); )
- {
- NamespaceInfo nsInfo = (NamespaceInfo)i.next();
- if (isMatchingString(nsInfo.uri, uri))
- {
- nsInfo.locationHint = locationHint;
- }
- }
- }
-
-
- public NamespaceInfo getNamespaceInfoForPrefix(String prefix)
- {
- prefix = prefix != null ? prefix : ""; //$NON-NLS-1$
- return (NamespaceInfo)hashtable.get(prefix);
- }
-
-
- public void visitXMLNamespaceAttribute(Attr attr, String namespacePrefix, String namespaceURI)
- {
- NamespaceInfo nsInfo = new NamespaceInfo();
- nsInfo.prefix = namespacePrefix;
- nsInfo.uri = namespaceURI;
-
- NamespaceInfo matchingNamespaceInfo = getNamespaceInfoForURI(namespaceURI);
- if (matchingNamespaceInfo != null)
- {
- nsInfo.locationHint = matchingNamespaceInfo.locationHint;
- }
-
- internalAddNamespaceInfo(namespacePrefix, nsInfo);
-
- super.visitXMLNamespaceAttribute(attr, namespacePrefix, namespaceURI);
- }
-
- public void visitXSISchemaLocationValuePair(String uri, String locationHint)
- {
- setLocationHintForURI(uri, locationHint);
- }
-
- public void addNamespaceInfo(NamespaceInfo info)
- {
- String key = (info.prefix != null) ? info.prefix : ""; //$NON-NLS-1$
- internalAddNamespaceInfo(key, info);
- }
-
- protected void internalAddNamespaceInfo(String key, NamespaceInfo info)
- {
- hashtable.put(key, info);
- }
-
- protected void addNamespaceInfoList(List list, boolean isImplied)
- {
- if (list != null)
- {
- for (Iterator i = list.iterator(); i.hasNext(); )
- {
- NamespaceInfo info = (NamespaceInfo)i.next();
- NamespaceInfo clone = new NamespaceInfo(info);
- if (isImplied)
- {
- clone.setProperty("isImplied", "true"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- addNamespaceInfo(clone);
- }
- }
- }
-
- public void addNamespaceInfoList(List list)
- {
- addNamespaceInfoList(list, false);
- }
-
- public void visitXSINoNamespaceSchemaLocationAttribute(Attr attr, String locationHint)
- {
- addNoNamespaceSchemaLocation(locationHint);
- }
-
- public void addNoNamespaceSchemaLocation(String locationHint)
- {
- NamespaceInfo nsInfo = new NamespaceInfo();
- nsInfo.prefix = null;
- nsInfo.uri = ""; //$NON-NLS-1$
- nsInfo.locationHint = locationHint;
- internalAddNamespaceInfo("", nsInfo); //$NON-NLS-1$
- }
-
- public void addNamespaceInfo(String prefix, String uri, String locationHint)
- {
- NamespaceInfo nsInfo = new NamespaceInfo();
- nsInfo.prefix = prefix;
- nsInfo.uri = uri;
- nsInfo.locationHint = locationHint;
- internalAddNamespaceInfo(prefix != null ? prefix : "", nsInfo); //$NON-NLS-1$
- }
-
- public void addElement(Element element)
- {
- visitElement(element);
- }
-
- public void addElementLineage(Element targetElement)
- {
- List list = NamespaceTable.getElementLineage(targetElement);
- for (Iterator i = list.iterator(); i.hasNext(); )
- {
- Element element = (Element)i.next();
- addElement(element);
- }
- }
-
- public static List getElementLineage(Element element)
- {
- List result = new ArrayList();
- for (Node node = element; node != null; node = node.getParentNode())
- {
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- result.add(0, node);
- }
- else
- {
- break;
- }
- }
- return result;
- }
-
- public Collection getNamespaceInfoCollection()
- {
- return hashtable.values();
- }
-
- public List getNamespaceInfoList()
- {
- List list = new Vector();
- list.addAll(hashtable.values());
- return list;
- }
-}

Back to the top