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.html.core/src/org/eclipse/wst/html/core/internal/htmlcss')
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractCSSModelAdapter.java105
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractStyleSheetAdapter.java249
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryContext.java137
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryDeclarationData.java44
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryTraverser.java115
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryValueData.java47
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLDocumentAdapter.java398
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapter.java141
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapterFactory.java77
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/LinkElementAdapter.java275
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAdapterFactory.java162
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAttrAdapter.java248
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleElementAdapter.java452
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleListener.java22
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLHelper.java33
-rw-r--r--bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLModelProvider.java451
16 files changed, 0 insertions, 2956 deletions
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractCSSModelAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractCSSModelAdapter.java
deleted file mode 100644
index 891868cb2f..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractCSSModelAdapter.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.wst.css.core.internal.document.CSSModelImpl;
-import org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter;
-import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Element;
-
-/**
- */
-public abstract class AbstractCSSModelAdapter implements ICSSModelAdapter {
- private final static String CSS_ID = ContentTypeIdForCSS.ContentTypeID_CSS;
-
- private Element element = null;
- private ICSSModel model = null;
-
- /**
- */
- AbstractCSSModelAdapter() {
- super();
- }
-
- /**
- */
- protected ICSSModel createModel() {
- // create embedded CSS model (not for external CSS)
- if (getElement() == null)
- return null;
- IStructuredModel baseModel = ((IDOMNode) getElement()).getModel();
- ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID);
- ((CSSModelImpl) newModel).setOwnerDOMNode(getElement());
- return newModel;
- }
-
- /**
- */
- public Element getElement() {
- return this.element;
- }
-
- /**
- */
- protected ICSSModel getExistingModel() {
- return this.model;
- }
-
- /**
- */
- protected void notifyStyleChanged(Element target) {
- INodeNotifier notifier = (INodeNotifier) target;
- if (notifier == null)
- return;
- Collection adapters = notifier.getAdapters();
- if (adapters == null)
- return;
- Iterator it = adapters.iterator();
- if (it == null)
- return;
- while (it.hasNext()) {
- INodeAdapter adapter = (INodeAdapter) it.next();
- if (adapter instanceof StyleListener) {
- StyleListener listener = (StyleListener) adapter;
- listener.styleChanged();
- }
- }
- }
-
- /**
- */
- void setElement(Element element) {
- this.element = element;
- }
-
- /**
- * check
- * 1. If attributes of element is valid (type,rel ...)
- * 2. If content model supports this element / attribute (future ?)
- */
- protected boolean isValidAttribute() {
- return (getElement() != null);
- }
-
- /**
- */
- protected void setModel(ICSSModel model) {
- this.model = model;
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractStyleSheetAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractStyleSheetAdapter.java
deleted file mode 100644
index 90514836eb..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/AbstractStyleSheetAdapter.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004-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
- *
- * Masaki Saitoh (MSAITOH@jp.ibm.com)
- * See Bug 153000 Style Adapters should be lazier
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153000
- *
- ********************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import org.eclipse.wst.css.core.internal.event.ICSSStyleListener;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector;
-import org.eclipse.wst.css.core.internal.util.ImportedCollector;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.document.XMLModelNotifier;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.stylesheets.DocumentStyle;
-import org.w3c.dom.stylesheets.StyleSheet;
-import org.w3c.dom.stylesheets.StyleSheetList;
-import org.w3c.dom.traversal.DocumentTraversal;
-import org.w3c.dom.traversal.NodeFilter;
-import org.w3c.dom.traversal.NodeIterator;
-
-/**
- */
-public abstract class AbstractStyleSheetAdapter extends AbstractCSSModelAdapter implements ICSSStyleListener, IStyleSheetAdapter {
-
- // this variable to hold the class is just a VAJava trick.
- // it improves performance in VAJava by minimizing class loading.
- private final Class StyleSheetAdapterClass = IStyleSheetAdapter.class;
- private Collection styleChangedNodes;
-
- /**
- */
- protected AbstractStyleSheetAdapter() {
- super();
- }
-
- /**
- */
- protected ICSSModel createModel() {
- return createModel(true);
- }
-
- /**
- */
- protected ICSSModel createModel(boolean notify) {
- ICSSModel newModel = super.createModel();
- if (notify && newModel != null) {
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- // notify adapter
- if (adapter != null)
- adapter.modelProvided(newModel);
- }
- return newModel;
- }
-
- /**
- */
- public StyleSheet getSheet() {
- ICSSModel model = getModel();
- if (model == null)
- return null;
- return (StyleSheet) model.getDocument();
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type
- * allows it to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return (type == StyleSheetAdapterClass);
- }
-
- /**
- */
- public void released() {
- ICSSModel currentModel = getModel();
-
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
-
- setElement(null);
- setModel(null);
-
- if (adapter != null)
- adapter.modelReleased(currentModel);
-
- if (currentModel != null)
- currentModel.releaseFromRead();
- }
-
- /**
- */
- public void removed() {
- ICSSModel currentModel = getModel();
-
- setModel(null);
-
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- if (adapter != null)
- adapter.modelRemoved(currentModel);
-
- if (currentModel != null)
- currentModel.releaseFromRead();
- }
-
- /**
- * @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
- * @param removed com.ibm.sed.css.model.interfaces.ICSSSelector[]
- * @param added com.ibm.sed.css.model.interfaces.ICSSSelector[]
- * @param media java.lang.String
- */
- public void styleChanged(ICSSModel srcModel, ICSSSelector[] removed, ICSSSelector[] added, String media) {
- Element element = getElement();
- if (element == null)
- return; // might released
- Document doc = element.getOwnerDocument();
- if (doc == null)
- return; // error
-
- // to notify GEF tree
- if (doc instanceof INodeNotifier) {
- Collection adapters = ((INodeNotifier) doc).getAdapters();
- if (adapters == null)
- return;
- Iterator it = adapters.iterator();
- if (it == null)
- return;
- while (it.hasNext()) {
- INodeAdapter adapter = (INodeAdapter) it.next();
- if (adapter instanceof ICSSStyleListener) {
- ((ICSSStyleListener) adapter).styleChanged(srcModel, removed, added, media);
- }
- }
- }
- //
-
- if (styleChangedNodes == null) {
- styleChangedNodes = new HashSet();
- }
-
- try {
- int removedSelNum = removed != null ? removed.length : 0;
- int addedSelNum = added != null ? added.length : 0;
-
- NodeIterator iter = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, null, true);
- Node node;
- while ((node = iter.nextNode()) != null) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element elm = (Element) node;
- boolean match = false;
- int i;
- for (i = 0; i < removedSelNum && !match; i++) {
- match = removed[i].match(elm, null);
- }
- for (i = 0; i < addedSelNum && !match; i++) {
- match = added[i].match(elm, null);
- }
- if (match) {
- if (!styleChangedNodes.contains(elm))
- styleChangedNodes.add(elm);
- // notifyStyleChanged(elm);
- }
- }
- }
- }
- catch (ClassCastException ex) {
- // Document doesn't implement DocumentTraversal...
- }
-
- }
-
- /**
- * @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
- */
- public void styleUpdate(ICSSModel srcModel) {
- IDOMNode node = (IDOMNode) getElement();
- if (node == null)
- return;
- IDOMModel model = node.getModel();
- if (model == null)
- return;
- XMLModelNotifier notifier = model.getModelNotifier();
- if (notifier == null)
- return;
-
- // before updating, all sub-models should be loaded!
- DocumentStyle document = (DocumentStyle) model.getDocument();
- StyleSheetList styles = document.getStyleSheets();
- if (styles != null) {
- int n = styles.getLength();
- ImportedCollector trav = new ImportedCollector();
- for (int i = 0; i < n; i++) {
- org.w3c.dom.stylesheets.StyleSheet sheet = styles.item(i);
- if (sheet instanceof ICSSNode)
- trav.apply((ICSSNode) sheet);
- }
- }
-
- // flash style changed events
- if (styleChangedNodes != null) {
- Object[] elements = styleChangedNodes.toArray();
- for (int i = 0; elements != null && i < elements.length; i++)
- notifyStyleChanged((Element) elements[i]);
- styleChangedNodes.clear();
- }
-
- // to notify GEF tree
- if (document instanceof INodeNotifier) {
- Collection adapters = ((INodeNotifier) document).getAdapters();
- if (adapters == null)
- return;
- Iterator it = adapters.iterator();
- if (it == null)
- return;
- while (it.hasNext()) {
- INodeAdapter adapter = (INodeAdapter) it.next();
- if (adapter instanceof ICSSStyleListener) {
- ((ICSSStyleListener) adapter).styleUpdate(srcModel);
- }
- }
- }
-
- notifier.propertyChanged(node);
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryContext.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryContext.java
deleted file mode 100644
index 1e98f23621..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryContext.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import java.util.Enumeration;
-
-import org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSValue;
-import org.eclipse.wst.css.core.internal.util.CSSLinkConverter;
-import org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext;
-
-/**
- */
-class CSSQueryContext extends CSSPropertyContext {
-
- /**
- */
- public CSSQueryContext() {
- super();
- }
-
- /**
- */
- public CSSQueryContext(ICSSStyleDeclaration decl) {
- super(decl);
- }
-
- /**
- *
- */
- public void applyFull(ICSSStyleDeclaration decl) {
- if (decl == null)
- return;
- Enumeration keys = fProperties.keys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- Object val = fProperties.get(key);
-
- if (val instanceof CSSQueryDeclarationData) {
- ICSSStyleDeclItem declItem = ((CSSQueryDeclarationData) val).getDeclItem();
- if (declItem.getLength() <= 0) {
- ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
- if (itemToRemove != null) {
- decl.removeDeclItemNode(itemToRemove);
- }
- }
- else {
- decl.setDeclItemNode(declItem);
- }
- }
- else {
- String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
-
- if (value == null || value.length() <= 0) {
- ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
- if (itemToRemove != null) {
- decl.removeDeclItemNode(itemToRemove);
- }
- }
- else {
- decl.setProperty(key.toString(), value, null);
- }
- }
- }
- }
-
- /**
- */
- private boolean check(String propName, boolean important, int specificity) {
- Object current = fProperties.get(propName);
- if (current != null && current instanceof CSSQueryValueData) {
- CSSQueryValueData currentValue = (CSSQueryValueData) current;
- if ((!important && currentValue.important) || (currentValue.getSpecificity() > specificity)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- */
- public void overrideWithExpand(ICSSStyleDeclaration decl, int specificity) {
- if (decl == null)
- return;
-
- CSSLinkConverter conv = new CSSLinkConverter(decl.getOwnerDocument().getModel());
-
- int nProperties = decl.getLength();
- for (int i = 0; i < nProperties; i++) {
- String propName = decl.item(i);
- if (propName != null) {
- String propN = propName.trim().toLowerCase();
- if (propN.length() != 0) {
- PropCMProperty prop = PropCMProperty.getInstanceOf(propN);
- String priority = decl.getPropertyPriority(propName);
- boolean important = priority != null && priority.length() > 0;
- if (prop != null && prop.isShorthand()) {
- // expand shorthand property
- CSSQueryContext context = new CSSQueryContext();
- expandToLeaf(prop, decl.getPropertyValue(propName), context);
-
- Enumeration properties = context.properties();
- while (properties.hasMoreElements()) {
- propN = properties.nextElement().toString();
- if (check(propN, important, specificity)) {
- fProperties.put(propN, new CSSQueryValueData(conv.toAbsolute(context.get(propN)), important, specificity));
- }
- }
- }
- else {
- if (check(propN, important, specificity)) {
- ICSSStyleDeclItem declItem = (ICSSStyleDeclItem) decl.getDeclItemNode(propName).cloneNode(true);
- int nValues = declItem.getLength();
- for (int j = 0; j < nValues; j++) {
- conv.toAbsolute(declItem.item(j));
- }
- declItem.setPriority(null);
- fProperties.put(propN, new CSSQueryDeclarationData(declItem, important, specificity));
- }
- }
- }
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryDeclarationData.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryDeclarationData.java
deleted file mode 100644
index 4f6125d0e7..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryDeclarationData.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
-
-
-
-/**
- */
-public class CSSQueryDeclarationData extends CSSQueryValueData {
-
-
- ICSSStyleDeclItem declItem;
-
- public CSSQueryDeclarationData(ICSSStyleDeclItem declItem, boolean imp, int specificity) {
- super(null, imp, specificity);
- this.declItem = declItem;
- }
-
- /**
- */
- ICSSStyleDeclItem getDeclItem() {
- return declItem;
- }
-
- /**
- */
- public String toString() {
- if (value == null && declItem != null) {
- value = declItem.getCSSValueText();
- }
- return value;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryTraverser.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryTraverser.java
deleted file mode 100644
index 860610a6e4..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryTraverser.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSSelector;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSSelectorList;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
-import org.eclipse.wst.css.core.internal.util.AbstractCssTraverser;
-import org.eclipse.wst.css.core.internal.util.CSSStyleDeclarationFactory;
-import org.w3c.dom.Element;
-import org.w3c.dom.css.ElementCSSInlineStyle;
-
-/**
- */
-public class CSSQueryTraverser extends AbstractCssTraverser {
-
- private Element element;
- private String pseudoName;
- private CSSQueryContext context = null;
- ICSSStyleDeclaration decl = null;
-
- /**
- */
- public ICSSStyleDeclaration getDeclaration() {
- try {
- ICSSStyleDeclaration inlineStyle = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) element).getStyle();
- if (inlineStyle != null) {
- if (context == null) {
- context = new CSSQueryContext();
- }
- context.overrideWithExpand(inlineStyle, 10000);
- // style attribute's specificity is 100 (in CSS2 spec.) and
- // our implement use 100 as base number (see CSSSelector.java)
- }
- }
- catch (ClassCastException ex) {
- // element is not ElementCSSInlineStyle ???
- }
- if (context == null)
- return null;
-
- if (decl == null)
- decl = CSSStyleDeclarationFactory.getInstance().createStyleDeclaration();
- context.applyFull(decl);
- return decl;
- }
-
- /**
- */
- private void overwriteDeclaration(ICSSStyleDeclaration d, int specificity) {
- if (d == null)
- return;
- if (context == null)
- context = new CSSQueryContext();
- context.overrideWithExpand(d, specificity);
- }
-
- /**
- */
- protected short postNode(ICSSNode node) {
- return TRAV_CONT;
- }
-
- /**
- */
- protected short preNode(ICSSNode node) {
- if (node instanceof ICSSStyleRule) {
- // style rule
- ICSSStyleRule style = (ICSSStyleRule) node;
- ICSSSelectorList list = style.getSelectors();
- int nSelectors = list.getLength();
- int maxSpecificity = -1;
- for (int iSelector = 0; iSelector < nSelectors; iSelector++) {
- // Check each Selector Lists
- ICSSSelector selector = list.getSelector(iSelector);
- int specificity = selector.getSpecificity();
- if (maxSpecificity < specificity && selector.match(element, pseudoName)) {
- maxSpecificity = specificity;
- }
- }
- if (maxSpecificity >= 0) {
- // apply this style to the element
- overwriteDeclaration((ICSSStyleDeclaration) style.getStyle(), maxSpecificity);
- }
- return TRAV_PRUNE;
- }
- return TRAV_CONT;
- }
-
- /**
- */
- private void resetContext() {
- context = null;
- }
-
- /**
- */
- public void setElement(Element element, String pseudoName) {
- this.element = element;
- this.pseudoName = pseudoName;
- resetContext();
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryValueData.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryValueData.java
deleted file mode 100644
index 6198156a74..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/CSSQueryValueData.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-import org.eclipse.wst.css.core.internal.util.declaration.ValueData;
-
-
-
-/**
- */
-class CSSQueryValueData extends ValueData {
-
- private int specificity;
-
- /**
- */
- public CSSQueryValueData() {
- super();
- }
-
- /**
- */
- public CSSQueryValueData(String val, boolean imp) {
- super(val, imp);
- }
-
- /**
- */
- public CSSQueryValueData(String val, boolean imp, int specificity) {
- super(val, imp);
- this.specificity = specificity;
- }
-
- /**
- */
- int getSpecificity() {
- return specificity;
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLDocumentAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLDocumentAdapter.java
deleted file mode 100644
index c3883053ce..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLDocumentAdapter.java
+++ /dev/null
@@ -1,398 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
-import org.eclipse.wst.css.core.internal.util.CSSClassTraverser;
-import org.eclipse.wst.css.core.internal.util.ImportRuleCollector;
-import org.eclipse.wst.html.core.internal.contentmodel.JSP11Namespace;
-import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.stylesheets.StyleSheet;
-import org.w3c.dom.stylesheets.StyleSheetList;
-
-
-
-/**
- */
-public class HTMLDocumentAdapter implements IStyleSheetListAdapter, StyleSheetList {
-
- private Document document = null;
- private Vector styleAdapters = null;
- private Vector oldStyleAdapters = null;
-
- /**
- */
- HTMLDocumentAdapter() {
- super();
- }
-
- /**
- */
- private void addStyleSheet(Element node) {
- IDOMElement element = (IDOMElement) node;
- String tagName = element.getTagName();
- if (tagName == null)
- return;
- boolean isContainer = false;
- if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.NOSCRIPT) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.BASE) || tagName.equalsIgnoreCase(JSP11Namespace.ElementName.ROOT) || (!element.isGlobalTag() && element.isContainer())) {
- isContainer = true;
- }
- else if (element.isCommentTag()) {
- Node parent = element.getParentNode();
- if (parent == element.getOwnerDocument()) {
- // This condition is too severe, actually do not work for JSF template.
- // But above (! globalTag() && isContainer()) cover JSF template + tpl template
- isContainer = true;
- }
- else if (parent.getNodeType() == Node.ELEMENT_NODE) {
- tagName = ((Element) parent).getTagName();
- if (tagName != null && tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD)) {
- isContainer = true;
- }
- }
- }
-
- else {
- String localName = element.getLocalName();
- if (localName != null && localName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML)) {
- // taglib html tag
- isContainer = true;
- }
- else {
- INodeNotifier notifier = element;
- INodeAdapter adapter = notifier.getAdapterFor(IStyleSheetAdapter.class);
- if (adapter != null && adapter instanceof IStyleSheetAdapter) {
- this.styleAdapters.addElement(adapter);
- }
- }
- }
- if (isContainer) {
- INodeNotifier notifier = element;
- if (notifier.getExistingAdapter(IStyleSheetListAdapter.class) == null) {
- notifier.addAdapter(this);
- }
- for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() != Node.ELEMENT_NODE)
- continue;
- addStyleSheet((Element) child);
- }
- }
- }
-
- /**
- */
- void childReplaced() {
- if (this.styleAdapters == null)
- return;
-
- // backup old adapters to be released on updating in getStyleSheets()
- this.oldStyleAdapters = this.styleAdapters;
- // invalidate the list
- this.styleAdapters = null;
-
- notifyStyleSheetsChanged(this.document);
- }
-
- /**
- */
- public Enumeration getClasses() {
- StyleSheetList sheetList = getStyleSheets();
- int nSheets = sheetList.getLength();
-
- final ArrayList classes = new ArrayList();
-
- CSSClassTraverser traverser = new CSSClassTraverser();
- traverser.setTraverseImported(true);
-
- for (int i = 0; i < nSheets; i++) {
- org.w3c.dom.stylesheets.StyleSheet sheet = sheetList.item(i);
- if (sheet instanceof ICSSNode) {
- traverser.apply((ICSSNode) sheet);
- }
- }
- classes.addAll(traverser.getClassNames());
-
- return new Enumeration() {
- int i = 0;
-
- public boolean hasMoreElements() {
- return i < classes.size();
- }
-
- public Object nextElement() {
- return classes.get(i++);
- }
- };
- }
-
- /**
- */
- private List getValidAdapters() {
- Vector validAdapters = new Vector();
- if (this.styleAdapters != null) {
- Iterator i = this.styleAdapters.iterator();
- while (i.hasNext()) {
- Object obj = i.next();
- if (obj instanceof AbstractStyleSheetAdapter && ((AbstractStyleSheetAdapter) obj).isValidAttribute()) {
- validAdapters.add(obj);
- }
- }
- }
- return validAdapters;
- }
-
- /**
- */
- public int getLength() {
- return getValidAdapters().size();
- }
-
- /**
- */
- public CSSStyleDeclaration getOverrideStyle(Element element, String pseudoName) {
- StyleSheetList ssl = getStyleSheets();
- int numStyles = ssl.getLength();
-
- CSSQueryTraverser query = new CSSQueryTraverser();
- query.setTraverseImported(true);
- query.setTraverseImportFirst(true);
- query.setElement(element, pseudoName);
-
- for (int i = 0; i < numStyles; i++) {
- // loop for styles (<style> and <link>)
- org.w3c.dom.stylesheets.StyleSheet ss = ssl.item(i);
-
- try {
- query.apply((ICSSNode) ss);
- }
- catch (ClassCastException ex) {
- // I can handle only CSS style
- }
- }
-
- return query.getDeclaration();
- }
-
- /**
- */
- public StyleSheetList getStyleSheets() {
- if (this.styleAdapters == null) {
- if (this.document == null)
- return null;
-
- this.styleAdapters = new Vector();
- for (Node child = this.document.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() != Node.ELEMENT_NODE)
- continue;
- addStyleSheet((Element) child);
- }
-
- removeOldStyleSheets();
- }
- return this;
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type
- * allows it to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return (type == IStyleSheetListAdapter.class);
- }
-
- /**
- */
- public StyleSheet item(int index) {
- if (this.styleAdapters == null)
- return null;
-
- List validAdapters = getValidAdapters();
-
- if (index < 0 || index >= validAdapters.size())
- return null;
- StyleSheet sheet = ((IStyleSheetAdapter) validAdapters.get(index)).getSheet();
- if (sheet == null) {// for LINK element whose link is broken
- ICSSModel model = ((AbstractStyleSheetAdapter) validAdapters.get(index)).createModel();
- sheet = ((model != null) ? (StyleSheet) model.getDocument() : null);
- }
- return sheet;
- }
-
- /**
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- Node node = null;
- switch (eventType) {
- case INodeNotifier.ADD :
- node = (Node) newValue;
- break;
- case INodeNotifier.REMOVE :
- node = (Node) oldValue;
- break;
- case INodeNotifier.CHANGE :
- node = (Node) notifier;
- break;
- default :
- break;
- }
- if (node == null || node.getNodeType() != Node.ELEMENT_NODE)
- return;
- IDOMElement element = (IDOMElement) node;
- String tagName = element.getTagName();
- if (tagName == null)
- return;
-
- if (eventType == INodeNotifier.CHANGE) {
- if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.BASE)) {
- refreshAdapters();
- }
- }
- else {
- if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.HEAD) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.STYLE) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.LINK) || tagName.equalsIgnoreCase(HTML40Namespace.ElementName.NOSCRIPT) || tagName.equalsIgnoreCase(JSP11Namespace.ElementName.ROOT) || element.isCommentTag() || (!element.isGlobalTag() && element.isContainer())) {
- childReplaced();
- }
- else if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.BASE)) {
- refreshAdapters();
- }
- else {
- String localName = element.getLocalName();
- if (localName != null && localName.equalsIgnoreCase(HTML40Namespace.ElementName.HTML)) {
- // taglib html tag
- childReplaced();
- }
- }
- }
- }
-
- /**
- * reload LINK / @import if BASE changed
- */
- private void refreshAdapters() {
- Iterator iAdapter = this.styleAdapters.iterator();
- while (iAdapter.hasNext()) {
- Object adapter = iAdapter.next();
- if (adapter instanceof LinkElementAdapter) {
- ((LinkElementAdapter) adapter).refreshSheet();
- }
- else if (adapter instanceof StyleElementAdapter) {
- ICSSModel model = ((StyleElementAdapter) adapter).getModel();
- ImportRuleCollector trav = new ImportRuleCollector();
- trav.apply(model);
- Iterator iRule = trav.getRules().iterator();
- while (iRule.hasNext()) {
- ICSSImportRule rule = (ICSSImportRule) iRule.next();
- rule.refreshStyleSheet();
- }
- }
- }
- }
-
- /**
- */
- private void notifyStyleSheetsChanged(Document target) {
- INodeNotifier notifier = (INodeNotifier) target;
- if (notifier == null)
- return;
- Collection adapters = notifier.getAdapters();
- if (adapters == null)
- return;
- Iterator it = adapters.iterator();
- if (it == null)
- return;
- while (it.hasNext()) {
- INodeAdapter adapter = (INodeAdapter) it.next();
- if (adapter instanceof StyleListener) {
- StyleListener listener = (StyleListener) adapter;
- listener.styleChanged();
- }
- }
- }
-
- /**
- */
- private void releaseOldStyleSheets() {
- if (this.oldStyleAdapters == null)
- return;
- Iterator it = this.oldStyleAdapters.iterator();
- while (it.hasNext()) {
- IStyleSheetAdapter adapter = (IStyleSheetAdapter) it.next();
- if (adapter == null)
- continue;
- // if the same adapter is in the current list,
- // do not release
- if (this.styleAdapters != null && this.styleAdapters.contains(adapter))
- continue;
- adapter.released();
- }
- this.oldStyleAdapters = null;
- }
-
- /**
- */
- public void releaseStyleSheets() {
- releaseOldStyleSheets();
-
- if (this.styleAdapters == null)
- return;
- Iterator it = this.styleAdapters.iterator();
- while (it.hasNext()) {
- IStyleSheetAdapter adapter = (IStyleSheetAdapter) it.next();
- if (adapter != null)
- adapter.released();
- }
- this.styleAdapters = null;
- }
-
- /**
- */
- private void removeOldStyleSheets() {
- if (this.oldStyleAdapters == null)
- return;
- Iterator it = this.oldStyleAdapters.iterator();
- while (it.hasNext()) {
- IStyleSheetAdapter adapter = (IStyleSheetAdapter) it.next();
- if (adapter == null)
- continue;
- // if the same adapter is in the current list,
- // do not release
- if (this.styleAdapters != null && this.styleAdapters.contains(adapter))
- continue;
- adapter.removed();
- }
- this.oldStyleAdapters = null;
- }
-
- /**
- */
- void setDocument(Document document) {
- this.document = document;
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapter.java
deleted file mode 100644
index cf58aa4247..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapter.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import com.ibm.icu.util.StringTokenizer;
-
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSelectorAdapter;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSSimpleSelector;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.w3c.dom.Element;
-
-/**
- * Insert the type's description here.
- */
-public class HTMLStyleSelectorAdapter implements IStyleSelectorAdapter {
-
- static private HTMLStyleSelectorAdapter instance;
- private Object toMatch = IStyleSelectorAdapter.class;
-
- public synchronized static HTMLStyleSelectorAdapter getInstance() {
- if (instance == null) {
- instance = new HTMLStyleSelectorAdapter();
- }
- return instance;
- }
-
- public boolean isAdapterForType(Object type) {
- return type == toMatch;
- }
-
- public boolean match(ICSSSimpleSelector selector, Element element, String pseudoName) {
- if (element == null)
- return false;
- int i;
- String key;
-
- // PseudoName
- i = selector.getNumOfPseudoNames();
- if (i > 0) {
- if (pseudoName == null || pseudoName.length() == 0)
- return false;
- for (i = i - 1; i >= 0; i--) {
- if (pseudoName.equalsIgnoreCase(selector.getPseudoName(i))) {
- break;
- }
- }
- if (i < 0)
- return false;
- }
-
- // check tag name
- if (!selector.isUniversal() && !element.getNodeName().equalsIgnoreCase(selector.getName()))
- return false;
-
- // check id
- i = selector.getNumOfIDs();
- if (i > 0) {
- if (i > 1)
- return false;
- key = element.getAttribute("id");//$NON-NLS-1$
- if (key == null)
- return false;
- if (!selector.getID(0).equals(key))
- return false;
- }
-
- // check class
- i = selector.getNumOfClasses();
- if (i > 0) {
- key = element.getAttribute("class");//$NON-NLS-1$
- if (key == null)
- return false;
- StringTokenizer tokenizer = new StringTokenizer(key);
- for (i = i - 1; i >= 0; i--) {
- boolean ok = false;
- while (tokenizer.hasMoreTokens()) {
- if (selector.getClass(i).equals(tokenizer.nextToken())) {
- ok = true;
- break;
- }
- }
- if (!ok)
- return false;
- }
- }
-
- // check attributes
- for (i = selector.getNumOfAttributes() - 1; i >= 0; i--) {
- StringTokenizer tokenizer = new StringTokenizer(selector.getAttribute(i), "=~| \t\r\n\f");//$NON-NLS-1$
- int countTokens = tokenizer.countTokens();
- if (countTokens > 0) {
- String attrValue = element.getAttribute(tokenizer.nextToken());
- if (attrValue == null)
- return false;
- if (countTokens > 1) {
- String token = tokenizer.nextToken("= \t\r\n\f");//$NON-NLS-1$
- StringTokenizer attrValueTokenizer = null;
- if (token.equals("~")) {//$NON-NLS-1$
- attrValueTokenizer = new StringTokenizer(attrValue);
- }
- else if (token.equals("|")) {//$NON-NLS-1$
- attrValueTokenizer = new StringTokenizer(attrValue, "-");//$NON-NLS-1$
- }
- if (attrValueTokenizer != null) {
- if (tokenizer.hasMoreTokens()) {
- token = tokenizer.nextToken();
- boolean ok = false;
- while (attrValueTokenizer.hasMoreTokens()) {
- if (token.equals(attrValueTokenizer.nextToken())) {
- ok = true;
- break;
- }
- }
- if (!ok)
- return false;
- }
- }
- else {
- if (!attrValue.equals(token))
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapterFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapterFactory.java
deleted file mode 100644
index 57cd685645..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/HTMLStyleSelectorAdapterFactory.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSelectorAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-
-/**
- * Insert the type's description here.
- */
-public class HTMLStyleSelectorAdapterFactory implements INodeAdapterFactory {
-
- private static HTMLStyleSelectorAdapterFactory instance;
- private Object toMatch = IStyleSelectorAdapter.class;
-
- /**
- * CSSModelProvideAdapterFactory constructor comment.
- */
- public HTMLStyleSelectorAdapterFactory() {
- super();
- }
-
- /**
- * Method that returns the adapter associated with the given object.
- * It may be a singleton or not ... depending on the needs of the INodeAdapter ...
- * but in general it is recommended for an adapter to be stateless,
- * so the efficiencies of a singleton can be gained.
- *
- * The implementation of this method should call addAdapter on the adapted
- * object with the correct instance of the adapter.
- */
- public INodeAdapter adapt(INodeNotifier notifier) {
- INodeAdapter adapter = notifier.getExistingAdapter(IStyleSelectorAdapter.class);
- if (adapter != null)
- return adapter;
- adapter = HTMLStyleSelectorAdapter.getInstance();
- notifier.addAdapter(adapter);
- return adapter;
- }
-
- public synchronized static HTMLStyleSelectorAdapterFactory getInstance() {
- if (instance == null)
- instance = new HTMLStyleSelectorAdapterFactory();
- return instance;
- }
-
- /**
- * isFactoryForType method comment.
- */
- public boolean isFactoryForType(Object type) {
- return type == toMatch;
- }
-
- public void release() {
- // default is to do nothing
- }
-
- /**
- * Overriding copy method
- */
- public INodeAdapterFactory copy() {
- return getInstance();
- }
-
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/LinkElementAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/LinkElementAdapter.java
deleted file mode 100644
index 0c73ac29d2..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/LinkElementAdapter.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter;
-import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.util.URIResolver;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/**
- */
-public class LinkElementAdapter extends AbstractStyleSheetAdapter {
-
- private final static String CSS_ID = ContentTypeIdForCSS.ContentTypeID_CSS;
- private boolean replaceModel = true;
- // this variable to hold the class is just a VAJava trick.
- // it improves performance in VAJava by minimizing class loading.
- private final Class ModelProvideAdapterClass = IModelProvideAdapter.class;
-
- /**
- */
- protected LinkElementAdapter() {
- super();
- }
-
- /**
- */
- private void attrReplaced() {
- this.replaceModel = true;
-
- Element element = getElement();
- if (element == null)
- return; // error
- Document document = element.getOwnerDocument();
- if (document == null)
- return; // error
- INodeNotifier notifier = (INodeNotifier) document;
- HTMLDocumentAdapter adapter = (HTMLDocumentAdapter) notifier.getAdapterFor(IStyleSheetListAdapter.class);
- if (adapter == null)
- return;
- adapter.childReplaced();
- }
-
- protected ICSSModel createModel() {
- // create phantom(broken link) external CSS model
- if (getElement() == null)
- return null;
- IStructuredModel baseModel = ((IDOMNode) getElement()).getModel();
- ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID);
-
- // calculate base location and set
- // get resolver in Model
- URIResolver resolver = baseModel.getResolver();
-
- // resolve to absolute url : this need not exact location of css file. It is important that absurl is not null.
- String ref = getElement().getAttribute(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_HREF);
- String absurl = (resolver != null && ref != null) ? resolver.getLocationByURI(ref, true) : null;
- if ((absurl == null) || (absurl.length() == 0)) {
- IPath basePath = new Path(baseModel.getBaseLocation());
- URLHelper helper = new URLHelper(basePath.removeLastSegments(1).toString());
- absurl = helper.toAbsolute(ref == null ? "" : ref);//$NON-NLS-1$
- }
- if ((absurl == null) || (absurl.length() == 0)) {
- absurl = ref;
- }
- if (absurl == null) {
- absurl = "";//$NON-NLS-1$
- }
- newModel.setBaseLocation(absurl);
-
- // set style listener
- newModel.addStyleListener(this);
-
- return newModel;
- }
-
- /**
- */
- public ICSSModel getModel() {
- ICSSModel model = getExistingModel();
- if (this.replaceModel) {
- ICSSModel oldModel = model;
- try {
- model = retrieveModel();
- setModel(model);
-
- // release old model
- if (oldModel != null) {
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- if (adapter != null)
- adapter.modelRemoved(oldModel);
- }
- }
- finally {
- if (oldModel != null)
- oldModel.releaseFromRead();
- }
- this.replaceModel = false;
- }
- return model;
- }
-
- /**
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (eventType != INodeNotifier.CHANGE)
- return;
- Attr attr = (Attr) changedFeature;
- if (attr == null)
- return;
- String name = attr.getName();
- if (name.equalsIgnoreCase("rel") || //$NON-NLS-1$
- name.equalsIgnoreCase("type") || //$NON-NLS-1$
- name.equalsIgnoreCase("href")) {//$NON-NLS-1$
- attrReplaced();
- }
- }
-
- /**
- */
- public void refreshSheet() {
- if (!replaceModel) {
- removed();
- replaceModel = true;
-
- IDOMNode node = (IDOMNode) getElement();
- if (node != null) {
- node.notify(INodeNotifier.CHANGE, getElement().getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_HREF), null, null, node.getStartOffset());
- }
- }
- }
-
- /**
- */
- public void released() {
- ICSSModel model = getExistingModel();
- if (model != null) {
- try {
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
-
- // set element to null first, so that no document wide updates
- setElement(null);
- setModel(null);
-
- if (adapter != null)
- adapter.modelReleased(model);
- }
- finally {
- model.releaseFromRead();
- }
- }
- this.replaceModel = false;
- }
-
- /**
- */
- public void removed() {
- ICSSModel model = getExistingModel();
- if (model != null) {
- try {
- setModel(null);
-
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- if (adapter != null)
- adapter.modelRemoved(model);
- }
- finally {
- model.releaseFromRead();
- }
- }
- this.replaceModel = false;
- }
-
- /**
- */
- protected boolean isValidAttribute() {
- Element element = getElement();
- if (element == null)
- return false;
- String rel = element.getAttribute("rel");//$NON-NLS-1$
- if (rel == null || !rel.equalsIgnoreCase("stylesheet"))//$NON-NLS-1$
- return false;
- String type = element.getAttribute("type");//$NON-NLS-1$
- if (type != null && !type.equalsIgnoreCase("text/css"))//$NON-NLS-1$
- return false;
- String href = element.getAttribute("href");//$NON-NLS-1$
- if (href == null || href.length() == 0)
- return false;
- return true;
- }
-
- /**
- */
- private ICSSModel retrieveModel() {
- if (!isValidAttribute()) {
- return null;
- }
-
- // null,attr check is done in isValidAttribute()
- Element element = getElement();
- String href = element.getAttribute("href");//$NON-NLS-1$
-
- IDOMModel baseModel = ((IDOMNode) element).getModel();
- if (baseModel == null)
- return null;
- Object id = baseModel.getId();
- if (!(id instanceof String))
- return null;
- //String base = (String)id;
-
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
-
- URLModelProvider provider = new URLModelProvider();
- try {
- IStructuredModel newModel = provider.getModelForRead(baseModel, href);
- if (newModel == null)
- return null;
- if (!(newModel instanceof ICSSModel)) {
- newModel.releaseFromRead();
- return null;
- }
-
- // notify adapter
- if (adapter != null)
- adapter.modelProvided(newModel);
-
- return (ICSSModel) newModel;
- }
- catch (UnsupportedEncodingException e) {
- }
- catch (IOException e) {
- }
-
- return null;
- }
-
- /**
- */
- protected void setModel(ICSSModel model) {
- ICSSModel oldModel = getExistingModel();
- if (model == oldModel)
- return;
- super.setModel(model);
- if (this.replaceModel)
- this.replaceModel = false;
- if (oldModel != null)
- oldModel.removeStyleListener(this);
- if (model != null)
- model.addStyleListener(this);
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAdapterFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAdapterFactory.java
deleted file mode 100644
index 922ee62e31..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAdapterFactory.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleDeclarationAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter;
-import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-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.CMNamedNodeMap;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- */
-public class StyleAdapterFactory implements INodeAdapterFactory {
-
- private static StyleAdapterFactory instance = null;
-
- // private static String CSS_CONTENT_TYPE = "text/css";//$NON-NLS-1$
- /**
- */
- private StyleAdapterFactory() {
- super();
- }
-
- /**
- */
- public INodeAdapter adapt(INodeNotifier notifier) {
- if (notifier == null)
- return null;
-
- Node node = (Node) notifier;
- short nodeType = node.getNodeType();
- if (nodeType == Node.DOCUMENT_NODE) {
- INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetListAdapter.class);
- if (adapter != null)
- return adapter;
- HTMLDocumentAdapter newAdapter = new HTMLDocumentAdapter();
- newAdapter.setDocument((Document) node);
- notifier.addAdapter(newAdapter);
- return newAdapter;
- }
- if (nodeType != Node.ELEMENT_NODE)
- return null;
-
- Element element = (Element) node;
- String tagName = element.getTagName();
- if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.STYLE)) {
- if (!isTagAvailable(element.getOwnerDocument(), HTML40Namespace.ElementName.STYLE)) {
- return null;
- }
- // String type = element.getAttribute(HTML40Namespace.ATTR_NAME_TYPE);
- // if (type != null && ! type.equalsIgnoreCase(CSS_CONTENT_TYPE)) {
- // return null;
- // }
- INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetAdapter.class);
- if (adapter != null)
- return adapter;
- StyleElementAdapter newAdapter = new StyleElementAdapter();
- newAdapter.setElement(element);
- notifier.addAdapter(newAdapter);
- return newAdapter;
- }
- else if (tagName.equalsIgnoreCase(HTML40Namespace.ElementName.LINK)) {
- if (!isTagAvailable(element.getOwnerDocument(), HTML40Namespace.ElementName.LINK)) {
- return null;
- }
- INodeAdapter adapter = notifier.getExistingAdapter(IStyleSheetAdapter.class);
- if (adapter != null)
- return adapter;
- LinkElementAdapter newAdapter = new LinkElementAdapter();
- newAdapter.setElement(element);
- notifier.addAdapter(newAdapter);
- return newAdapter;
- }
-
- INodeAdapter adapter = notifier.getExistingAdapter(IStyleDeclarationAdapter.class);
- if (adapter != null)
- return adapter;
-
- if (!isAttributeAvailable(element, HTML40Namespace.ATTR_NAME_STYLE)) {
- return null;
- }
- StyleAttrAdapter newAdapter = new StyleAttrAdapter();
- newAdapter.setElement(element);
- notifier.addAdapter(newAdapter);
- return newAdapter;
- }
-
- /**
- */
- public synchronized static StyleAdapterFactory getInstance() {
- if (instance == null)
- instance = new StyleAdapterFactory();
- return instance;
- }
-
- /**
- */
- public boolean isFactoryForType(Object type) {
- return (type == IStyleSheetAdapter.class || type == IStyleDeclarationAdapter.class || type == IStyleSheetListAdapter.class);
- }
-
- public void release() {
- // default is to do nothing
- }
-
- private static boolean isTagAvailable(Document document, String elementName) {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
- if (modelQuery != null) {
- CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
- CMNamedNodeMap map = cmdoc.getElements();
- if ((CMElementDeclaration) map.getNamedItem(elementName) != null) {
- return true;
- }
- }
-
- return false;
- }
-
- private static boolean isAttributeAvailable(Element element, String attrName) {
- ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
- if (modelQuery != null) {
- CMElementDeclaration decl = modelQuery.getCMElementDeclaration(element);
- if (decl != null) {
- CMNamedNodeMap map = decl.getAttributes();
- if ((CMAttributeDeclaration) map.getNamedItem(attrName) != null) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Overriding Object's clone() method
- */
- public INodeAdapterFactory copy() {
- return getInstance();
- }
-
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAttrAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAttrAdapter.java
deleted file mode 100644
index a4d8c7327a..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleAttrAdapter.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import org.eclipse.wst.css.core.internal.parser.CSSSourceParser;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleDeclarationAdapter;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
-import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.css.CSSStyleDeclaration;
-
-/**
- */
-public class StyleAttrAdapter extends AbstractCSSModelAdapter implements IStructuredDocumentListener, IStyleDeclarationAdapter {
-
- private boolean ignoreNotification = false;
- private final static String STYLE = "style";//$NON-NLS-1$
-
- /**
- */
- StyleAttrAdapter() {
- super();
- }
-
- /**
- */
- public ICSSModel getModel() {
- ICSSModel model = getExistingModel();
- if (model == null && isModelNecessary()) {
- model = createModel();
- if (model == null)
- return null;
-
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return null;
-
- RegionParser parser = structuredDocument.getParser();
- if (parser instanceof CSSSourceParser) {
- ((CSSSourceParser)parser).setParserMode(CSSSourceParser.MODE_DECLARATION);
- } else {
- return null;
- }
-
- structuredDocument.addDocumentChangedListener(this);
-
- setModel(model); // need to set before valueChanged()
- valueChanged();
- }
- if (model != null && !isModelNecessary()) {
- model = null;
- valueChanged();
- }
- return model;
- }
-
- /**
- */
- public CSSStyleDeclaration getStyle() {
- ICSSModel model = getModel();
- if (model == null)
- return null;
- return (CSSStyleDeclaration) model.getDocument();
- }
-
- /**
- * Allowing the INodeAdapter to compare itself against the type
- * allows it to return true in more than one case.
- */
- public boolean isAdapterForType(Object type) {
- return (type == IStyleDeclarationAdapter.class);
- }
-
- /**
- */
- public void newModel(NewDocumentEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == this)
- return;
-
- setValue();
- }
-
- /**
- */
- public void noChange(NoChangeEvent structuredDocumentEvent) {
- }
-
- /**
- */
- public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == this)
- return;
-
- setValue();
- }
-
- /**
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (this.ignoreNotification)
- return;
-
- if (eventType != INodeNotifier.CHANGE)
- return;
- Attr attr = (Attr) changedFeature;
- if (attr == null)
- return;
- String name = attr.getName();
- if (name.equalsIgnoreCase(STYLE)) {
- valueChanged();
- }
- }
-
- /**
- */
- public void regionChanged(RegionChangedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == this)
- return;
-
- setValue();
- }
-
- /**
- */
- public void regionsReplaced(RegionsReplacedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == this)
- return;
-
- setValue();
- }
-
- /**
- */
- private void setValue() {
- Element element = getElement();
- if (element == null)
- return;
- ICSSModel model = getExistingModel();
- if (model == null)
- return;
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return;
-
- String value = null;
- IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
- if (flatNodes != null) {
- int count = flatNodes.getLength();
- if (count > 0) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion flatNode = flatNodes.item(i);
- if (flatNode == null)
- continue;
- buffer.append(flatNode.getText());
- }
- value = buffer.toString();
- }
- }
-
- this.ignoreNotification = true;
- if (value == null || value.length() == 0) {
- element.removeAttribute(STYLE);
- }
- else {
- Attr attr = element.getAttributeNode(STYLE);
- if (attr != null) {
- ((IDOMNode) attr).setValueSource(value);
- }
- else {
- Document document = element.getOwnerDocument();
- attr = document.createAttribute(STYLE);
- ((IDOMNode) attr).setValueSource(value);
- element.setAttributeNode(attr);
- }
- }
- this.ignoreNotification = false;
-
- notifyStyleChanged(element);
- }
-
- /**
- */
- private void valueChanged() {
- Element element = getElement();
- if (element == null)
- return;
- if (!isModelNecessary()) { // removed
- setModel(null);
-
- notifyStyleChanged(element);
- return;
- }
-
- ICSSModel model = getExistingModel();
- if (model == null)
- return; // defer
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return; // error
-
- String value = null;
- Attr attr = element.getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_STYLE);
- if (attr != null)
- value = ((IDOMNode) attr).getValueSource();
- structuredDocument.setText(this, value);
-
- notifyStyleChanged(element);
- }
-
- /**
- * @return boolean
- */
- private boolean isModelNecessary() {
- return getElement() != null && getElement().getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_STYLE) != null;
- }
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleElementAdapter.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleElementAdapter.java
deleted file mode 100644
index 3ef97b9cc9..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleElementAdapter.java
+++ /dev/null
@@ -1,452 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004-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
- *
- * Masaki Saitoh (MSAITOH@jp.ibm.com)
- * See Bug 153000 Style Adapters should be lazier
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153000
- *
- ********************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter;
-import org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetListAdapter;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
-import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
-import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- */
-public class StyleElementAdapter extends AbstractStyleSheetAdapter implements IStructuredDocumentListener {
-
- private boolean replaceModel = true;
- private boolean ignoreNotification = false;
-
- /**
- */
- protected StyleElementAdapter() {
- super();
- }
-
- /**
- * Preparation of applying changes from CSS sub-model to HTML model
- */
- private void changeStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
- if (flatNode == null)
- return;
- Element element = getElement();
- if (element == null)
- return;
- ICSSModel model = getExistingModel();
- if (model == null)
- return;
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return;
-
- // get old content length
- Node child = element.getFirstChild();
- if (child == null || child.getNodeType() != Node.TEXT_NODE)
- return;
- IDOMNode content = (IDOMNode) child;
- int oldLength = content.getEndOffset() - content.getStartOffset();
-
- // get new content length
- int newLength = 0;
- IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
- if (flatNodes != null) {
- int count = flatNodes.getLength();
- if (count > 0) {
- IStructuredDocumentRegion last = flatNodes.item(count - 1);
- if (last != null)
- newLength = last.getEnd();
- }
- }
-
- int offset = flatNode.getStart();
- int end = flatNode.getEnd();
- int diff = oldLength - newLength;
- int length = end - offset + diff;
- String data = flatNode.getText();
-
- replaceData(offset, length, data);
- }
-
- /**
- * Apply changes from HTML model to CSS sub-model
- */
- private void contentChanged() {
- Element element = getElement();
- if (element == null)
- return;
- ICSSModel model = getExistingModel();
- if (model == null)
- return;
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return;
-
- String data = null;
- Node child = element.getFirstChild();
- if (child != null && child.getNodeType() == Node.TEXT_NODE && child.getNextSibling() == null) {
- data = child.getNodeValue();
- }
- if (data == null)
- data = "";//$NON-NLS-1$
-
- // minimize replace range
- int start = 0, end = 0;
- String oldData = structuredDocument.get();
- if (oldData == null)
- oldData = "";//$NON-NLS-1$
-
- // search differenct character position from first
- for (; start < oldData.length() && start < data.length(); start++)
- if (oldData.charAt(start) != data.charAt(start))
- break;
-
- if (start == oldData.length() && start == data.length())
- return; // no change
- else if (start == oldData.length()) {
- structuredDocument.replaceText(getRequesterH2C(), start, 0, data.substring(start)); // append text to last
- }
- else if (start == data.length()) {
- structuredDocument.replaceText(getRequesterH2C(), start, oldData.length() - start, ""); // remove text of last //$NON-NLS-1$
- }
- else {
- // search differenct character position from last
- for (; start < oldData.length() - end && start < data.length() - end; end++) {
- if (oldData.charAt(oldData.length() - end - 1) != data.charAt(data.length() - end - 1))
- break;
- }
- structuredDocument.replaceText(getRequesterH2C(), start, oldData.length() - end - start, data.substring(start, data.length() - end));
- }
-
- }
-
- /**
- */
- public ICSSModel getModel() {
- ICSSModel model = getExistingModel();
- if (this.replaceModel) {
- ICSSModel oldModel = model;
- model = createModel(false);
-
- setModel(model, false); // need to set before contentChanged()
- contentChanged();
-
- // from super.createModel()
- // get ModelProvideAdapter
- IModelProvideAdapter modelProvideAdapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- // notify adapter
- if (modelProvideAdapter != null)
- modelProvideAdapter.modelProvided(model);
-
- // from createModel()
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return null;
- structuredDocument.addDocumentChangedListener(this);
-
- // from setModel()
- if (oldModel != null)
- oldModel.removeStyleListener(this);
- if (model != null)
- model.addStyleListener(this);
-
- if (oldModel != null) {
- // get ModelProvideAdapter
- IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
- if (adapter != null) {
- adapter.modelRemoved(oldModel);
- }
- }
-
- this.replaceModel = false;
- }
- return model;
- }
-
- /**
- */
- protected boolean isValidAttribute() {
- Element element = getElement();
- if (element == null) {
- return false;
- }
- String type = element.getAttribute(HTML40Namespace.ATTR_NAME_TYPE);
- if (type != null && type.length() > 0 && !type.equalsIgnoreCase("text/css")) { //$NON-NLS-1$
- return false;
- }
- return true;
- }
-
- /**
- */
- protected ICSSModel createModel() {
- return createModel(true);
- }
-
- /**
- */
- protected ICSSModel createModel(boolean addListener) {
- if (!isValidAttribute()) {
- return null;
- }
-
- if (!addListener)
- return super.createModel(false);
-
- ICSSModel model = super.createModel();
- IStructuredDocument structuredDocument = model.getStructuredDocument();
- if (structuredDocument == null)
- return null;
- structuredDocument.addDocumentChangedListener(this);
-
- return model;
- }
-
- /**
- */
- // public ICSSModel getModel() {
- // ICSSModel model = getExistingModel();
- // if (model == null) {
- // model = createModel();
- // if (model == null) return null;
- // IStructuredDocument structuredDocument = model.getStructuredDocument();
- // if (structuredDocument == null) return null;
- // structuredDocument.addModelChangedListener(this);
- // setModel(model); // need to set before contentChanged()
- // contentChanged();
- // }
- // return model;
- // }
- /**
- */
- private Object getRequesterH2C() {
- return (getElement() != null && ((IDOMNode) getElement()).getModel() != null) ? (Object) ((IDOMNode) getElement()).getModel() : this;
- }
-
- /**
- */
- private Object getRequesterC2H() {
- return (getModel() != null) ? (Object) getModel() : this;
- }
-
- /**
- * Implementing IStructuredDocumentListener's method
- * Event from CSS Flat Model
- */
- public void newModel(NewDocumentEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == getRequesterH2C())
- return;
- IStructuredDocument structuredDocument = event.getStructuredDocument();
- if (structuredDocument == null)
- return;
- IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
- if (flatNodes == null)
- return;
-
- replaceStructuredDocumentRegions(flatNodes, null);
- }
-
- /**
- * Implementing IStructuredDocumentListener's method
- * Event from CSS Flat Model
- */
- public void noChange(NoChangeEvent structuredDocumentEvent) {
- }
-
- /**
- * Implementing IStructuredDocumentListener's method
- * Event from CSS Flat Model
- */
- public void nodesReplaced(StructuredDocumentRegionsReplacedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == getRequesterH2C())
- return;
- IStructuredDocumentRegionList oldStructuredDocumentRegions = event.getOldStructuredDocumentRegions();
- IStructuredDocumentRegionList newStructuredDocumentRegions = event.getNewStructuredDocumentRegions();
- if (oldStructuredDocumentRegions == null && newStructuredDocumentRegions == null)
- return;
-
- replaceStructuredDocumentRegions(newStructuredDocumentRegions, oldStructuredDocumentRegions);
- }
-
- /**
- * Overriding INodeAdapter's method
- * Event from <STYLE> element
- */
- public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
- if (this.ignoreNotification)
- return;
-
- if (eventType == INodeNotifier.ADD || eventType == INodeNotifier.REMOVE || eventType == INodeNotifier.CONTENT_CHANGED) {
- contentChanged();
- }
- else if (eventType == INodeNotifier.CHANGE) {
- Attr attr = (Attr) changedFeature;
- if (attr == null)
- return;
- String name = attr.getName();
- if (name.equalsIgnoreCase("type")) { //$NON-NLS-1$
- this.replaceModel = true;
-
- Element element = getElement();
- if (element == null) {
- return;
- }
- Document document = element.getOwnerDocument();
- if (document == null) {
- return;
- }
- HTMLDocumentAdapter adapter = (HTMLDocumentAdapter) ((INodeNotifier) document).getAdapterFor(IStyleSheetListAdapter.class);
- if (adapter != null) {
- adapter.childReplaced();
- }
- }
- }
- }
-
- /**
- * Implementing IStructuredDocumentListener's method
- * Event from CSS Flat Model
- */
- public void regionChanged(RegionChangedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == getRequesterH2C())
- return;
- IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
- if (flatNode == null)
- return;
-
- changeStructuredDocumentRegion(flatNode);
- }
-
- /**
- * Implementing IStructuredDocumentListener's method
- * Event from CSS Flat Model
- */
- public void regionsReplaced(RegionsReplacedEvent event) {
- if (event == null)
- return;
- if (event.getOriginalRequester() == getRequesterH2C())
- return;
- IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
- if (flatNode == null)
- return;
-
- changeStructuredDocumentRegion(flatNode);
- }
-
- /**
- * Apply changes from CSS sub-model to HTML model
- */
- private void replaceData(int offset, int length, String data) {
- IDOMNode element = (IDOMNode) getElement();
- if (element == null)
- return;
- IDOMModel ownerModel = element.getModel();
- if (ownerModel == null)
- return;
- IStructuredDocument structuredDocument = ownerModel.getStructuredDocument();
- if (structuredDocument == null)
- return;
- IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
- if (flatNode == null)
- return;
-
- int contentOffset = flatNode.getEndOffset();
- if (data == null)
- data = "";//$NON-NLS-1$
-
- this.ignoreNotification = true;
- structuredDocument.replaceText(getRequesterC2H(), contentOffset + offset, length, data);
- this.ignoreNotification = false;
- }
-
- /**
- * Preparation of applying changes from CSS sub-model to HTML model
- */
- private void replaceStructuredDocumentRegions(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
- int offset = 0;
- int length = 0;
- if (oldStructuredDocumentRegions != null) {
- int count = oldStructuredDocumentRegions.getLength();
- if (count > 0) {
- IStructuredDocumentRegion first = oldStructuredDocumentRegions.item(0);
- if (first != null)
- offset = first.getStart();
- IStructuredDocumentRegion last = oldStructuredDocumentRegions.item(count - 1);
- if (last != null)
- length = last.getEnd() - offset;
- }
- }
- String data = null;
- if (newStructuredDocumentRegions != null) {
- int count = newStructuredDocumentRegions.getLength();
- if (count > 0) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < count; i++) {
- IStructuredDocumentRegion flatNode = newStructuredDocumentRegions.item(i);
- if (flatNode == null)
- continue;
- buffer.append(flatNode.getText());
- if (i == 0)
- offset = flatNode.getStart();
- }
- data = buffer.toString();
- }
- }
-
- replaceData(offset, length, data);
- }
-
- /**
- */
- protected void setModel(ICSSModel model) {
- setModel(model, true);
- }
-
- /**
- */
- protected void setModel(ICSSModel model, boolean setupListener) {
- ICSSModel oldModel = getExistingModel();
- if (model == oldModel)
- return;
- super.setModel(model);
- if (!setupListener)
- return;
- if (oldModel != null)
- oldModel.removeStyleListener(this);
- if (model != null)
- model.addStyleListener(this);
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleListener.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleListener.java
deleted file mode 100644
index 5dc6d51a58..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/StyleListener.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-/**
- */
-public interface StyleListener {
-
- /**
- */
- void styleChanged();
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLHelper.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLHelper.java
deleted file mode 100644
index 68559e3854..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLHelper.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-/**
- * @deprecated
- */
-public class URLHelper extends org.eclipse.wst.css.core.internal.util.URLHelper {
-
- /**
- * @param baseUrl
- */
- public URLHelper(String baseUrl) {
- super(baseUrl);
- }
-
- /**
- * @param baseUrl
- * @param docRoot
- */
- public URLHelper(String baseUrl, String docRoot) {
- super(baseUrl, docRoot);
- }
-
-}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLModelProvider.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLModelProvider.java
deleted file mode 100644
index 821b118efd..0000000000
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/htmlcss/URLModelProvider.java
+++ /dev/null
@@ -1,451 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.html.core.internal.htmlcss;
-
-
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.UnsupportedCharsetException;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.encoding.EncodingRule;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists;
-import org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse;
-import org.eclipse.wst.sse.core.internal.util.PathHelper;
-import org.eclipse.wst.sse.core.internal.util.ProjectResolver;
-import org.eclipse.wst.sse.core.internal.util.URIResolver;
-import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-// TODO when this class is removed from .core, PathHelper and URLHelper class
-// also can be removed.
-
-/**
- */
-public class URLModelProvider {
-
- private static final int GET_MODEL_FOR_READ = 1;
- // private static final int GET_NEW_MODEL_FOR_READ = 2;
- private static final int GET_MODEL_FOR_EDIT = 3;
- // private static final int GET_NEW_MODEL_FOR_EDIT = 4;
- // private static final int READ_BUFFER_SIZE = 4096;
- // IModelManager
- private IModelManager modelManager = null;
-
- /**
- */
- public URLModelProvider() {
- super();
-
- // obtain model manager
- modelManager = StructuredModelManager.getModelManager();
- }
-
- /**
- * Calculate ID from a filename. This must be same as
- * FileModelProvider.calculateId(IFile)
- */
- private static String calculateId(IPath fullIPath) {
- return fullIPath.toString();
- }
-
- /**
- * <code>baseModel</code>: the model containing the link
- * <code>ref</code>: the link URL string
- */
- private IStructuredModel getCommonModelFor(final IStructuredModel baseModel, final String ref, final int which) throws IOException {
- // first, create absolute url
- String absURL = resolveURI(baseModel, ref, true);
- if ((absURL == null) || (absURL.length() == 0)) {
- return null;
- }
-
- // need to remove file:// scheme if necessary
- try {
- final java.net.URL aURL = new java.net.URL(absURL);
- // An actual URL was given, only file:/// is supported
- // resolve it by finding the file it points to
- if (!aURL.getProtocol().equals("platform")) { //$NON-NLS-1$
- if (aURL.getProtocol().equals("file") && (aURL.getHost().equals("localhost") || aURL.getHost().length() == 0)) {//$NON-NLS-2$//$NON-NLS-1$
- absURL = aURL.getFile();
- final IPath ipath = new Path(absURL);
- // if path has a device, and if it begins with
- // IPath.SEPARATOR, remove it
- final String device = ipath.getDevice();
- if ((device != null) && (device.length() > 0)) {
- if (device.charAt(0) == IPath.SEPARATOR) {
- final String newDevice = device.substring(1);
- absURL = ipath.setDevice(newDevice).toString();
- }
- }
-
- }
- }
- }
- catch (java.net.MalformedURLException mfuExc) {
- }
-
-
- // next, decide project
- IProject project = null;
- final IPath fullIPath = new Path(absURL);
- IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
- IContainer container = workspace.getContainerForLocation(fullIPath);
- if (container != null) {
- // fullIPath doesn't exist in workspace
- project = container.getProject();
- }
-
- // If HTML document has a link to an extern CSS which is not in
- // IProject
- // workspace.getContainerForLoation() may return null. We need to take
- // care
- // of this case
-
- // now, get absURL's IFile
- if ((project != null) && (project.getLocation().isPrefixOf(fullIPath) == false)) {
- // it's at outside of Project
- return null;
- }
-
- IStructuredModel model = null;
- if (project != null) {
- IPath filePath = fullIPath.removeFirstSegments(project.getLocation().segmentCount());
- IFile file = (filePath != null && !filePath.isEmpty()) ? project.getFile(filePath) : null;
- if (file == null) {
- return null;
- }
-
- // obtain model
- if (which == GET_MODEL_FOR_EDIT) {
- model = getModelForEdit(file);
- }
- else if (which == GET_MODEL_FOR_READ) {
- model = getModelForRead(file);
- }
-
- // setting synchronization stamp is IModelManager's client's
- // responsibility
- if (model != null && model.getSynchronizationStamp() == IResource.NULL_STAMP)
- model.resetSynchronizationStamp(file);
- }
- else {
- String id = null;
- InputStream inStream = null;
- // obtain resolver
- URIResolver resolver = (project != null) ? (URIResolver) project.getAdapter(URIResolver.class) : null;
- if (resolver == null) {
- // ProjectResolver can take care of the case if project is
- // null.
- resolver = new ProjectResolver(project);
- }
- if (resolver == null) {
- return null;
- }
-
- // there is no project. we can't expect IProject help to create
- // id/inputStream
- java.io.File file = fullIPath.toFile();
-
- // obatin id
- id = calculateId(fullIPath);
-
- // obtain InputStream
- try {
- inStream = new FileInputStream(file);
- }
- catch (FileNotFoundException fnfe) {
- // the file does not exist, or we don't have read permission
- return null;
- }
-
- // obtain model
- try {
- if (which == GET_MODEL_FOR_EDIT) {
- model = getModelManager().getModelForEdit(id, inStream, resolver);
- }
- else if (which == GET_MODEL_FOR_READ) {
- model = getModelManager().getModelForRead(id, inStream, resolver);
- }
- }
- catch (UnsupportedEncodingException ue) {
- }
- catch (IOException ioe) {
- }
- finally {
- // close now !
- if (inStream != null) {
- inStream.close();
- }
- }
- }
-
-
- // set locationid
- if (model != null && model.getBaseLocation() == null) {
- model.setBaseLocation(fullIPath.toString());
- }
-
- return model;
- }
-
- /**
- * <code>baseModel</code>: the model containing the link
- * <code>ref</code>: the link URL string
- */
- public IStructuredModel getModelForEdit(IStructuredModel baseModel, String ref) throws IOException {
- return getCommonModelFor(baseModel, ref, GET_MODEL_FOR_EDIT);
- }
-
- /**
- */
- private IStructuredModel getModelForEdit(IFile file) throws IOException {
- if (file == null)
- return null;
- IModelManager manager = getModelManager();
-
- // create a fake InputStream
- IStructuredModel model = null;
- try {
- model = manager.getModelForEdit(file);
- }
- catch (UnsupportedCharsetException ex) {
- try {
- model = manager.getModelForEdit(file, EncodingRule.FORCE_DEFAULT);
- }
- catch (IOException ioe) {
- }
- catch (CoreException ce) {
- }
- }
- catch (CoreException ce) {
- }
- return model;
- }
-
- /**
- * <code>baseModel</code>: the model containing the link
- * <code>ref</code>: the link URL string
- */
- public IStructuredModel getModelForRead(IStructuredModel baseModel, String ref) throws UnsupportedEncodingException, IOException {
- return getCommonModelFor(baseModel, ref, GET_MODEL_FOR_READ);
- }
-
- /**
- */
- private IStructuredModel getModelForRead(IFile file) throws IOException {
- if (file == null)
- return null;
- IModelManager manager = getModelManager();
-
- // create a fake InputStream
- IStructuredModel model = null;
- try {
- model = manager.getModelForRead(file);
- }
- catch (UnsupportedCharsetException ex) {
- try {
- model = manager.getModelForRead(file, EncodingRule.FORCE_DEFAULT);
- }
- catch (IOException ioe) {
- }
- catch (CoreException ce) {
- }
- }
- catch (CoreException ce) {
- }
- return model;
- }
-
- /**
- */
- private IModelManager getModelManager() {
- return modelManager;
- }
-
- public IStructuredModel getNewModelForEdit(IFile iFile) {
- if (iFile == null)
- return null;
- IModelManager manager = getModelManager();
- if (manager == null)
- return null;
-
- IStructuredModel model = null;
- try {
- model = manager.getNewModelForEdit(iFile, false);
- }
- catch (IOException ex) {
- }
- catch (ResourceInUse riu) {
- }
- catch (ResourceAlreadyExists rae) {
- }
- catch (CoreException ce) {
- }
- return model;
- }
-
- public IStructuredModel getNewModelForRead(IFile iFile) {
- if (iFile == null)
- return null;
- IModelManager manager = getModelManager();
- if (manager == null)
- return null;
-
- IStructuredModel model = null;
- try {
- model = manager.getNewModelForEdit(iFile, false);
- }
- catch (IOException ex) {
- }
- catch (ResourceInUse riu) {
- }
- catch (ResourceAlreadyExists rae) {
- }
- catch (CoreException ce) {
- }
- return model;
- }
-
- /**
- * Utility to check the model is HTML family or not
- */
- static private boolean isHTMLFamily(IStructuredModel model) {
- if (model instanceof IDOMModel) {
- IDOMDocument document = ((IDOMModel) model).getDocument();
- DocumentTypeAdapter adapter = (DocumentTypeAdapter) document.getAdapterFor(DocumentTypeAdapter.class);
- if (adapter != null)
- return adapter.hasFeature(HTMLDocumentTypeConstants.HTML);
- }
- return false;
- }
-
- /**
- * <code>baseModel</code>: the model containing the link
- * <code>ref</code>: the link URL string
- * <code>resolveCrossProjectLinks</code>: If resolveCrossProjectLinks
- * is set to true, then this method will properly resolve the URI if it is
- * a valid URI pointing to another (appropriate) project.
- */
- public static String resolveURI(IStructuredModel baseModel, String ref, boolean resolveCrossProjectLinks) {
- if (baseModel == null)
- return null;
- // for HTML, 'href' attribute value of BASE element
- // should be used, if exists any
- String baseHref = null;
- // dmw_TODO needs to be changed to handle a content model
- // of HTML or XHTML
- if (isHTMLFamily(baseModel)) {
- final IDOMModel xmlmodel = (IDOMModel) baseModel;
- final IDOMDocument doc = xmlmodel.getDocument();
- // look for <BASE> w/ href
- final NodeList nl = doc.getElementsByTagName("BASE");//$NON-NLS-1$
- if ((nl != null) && (nl.getLength() > 0)) {
- // per each <BASE>
- for (int i = 0; i < nl.getLength(); i++) {
- final Node baseNode = nl.item(i);
- if (baseNode != null) {
- // get all attrs
- final NamedNodeMap attrNodes = baseNode.getAttributes();
- if (attrNodes != null) {
- final Node attrNode = attrNodes.getNamedItem("HREF");//$NON-NLS-1$
- if (attrNode != null) {
- // found href=""
- final String attrValue = attrNode.getNodeValue();
- if (attrValue != null) {
- baseHref = attrValue.trim();
- }
- }
- }
- }
- // what if there are multiple <BASE> tags ??
- if (baseHref != null) {
- break;
- }
- }
- }
- }
-
- // get resolver in Model
- final URIResolver resolver = baseModel.getResolver();
-
- // resolve to absolute url
- final String absurl = (resolver != null) ? ((baseHref != null) ? resolver.getLocationByURI(ref, baseHref, resolveCrossProjectLinks) : resolver.getLocationByURI(ref, resolveCrossProjectLinks)) : null;
- if ((resolver != null) && (absurl == null) && (ref != null) && (ref.trim().length() > 0) && (ref.trim().charAt(0) == '/')) {
- // to reach here means :
- // ref is a Docroot relative
- // resolver can't resolve ref
- // so that href is a broken and should not create model
- return null;
- }
- if ((absurl != null) && (absurl.length() > 0)) {
- return absurl;
- }
-
- // maybe ref is at outside of the Project
- // obtain docroot;
- final IContainer container = (resolver != null) ? resolver.getRootLocation() : null;
- String docroot = null;
- if (container != null) {
- IPath containerLocation = container.getLocation();
- if (containerLocation != null) {
- docroot = containerLocation.toString();
- }
- else if (container.getLocationURI() != null) {
- docroot = container.getLocationURI().toString();
- }
- }
- if (docroot == null) {
- docroot = baseModel.getBaseLocation();
- }
- if (docroot == null) {
- // should not be
- return null;
- }
-
- // obtain document url
- String modelBaseLocation = baseModel.getBaseLocation();
- if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
- // fallback...
- modelBaseLocation = baseModel.getId();
- }
- if ((modelBaseLocation == null) || (modelBaseLocation.length() == 0)) {
- // i can't resolve uri !
- return null;
- }
-
- // resolve url
- URLHelper helper = new URLHelper(PathHelper.getContainingFolderPath(modelBaseLocation), PathHelper.getContainingFolderPath(PathHelper.appendTrailingURLSlash(docroot)));
- return helper.toAbsolute(ref);
- }
-
-}
-

Back to the top