diff options
author | nitind | 2008-11-28 19:58:37 +0000 |
---|---|---|
committer | nitind | 2008-11-28 19:58:37 +0000 |
commit | fc4fb68a1b0da4201288261912a83b647a970238 (patch) | |
tree | f0a2773af842fdf4635bc18d37a108e1cf011bb7 /bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal | |
parent | 027990080f12c16bc02d3a65748113fd9c56e658 (diff) | |
download | webtools.sourceediting-200811282000.tar.gz webtools.sourceediting-200811282000.tar.xz webtools.sourceediting-200811282000.zip |
This commit was manufactured by cvs2svn to create tag 'v200811282000'.v200811282000
Diffstat (limited to 'bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal')
14 files changed, 0 insertions, 1860 deletions
diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractContentSettingsHandler.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractContentSettingsHandler.java deleted file mode 100644 index 420e3a0174..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractContentSettingsHandler.java +++ /dev/null @@ -1,83 +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.sse.internal.contentproperties; - -import org.eclipse.core.resources.IResourceDelta; - -/** - * @deprecated This is package protected so no one cares anyways. - */ -abstract class AbstractContentSettingsHandler implements IContentSettingsHandler { - - - private IContentSettings contentSettings = ContentSettingsCreator.create(); - private IResourceDelta fDelta; - - private void commonWithRespectToKind() { - getContentSettings().releaseCache(); - } - - protected final IContentSettings getContentSettings() { - return contentSettings; - } - - protected final IResourceDelta getDelta() { - return fDelta; - } - - - /* - * @see IContentSettingsHandler#handle(IResourceDelta) - */ - public void handle(final IResourceDelta delta) { - this.fDelta = delta; - // get Resource delta kind - final int kind = delta.getKind(); - // never used!? - //IResource resource = delta.getResource(); - - - switch (kind) { - case IResourceDelta.CHANGED : { - handleChanged(); - } - break; - case IResourceDelta.REMOVED : { - handleRemoved(); - } - break; - case IResourceDelta.ADDED : { - handleAdded(); - } - break; - - - } - - - - } - - protected void handleAdded() { - commonWithRespectToKind(); - } - - protected void handleChanged() { - commonWithRespectToKind(); - } - - protected void handleRemoved() { - commonWithRespectToKind(); - } - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractSubject.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractSubject.java deleted file mode 100644 index fcc98bcfb2..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/AbstractSubject.java +++ /dev/null @@ -1,54 +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.sse.internal.contentproperties; - -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public abstract class AbstractSubject implements INotify, ISubject { - - - - private static Map listenerList = new Hashtable(); - - public synchronized void addListener(IContentSettingsListener listener) { - listenerList.put(listener, listener); - } - - /* - * @see IContentSettingsEventSubject#notifyContentSettingsListeners(Object) - */ - public synchronized void notifyListeners(org.eclipse.core.resources.IResource changedResource) { - - Set keys = listenerList.keySet(); - Iterator iter = keys.iterator(); - - while (iter.hasNext()) { - IContentSettingsListener csl = (IContentSettingsListener) iter.next(); - csl.contentSettingsChanged(changedResource); - } - } - - public synchronized void removeListener(IContentSettingsListener listener) { - listenerList.remove(listener); - } - - - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettings.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettings.java deleted file mode 100644 index 0c797e3706..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettings.java +++ /dev/null @@ -1,689 +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.sse.internal.contentproperties; - - - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.wst.sse.core.internal.Logger; -import org.eclipse.wst.sse.core.internal.SSECorePlugin; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public class ContentSettings implements IContentSettings { - private static final String contentSettingsName = ".contentsettings";//$NON-NLS-1$ - - private static SimpleNodeOperator domOperator; - - private static IProject preProject; - - private static final IContentSettings singleton = new ContentSettings(); - - public static final String getContentSettingsName() { - return contentSettingsName; - } - - public synchronized static IContentSettings getInstance() { - return singleton; - } - - private String contentSettingsPath; - private IProject currProject; - private final String fileElementName = "file";//$NON-NLS-1$ - private final String PATHATTR = "path"; //$NON-NLS-1$ - private final String projectElementName = "project";//$NON-NLS-1$ - - - - private final String rootElementName = "contentsettings";//$NON-NLS-1$ - - - - private ContentSettings() { - currProject = null; - contentSettingsPath = null; - } - - - private void _setProperties(final IResource resource, final Map properties) { - if (resource == null || properties == null || properties.isEmpty()) - return; - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return; - - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return; - - try { - - if (!existsContentSettings()) { - // create DOM tree for new XML Document - createNewDOMTree(); - } - else { - // create DOM tree from existing contentsettings. - createDOMTree(); - } - - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e) { - Logger.logException(e); - try { - createNewDOMTree(); - writeDOMDocument(); - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e) { - Logger.logException(e); - preProject = currProject; - return; - } - - Element e = null; - if (resource.getType() == IResource.PROJECT) { - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - if (e == null) { - // create project Element and add it into tree - e = (Element) domOperator.addElementUnderRoot(this.projectElementName); - } - } - else if (resource.getType() == IResource.FILE) { - // check exists file Element - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - if (e == null) { - // create file Element and add path into it. - e = (Element) domOperator.addElementUnderRoot(this.fileElementName); - domOperator.addAttributeAt(e, getPathAttr(), getRelativePathFromProject(resource)); - } - } - - // check exists propertyName attribute - Map attrList = domOperator.getAttributesOf(e); - boolean hasAttr = true; - if (attrList == null || attrList.isEmpty()) - hasAttr = false; - Set keys = properties.keySet(); - Iterator ii = keys.iterator(); - while (ii.hasNext()) { - String propertyName = (String) ii.next(); - String propertyValue = (String) properties.get(propertyName); - - - if (!hasAttr || (String) attrList.get(propertyName) == null) - // create propertyName attribute and add - domOperator.addAttributeAt(e, propertyName, propertyValue); - else - // set attribute value - domOperator.updateAttributeAt(e, propertyName, propertyValue); - } - - // write dom tree into .contentsettings - try { - writeDOMDocument(); - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException ex) { - Logger.logException(ex); - preProject = currProject; - return; - } - - preProject = currProject; - - - } - - - private void _setProperty(final IResource resource, final String propertyName, final String propertyValue) { - if (resource == null || propertyName == null) - return; - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return; - - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return; - - try { - - if (!existsContentSettings()) { - // create DOM tree for new XML Document - createNewDOMTree(); - } - else { - // create DOM tree from existing contentsettings. - createDOMTree(); - } - - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e) { - Logger.logException(e); - try { - createNewDOMTree(); - writeDOMDocument(); - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e) { - Logger.logException(e); - preProject = currProject; - return; - } - - Element e = null; - if (resource.getType() == IResource.PROJECT) { - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - if (e == null) { - // create project Element and add it into tree - e = (Element) domOperator.addElementUnderRoot(this.projectElementName); - } - } - else if (resource.getType() == IResource.FILE) { - // check exists file Element - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - if (e == null) { - // create file Element and add path into it. - e = (Element) domOperator.addElementUnderRoot(this.fileElementName); - domOperator.addAttributeAt(e, getPathAttr(), getRelativePathFromProject(resource)); - } - } - - // check exists propertyName attribute - - Map attrList = domOperator.getAttributesOf(e); - if (attrList == null || attrList.isEmpty() || (String) attrList.get(propertyName) == null) - // create propertyName attribute and add - domOperator.addAttributeAt(e, propertyName, propertyValue); - else - // set attribute value - domOperator.updateAttributeAt(e, propertyName, propertyValue); - - - // write dom tree into .contentsettings - try { - writeDOMDocument(); - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException ex) { - Logger.logException(ex); - preProject = currProject; - return; - } - - preProject = currProject; - - - } - - - private void createDOMTree() throws SimpleNodeOperator.ReadContentSettingsFailureException { - if (domOperator == null || (currProject != null && (!currProject.equals(preProject)) && contentSettingsPath != null)) - domOperator = new SimpleNodeOperator(contentSettingsPath); - - - } - - /* - * private void createNewDOMTree() throws - * SimpleNodeOperator.CreateContentSettingsFailureException{ // create New - * document when no file exists. DOMImplementation impl = - * DOMImplementationImpl.getDOMImplementation(); Document document = - * impl.createDocument(null,rootElementName,null); domOperator = new - * SimpleNodeOperator(document); } - */ - private void createNewDOMTree() throws SimpleNodeOperator.CreateContentSettingsFailureException { - Document document = null; - try { - document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - } - catch (ParserConfigurationException e) { - Logger.logException("exception creating document", e); //$NON-NLS-1$ - } - catch (FactoryConfigurationError e) { - Logger.logException("exception creating document", e); //$NON-NLS-1$ - } - if (document != null) { - document.appendChild(document.createElement(rootElementName)); - domOperator = new SimpleNodeOperator(document); - } - } - - - /** - * - */ - public synchronized void deleteAllProperties(final IResource deletedFile) { - if (deletedFile == null) - return; - // if (deletedFile.exists()) return; - if ((deletedFile).getType() != IResource.FILE && (deletedFile).getType() != IResource.PROJECT) - return; - - - contentSettingsPath = getContentSettingsPath(deletedFile);// getProjectOf((IResource)deletedFile) - // + - // IPath.SEPARATOR - // + - // contentSettingsName; - if (contentSettingsPath == null) - return; - if (!existsContentSettings()) - return; - - try { - createDOMTree(); - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e) { - Logger.logException(e); - return; - } - - Element e = null; - if (deletedFile.getType() == IResource.PROJECT) - // select project element and get attribute - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - else if (deletedFile.getType() == IResource.FILE) - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(deletedFile)); - if (e == null) { - preProject = currProject; - return; - } - - - // when deletedFile entry exists. - if (deletedFile.getType() == IResource.PROJECT) - domOperator.removeElementWith(this.projectElementName); - else if (deletedFile.getType() == IResource.FILE) - domOperator.removeElementWith(getPathAttr(), getRelativePathFromProject(deletedFile)); - - - // write dom tree into .contentsettings - try { - writeDOMDocument(); - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException ex) { - Logger.logException(ex); - preProject = currProject; - return; - } - - preProject = currProject; - - - } - - public synchronized void deleteProperty(final IResource resource, final String propertyName) { - if (resource == null) - return; - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return; - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return; - - if (!existsContentSettings()) { - return; // when .contentsettings.xml is NOT exist. - } - try { - createDOMTree(); - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e) { - Logger.logException(e); - try { - createNewDOMTree(); - writeDOMDocument(); - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return; - } - } - - Element e = null; - if (resource.getType() == IResource.PROJECT) - // select project element and get attribute - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - else if (resource.getType() == IResource.FILE) - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - - - if (e != null) { - domOperator.removeAttributeAt(e, propertyName); - // write dom tree into .contentsettings - try { - writeDOMDocument(); - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException ex) { - Logger.logException(ex); - preProject = currProject; - return; - } - } - - preProject = currProject; - - } - - - private boolean existsContentSettings() { - if (contentSettingsPath == null) - return false; - - IResource file = currProject.getFile(contentSettingsName); - if (file == null) - return false; - if (file.isAccessible()) - return true; - else - return false; - - } - - public boolean existsProperties(IResource resource) { - if (resource == null) - return false; - - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return false; - - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return false; - - if (!existsContentSettings()) - return false; // when .contentsettings.xml is NOT exist. - - try { - createDOMTree(); - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e1) { - return false; - } - - Element e = null; - if (resource.getType() == IResource.PROJECT) - // select project element and get attribute - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - else if (resource.getType() == IResource.FILE) - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - - preProject = currProject; - if (e == null) - return false; - - Map properties = domOperator.getAttributesOf(e); - if (properties == null) - return false; - properties.remove(getPathAttr());// if IFile,removed - if (properties.isEmpty()) - return false; - return true; - - } - - private String getContentSettingsPath(IResource resource) { - IProject project = null; - if (resource.getType() == IResource.PROJECT) - project = (IProject) resource; - else - project = resource.getProject(); - - IPath projectLocation = project.getLocation(); - if (projectLocation == null) { - /** - * As a deprecated class, perfect operation in new scenarios such - * as with EFS is not promised. - */ - return SSECorePlugin.getDefault().getStateLocation().append(rootElementName).append(project.getName()).toString(); - } - - return projectLocation.addTrailingSeparator().append(contentSettingsName).toString(); - } - - public final String getPathAttr() { - return PATHATTR; - } - - public synchronized Map getProperties(final IResource resource) { - if (resource == null) - return null; - - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return null; - - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return null; - - if (!existsContentSettings()) { - return null; // when .contentsettings.xml is NOT exist. - } - - - try { - createDOMTree(); - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e1) { - Logger.logException(e1); - // create DOM tree for new XML Document - try { - createNewDOMTree(); - writeDOMDocument(); - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return null; - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return null; - } - - } - - - Element e = null; - if (resource.getType() == IResource.PROJECT) - // select project element and get attribute - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - else if (resource.getType() == IResource.FILE) - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - - - if (e != null) { - - Map properties = domOperator.getAttributesOf(e); - preProject = currProject; - if (properties == null) - return null; - if (properties.isEmpty()) - return null; - properties.remove(getPathAttr()); - return properties; - } - else { - preProject = currProject; - return null;// when project or file element is NOT exist. - } - } - - public synchronized String getProperty(final IResource resource, final String propertyName) { - if (resource == null) - return null; - - if (!(resource.getType() == IResource.PROJECT || resource.getType() == IResource.FILE)) - return null; - - contentSettingsPath = getContentSettingsPath(resource); - if (contentSettingsPath == null) - return null; - - if (!existsContentSettings()) { - return null; // when .contentsettings.xml is NOT exist. - } - - - try { - createDOMTree(); - } - catch (SimpleNodeOperator.ReadContentSettingsFailureException e1) { - Logger.logException(e1); - // create DOM tree for new XML Document - try { - createNewDOMTree(); - writeDOMDocument(); - } - catch (SimpleNodeOperator.CreateContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return null; - } - catch (SimpleNodeOperator.WriteContentSettingsFailureException e2) { - Logger.logException(e2); - preProject = currProject; - return null; - } - - } - - - Element e = null; - if (resource.getType() == IResource.PROJECT) - // select project element and get attribute - e = (Element) domOperator.getElementWithNodeName(this.projectElementName); - else if (resource.getType() == IResource.FILE) - e = (Element) domOperator.getElementWithAttribute(getPathAttr(), getRelativePathFromProject(resource)); - - - if (e != null) { - String result = e.getAttribute(propertyName); - preProject = currProject; - return result; - } - else { - preProject = currProject; - return null;// when project or file element is NOT exist. - } - } - - private String getRelativePathFromProject(IResource resource) { - if (resource == null) - return null; - - IPath path = resource.getProjectRelativePath(); - if (path == null) - return null; // if resource is project or workspace root - String resourcePath = path.toString(); - - return resourcePath; - - } - - public synchronized void releaseCache() { - domOperator = null; - } - - public synchronized void setProperties(final IResource resource, final Map properties) { - // deny to set "path" attribute value. - Set keys = properties.keySet(); - Iterator ii = keys.iterator(); - while (ii.hasNext()) { - if (this.getPathAttr().equals(ii.next())) - return; - } - this._setProperties(resource, properties); - } - - public synchronized void setProperty(final IResource resource, final String propertyName, final String propertyValue) { - // deny to set "path" attribute value. - if (this.getPathAttr().equals(propertyName)) - return; - this._setProperty(resource, propertyName, propertyValue); - } - - private void writeDOMDocument() throws SimpleNodeOperator.WriteContentSettingsFailureException { - try { - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - domOperator.writeDocument(outputStream); - outputStream.flush(); - outputStream.close(); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - - IFile outputFile = currProject.getFile(contentSettingsName); - if (outputFile.exists()) - outputFile.setContents(inputStream, true, true, null); - else - outputFile.create(inputStream, true, null); - - inputStream.close(); - } - catch (CoreException e) { - Logger.logException(e); - throw new SimpleNodeOperator.WriteContentSettingsFailureException("invalid outputFile in writeDOMDocument()");//$NON-NLS-1$ - } - catch (IOException e) { - Logger.logException(e); - throw new SimpleNodeOperator.WriteContentSettingsFailureException("invalid outputStream or inputStream in writeDOMDocument()");//$NON-NLS-1$ - } - } - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsChangeSubject.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsChangeSubject.java deleted file mode 100644 index 7bc580b0af..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsChangeSubject.java +++ /dev/null @@ -1,62 +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.sse.internal.contentproperties; - - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public class ContentSettingsChangeSubject extends AbstractSubject { - - - private static INotify notify; - private static ISubject subject; - - protected static INotify getNotify() { - if (notify == null && subject == null) { - synchronized (ContentSettingsChangeSubject.class) { - if (notify == null && subject == null) { - notify = new ContentSettingsChangeSubject(); - subject = (ISubject) notify; - } - } - } - - return notify; - } - - public static ISubject getSubject() { - if (subject == null && notify == null) { - synchronized (ContentSettingsChangeSubject.class) { - if (subject == null && notify == null) { - subject = new ContentSettingsChangeSubject(); - notify = (INotify) subject; - } - } - } - return subject; - } - - public synchronized void addListener(IContentSettingsListener listener) { - super.addListener(listener); - } - - public synchronized void notifyListeners(org.eclipse.core.resources.IResource changedResource) { - super.notifyListeners(changedResource); - } - - public synchronized void removeListener(IContentSettingsListener listener) { - super.removeListener(listener); - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsCreator.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsCreator.java deleted file mode 100644 index 9dd355c664..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsCreator.java +++ /dev/null @@ -1,26 +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.sse.internal.contentproperties; - - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public class ContentSettingsCreator { - - public final static IContentSettings create() { - return ContentSettings.getInstance(); - } - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsFileHandler.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsFileHandler.java deleted file mode 100644 index 0c526049da..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsFileHandler.java +++ /dev/null @@ -1,147 +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.sse.internal.contentproperties; - - - -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; - -/** -* @deprecated This is package protected so no one cares anyways. -*/ -class ContentSettingsFileHandler extends AbstractContentSettingsHandler { - - - - private Map properties; - - - private void getProperties(IResource file) { - properties = getContentSettings().getProperties(file); - } - - /* - * @see AbstractContentSettingsHandler#handleAdded() - */ - protected void handleAdded() { - super.handleAdded(); - - if (super.getDelta().getFlags() == 0) { - // pulldown memu->copy->create file without override, new file, - // import without override - // copy,new,import has same kind(=1) and flag(=0). - - } else if ((getDelta().getFlags() & IResourceDelta.MOVED_FROM) != 0) { - // pulldown menu-> rename without override,pulldown menu->move - // without override - // instead of this method,handleRemoved() works for this delta - - } - - } - - - /* - * @see AbstractContentSettingsHandler#handleChanged() - */ - protected void handleChanged() { - // edit - if (getDelta().getFlags() == IResourceDelta.CONTENT && (getDelta().getFlags() & IResourceDelta.REPLACED) == 0) { - super.handleChanged(); - - } else if (getDelta().getFlags() == IResourceDelta.CONTENT && (getDelta().getFlags() & IResourceDelta.REPLACED) != 0) { - // override as a result of copy or import - // in Web project, copy with override doesn't happen - - // override as move or rename - // handleRemoved() works for this delta - super.handleChanged(); - - } - - - } - - /* - * @see AbstractContentSettingsHandler#handleRemoved() - */ - protected void handleRemoved() { - super.handleRemoved(); - IFile deletedFile = null; - - // if entry exists then remove it. - if (getDelta().getFlags() == 0) { - // pulldown menu->delete - deletedFile = (IFile) getDelta().getResource(); - - if (deletedFile == null) - return; - getContentSettings().deleteAllProperties(deletedFile); - - getContentSettings().releaseCache(); - } - - else if ((getDelta().getFlags() & IResourceDelta.MOVED_TO) != 0) { - - // pulldown menu-> rename, pulldown menu->move - deletedFile = (IFile) getDelta().getResource(); - getProperties(deletedFile); - - // get destination IResource - IPath targetPath = getDelta().getMovedToPath(); - IWorkspaceRoot iwr = ResourcesPlugin.getWorkspace().getRoot(); - IResource targetFile = iwr.getFile(targetPath);//iwr.findMember(targetPath); - - // set property of destination file - getContentSettings().deleteAllProperties(targetFile); - setProperties(targetFile); - if (properties != null) - properties.clear(); - properties = null; - } - - if (deletedFile == null) - return; - getContentSettings().deleteAllProperties(deletedFile); - - getContentSettings().releaseCache(); - - } - - private void setProperties(IResource file) { - if (file.getFileExtension() == null) - return; - if (!(file.getFileExtension().equalsIgnoreCase("shtml")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("htm")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("html")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("jhtml")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("xhtml")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("jsp")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("css")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("jsf")//$NON-NLS-1$ - || file.getFileExtension().equalsIgnoreCase("jspf")))//$NON-NLS-1$ - return; - if (properties == null || properties.isEmpty()) - return; - getContentSettings().setProperties(file, properties); - } - - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSelfHandler.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSelfHandler.java deleted file mode 100644 index 27aa2b80f6..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSelfHandler.java +++ /dev/null @@ -1,93 +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.sse.internal.contentproperties; - - - -import org.eclipse.core.resources.IResourceDelta; - -/** -* @deprecated This is package protected so no one cares anyways. -*/ -final class ContentSettingsSelfHandler extends AbstractContentSettingsHandler { - - private static INotify notify;// = new ContentSettingsChangedSubject(); - - - private final void getSubject() { - notify = ContentSettingsChangeSubject.getNotify(); - } - - /* - * @see AbstractContentSettingsHandler#handleAdded() - */ - protected void handleAdded() { - getSubject(); - if (super.getDelta().getFlags() == 0) { - // pulldown memu->copy->create file without override, new file, - // property page create .contentsettings - super.handleAdded(); - notify.notifyListeners(getDelta().getResource()); - - } else if ((getDelta().getFlags() & IResourceDelta.MOVED_FROM) != 0) { - // pulldown menu-> rename without override,pulldown menu->move - // without override - super.handleAdded(); - notify.notifyListeners(getDelta().getResource()); - - } - - } - - - /* - * @see AbstractContentSettingsHandler#handleChanged() - */ - protected void handleChanged() { - getSubject(); - if ((getDelta().getFlags() & IResourceDelta.CONTENT) != 0 && (getDelta().getFlags() & IResourceDelta.REPLACED) == 0) { - // result of edit, property page operate setProperty(apply or ok - // button) in .contentsettings - super.handleChanged(); - - notify.notifyListeners(getDelta().getResource()); - - } else if ((getDelta().getFlags() & IResourceDelta.CONTENT) != 0 && (getDelta().getFlags() & IResourceDelta.REPLACED) != 0) { - super.handleChanged(); - notify.notifyListeners(getDelta().getResource()); - - } - - - } - - /* - * @see AbstractContentSettingsHandler#handleRemoved() - */ - protected void handleRemoved() { - getSubject(); - if (getDelta().getFlags() == 0) { - // pulldown menu->delete - super.handleRemoved(); - notify.notifyListeners(getDelta().getResource()); - - } else if ((getDelta().getFlags() & IResourceDelta.MOVED_TO) != 0) { - // pulldown menu-> rename, pulldown menu->move - super.handleRemoved(); - notify.notifyListeners(getDelta().getResource()); - - } - - } - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSynchronizer.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSynchronizer.java deleted file mode 100644 index 0dc38b18d8..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ContentSettingsSynchronizer.java +++ /dev/null @@ -1,174 +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.sse.internal.contentproperties; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.sse.core.internal.Logger; - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public class ContentSettingsSynchronizer implements IResourceChangeListener { - class ContentSettingsVisitor implements IResourceDeltaVisitor { - // redefinition in ContentSettings.java - private String contentSettingsName = ContentSettings.getContentSettingsName(); //$NON-NLS-1$ - private IResourceChangeEvent fEvent; - private IContentSettingsHandler handler; - - public ContentSettingsVisitor(IResourceChangeEvent event) { - this.fEvent = event; - } - - /** - * @see IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) - */ - public boolean visit(IResourceDelta delta) { - if (delta == null) - return false; - IResource resource = delta.getResource(); - if (resource == null) - return false; - // parent folder or project - if (delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() == 0) - return true; - final int resourceType = resource.getType(); - switch (resourceType) { - case IResource.PROJECT : - return false; - case IResource.FILE : - // whether resource is .contentsettings file or not - IProject project = delta.getResource().getProject(); - if (this.fEvent.getType() == IResourceChangeEvent.POST_CHANGE && resource.equals(project.getFile(this.contentSettingsName))) { - // new object for .contentsettings - handler = new ContentSettingsSelfHandler(); - } - else if (this.fEvent.getType() == IResourceChangeEvent.PRE_BUILD && resource.getFileExtension() != null) { - // TODO change to content type! - if (resource.getFileExtension().equalsIgnoreCase("shtml") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("htm") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("html") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("jhtml") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("xhtml") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("jsp") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("css") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("jsf") //$NON-NLS-1$ - || resource.getFileExtension().equalsIgnoreCase("jspf")) { //$NON-NLS-1$ - // new object for IFile - handler = new ContentSettingsFileHandler(); - handler.handle(delta); - handler = null; - return true; - } - } - else - return false; // true or false;motomoto true; - break; - case IResource.FOLDER : - return true; - default : - return true; - } -// final IResourceDelta fDelta = delta; -// final IContentSettingsHandler deltaHandler = this.handler; - // XXX FIXME - // I commented out following to move this to "model" - // packages. Since wasnt't hooked up/working anyway, I think - // ok for now, but need to re-work as Job, once we do implement - // settings for resources again. -// Display display = getDisplay(); -// if (display != null && !display.isDisposed()) { -// display.asyncExec(new Runnable() { -// public void run() { -// if (deltaHandler != null) { -// deltaHandler.handle(fDelta); -// } -// } -// }); -// } -// else if (deltaHandler != null) { -// deltaHandler.handle(fDelta); -// } - handler = null; - return true; // true or false;motomoto true; - } - } - - private static ContentSettingsSynchronizer instance = null; - - public synchronized static ContentSettingsSynchronizer getInstance() { - if (instance == null) - instance = new ContentSettingsSynchronizer(); - return instance; - } - - private ContentSettingsVisitor csVisitor; - private boolean fListening = false; - private IProject fProject; - - - private final IProject getProject() { - return fProject; - } - - private final IWorkspace getWorkspace() { - if (getProject() == null) - return ResourcesPlugin.getWorkspace(); - return getProject().getWorkspace(); - } - - public synchronized void install() { - if (!fListening) { - getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.PRE_BUILD | IResourceChangeEvent.POST_CHANGE); - fListening = true; - } - } - - /** - * @return - */ - public synchronized boolean isListening() { - return fListening; - } - - /* - * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) - */ - public void resourceChanged(IResourceChangeEvent event) { - IResourceDelta delta = event.getDelta(); - if (delta != null) { - try { - if (csVisitor == null) - csVisitor = new ContentSettingsVisitor(event); - delta.accept(csVisitor); - } - catch (CoreException e) { - Logger.logException(e); - } - } - csVisitor = null; - } - - public synchronized void unInstall() { - getWorkspace().removeResourceChangeListener(this); - fListening = false; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettings.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettings.java deleted file mode 100644 index 058dd5c3a6..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettings.java +++ /dev/null @@ -1,83 +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.sse.internal.contentproperties; - - - -import java.util.Map; - -import org.eclipse.core.resources.IResource; - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public interface IContentSettings { - /** - * - */ - public final String CSS_PROFILE = "css-profile"; //$NON-NLS-1$ - /** - * - */ - public final String DEVICE_PROFILE = "target-device"; //$NON-NLS-1$ - - /** - * - */ - public final String DOCUMENT_TYPE = "document-type"; //$NON-NLS-1$ - /** - * - */ - public final String HTML_DOCUMENT_TYPE = "html-document-type"; //$NON-NLS-1$ - - /** - * - */ - public void deleteAllProperties(final IResource deletedFile); - - /** - * - */ - public void deleteProperty(final IResource resource, final String propertyName); - - /** - * - */ - public boolean existsProperties(IResource resource); - - /** - * - */ - public Map getProperties(final IResource resource); - - /** - * - */ - public String getProperty(final IResource resource, final String propertyName); - - /** - * release cache of DOM tree in .contentsettings - */ - public void releaseCache(); - - /** - * - */ - public void setProperties(final IResource resource, final Map properties); - - /** - * - */ - public void setProperty(final IResource resource, final String propertyName, final String propertyValue); -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsHandler.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsHandler.java deleted file mode 100644 index 8ef8b45964..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsHandler.java +++ /dev/null @@ -1,25 +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.sse.internal.contentproperties; - - - -import org.eclipse.core.resources.IResourceDelta; - -/** -* @deprecated This is package protected so no one cares anyways. -*/ -interface IContentSettingsHandler { - - public void handle(final IResourceDelta delta); -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsListener.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsListener.java deleted file mode 100644 index 41151f88a3..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/IContentSettingsListener.java +++ /dev/null @@ -1,22 +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.sse.internal.contentproperties; - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public interface IContentSettingsListener { - - void contentSettingsChanged(org.eclipse.core.resources.IResource e); -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/INotify.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/INotify.java deleted file mode 100644 index 4dcf5fecea..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/INotify.java +++ /dev/null @@ -1,22 +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.sse.internal.contentproperties; - - -/** -* @deprecated This is package protected so no one cares anyways. -*/ -interface INotify { - - void notifyListeners(org.eclipse.core.resources.IResource resource); -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ISubject.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ISubject.java deleted file mode 100644 index 4ff403063a..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/ISubject.java +++ /dev/null @@ -1,26 +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.sse.internal.contentproperties; - - -/** - * @deprecated See - * org.eclipse.html.core.internal.contentproperties.HTMLContentProperties - */ -public interface ISubject { - - void addListener(IContentSettingsListener listener); - - void removeListener(IContentSettingsListener listener); - -} diff --git a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/SimpleNodeOperator.java b/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/SimpleNodeOperator.java deleted file mode 100644 index 16da926575..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src-contentproperties/org/eclipse/wst/sse/internal/contentproperties/SimpleNodeOperator.java +++ /dev/null @@ -1,354 +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.sse.internal.contentproperties; - - - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.FactoryConfigurationError; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.eclipse.wst.sse.core.internal.Logger; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.traversal.NodeIterator; -import org.xml.sax.SAXException; - -/** -* @deprecated This is package protected so no one cares anyways. -*/ -class SimpleNodeOperator { - - class CreateContentSettingsFailureException extends Exception { - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 1L; - - public CreateContentSettingsFailureException(String reason) { - super(reason); - } - } - - - class ReadContentSettingsFailureException extends Exception { - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 1L; - - public ReadContentSettingsFailureException(String reason) { - super(reason); - } - } - - static class WriteContentSettingsFailureException extends Exception { - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 1L; - - public WriteContentSettingsFailureException(String reason) { - super(reason); - } - } - - // writer class for .contentSettings. - class XMLDocumentWriter { - OutputStream fOut; - - protected XMLDocumentWriter(OutputStream out) { - this.fOut = out; - } - - protected final void close() { - try { - fOut.close(); - } catch (IOException e) { - // do nothing, shouldn't matter - } - } - - protected void serialize(Document sourceDocument) throws WriteContentSettingsFailureException { - // JAXP transformation - Source domSource = new DOMSource(sourceDocument); - try { - Transformer serializer = TransformerFactory.newInstance().newTransformer(); - try { - serializer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ - serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (IllegalArgumentException e) { - // unsupported properties - } - serializer.transform(domSource, new StreamResult(fOut)); - } catch (TransformerConfigurationException e) { - throw new WriteContentSettingsFailureException(e.getMessage()); - } catch (TransformerFactoryConfigurationError e) { - throw new WriteContentSettingsFailureException(e.getMessage()); - } catch (TransformerException e) { - throw new WriteContentSettingsFailureException(e.getMessage()); - } - } - } - - public static void main(String[] args) { - SimpleNodeOperator a = null; - try { - a = new SimpleNodeOperator("workspace/org.eclipse.examples.contentsettings/.contentsettings.xml");//$NON-NLS-1$ - } catch (Exception e) { - System.exit(0); - } - - // print all Elements - //a.printTree(iter); - - // add Element - Map attMap = new Hashtable(); - attMap.put("path", "hogepath");//$NON-NLS-1$ //$NON-NLS-2$ - attMap.put("fDocument-type", "documenthogehoge");//$NON-NLS-1$ //$NON-NLS-2$ - a.addElementUnderRoot("file", attMap);//$NON-NLS-1$ - - try { - a.writeDocument(System.out); - } catch (Exception e) { - System.err.println(e.toString()); - } - - } - - //never used - //private DOMParser parser; - private Document fDocument; - private Node root; - - private String settingsFileName; - - - public SimpleNodeOperator(Document doc) throws CreateContentSettingsFailureException { - - if (doc == null) - throw new CreateContentSettingsFailureException("Document doc==null");//$NON-NLS-1$ - fDocument = doc; - root = fDocument.getLastChild(); - if (root == null) - throw new CreateContentSettingsFailureException("Node root==null");//$NON-NLS-1$ - } - - public SimpleNodeOperator(String fullPath) throws ReadContentSettingsFailureException { - this.settingsFileName = fullPath; - createObjectOfDocument(); - } - - // add attribute(attName=attValue) of ele without checking overlapping of - // another attributes of ele. - // if overlapping ,override - protected Node addAttributeAt(Element ele, String attName, String attValue) { - Attr att = fDocument.createAttribute(attName); - att.setValue(attValue); - if (ele != null) - ele.setAttributeNode(att); - return ele; - } - - protected Node addElementUnder(Node parent, String tagName, Map attMap) { - if (parent == null || tagName == null) - return null; - Element e = fDocument.createElement(tagName); - if (attMap != null) { - if (!attMap.isEmpty()) { - Set attKeys = attMap.keySet(); - Iterator iter = attKeys.iterator(); - while (iter.hasNext()) { - String key = (String) iter.next(); - e.setAttribute(key, (String) attMap.get(key)); - } - } - } - parent.appendChild(e); - return e; - } - - protected final Node addElementUnderRoot(String tagName) { - return addElementUnder(root, tagName, null); - } - - // add element with attMap as attribute without checking overlapping. - protected final Node addElementUnderRoot(String tagName, Map attMap) { - return addElementUnder(root, tagName, attMap); - } - - private void createObjectOfDocument() throws ReadContentSettingsFailureException { - try { - fDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(settingsFileName)); - } catch (SAXException e) { - Logger.logException("exception parsing" + settingsFileName, e); //$NON-NLS-1$ - } catch (IOException e) { - Logger.logException("I/O exception parsing" + settingsFileName, e); //$NON-NLS-1$ - } catch (ParserConfigurationException e) { - Logger.logException("exception accessing DOMImplementation", e); //$NON-NLS-1$ - } catch (FactoryConfigurationError e) { - Logger.logException("exception accessing DOMImplementation", e); //$NON-NLS-1$ - } - //get the root of the XML fDocument - root = fDocument.getLastChild(); - if (root == null) { - throw new ReadContentSettingsFailureException("Error: Node root==null");//$NON-NLS-1$ - } - } - - protected Map getAttributesOf(Node node) { - if (!node.hasAttributes()) - return null; - Map map = new HashMap(); - NamedNodeMap attrs = node.getAttributes(); - int size = attrs.getLength(); - for (int i = 0; i < size; i++) { - Attr attr = (Attr) attrs.item(i); - map.put(attr.getName(), attr.getValue()); - } - return (map); - } - - private Node getElementWithAttribute(Node first, String attName, String attValue) { - Node navpoint = first; - while (navpoint != null) { - if (navpoint.getNodeType() == Node.ELEMENT_NODE) { - NamedNodeMap m = navpoint.getAttributes(); - if (m == null) - continue; - if (m.getNamedItem(attName) != null) { - if (attValue.equals(((Attr) m.getNamedItem(attName)).getNodeValue())) - return navpoint; - } - NodeList childNodes = navpoint.getChildNodes(); - if (childNodes != null && childNodes.getLength() > 0) { - Node holdNode = getElementWithAttribute(navpoint.getFirstChild(), attName, attValue); - if (holdNode != null) { - return holdNode; - } - } - } - navpoint = navpoint.getNextSibling(); - } - return null; - } - - - // return a (first) Element with attr(attName=attValue) it if exists, - // otherwise return null - protected Node getElementWithAttribute(String attName, String attValue) { - if (attName == null || attValue == null || !fDocument.hasChildNodes()) - return null; - return getElementWithAttribute(fDocument.getFirstChild(), attName, attValue); - } - - // retrun Element which has nodeName as Node Name - protected Node getElementWithNodeName(String nodeName) { - if (nodeName == null) - return null; - NodeList nodes = fDocument.getElementsByTagName(nodeName); - if (nodes.getLength() > 0) { - return nodes.item(0); - } - return null; - } - - public void printTree(NodeIterator iter) { - Node n; - while ((n = iter.nextNode()) != null) { - System.out.println(n.getNodeName() + ":");//$NON-NLS-1$ - NamedNodeMap m = n.getAttributes(); - if (m == null) - continue; - for (int i = 0; i < m.getLength(); i++) { - String attName = m.item(i).getNodeName(); - System.out.print(" " + attName + "=" + m.item(i).getNodeValue());//$NON-NLS-1$ //$NON-NLS-2$ - } - System.out.println("");//$NON-NLS-1$ - } - } - - - // remove attribute(attName) at ele. - protected Attr removeAttributeAt(Element ele, String attName) { - if (ele == null || attName == null) - return null; - Attr att = ele.getAttributeNode(attName); - ele.removeAttribute(attName); - return att; - } - - protected Element removeElementWith(String nodeName) { - NodeList nodes = fDocument.getElementsByTagName(nodeName); - for (int i = 0; i < nodes.getLength(); i++) { - nodes.item(i).getParentNode().removeChild(nodes.item(i)); - } - return null; - } - - // remove a (first) Element with attr(attName=attValue) and return it if - // exists, otherwise return null - protected Element removeElementWith(String attName, String attValue) { - if (fDocument.hasChildNodes()) { - Node element = getElementWithAttribute(attName, attValue); - if (element != null && element.getNodeType() == Node.ELEMENT_NODE) { - element.getParentNode().removeChild(element); - return (Element) element; - } - } - return null; - - } - - // update attribute(attName=newValue) at ele if both ele and attribute of - // ele exist - protected void updateAttributeAt(Element ele, String attName, String newValue) { - Attr att = null; - if (ele != null) - if ((att = ele.getAttributeNode(attName)) != null) - att.setValue(newValue); - } - - protected void writeDocument(OutputStream out) throws WriteContentSettingsFailureException { - XMLDocumentWriter writer = new XMLDocumentWriter(out); - try { - writer.serialize(fDocument); - } finally { - writer.close(); - } - } - - -} |