diff options
Diffstat (limited to 'jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument')
16 files changed, 0 insertions, 1705 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IDOMContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IDOMContextResolver.java deleted file mode 100644 index 4677bc851..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IDOMContextResolver.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument; - -import org.eclipse.jst.jsf.context.resolver.IDocumentContextResolver; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Defines a type of context resolver used to resolve the current context - * in the XML DOM context. - * - * This interface may be sub-classed or implemented by clients - * - * @author cbateman - * - */ -public interface IDOMContextResolver extends IDocumentContextResolver -{ - /** - * @return the complete DOM Document for this context or null if it - * cannot be resolved. - */ - Document getDOMDocument(); - - /** - * @return the node which the current context is pointing to. - * If document context is on an attribute will return that attribute - */ - Node getNode(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IMetadataContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IMetadataContextResolver.java deleted file mode 100644 index 12e9987cc..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IMetadataContextResolver.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument; - -import java.util.List; - -import org.eclipse.jst.jsf.context.resolver.IDocumentContextResolver; - -/** - * Resolves meta-data for a particular context - * - * This interface may sub-classed or implemented by clients - * - * @author cbateman - * - */ -public interface IMetadataContextResolver extends IDocumentContextResolver -{ - /** - * @param key - * @return a list of one or more String values associated with key - * for the current context location. - */ - List getPropertyValue(String key); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IStructuredDocumentContextResolverFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IStructuredDocumentContextResolverFactory.java deleted file mode 100644 index 1727b2f39..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IStructuredDocumentContextResolverFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument; - -import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver; -import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl.StructuredDocumentContextResolverFactory; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; - - -/** - * A factory for creating context resolvers that work with structured - * document contexts - * - * This factory may be used but not implemented or extended by clients. - * TODO: - * Note that getTextRegionResolver() will be moved to to an internal factory - * interface and should not be considered part of the provisional API - * - * @author cbateman - * - */ -public interface IStructuredDocumentContextResolverFactory -{ - - /** - * The global instance of the factory - */ - public static final IStructuredDocumentContextResolverFactory INSTANCE = StructuredDocumentContextResolverFactory.getInstance(); - - /** - * @param context - * @return a resolver capable of resolving information in context or null - * if one cannot be created. - */ - IDOMContextResolver getDOMContextResolver(IStructuredDocumentContext context); - - /** - * **Non-WTP Clients: this method should not be considered API** - * - * @param context - * @return a resolver capable of resolving information in the context or - * null if one cannot be created - */ - ITextRegionContextResolver getTextRegionResolver(IStructuredDocumentContext context); - - /** - * @param context - * @return a resolver capable of resolving information in the context or - * null if one cannot be created - */ - IWorkspaceContextResolver getWorkspaceContextResolver(IStructuredDocumentContext context); - - /** - * @param context - * @return a resolver capable of resolving information in the context - * or null one cannot be created - */ - ITaglibContextResolver getTaglibContextResolver(IStructuredDocumentContext context); - - /** - * @param context - * @return a resolver capable of resolving information in the context - * or null if one cannot be created - */ - IMetadataContextResolver getMetadataContextResolver(IStructuredDocumentContext context); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/ITaglibContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/ITaglibContextResolver.java deleted file mode 100644 index 34c4b6f6f..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/ITaglibContextResolver.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument; - -import org.eclipse.jst.jsf.context.resolver.IDocumentContextResolver; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Defines a context resolver that resolves tag library information - * for a particular context. - * - * This interface may be sub-classed or implemented by clients - * - * @author cbateman - * - */ -public interface ITaglibContextResolver extends IDocumentContextResolver -{ - /** - * @param node - * @return the URI corresponding to the taglib that defines the - * node in the context document or null if it cannot be found - */ - String getTagURIForNodeName(Node node); - - /** - * @param uri - * @return the tag prefix used in the context document for - * the provided uri or null if it cannot be found. - */ - String getTagPrefixForURI(String uri); - - /** - * A list all tags in the document context that are called - * tagName defined in the namespace indicated by uri - * - * @param uri - * @param tagName - * @return a (possibly empty) list of tags -- must never - * be null. Indicate none found with an empty list. - */ - NodeList getTagsByNamespaceURI(String uri, String tagName); - - /** - * @param node - * @return true if node has a tag library associated with it in this context - */ - public boolean hasTag(Node node); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IWorkspaceContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IWorkspaceContextResolver.java deleted file mode 100644 index 9a9f39994..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/IWorkspaceContextResolver.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.jst.jsf.context.resolver.IDocumentContextResolver; - -/** - * A resolver to determine the current context within the Eclipse - * workspace. - * - * This interface may be sub-classed or implemented by clients - * - * @author cbateman - * - */ -public interface IWorkspaceContextResolver extends IDocumentContextResolver -{ - /** - * @return the project that contains the document context - * or null if it cannot be determined - */ - IProject getProject(); - - /** - * @return the resource that contains the document context - * or null if it cannot be determined. - * This should normally be an IFile. - */ - IResource getResource(); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/IStructuredDocumentContextResolverFactory2.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/IStructuredDocumentContextResolverFactory2.java deleted file mode 100644 index c344ac384..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/IStructuredDocumentContextResolverFactory2.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal; - -import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory; -import org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; - -/** - * An additional factory interface for context resolvers. - * - * @author cbateman - * - */ -public interface IStructuredDocumentContextResolverFactory2 extends - IStructuredDocumentContextResolverFactory -{ - /** - * The global instance of the factory - */ - public static final IStructuredDocumentContextResolverFactory2 INSTANCE = - (IStructuredDocumentContextResolverFactory2) IStructuredDocumentContextResolverFactory.INSTANCE; - - /** - * Same as getTaglibContextResolver but checks delegate factory first. - * - * @param context - * @return a resolver capable of resolving information in the context - * or null one cannot be created - */ - ITaglibContextResolver getTaglibContextResolverFromDelegates(IStructuredDocumentContext context); - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ITextRegionContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ITextRegionContextResolver.java deleted file mode 100644 index aca84351e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ITextRegionContextResolver.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal; - -import org.eclipse.jst.jsf.context.resolver.IDocumentContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; - -/** - * Defines a resolver that can resolve context information in the - * structured document region context. - * - * Unless otherwise stated, the context region is the most specific - * region (leaf) in which the current context is contained. - * - * Note: this interface may use internal/provisional types. - * - * @author cbateman - * - */ -public interface ITextRegionContextResolver extends IDocumentContextResolver -{ - /** - * @return the text for the context region - */ - String getRegionText(); - - /** - * @return the document relative offset of the start of the region - * in which the context in is contained or -1 if the offset cannot be determined. - */ - int getStartOffset(); - - /** - * @return the document relative offset of the end of the region - * in which the context is contained or -1 if the offset cannot be determined - */ - int getEndOffset(); - - /** - * @return the length of the most specific region in which the context - * is contained or -1 if the length cannot be determined. - */ - int getLength(); - - /** - * @return the most specific TextRegion type for the current context - */ - String getRegionType(); - - /** - * @return the path to the most specific TextRegtion for the current context - * note that this does not include the actual region for the current region. - * That is returned by getRegionType(). - * - */ - String[] getRegionTypePath(); - - - /** - * The offset into the structured document will be set to be - * the start offset of the previous region - * - * @return a context for the previous sibling of this context's - * text region parent or null if no previous sibling exists - */ - IStructuredDocumentContext getPreviousContext(); - - /** - * The offset into the structured document will be set to be - * the start offset of the next region - * - * @return a context for the next sibling of this context's - * text region parent or null if no next sibling exists - */ - IStructuredDocumentContext getNextContext(); - - /** - * Relative path works backwards from the current context. So if the - * path to current context is /a/b/c/d/e then: - * - * matchesRelative({"e"}) == true - * matchesRelative({"d", "e"}) == true - * matchesRelative({"c", "d", "e"}) == true - * matchesRelative({"b", "c", "d", "e"}) == true - * matchesRelative({"a", "b", "c", "d", "e"}) == true - * - * because in every case the path matches working backward from the current - * context - * - * but - * - * matchesRelative({a}) == false because context/.. == e not a - * - * TODO: what does path = new String[0] mean? - * - * @param path - * @return true if the relative path matches the path to the current context - * working relative to the current context. - */ - boolean matchesRelative(String[] path); - - /** - * Absolute path works forward from the root of the document to the - * current context. So if the path to the current context is /a/b/c/d/e then: - * - * matchesAbsolute({"a", "b", "c", "d", "e"}) == true - * - * but - * - * matchesAbsolute({"b", "c", "d", "e"}) == true because starting from the root - * you cannot follow /b/c/d/e to the context. - * - * @param path - * @return true if the absolute path from the root of the document - * matches the current context - */ - boolean matchesAbsolute(String[] path); -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ResolverUtil.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ResolverUtil.java deleted file mode 100644 index fda4dbc56..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/ResolverUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 Oracle 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: - * Oracle Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IWorkspaceContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory; - -/** - * Internal convenience class to simplify regularly repeated tasks - * @author cbateman - * - */ -public final class ResolverUtil -{ - /** - * This method will generally only work if the document is an - * IStructuredDocument. - * - * @param document - * @return the IFile corresponding to document or null if not applicable. - * - */ - public static IFile getFileForDocument(final IDocument document) - { - final IStructuredDocumentContext context = - IStructuredDocumentContextFactory.INSTANCE.getContext(document, - -1); - - if (context != null) - { - final IWorkspaceContextResolver wkResolver = - IStructuredDocumentContextResolverFactory.INSTANCE - .getWorkspaceContextResolver(context); - - if (wkResolver != null) - { - final IResource res = wkResolver.getResource(); - - if (res instanceof IFile) - { - return (IFile) res; - } - } - } - return null; - } - - private ResolverUtil() - { - // no instantiation - throw new UnsupportedOperationException(); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/DOMContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/DOMContextResolver.java deleted file mode 100644 index 76d75938c..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/DOMContextResolver.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -import org.eclipse.jst.jsf.context.IModelContext; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Resolves DOM-related information in the provided context - * - * @author cbateman - * - */ -class DOMContextResolver implements IDOMContextResolver -{ - private final IStructuredDocumentContext _context; - //private ITextRegionContextResolver _regionResolver; // null; lazy initialized if needed - - DOMContextResolver(IStructuredDocumentContext context) - { - _context = context; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver#getDOMDocument() - */ - public Document getDOMDocument() - { - return StructuredDocumentResolverUtil.getDOMDocument((IStructuredDocument)_context.getStructuredDocument()); - } - - public Node getNode() - { - IndexedRegion region = StructuredDocumentResolverUtil.getIndexedRegion((IStructuredDocument) _context.getStructuredDocument(), _context.getDocumentPosition()); - - if (region instanceof Node) - { - return (Node) region; - } - - return null; - } - - - public boolean canResolveContext(IModelContext modelContext) - { - return modelContext.getAdapter(IStructuredDocumentContext.class) != null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/MetadataContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/MetadataContextResolver.java deleted file mode 100644 index 495589f86..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/MetadataContextResolver.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jst.jsf.common.metadata.Trait; -import org.eclipse.jst.jsf.common.metadata.internal.TraitValueHelper; -import org.eclipse.jst.jsf.common.metadata.query.ITaglibDomainMetaDataModelContext; -import org.eclipse.jst.jsf.common.metadata.query.TaglibDomainMetaDataQueryHelper; -import org.eclipse.jst.jsf.context.IModelContext; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IMetadataContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * A default implementation of meta-data context resolver - * - * @author cbateman - * - */ -class MetadataContextResolver implements IMetadataContextResolver -{ - private final IStructuredDocumentContext _context; - - /** - * @param context - */ - public MetadataContextResolver(IStructuredDocumentContext context) - { - _context = context; - } - - public List getPropertyValue(final String key) - { - final DOMContextResolver domResolver = new DOMContextResolver(_context); - final WorkspaceContextResolver wsResolver = new WorkspaceContextResolver(_context); - final TaglibContextResolver tagResolver = - new TaglibContextResolver(_context); - - final Node curNode = domResolver.getNode(); - - if (curNode instanceof Attr) - { - final Attr attribute = (Attr) curNode; - final Element element = attribute.getOwnerElement(); - final String uri = tagResolver.getTagURIForNodeName(element); - final IProject project = wsResolver.getProject(); - - final ITaglibDomainMetaDataModelContext mdContext = TaglibDomainMetaDataQueryHelper.createMetaDataModelContext(project, uri); - Trait trait = TaglibDomainMetaDataQueryHelper.getTrait(mdContext, element.getLocalName()+"/"+attribute.getLocalName(), key); //$NON-NLS-1$ - if( trait != null ) - { - return TraitValueHelper.getValueAsListOfStrings(trait); - } - - } - else if (curNode instanceof Element) - { - final Element element = (Element) curNode; - final String uri = tagResolver.getTagURIForNodeName(element); - final IProject project = wsResolver.getProject(); - - final ITaglibDomainMetaDataModelContext mdContext = TaglibDomainMetaDataQueryHelper.createMetaDataModelContext(project, uri); - Trait trait = TaglibDomainMetaDataQueryHelper.getTrait(mdContext, element.getLocalName(), key); - if( trait != null ) - { - return TraitValueHelper.getValueAsListOfStrings(trait); - } - } - - return Collections.EMPTY_LIST; - } - - public boolean canResolveContext(IModelContext modelContext) { - return (modelContext.getAdapter(IStructuredDocumentContext.class) != null); - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java deleted file mode 100644 index 2b0cf8ad3..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentContextResolverFactory.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jst.jsf.context.AbstractDelegatingFactory; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IMetadataContextResolver; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory; -import org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IWorkspaceContextResolver; -import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.IStructuredDocumentContextResolverFactory2; -import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * Implements a factory for creating context resolvers for structured document - * contexts. - * - * @author cbateman - * - */ -public class StructuredDocumentContextResolverFactory extends -AbstractDelegatingFactory implements -IStructuredDocumentContextResolverFactory, IStructuredDocumentContextResolverFactory2 -{ - /* static attributes */ - private static StructuredDocumentContextResolverFactory INSTANCE; - - /** - * @return an instance (possibly shared) of the this factory - */ - public synchronized static StructuredDocumentContextResolverFactory getInstance() - { - if (INSTANCE == null) - { - INSTANCE = new StructuredDocumentContextResolverFactory(); - } - - return INSTANCE; - } - - /** - * Constructor - */ - protected StructuredDocumentContextResolverFactory() - { - super(new Class[] - { IStructuredDocumentContextResolverFactory.class }); - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory#getDOMContextResolver(org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext) - */ - public IDOMContextResolver getDOMContextResolver( - final IStructuredDocumentContext context) - { - IDOMContextResolver resolver = internalGetDOMResolver(context); - - if (resolver == null) - { - resolver = delegateGetDOMResolver(context); - } - - return resolver; - } - - private IDOMContextResolver internalGetDOMResolver( - final IStructuredDocumentContext context) - { - if (context.getStructuredDocument() instanceof IStructuredDocument) - { - return new DOMContextResolver(context); - } - - return null; - } - - private IDOMContextResolver delegateGetDOMResolver( - final IStructuredDocumentContext context) - { - synchronized (_delegates) - { - for (final IAdaptable adaptable : _delegates) - { - - final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) adaptable - .getAdapter(IStructuredDocumentContextResolverFactory.class); - - if (delegateFactory != null) - { - final IDOMContextResolver contextResolver = delegateFactory - .getDOMContextResolver(context); - - if (contextResolver != null) - { - return contextResolver; - } - } - } - - return null; - } - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory#getTextRegionResolver(org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext) - */ - public ITextRegionContextResolver getTextRegionResolver( - final IStructuredDocumentContext context) - { - ITextRegionContextResolver resolver = internalGetTextRegionResolver(context); - - if (resolver == null) - { - resolver = delegateGetTextRegionResolver(context); - } - - return resolver; - } - - private ITextRegionContextResolver internalGetTextRegionResolver( - final IStructuredDocumentContext context) - { - if (context.getStructuredDocument() instanceof IStructuredDocument) - { - return new TextRegionContextResolver(context); - } - - return null; - } - - private ITextRegionContextResolver delegateGetTextRegionResolver( - final IStructuredDocumentContext context) - { - synchronized (_delegates) - { - for (final Object element : _delegates) - { - final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element) - .getAdapter(IStructuredDocumentContextResolverFactory.class); - final ITextRegionContextResolver contextResolver = delegateFactory - .getTextRegionResolver(context); - - if (contextResolver != null) - { - return contextResolver; - } - } - - return null; - } - } - - public IWorkspaceContextResolver getWorkspaceContextResolver( - final IStructuredDocumentContext context) - { - IWorkspaceContextResolver resolver = internalGetWorkspaceContextResolver(context); - - if (resolver == null) - { - resolver = delegateGetWorkspaceContextResolver(context); - } - - return resolver; - - } - - private IWorkspaceContextResolver internalGetWorkspaceContextResolver( - final IStructuredDocumentContext context) - { - if (context.getStructuredDocument() instanceof IStructuredDocument) - { - return new WorkspaceContextResolver(context); - } - - return null; - } - - private IWorkspaceContextResolver delegateGetWorkspaceContextResolver( - final IStructuredDocumentContext context) - { - synchronized (_delegates) - { - for (final Object element : _delegates) - { - final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element) - .getAdapter(IStructuredDocumentContextResolverFactory.class); - final IWorkspaceContextResolver contextResolver = delegateFactory - .getWorkspaceContextResolver(context); - - if (contextResolver != null) - { - return contextResolver; - } - } - - return null; - } - } - - public ITaglibContextResolver getTaglibContextResolver( - final IStructuredDocumentContext context) - { - // check the delegats first - ITaglibContextResolver resolver = internalGetTaglibContextResolver(context); - - if (resolver == null) - { - resolver = delegateGetTaglibContextResolver(context); - } - - return resolver; - } - - public ITaglibContextResolver getTaglibContextResolverFromDelegates( - final IStructuredDocumentContext context) - { - // check the delegats first - ITaglibContextResolver resolver = delegateGetTaglibContextResolver(context); - - if (resolver == null) - { - resolver = internalGetTaglibContextResolver(context); - } - - return resolver; - } - - private ITaglibContextResolver internalGetTaglibContextResolver( - final IStructuredDocumentContext context) - { - if (context.getStructuredDocument() instanceof IStructuredDocument) - { - return new TaglibContextResolver(context); - } - - return null; - } - - private ITaglibContextResolver delegateGetTaglibContextResolver( - final IStructuredDocumentContext context) - { - synchronized (_delegates) - { - for (final IAdaptable adapter : _delegates) - { - final IStructuredDocumentContextResolverFactory delegateFactory = - (IStructuredDocumentContextResolverFactory) adapter - .getAdapter(IStructuredDocumentContextResolverFactory.class); - - if (delegateFactory != null) - { - final ITaglibContextResolver contextResolver = delegateFactory - .getTaglibContextResolver(context); - - if (contextResolver != null) - { - return contextResolver; - } - } - } - - return null; - } - } - - public IMetadataContextResolver getMetadataContextResolver( - final IStructuredDocumentContext context) - { - IMetadataContextResolver resolver = internalGetMetadataContextResolver(context); - - if (resolver == null) - { - resolver = delegateGetMetadataContextResolver(context); - } - - return resolver; - } - - private IMetadataContextResolver internalGetMetadataContextResolver( - final IStructuredDocumentContext context) - { - if (context.getStructuredDocument() instanceof IStructuredDocument) - { - return new MetadataContextResolver(context); - } - - return null; - } - - private IMetadataContextResolver delegateGetMetadataContextResolver( - final IStructuredDocumentContext context) - { - synchronized (_delegates) - { - for (final Object element : _delegates) - { - final IStructuredDocumentContextResolverFactory delegateFactory = (IStructuredDocumentContextResolverFactory) ((IAdaptable) element) - .getAdapter(IStructuredDocumentContextResolverFactory.class); - final IMetadataContextResolver contextResolver = delegateFactory - .getMetadataContextResolver(context); - - if (contextResolver != null) - { - return contextResolver; - } - } - - return null; - } - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentResolverUtil.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentResolverUtil.java deleted file mode 100644 index 9a4a780ac..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/StructuredDocumentResolverUtil.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -import org.eclipse.wst.sse.core.StructuredModelManager; -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.IndexedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; -import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * @author cbateman - * - * Defines common utility methods for document resolvers - */ -final class StructuredDocumentResolverUtil -{ - static IDOMDocument getDOMDocument(IStructuredDocument document) - { - IStructuredModel model = getStructuredModel(document); - - try - { - if (model instanceof IDOMModel) - { - return ((IDOMModel)model).getDocument(); - } - } - finally - { - if (model != null) - { - model.releaseFromRead(); - } - } - - return null; - } - - static IndexedRegion getIndexedRegion(final IStructuredDocument document, final int documentOffset) - { - // C.B: most of this logic was copied from ContentAssistUtils.getNodeAt - // I chose to copy rather than just call that because ContentAssistUtils is - // internal - IStructuredModel model = getStructuredModel(document); - IndexedRegion region = null; - if (model != null) - { - try - { - int lastOffset = documentOffset; - region = model.getIndexedRegion(documentOffset); - while (region == null && lastOffset >= 0) { - lastOffset--; - region = model.getIndexedRegion(lastOffset); - } - - // now we assume we have an element. But our context may be - // on an attribute in that node, so we need to check - if (region instanceof IDOMElement) - { - IDOMElement domElement = (IDOMElement) region; - - NamedNodeMap attributes = domElement.getAttributes(); - - for (int i = 0; i < attributes.getLength(); i++) - { - Node attrNode = attributes.item(i); - - if (attrNode instanceof IDOMAttr) - { - IDOMAttr attr = (IDOMAttr) attrNode; - - if (documentOffset >= attr.getStartOffset() - && documentOffset < attr.getEndOffset()) - { - region = attr; - break; - } - } - } - } - } - finally - { - model.releaseFromRead(); - } - } - - return region; - } - - /** - * @param document - * @return a structured model or null if one cannot be opened for document. - * Note: the caller is responsible for releasing the instance of structured - * model that gets returned. - */ - private static IStructuredModel getStructuredModel(IStructuredDocument document) - { - IModelManager modelManager = StructuredModelManager.getModelManager(); - - if (modelManager != null) - { - return StructuredModelManager.getModelManager().getModelForRead(document); - } - - return null; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TaglibContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TaglibContextResolver.java deleted file mode 100644 index 16fb2fc9e..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TaglibContextResolver.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -import java.util.Iterator; - -import org.eclipse.jst.jsf.common.internal.JSPUtil; -import org.eclipse.jst.jsf.context.IModelContext; -import org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * TODO: this resolver only applies to structured documents that can have - * taglibs (I think only JSPs). Should we move a different package? - * Default taglib context resolver - * - * @author cbateman - * - */ -class TaglibContextResolver implements ITaglibContextResolver -{ - private final IStructuredDocumentContext _context; - - TaglibContextResolver(IStructuredDocumentContext context) - { - _context = context; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver#getTagPrefixForURI(java.lang.String) - */ - public String getTagPrefixForURI(String uri) - { - return null; - } - - public boolean hasTag(final Node node) - { - Node checkNode = node; - - if (node instanceof Attr) - { - checkNode = ((Attr)node).getOwnerElement(); - } - - return getTracker(checkNode) != null; - } - - private TaglibTracker getTracker(Node node) - { - final String prefix = node.getPrefix(); - - final TLDCMDocumentManager docMgr = - TaglibController.getTLDCMDocumentManager(_context.getStructuredDocument()); - - // if there's no prefix, there's no way to id the tag library - // TODO: is this always true? need to consult spec - // similar problem if couldn't load docMgr - if (prefix == null - || docMgr == null) - { - return null; - } - - for (final Iterator it = docMgr.getTaglibTrackers().iterator(); it.hasNext();) - { - final TaglibTracker tracker = (TaglibTracker) it.next(); - - if (prefix.equals(tracker.getPrefix())) - { - return tracker; - } - } - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver#getTagURIForNodeName(org.w3c.dom.Node) - */ - public String getTagURIForNodeName(final Node node) - { - Node checkNode = node; - - if (node instanceof Attr) - { - checkNode = ((Attr)node).getOwnerElement(); - } - - final TaglibTracker tracker = getTracker(checkNode); - - if (tracker != null) - { - return tracker.getURI(); - } - - - return null; - } - - - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.ITaglibContextResolver#getTagsByNamespaceURI(java.lang.String, java.lang.String) - */ - public NodeList getTagsByNamespaceURI(String uri, String tagName) - { - //Document domDoc = new DOMContextResolver(_context).getDOMDocument(); - return null; - - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsf.context.resolver.IContextResolver#canResolveContext(org.eclipse.jst.jsf.context.IModelContext) - */ - public boolean canResolveContext(IModelContext modelContext) - { - // must be a JSP page - Object adapter = modelContext.getAdapter(IStructuredDocumentContext.class); - - if (adapter instanceof IStructuredDocumentContext) - { - IStructuredDocumentContext context = - (IStructuredDocumentContext) adapter; - IStructuredModel smodel = null; - - try - { - smodel = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument)context.getStructuredDocument()); - return JSPUtil.isJSPContentType(smodel.getContentTypeIdentifier()); //$NON-NLS-1$ - } - finally - { - if (smodel != null) - { - smodel.releaseFromRead(); - } - } - } - - return false; - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TextRegionContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TextRegionContextResolver.java deleted file mode 100644 index 9cf0f218b..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/TextRegionContextResolver.java +++ /dev/null @@ -1,295 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jst.jsf.context.IModelContext; -import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; - -/*package*/ class TextRegionContextResolver implements ITextRegionContextResolver { - - private final IStructuredDocumentContext _context; - - /*package*/ TextRegionContextResolver(IStructuredDocumentContext context) - { - _context = context; - } - - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getRegionText() - */ - public String getRegionText() - { - final ITextRegionCollection parent = getParentRegion(); - String text = null; - - if (parent != null) - { - ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - text = parent.getText(me); - } - - return text; - } - - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getEndOffset() - */ - public int getEndOffset() { - final ITextRegionCollection parent = getParentRegion(); - int endOffset = -1; - if (parent != null) - { - ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - endOffset = parent.getEndOffset(me); - } - - return endOffset; - } - - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getLength() - */ - public int getLength() { - final ITextRegionCollection parent = getParentRegion(); - int length = -1; - if (parent != null) - { - ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - length = me.getLength(); - } - - return length; - - } - - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getStartOffset() - */ - public int getStartOffset() - { - final ITextRegionCollection parent = getParentRegion(); - int startOffset = -1; - if (parent != null) - { - ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - startOffset = parent.getStartOffset(me); - } - - return startOffset; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getRegionType() - */ - public String getRegionType() - { - final ITextRegionCollection parent = getParentRegion(); - String regionType = null; - - if (parent != null) - { - ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - - if (me != null) - { - regionType = me.getType(); - } - } - - return regionType; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getRegionTypePath() - */ - public String[] getRegionTypePath() { - final ITextRegion[] path = createPathToContext(); - final String[] typePath = new String[path.length]; - - for (int i = 0; i < path.length; i++) - { - typePath[i] = path[i].getType(); - } - - return typePath; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getNextContext() - */ - public IStructuredDocumentContext getNextContext() - { - ITextRegionCollection parent = getParentRegion(); - IStructuredDocumentContext newContext = null; - - if (parent != null) - { - final ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - ITextRegionList regions = parent.getRegions(); - ITextRegion nextRegion = null; - for (final Iterator it = regions.iterator(); it.hasNext();) - { - if (it.next() == me - && it.hasNext()) - { - nextRegion = (ITextRegion) it.next(); - } - } - - if (nextRegion != null) - { - // use the first position offset in the next region - final int documentPosition = parent.getStartOffset(nextRegion); - newContext = - IStructuredDocumentContextFactory.INSTANCE.getContext(_context.getStructuredDocument(), documentPosition); - } - } - - return newContext; - } - - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#getPreviousContext() - */ - public IStructuredDocumentContext getPreviousContext() - { - ITextRegionCollection parent = getParentRegion(); - IStructuredDocumentContext newContext = null; - - if (parent != null) - { - final ITextRegion me = parent.getRegionAtCharacterOffset(_context.getDocumentPosition()); - ITextRegionList regions = parent.getRegions(); - final Iterator it = regions.iterator(); - ITextRegion prevRegion = null; - ITextRegion nextRegion = null; - - SEARCH_LOOP: while (it.hasNext()) - { - nextRegion = (ITextRegion) it.next(); - - if (nextRegion == me) - { - break SEARCH_LOOP; - } - - prevRegion = nextRegion; - } - - if (prevRegion != null) - { - // use the last position offset in the prev region - final int documentPosition = parent.getStartOffset(prevRegion); - newContext = - IStructuredDocumentContextFactory.INSTANCE.getContext(_context.getStructuredDocument(), documentPosition); - } - } - - return newContext; - } - - private ITextRegionCollection getParentRegion() - { - final ITextRegion[] path = createPathToContext(); - ITextRegionCollection parent = null; - - if (path.length > 0) - { - parent = (ITextRegionCollection) path[path.length-1]; - } - - return parent; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#matchesRelative(java.lang.String[]) - */ - public boolean matchesRelative(String[] path) { - final ITextRegion[] myPath = createPathToContext(); - return matchPath(myPath, path); - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver#matchesAbsolute(java.lang.String[]) - */ - public boolean matchesAbsolute(String[] path) - { - final ITextRegion[] myPath = createPathToContext(); - // only works if myPath and path are the same length - return (myPath.length == path.length) - && matchPath(myPath, path); - } - - private boolean matchPath(ITextRegion[] myPath, String[] path) - { - boolean matches = false; - - // only makes sense if path is a containing subset of myPath - if (path.length <= myPath.length) - { - matches = true; - SEARCH_LOOP: - for (int i = 1; i <= path.length; i++) - { - if (!path[path.length-i].equals(myPath[myPath.length-i].getType())) - { - matches = false; - break SEARCH_LOOP; - } - } - } - - return matches; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.IContextResolver#canResolveContext(org.eclipse.jst.jsf.context.IModelContext) - */ - public boolean canResolveContext(IModelContext modelContext) - { - return (modelContext.getAdapter(IStructuredDocumentContext.class) != null); - } - - private ITextRegion[] createPathToContext() - { - final List regionPath = new ArrayList(); - - final IStructuredDocument doc = (IStructuredDocument) _context.getStructuredDocument(); - - ITextRegion container = doc.getRegionAtCharacterOffset(_context.getDocumentPosition()); - - while(container != null - && container instanceof ITextRegionCollection) - { - regionPath.add(container); - container = ((ITextRegionCollection)container).getRegionAtCharacterOffset(_context.getDocumentPosition()); - } - - return (ITextRegion[]) regionPath.toArray(new ITextRegion[0]); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/WorkspaceContextResolver.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/WorkspaceContextResolver.java deleted file mode 100644 index cb6363065..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/internal/impl/WorkspaceContextResolver.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Cameron Bateman/Oracle - initial API and implementation - * - ********************************************************************************/ - -package org.eclipse.jst.jsf.context.resolver.structureddocument.internal.impl; - -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.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.jsf.context.IModelContext; -import org.eclipse.jst.jsf.context.resolver.structureddocument.IWorkspaceContextResolver; -import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; - -/** - * - * @author cbateman - * - */ -/*package*/ class WorkspaceContextResolver implements IWorkspaceContextResolver -{ - private final IStructuredDocumentContext _context; - - /*package*/WorkspaceContextResolver(IStructuredDocumentContext context) - { - _context = context; - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.structureddocument.IWorkspaceContextResolver#getProject() - */ - public IProject getProject() - { - // copied from ModelManagerImpl (with some rework by C.B.) - final String path = getPath(); - - if (path == null) - { - return null; - } - - // TOODO needs rework for linked resources - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IPath iPath = new Path(path); - if (iPath.isAbsolute()) - { - String projectName = iPath.segment(0); - - IProject projects[] = root.getProjects(); - - for (int i = 0; i < projects.length; i++) - { - IProject project = projects[i]; - - if (project.isOpen() - && projectName.equals(project.getFullPath().segment(0))) - { - return project; // - } - } - } - - return null; - } - - public IResource getResource() - { - IProject project = getProject(); - - if (project != null) - { - final String path = getPath(); - - if (path != null) - { - final IPath iPath = new Path(path); - if (iPath.isAbsolute()) - { - return project.getFile(iPath.removeFirstSegments(1)); - } - } - } - return null; - } - - private String getPath() - { - IStructuredModel model = null; - - try - { - model = StructuredModelManager.getModelManager().getExistingModelForRead(_context.getStructuredDocument()); - - if (model == null) - return null; - String path = model.getBaseLocation(); - if (path == null || path.length() == 0) - { - Object id = model.getId(); - if (id == null) - return null; - path = id.toString(); - } - - return path; - } - finally - { - if (model != null) - { - model.releaseFromRead(); - } - } - } - - /** - * @see org.eclipse.jst.jsf.context.resolver.IContextResolver#canResolveContext(org.eclipse.jst.jsf.context.IModelContext) - */ - public boolean canResolveContext(IModelContext modelContext) - { - return (modelContext.getAdapter(IStructuredDocumentContext.class) != null); - } -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/package-info.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/package-info.java deleted file mode 100644 index 538982108..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/context/resolver/structureddocument/package-info.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle Corporation. - * 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: - * Oracle - initial API and implementation - * - ********************************************************************************/ - -/** - * Context resolvers for contexts based on SSE structured documents. - */ -package org.eclipse.jst.jsf.context.resolver.structureddocument; |