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.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon')
-rw-r--r--bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java308
-rw-r--r--bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java277
2 files changed, 0 insertions, 585 deletions
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java
deleted file mode 100644
index d26d64bacf..0000000000
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.jst.jsp.ui.openon;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jst.jsp.core.JSP11Namespace;
-import org.eclipse.jst.jsp.core.contentmodel.ITaglibRecord;
-import org.eclipse.jst.jsp.core.contentmodel.JarRecord;
-import org.eclipse.jst.jsp.core.contentmodel.TLDRecord;
-import org.eclipse.jst.jsp.core.contentmodel.TaglibIndex;
-import org.eclipse.jst.jsp.core.contentmodel.URLRecord;
-import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation;
-import org.eclipse.jst.jsp.core.internal.java.JSPTranslation;
-import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter;
-import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-import org.eclipse.ui.IStorageEditorInput;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
-import org.eclipse.wst.html.ui.openon.DefaultOpenOnHTML;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.xml.core.document.XMLDocument;
-import org.eclipse.wst.xml.core.document.XMLModel;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-/**
- * This action opens classes referenced in JSP directive tags of a JSP page.
- */
-public class JSPDirectiveOpenOnJSP extends DefaultOpenOnHTML {
- JSPJavaOpenOnJSP jspJavaOpenOn;
-
- static class StorageEditorInput implements IStorageEditorInput {
- IStorage fStorage = null;
-
- StorageEditorInput(IStorage storage) {
- fStorage = storage;
- }
-
- public IStorage getStorage() throws CoreException {
- return fStorage;
- }
-
- public boolean exists() {
- return fStorage != null;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return fStorage.getName();
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return fStorage.getFullPath().toString();
- }
-
- public Object getAdapter(Class adapter) {
- return null;
- }
- }
-
- static class ZipStorage implements IStorage {
- File fFile = null;
- String fEntryName = null;
- String fTitle = null;
-
- ZipStorage(File file, String entryName, String title) {
- fFile = file;
- fEntryName = entryName;
- fTitle = title;
- }
-
- public InputStream getContents() throws CoreException {
- InputStream stream = null;
- try {
- ZipFile file = new ZipFile(fFile);
- ZipEntry entry = file.getEntry(fEntryName);
- stream = file.getInputStream(entry);
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, fTitle, e));
- }
- return stream;
- }
-
- public IPath getFullPath() {
- return new Path(fFile.getAbsolutePath() + IPath.SEPARATOR + fEntryName);
- }
-
- public String getName() {
- return fEntryName;
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- public Object getAdapter(Class adapter) {
- return null;
- }
- }
-
- static class URLStorage implements IStorage {
- URL fURL = null;
-
- URLStorage(URL url) {
- fURL = url;
- }
-
- public InputStream getContents() throws CoreException {
- InputStream stream = null;
- try {
- stream = fURL.openStream();
- }
- catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, fURL.toString(), e));
- }
- return stream;
- }
-
- public IPath getFullPath() {
- return new Path(fURL.toString());
- }
-
- public String getName() {
- return new Path(fURL.getFile()).lastSegment();
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- public Object getAdapter(Class adapter) {
- return null;
- }
-
- }
-
- private JSPJavaOpenOnJSP getJSPJavaOpenOn() {
- if (jspJavaOpenOn == null) {
- jspJavaOpenOn = new JSPJavaOpenOnJSP();
- // set the document to current document
- jspJavaOpenOn.setDocument(getDocument());
- }
- return jspJavaOpenOn;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.sse.editor.openon.AbstractOpenOn#setDocument(org.eclipse.jface.text.IDocument)
- */
- public void setDocument(IDocument doc) {
- super.setDocument(doc);
-
- // also set the document for jspJavaOpenOn
- if (jspJavaOpenOn != null) {
- jspJavaOpenOn.setDocument(doc);
- }
- }
-
- /**
- * Get JSP translation object
- *
- * @return JSPTranslation if one exists, null otherwise
- */
- private JSPTranslation getJSPTranslation() {
- // get JSP translation object for this action's editor's document
- XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- if (xmlModel != null) {
- XMLDocument xmlDoc = xmlModel.getDocument();
- xmlModel.releaseFromRead();
- JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
- if (adapter != null) {
- return adapter.getJSPTranslation();
- }
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.sse.editor.AbstractOpenOn#doOpenOn(org.eclipse.jface.text.IRegion)
- */
- protected void doOpenOn(IRegion region) {
- boolean opened = false;
- IRegion newRegion = doGetOpenOnRegion(region.getOffset());
- // if there is a corresponding Java source offset, then use
- // JSPJavaOpenOnJSP
- JSPTranslation jspTranslation = getJSPTranslation();
- if ((jspTranslation != null) && (newRegion != null) && (jspTranslation.getJavaOffset(newRegion.getOffset()) > -1)) {
- getJSPJavaOpenOn().doOpenOn(newRegion);
- opened = true;
- }
-
- // check servlet and taglib mappings
- if (!opened) {
- Node current = getCurrentNode(newRegion.getOffset());
- if (current.getNodeType() == Node.ELEMENT_NODE) {
- Attr attr = getLinkableAttr((Element) current);
- if (attr != null) {
- ITaglibRecord reference = TaglibIndex.resolve(getBaseLocation(), attr.getValue(), false);
- if (reference != null) {
- try {
- switch (reference.getRecordType()) {
- case (ITaglibRecord.TLD) : {
- TLDRecord record = (TLDRecord) reference;
- openFileInEditor(record.getLocation().toString());
- opened = true;
- }
- break;
- case (ITaglibRecord.JAR) : {
- JarRecord record = (JarRecord) reference;
- IEditorInput input = new StorageEditorInput(new ZipStorage(record.getLocation().toFile(), "META-INF/taglib.tld", record.getLocation().toString()));
- IEditorDescriptor editor = IDE.getEditorDescriptor(input.getName());
- if (editor != null) {
- IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, editor.getId(), true);
- opened = true;
- }
- }
- break;
- case (ITaglibRecord.URL) : {
- URLRecord record = (URLRecord) reference;
- IEditorInput input = new StorageEditorInput(new URLStorage(record.getURL()));
- IEditorDescriptor editor = IDE.getEditorDescriptor(input.getName());
- if (editor != null) {
- IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, editor.getId(), true);
- opened = true;
- }
- }
- }
- }
- catch (Exception e) {
- openFileFailed();
- }
- }
- }
- }
- }
-
- if (!opened)
- super.doOpenOn(newRegion);
- }
-
- /**
- * Return an attr of element that is of type URI if one exists. or if
- * element is jsp:usebean return the type or class attribute. null
- * otherwise.
- *
- * @param element -
- * cannot be null
- * @return Attr
- */
- protected Attr getLinkableAttr(Element element) {
- String tagName = element.getTagName();
-
- // usebean
- if (JSP11Namespace.ElementName.USEBEAN.equalsIgnoreCase(tagName)) {
- // get the list of attributes for this node
- NamedNodeMap attrs = element.getAttributes();
- for (int i = 0; i < attrs.getLength(); ++i) {
- Attr att = (Attr) attrs.item(i);
- String attName = att.getName();
- // look for the type or class attribute
- if ((JSP11Namespace.ATTR_NAME_TYPE.equalsIgnoreCase(attName)) || (JSP11Namespace.ATTR_NAME_CLASS.equalsIgnoreCase(attName))) {
- return att;
- }
- }
- }
-
- // otherwise, just look for attribute value of type URI
- return super.getLinkableAttr(element);
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java
deleted file mode 100644
index 0538f60b7d..0000000000
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004 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.jst.jsp.ui.openon;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.ILocalVariable;
-import org.eclipse.jdt.core.ISourceRange;
-import org.eclipse.jdt.core.ISourceReference;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.ui.JavaElementLabelProvider;
-import org.eclipse.jdt.ui.JavaUI;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation;
-import org.eclipse.jst.jsp.core.internal.java.JSPTranslation;
-import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter;
-import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin;
-import org.eclipse.jst.jsp.ui.internal.Logger;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.sse.core.IStructuredModel;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.util.ResourceUtil;
-import org.eclipse.wst.sse.ui.openon.AbstractOpenOn;
-import org.eclipse.wst.xml.core.document.XMLDocument;
-import org.eclipse.wst.xml.core.document.XMLModel;
-
-/**
- * This action opens classes referenced in JSP Java content of a JSP page.
- */
-public class JSPJavaOpenOnJSP extends AbstractOpenOn {
-
- //private final String SSE_MODEL_ID = IModelManagerPlugin.ID; //$NON-NLS-1$
- private final String SELECT_JAVA_TITLE = JSPUIPlugin.getResourceString("%JSPJavaOpenOnJSP.0"); //$NON-NLS-1$
- private final String SELECT_JAVA_MESSAGE = JSPUIPlugin.getResourceString("%JSPJavaOpenOnJSP.1"); //$NON-NLS-1$
-
- /**
- * Get JSP translation object
- *
- * @return JSPTranslation if one exists, null otherwise
- */
- private JSPTranslation getJSPTranslation() {
- // get JSP translation object for this action's editor's document
- XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- if (xmlModel != null) {
- XMLDocument xmlDoc = xmlModel.getDocument();
- xmlModel.releaseFromRead();
- JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
- if (adapter != null) {
- return adapter.getJSPTranslation();
- }
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.sse.editor.AbstractOpenOn#doOpenOn(org.eclipse.jface.text.IRegion)
- */
- protected void doOpenOn(IRegion region) {
- JSPTranslation jspTranslation = getJSPTranslation();
- if (jspTranslation != null) {
- IJavaElement element = getJavaElement(region, jspTranslation);
-
- // open local variable in the JSP file...
- if (element instanceof ILocalVariable) {
- // source reference has java text range info
- if (element instanceof ISourceReference) {
- try {
- // get Java range, translate coordinate to JSP
- ISourceRange range = ((ISourceReference) element).getSourceRange();
- int jspStart = jspTranslation.getJspOffset(range.getOffset());
-
- // open the JSP editor
- IEditorPart jspEditor = openDocumentEditor();
- // set the cursor to the declaration of the variable
- if (jspEditor instanceof ITextEditor) {
- ((ITextEditor) jspEditor).setHighlightRange(jspStart, 0, true);
- }
- }
- catch (JavaModelException jme) {
- Logger.logException("error getting source range from java element (local variable)", jme); //$NON-NLS-1$
- }
- }
- }
- else {
- try {
- IEditorPart part = JavaUI.openInEditor(element);
- if (part != null) {
- if (element != null)
- JavaUI.revealInEditor(part, element);
- }
- else {
- // could not open editor
- openFileFailed();
- }
- }
- catch (Exception e) {
- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
- }
- }
- }
- }
-
- /**
- * Determine the one Java element to open file on
- *
- * @param region
- * IRegion
- * @param translation
- * jsp java translation
- * @return the one Java element to open file on
- */
- private IJavaElement getJavaElement(IRegion region, JSPTranslation translation) {
- if (region == null) {
- return null;
- }
-
- IJavaElement[] elements = translation.getElementsFromJspRange(region.getOffset(), region.getOffset() + region.getLength());
- if (elements == null || elements.length == 0)
- return null;
- IJavaElement candidate = elements[0];
- // more than one Java element was selected so ask user which element
- // should open file open
- if (elements.length > 1) {
- candidate = selectJavaElement(elements);
- }
- return candidate;
- }
-
- /**
- * Shows a dialog for resolving an ambigous java element. This method was
- * copied from org.eclipse.jdt.internal.ui.actions.OpenActionUtil except I
- * set the shell, title, message in this method instead of passing it and
- * this method is private
- */
- private IJavaElement selectJavaElement(IJavaElement[] elements) {
-
- int nResults = elements.length;
- if (nResults == 0)
- return null;
- if (nResults == 1)
- return elements[0];
- int flags = JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT;
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, new JavaElementLabelProvider(flags));
- dialog.setTitle(SELECT_JAVA_TITLE);
- dialog.setMessage(SELECT_JAVA_MESSAGE);
- dialog.setElements(elements);
- if (dialog.open() == Window.OK) {
- Object[] selection = dialog.getResult();
- if (selection != null && selection.length > 0) {
- nResults = selection.length;
- for (int i = 0; i < nResults; i++) {
- Object current = selection[i];
- if (current instanceof IJavaElement)
- return (IJavaElement) current;
- }
- }
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.ibm.sse.editor.AbstractOpenOn#doGetOpenOnRegion(int)
- */
- protected IRegion doGetOpenOnRegion(int offset) {
- IRegion region;
-
- // check and make sure this is a valid Java type
- JSPTranslation jspTranslation = getJSPTranslation();
- IJavaElement[] elements = jspTranslation.getElementsFromJspRange(offset, offset);
- // if no Java element found, this is not a valid openable region
- if (elements == null || elements.length == 0)
- region = null;
- else {
- // return the type region
- region = selectWord(getDocument(), offset);
- }
- return region;
- }
-
- /**
- * Java always selects word when defining region
- *
- * @param document
- * @param anchor
- * @return IRegion
- */
- private IRegion selectWord(IDocument document, int anchor) {
-
- try {
- int offset = anchor;
- char c;
-
- while (offset >= 0) {
- c = document.getChar(offset);
- if (!Character.isJavaIdentifierPart(c))
- break;
- --offset;
- }
-
- int start = offset;
-
- offset = anchor;
- int length = document.getLength();
-
- while (offset < length) {
- c = document.getChar(offset);
- if (!Character.isJavaIdentifierPart(c))
- break;
- ++offset;
- }
-
- int end = offset;
-
- if (start == end)
- return new Region(start, 0);
- else
- return new Region(start + 1, end - start - 1);
-
- }
- catch (BadLocationException x) {
- return null;
- }
- }
-
- /**
- * Open the editor associated with the current document
- *
- * @return the editor opened or null if an external editor was opened or
- * no editor was opened
- */
- private IEditorPart openDocumentEditor() {
- IEditorPart theEditor = null;
-
- IStructuredModel model = null;
- IFile file = null;
- try {
- model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- IFile[] files = ResourceUtil.getFilesFor(model);
- int i = 0;
- while (i < files.length && file == null) {
- if (files[i].exists()) {
- file = files[i];
- }
- else {
- ++i;
- }
- }
- }
- finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- if (file != null) {
- theEditor = openFileInEditor(file);
- }
- return theEditor;
- }
-} \ No newline at end of file

Back to the top