diff options
Diffstat (limited to 'bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util')
13 files changed, 0 insertions, 1967 deletions
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/AbstractMemoryListener.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/AbstractMemoryListener.java deleted file mode 100644 index 46c60a85e4..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/AbstractMemoryListener.java +++ /dev/null @@ -1,205 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2009 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.sse.core.internal.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.wst.sse.core.internal.Logger;
-import org.eclipse.wst.sse.core.internal.SSECorePlugin;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
-
-/**
- * This responds to memory events.
- *
- * Create an instance of a child of this class with the events you are interested in.
- * Then call connect() to start listening. To stop listening call disconnect();
- */
-public abstract class AbstractMemoryListener implements EventHandler {
- /**
- * The event that indicates that memory is running low at the lowest severity.
- * Listeners are requested to release caches that can easily be recomputed.
- * The Java VM is not seriously in trouble, but process size is getting higher than
- * is deemed acceptable.
- */
- public static final String SEV_NORMAL = "org/eclipse/equinox/events/MemoryEvent/NORMAL"; //$NON-NLS-1$
-
- /**
- * The event that indicates that memory is running low at medium severity.
- * Listeners are requested to release intermediate build results, complex models, etc.
- * Memory is getting low and may cause operating system level stress, such as swapping.
- */
- public static final String SEV_SERIOUS = "org/eclipse/equinox/events/MemoryEvent/SERIOUS"; //$NON-NLS-1$
-
- /**
- * The event that indicates that memory is running low at highest severity.
- * Listeners are requested to do things like close editors and perspectives, close database connections, etc.
- * Restoring these resources and caches constitutes lots of work, but memory is so low that
- * drastic measures are required.
- */
- public static final String SEV_CRITICAL = "org/eclipse/equinox/events/MemoryEvent/CRITICAL"; //$NON-NLS-1$
-
- /**
- * All of the valid memory severities
- */
- public static final String[] SEV_ALL = { SEV_NORMAL, SEV_SERIOUS, SEV_CRITICAL };
-
- /**
- * Used to register the {@link EventAdmin} listener
- */
- private static BundleContext CONTEXT =
- (SSECorePlugin.getDefault() != null) ?
- SSECorePlugin.getDefault().getBundle().getBundleContext() : null;
-
- /**
- * the severities that will be reacted to
- */
- private final List fSeverities;
-
- /**
- * service used to register this listener
- */
- private ServiceRegistration fRegisterService;
-
- /**
- * Will listen to all memory events
- */
- public AbstractMemoryListener() {
- this(AbstractMemoryListener.SEV_ALL);
- }
-
- /**
- * Will listen to memory events of the given <code>severity</code>
- *
- * @param severity listen for memory events of this severity
- */
- public AbstractMemoryListener(String severity) {
- Assert.isNotNull(severity, "Severity can not be null"); //$NON-NLS-1$
-
- List severities = new ArrayList(1);
- severities.add(severity);
- fSeverities = severities;
- }
-
- /**
- * Will listen to memory events of the given <code>severities</code>
- *
- * @param severities listen for memory events for any of these severities
- */
- public AbstractMemoryListener(String[] severities) {
- Assert.isNotNull(severities, "Severities can not be null"); //$NON-NLS-1$
- Assert.isLegal(severities.length > 0, "Severities must specify at least one severity"); //$NON-NLS-1$
-
- fSeverities = Arrays.asList(severities);
- }
-
- /**
- * Will listen to memory events of the given <code>severities</code>
- *
- * @param severities listen for memory events for any of these severities
- */
- public AbstractMemoryListener(List severities) {
- Assert.isNotNull(severities, "Severities can not be null"); //$NON-NLS-1$
- Assert.isLegal(!severities.isEmpty(), "Severities must specify at least one severity"); //$NON-NLS-1$
- fSeverities = severities;
- }
-
- /**
- * Connect this listener to the {@link EventAdmin}
- */
- public final void connect() {
- if (CONTEXT != null) {
- // NOTE: This is TEMPORARY CODE needed to load the plugin
- // until its done automatically by the product
- // TODO: Remove me
- Bundle b = Platform.getBundle("org.eclipse.equinox.event"); //$NON-NLS-1$
- if (b != null && b.getState() == Bundle.RESOLVED) {
- try {
- b.start(Bundle.START_TRANSIENT);
- }
- catch (BundleException e) {
- e.printStackTrace();
- }
- }
- // end remove me
-
- //register this handler
- String[] severities = (String[])fSeverities.toArray(new String[fSeverities.size()]);
- Hashtable prop = new Hashtable(1);
- prop.put(EventConstants.EVENT_TOPIC, severities);
- fRegisterService = CONTEXT.registerService(EventHandler.class.getName(), this, prop);
-
- //call any implementer specific connect code
- doConnect();
- } else {
- Logger.log(Logger.WARNING, "Error accessing bundle context. Is Platform running? Not tracking memory events. "); //$NON-NLS-1$
- }
- }
-
- /**
- * Disconnect this listener to the {@link EventAdmin}
- */
- public final void disconnect() {
- if (fRegisterService != null) {
- fRegisterService.unregister();
- fRegisterService = null;
- }
-
- //call any implementer specific disconnect code
- doDisconnect();
- }
-
- /**
- * <p>Filter out any events that are not of the type that this listener handles</p>
- *
- * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)
- */
- public final void handleEvent(Event event) {
- if (fSeverities.contains(event.getTopic())) {
- handleMemoryEvent(event);
- }
- }
-
- /**
- * Implementing child classes may assume that only {@link Event}s of the types
- * given to the constructor will be given to this method.
- *
- * @param event the {@link Event} with a topic equal to one of the memory
- * severities that this listener is listening for
- */
- protected abstract void handleMemoryEvent(Event event);
-
- /**
- * Implementers may overrun this method to do setup after connection of this listener
- */
- protected void doConnect() {
- //do nothing by default
- }
-
- /**
- * Implementers may overrun this method to do tear down after disconnection of this listener
- */
- protected void doDisconnect() {
- //do nothing by default
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Assert.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Assert.java deleted file mode 100644 index f3d1ee04ab..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Assert.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - -/** - * <code>Assert</code> is useful for for embedding runtime sanity checks in - * code. The predicate methods all test a condition and throw some type of - * unchecked exception if the condition does not hold. - * <p> - * Assertion failure exceptions, like most runtime exceptions, are thrown when - * something is misbehaving. Assertion failures are invariably unspecified - * behavior; consequently, clients should never rely on these being thrown - * (and certainly should not being catching them specifically). - * </p> - */ -public final class Assert { - - /** - * <code>AssertionFailedException</code> is a runtime exception thrown - * by some of the methods in <code>Assert</code>. - * <p> - * This class is not declared public to prevent some misuses; programs - * that catch or otherwise depend on assertion failures are susceptible to - * unexpected breakage when assertions in the code are added or removed. - * </p> - */ - class AssertionFailedException extends RuntimeException { - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a new exception. - */ - public AssertionFailedException() { - super(); - } - - /** - * Constructs a new exception with the given message. - */ - public AssertionFailedException(String detail) { - super(detail); - } - } - - /** - * Asserts that an argument is legal. If the given boolean is not - * <code>true</code>, an <code>IllegalArgumentException</code> is - * thrown. - * - * @param expression - * the outcode of the check - * @return <code>true</code> if the check passes (does not return if the - * check fails) - * @exception IllegalArgumentException - * if the legality test failed - */ - public static boolean isLegal(boolean expression) { - return isLegal(expression, ""); //$NON-NLS-1$ - } - - /** - * Asserts that an argument is legal. If the given boolean is not - * <code>true</code>, an <code>IllegalArgumentException</code> is - * thrown. The given message is included in that exception, to aid - * debugging. - * - * @param expression - * the outcode of the check - * @param message - * the message to include in the exception - * @return <code>true</code> if the check passes (does not return if the - * check fails) - * @exception IllegalArgumentException - * if the legality test failed - */ - public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException(); - return expression; - } - - /** - * Asserts that the given object is not <code>null</code>. If this is - * not the case, some kind of unchecked exception is thrown. - * - * @param object - * the value to test - * @exception IllegalArgumentException - * if the object is <code>null</code> - */ - public static void isNotNull(Object object) { - isNotNull(object, ""); //$NON-NLS-1$ - } - - /** - * Asserts that the given object is not <code>null</code>. If this is - * not the case, some kind of unchecked exception is thrown. The given - * message is included in that exception, to aid debugging. - * - * @param object - * the value to test - * @param message - * the message to include in the exception - * @exception IllegalArgumentException - * if the object is <code>null</code> - */ - public static void isNotNull(Object object, String message) { - if (object == null) { - //Logger.log(Logger.ERROR, "null_argument: " + message); //$NON-NLS-1$ - throw new Assert().new AssertionFailedException(message); - } - } - - /** - * Asserts that the given boolean is <code>true</code>. If this is not - * the case, some kind of unchecked exception is thrown. - * - * @param expression - * the outcode of the check - * @return <code>true</code> if the check passes (does not return if the - * check fails) - */ - public static boolean isTrue(boolean expression) { - return isTrue(expression, ""); //$NON-NLS-1$ - } - - /** - * Asserts that the given boolean is <code>true</code>. If this is not - * the case, some kind of unchecked exception is thrown. The given message - * is included in that exception, to aid debugging. - * - * @param expression - * the outcode of the check - * @param message - * the message to include in the exception - * @return <code>true</code> if the check passes (does not return if the - * check fails) - */ - public static boolean isTrue(boolean expression, String message) { - if (!expression) { - throw new Assert().new AssertionFailedException(message); - } - return expression; - } - - /* This class is not intended to be instantiated. */ - private Assert() { - super(); - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Debug.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Debug.java deleted file mode 100644 index 3df89548da..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Debug.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Carver (Intalio) - bug 300430 - String concatenation - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - - -import java.util.Enumeration; - -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.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.ITextRegionContainer; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; - - -public final class Debug { - public static final boolean checkForMemoryLeaks = false; - - public static final boolean collectStats = false; - - public static final int DEBUG = 0; - - public static final boolean DEBUG_THREADLOCAL = false; - - public static final boolean debugBreakpoints = false; - public static final boolean debugCaretMediator = false; - public static final boolean debugDisplayTreePositions = false; - // - public static final boolean debugMediator = false; - // - public static final boolean debugNotification = false; - public static final boolean debugNotificationAndEvents = false; - - public static final boolean debugNotifyDeferred = false; - public static final boolean debugReconciling = false; - // - public static final boolean debugRtfFormatProvider = false; - // - public static final boolean debugStructuredDocument = false; - public static final boolean debugTaglibs = false; - // - public static final boolean debugTokenizer = false; - // - public static final boolean debugTreeModel = false; - public static final boolean debugUpdateTreePositions = false; - public static final boolean displayInfo = false; - - /** effects output of Logger */ - public static final boolean displayToConsole = true; - public static final boolean displayWarnings = false; - // - public static final boolean headParsing = false; - public static final boolean jsDebugContextAssist = false; - // - public static final boolean jsDebugSyntaxColoring = false; - - public static final boolean LOCKS = false; - // - public static final boolean perfTest = false; - public static final boolean perfTestAdapterClassLoading = false; - public static final boolean perfTestFormat = false; - public static final boolean perfTestRawStructuredDocumentOnly = false; - public static final boolean perfTestStructuredDocumentEventOnly = false; - public static final boolean perfTestStructuredDocumentOnly = false; - - // - public static final boolean syntaxHighlighting = false; - // - public static final boolean useStandardEolInWidget = false; - - /** - * For tests and debug only - */ - - public static final void dump(IStructuredDocument structuredDocument) { - dump(structuredDocument, false); - } - - public static final void dump(IStructuredDocument structuredDocument, boolean verbose) { - ITextRegionCollection flatNode = null; - System.out.println("Dump of structuredDocument:"); //$NON-NLS-1$ - IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList(); - Enumeration structuredDocumentRegions = flatNodes.elements(); - while (structuredDocumentRegions.hasMoreElements()) { - flatNode = (ITextRegionCollection) structuredDocumentRegions.nextElement(); - if (!verbose) { - String outString = flatNode.toString(); - outString = org.eclipse.wst.sse.core.utils.StringUtils.escape(outString); - System.out.println(outString); - } else { - dump(flatNode, verbose); - } - } - System.out.println(); - System.out.println("= = = = = ="); //$NON-NLS-1$ - System.out.println(); - } - - /** - * @param flatNode - * @param verbose - */ - public static final void dump(ITextRegionCollection region, boolean verbose) { - if (region == null) - return; - if (verbose) { - printParent(region); - } - printChildRegions(region, 0); - } - - private static void printChildRegions(ITextRegionCollection region, int depth) { - if (region != null) { - // ==> // ITextRegionCollection regionCollection = region; - System.out.println(region); - ITextRegionList regionList = region.getRegions(); - for (int i = 0; i < regionList.size(); i++) { - ITextRegion r = regionList.get(i); - if (r instanceof ITextRegionCollection) { - ITextRegionCollection rc = (ITextRegionCollection) r; - printChildRegions(rc, depth++); - } else { - System.out.println(space(depth) + r); - depth--; - } - } - } - } - - /** - * Simple utility to make sure println's are some what in order - */ - public static final synchronized void println(String msg) { - System.out.println(System.currentTimeMillis() + "\t" + msg); //$NON-NLS-1$ - } - - private static void printParent(IStructuredDocumentRegion region) { - System.out.println(" [parent document: " + toStringUtil(region.getParentDocument()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - private static void printParent(ITextRegionCollection region) { - if (region instanceof IStructuredDocumentRegion) { - printParent((IStructuredDocumentRegion) region); - } else if (region instanceof ITextRegionContainer) { - printParent((ITextRegionContainer) region); - } else - System.out.println(" [parent document: " + "(na)" + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - private static void printParent(ITextRegionContainer region) { - System.out.println(" [parent document: " + toStringUtil(region.getParent()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * @param depth - * @return - */ - private static String space(int depth) { - String result = " "; //$NON-NLS-1$ - StringBuffer sb = new StringBuffer(result); - for (int i = 0; i < depth; i++) { - sb.append(" "); //$NON-NLS-1$ - } - result = sb.toString(); - return result; - } - - public static final String toStringUtil(IStructuredDocument object) { - String className = object.getClass().getName(); - String shortClassName = className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$ - String result = shortClassName; - // NOTE: if the document held by any region has been updated and the - // region offsets have not - // yet been updated, the output from this method invalid. - return result; - - } - - public static final String toStringUtil(ITextRegionCollection object) { - String className = object.getClass().getName(); - String shortClassName = className.substring(className.lastIndexOf(".") + 1); //$NON-NLS-1$ - String result = shortClassName; - // NOTE: if the document held by any region has been updated and the - // region offsets have not - // yet been updated, the output from this method invalid. - return result; - - } - - /** - * Debug constructor comment. - */ - public Debug() { - super(); - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/DocumentInputStream.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/DocumentInputStream.java deleted file mode 100644 index fad095102a..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/DocumentInputStream.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; - -public class DocumentInputStream extends InputStream { - private IDocument fDocument; - private int fMark = -1; - private int fPosition = 0; - - public DocumentInputStream(IDocument source) { - super(); - fDocument = source; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#available() - */ - public int available() throws IOException { - return fDocument.getLength() - fPosition; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#close() - */ - public void close() throws IOException { - this.fDocument = null; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#mark(int) - */ - public synchronized void mark(int readlimit) { - fMark = fPosition; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#markSupported() - */ - public boolean markSupported() { - return true; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#read() - */ - public int read() throws IOException { - try { - if (fPosition < fDocument.getLength()) - return fDocument.getChar(fPosition++); - else - return -1; - } catch (BadLocationException e) { - throw new IOException(e.getMessage()); - } - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#reset() - */ - public synchronized void reset() throws IOException { - fPosition = fMark; - } - - /* - * (non-Javadoc) - * - * @see java.io.InputStream#skip(long) - */ - public long skip(long n) throws IOException { - long skipped = n; - if (n < fDocument.getLength() - fPosition) { - skipped = n; - fPosition += skipped; - } else { - skipped = fDocument.getLength() - fPosition; - fPosition = fDocument.getLength(); - } - return skipped; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/JarUtilities.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/JarUtilities.java deleted file mode 100644 index bf621e0992..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/JarUtilities.java +++ /dev/null @@ -1,390 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.JarURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; -import java.util.zip.ZipInputStream; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -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.sse.core.internal.Logger; - - -public class JarUtilities { - - /** - * @see http://java.sun.com/products/jsp/errata_1_1_a_042800.html, Issues - * 8 & 9 - * - * "There are two cases. In both cases the TLD_URI is to be - * interpreted relative to the root of the Web Application. In the - * first case the TLD_URI refers to a TLD file directly. In the - * second case, the TLD_URI refers to a JAR file. If so, that JAR - * file should have a TLD at location META-INF/taglib.tld." - */ - public static final String JSP11_TAGLIB = "META-INF/taglib.tld"; //$NON-NLS-1$ - - public static void closeJarFile(ZipFile file) { - if (file == null) - return; - try { - file.close(); - } - catch (IOException ioe) { - // no cleanup can be done - } - } - - /** - * Provides a stream to a local copy of the input or null if not possible - */ - protected static InputStream getCachedInputStream(String jarFilename, String entryName) { - File testFile = new File(jarFilename); - if (!testFile.exists()) - return getInputStream(ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(jarFilename)), entryName); - - InputStream cache = null; - ZipFile jarfile = null; - try { - jarfile = new ZipFile(jarFilename); - } - catch (IOException ioExc) { - closeJarFile(jarfile); - } - - if (jarfile != null) { - try { - ZipEntry zentry = jarfile.getEntry(entryName); - if (zentry != null) { - InputStream entryInputStream = null; - try { - entryInputStream = jarfile.getInputStream(zentry); - } - catch (IOException ioExc) { - // no cleanup can be done - } - - if (entryInputStream != null) { - int c; - ByteArrayOutputStream buffer = null; - if (zentry.getSize() > 0) { - buffer = new ByteArrayOutputStream((int) zentry.getSize()); - } - else { - buffer = new ByteArrayOutputStream(); - } - // array dim restriction? - byte bytes[] = new byte[2048]; - try { - while ((c = entryInputStream.read(bytes)) >= 0) { - buffer.write(bytes, 0, c); - } - cache = new ByteArrayInputStream(buffer.toByteArray()); - closeJarFile(jarfile); - } - catch (IOException ioe) { - // no cleanup can be done - } - finally { - try { - entryInputStream.close(); - } - catch (IOException e) { - // no cleanup can be done - } - } - } - } - } - finally { - closeJarFile(jarfile); - } - } - return cache; - } - - private static InputStream copyAndCloseStream(InputStream original) { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - InputStream cachedCopy = null; - - if (original != null) { - int c; - // array dim restriction? - byte bytes[] = new byte[2048]; - try { - while ((c = original.read(bytes)) >= 0) { - buffer.write(bytes, 0, c); - } - cachedCopy = new ByteArrayInputStream(buffer.toByteArray()); - closeStream(original); - } - catch (IOException ioe) { - // no cleanup can be done - } - } - return cachedCopy; - } - - /** - * @param jarResource - * the zip file - * @return a string array containing the entry paths to every file in this - * zip resource, excluding directories - */ - public static String[] getEntryNames(IResource jarResource) { - if (jarResource == null || jarResource.getType() != IResource.FILE || !jarResource.isAccessible()) - return new String[0]; - - try { - return getEntryNames(jarResource.getFullPath().toString(), new ZipInputStream(((IFile) jarResource).getContents()), true); - } - catch (CoreException e) { - // no cleanup can be done - } - - IPath location = jarResource.getLocation(); - if (location != null) - return getEntryNames(location.toString()); - return new String[0]; - } - - /** - * @param jarFilename - * the location of the zip file - * @return a string array containing the entry paths to every file in the - * zip file at this location, excluding directories - */ - public static String[] getEntryNames(String jarFilename) { - return getEntryNames(jarFilename, true); - } - - private static String[] getEntryNames(String filename, ZipInputStream jarInputStream, boolean excludeDirectories) { - List entryNames = new ArrayList(); - try { - ZipEntry z = jarInputStream.getNextEntry(); - while (z != null) { - if (!(z.isDirectory() && excludeDirectories)) - entryNames.add(z.getName()); - z = jarInputStream.getNextEntry(); - } - } - catch (ZipException zExc) { - Logger.log(Logger.WARNING_DEBUG, "JarUtilities ZipException: (stream) " + filename, zExc); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (IOException ioExc) { - // no cleanup can be done - } - finally { - closeStream(jarInputStream); - } - String[] names = (String[]) entryNames.toArray(new String[0]); - return names; - } - - private static void closeStream(InputStream inputStream) { - try { - inputStream.close(); - } - catch (IOException e) { - // no cleanup can be done - } - } - - /** - * @param jarFilename - * the location of the zip file - * @param excludeDirectories - * whether to not include directories in the results - * @return a string array containing the entry paths to every file in the - * zip file at this location, excluding directories if indicated - */ - public static String[] getEntryNames(String jarFilename, boolean excludeDirectories) { - ZipFile jarfile = null; - List entryNames = new ArrayList(); - File f = new File(jarFilename); - if (f.exists() && f.canRead()) { - try { - jarfile = new ZipFile(f); - Enumeration entries = jarfile.entries(); - while (entries.hasMoreElements()) { - ZipEntry z = (ZipEntry) entries.nextElement(); - if (!(z.isDirectory() && excludeDirectories)) - entryNames.add(z.getName()); - } - } - catch (ZipException zExc) { - Logger.log(Logger.WARNING_DEBUG, "JarUtilities ZipException: " + jarFilename + " " + zExc.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (IOException ioExc) { - // no cleanup can be done - } - finally { - closeJarFile(jarfile); - } - } - String[] names = (String[]) entryNames.toArray(new String[0]); - return names; - } - - /** - * @param jarResource - * the zip file - * @param entryName - * the entry's path in the zip file - * @return an InputStream to the contents of the given entry or null if - * not possible - */ - public static InputStream getInputStream(IResource jarResource, String entryName) { - if (jarResource == null || jarResource.getType() != IResource.FILE || !jarResource.isAccessible()) - return null; - - try { - InputStream zipStream = ((IFile) jarResource).getContents(); - return getInputStream(jarResource.getFullPath().toString(), new ZipInputStream(zipStream), entryName); - } - catch (CoreException e) { - // no cleanup can be done, probably out of sync - } - - IPath location = jarResource.getLocation(); - if (location != null) { - return getInputStream(location.toString(), entryName); - } - return null; - } - - private static InputStream getInputStream(String filename, ZipInputStream zip, String entryName) { - InputStream result = null; - try { - ZipEntry z = zip.getNextEntry(); - while (z != null && !z.getName().equals(entryName)) { - z = zip.getNextEntry(); - } - if (z != null) { - result = copyAndCloseStream(zip); - } - } - catch (ZipException zExc) { - Logger.log(Logger.WARNING_DEBUG, "JarUtilities ZipException: (stream) " + filename, zExc); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch (IOException ioExc) { - // no cleanup can be done - } - finally { - closeStream(zip); - } - return result; - } - - /** - * @param jarFilename - * the location of the zip file - * @param entryName - * the entry's path in the zip file - * @return an InputStream to the contents of the given entry or null if - * not possible - */ - public static InputStream getInputStream(String jarFilename, String entryName) { - // check sanity - if (jarFilename == null || jarFilename.length() < 1 || entryName == null || entryName.length() < 1) - return null; - - // JAR files are not allowed to have leading '/' in member names - String internalName = null; - if (entryName.startsWith("/")) //$NON-NLS-1$ - internalName = entryName.substring(1); - else - internalName = entryName; - - return getCachedInputStream(jarFilename, internalName); - } - - /** - * @param url - * a URL pointint to a zip file - * @return a cached copy of the contents at this URL, opening it as a file - * if it is a jar:file: URL, and using a URLConnection otherwise, - * or null if it could not be read. All sockets and file handles - * are closed as quickly as possible. - */ - public static InputStream getInputStream(URL url) { - String urlString = url.toString(); - if (urlString.length() > 12 && urlString.startsWith("jar:file:") && urlString.indexOf("!/") > 9) { //$NON-NLS-1$ //$NON-NLS-2$ - int fileIndex = urlString.indexOf("!/"); //$NON-NLS-1$ - String jarFileName = urlString.substring(9, fileIndex); - if (fileIndex < urlString.length()) { - String jarPath = urlString.substring(fileIndex + 1); - return getInputStream(jarFileName, jarPath); - } - } - - InputStream input = null; - JarURLConnection jarUrlConnection = null; - try { - URLConnection openConnection = url.openConnection(); - openConnection.setDefaultUseCaches(false); - openConnection.setUseCaches(false); - if (openConnection instanceof JarURLConnection) { - jarUrlConnection = (JarURLConnection) openConnection; - JarFile jarFile = jarUrlConnection.getJarFile(); - input = jarFile.getInputStream(jarUrlConnection.getJarEntry()); - } - else { - input = openConnection.getInputStream(); - } - if (input != null) { - return copyAndCloseStream(input); - } - } - catch (IOException e) { - Logger.logException(e); - } - finally { - if (jarUrlConnection != null) { - try { - jarUrlConnection.getJarFile().close(); - } - catch (IOException e) { - // ignore - } - catch (IllegalStateException e) { - /* - * ignore. Can happen in case the stream.close() did close - * the jar file see - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=140750 - */ - } - - } - } - return null; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/PathHelper.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/PathHelper.java deleted file mode 100644 index b83508559c..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/PathHelper.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2010 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * David Carver (Intalio) - bug 300430 - String concatenation - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - - -import java.io.File; -import com.ibm.icu.util.StringTokenizer; - -/** - * Collection of helper methods to manage and convert links Originally part of - * the LinksManager - */ -public class PathHelper { - public static final String BACKWARD_SLASH = "\\";//$NON-NLS-1$ - - public static final String FORWARD_SLASH = "/";//$NON-NLS-1$ - public static final String RELATIVE_PATH_SIG = "../";//$NON-NLS-1$ - - /** - * adjust relative path isside the absolute path - */ - public static String adjustPath(String path) { - int i = 0; - while ((i = path.indexOf(RELATIVE_PATH_SIG)) > 0) { - // split the string into two - String part1 = path.substring(0, i - 1); - String part2 = path.substring(i + RELATIVE_PATH_SIG.length() - 1); - // strip one path seg from part1 - int j = part1.lastIndexOf(FORWARD_SLASH); - if (j == -1) { - // can't resolve. passed path is like - // E:/eclipseproject/../../sample.css. - return "";//$NON-NLS-1$ - } - part1 = part1.substring(0, j); - path = part1 + part2; - } - return path; - } - - /** - * Append trailing url slash if needed - */ - public static String appendTrailingURLSlash(String input) { - // check to see already a slash - if (!input.endsWith(FORWARD_SLASH)) { - input += FORWARD_SLASH; - } - return input; - } - - /** - * Convert to relative url based on base - */ - public static String convertToRelative(String input, String base) { - // tokenize the strings - StringTokenizer inputTokenizer = new StringTokenizer(input, FORWARD_SLASH); - StringTokenizer baseTokenizer = new StringTokenizer(base, FORWARD_SLASH); - String token1 = "", token2 = "";//$NON-NLS-2$//$NON-NLS-1$ - // - // Go through until equls - while (true) { - if (!inputTokenizer.hasMoreTokens() || !baseTokenizer.hasMoreTokens()) - break; - token1 = baseTokenizer.nextToken(); - token2 = inputTokenizer.nextToken(); - if (!token1.equals(token2)) - break; - } - // now generate the backs - String output = "";//$NON-NLS-1$ - StringBuffer sb = new StringBuffer(output); - while (baseTokenizer.hasMoreTokens()) { - baseTokenizer.nextToken(); - sb.append("../"); //$NON-NLS-1$ - } - sb.append(token2); - // generate the rest - while (inputTokenizer.hasMoreTokens()) { - sb.append(FORWARD_SLASH); - sb.append(inputTokenizer.nextToken()); - } - output = sb.toString(); - return output; - } - - /** - * Return the containing folder path. Will handle both url and file path - */ - public static String getContainingFolderPath(String path) { - String retValue = path; - - int urlSlashIndex = path.lastIndexOf(FORWARD_SLASH); - int filePathSlashIndex = path.lastIndexOf(File.separator); - int index = filePathSlashIndex; - if (urlSlashIndex > filePathSlashIndex) - index = urlSlashIndex; - if (index >= 0) - retValue = path.substring(0, index); - return retValue; - } - - /** - * Remove leading path separator - */ - public static String removeLeadingPathSeparator(String path) { - if (path.startsWith(File.separator)) - path = path.substring(File.separator.length()); - return path; - } - - /** - * Remove leading path separator - */ - public static String removeLeadingSeparator(String path) { - if (path.startsWith(File.separator)) - path = path.substring(File.separator.length()); - else if (path.startsWith(FORWARD_SLASH) || path.startsWith(BACKWARD_SLASH)) - path = path.substring(FORWARD_SLASH.length()); - return path; - } - - /** - * Switch to file path slashes - */ - public static String switchToFilePathSlashes(String path) { - path = path.replace(FORWARD_SLASH.charAt(0), File.separatorChar); - path = path.replace(BACKWARD_SLASH.charAt(0), File.separatorChar); - return path; - } - - /** - * Switch to file path slashes - */ - public static String switchToForwardSlashes(String path) { - path = path.replace(File.separatorChar, FORWARD_SLASH.charAt(0)); - path = path.replace(BACKWARD_SLASH.charAt(0), FORWARD_SLASH.charAt(0)); - return path; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ProjectResolver.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ProjectResolver.java deleted file mode 100644 index 0a21f95409..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ProjectResolver.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; - -import com.ibm.icu.util.StringTokenizer; - -/** - * @deprecated The URIResolver interface is deprecated. Use the resolver from - * org.eclipse.wst.common.uriresolver. - */ -public class ProjectResolver implements URIResolver { - private String fFileBaseLocation = null; - private IProject fProject = null; - - /** - * It is strongly recommended that clients use - * project.getAdapter(URIResolver.class) to obtain a URIResolver aware of - * the Project's special requirements. Note that a URIResolver may not be - * returned at all so manually creating this object may still be required. - */ - public ProjectResolver(IProject project) { - super(); - fProject = project; - } - - public String getFileBaseLocation() { - return fFileBaseLocation; - } - - public String getLocationByURI(String uri) { - return getLocationByURI(uri, getFileBaseLocation()); - } - - // defect 244817 end - /** - * Resolve the (possibly relative) URI acording to RFC1808 using the - * default file base location. Resolves resource references into absolute - * resource locations without ensuring that the resource actually exists. - * - * Note: currently resolveCrossProjectLinks is ignored in this - * implementation. - */ - public String getLocationByURI(String uri, boolean resolveCrossProjectLinks) { - return getLocationByURI(uri, getFileBaseLocation(), resolveCrossProjectLinks); - } - - public String getLocationByURI(String uri, String baseReference) { - if (uri == null) - return null; - /* - * defect 244817 try { URL aURL = new URL(uri); - */ - /** - * An actual URL was given, but only the "file:///" protocol is - * supported. Resolve the URI by finding the file to which it points. - */ - /* - * defect 244817 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$ return aURL.getFile(); } return - * uri; } } catch (MalformedURLException mfuExc) { } - */ - // defect 244817 start - if (isFileURL(uri)) { - try { - URL url = new URL(uri); - return getPath(url); - } - catch (MalformedURLException e) { - } - } - // defect 244817 end - - // which of the serveral are we suppose to use here? - // - - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71223 - // Workaround for problem in URIHelper; uris starting with '/' are - // returned as-is. - String location = null; - if (uri.startsWith("/")) { //$NON-NLS-1$ - IProject p = getProject(); - if (p != null && p.isAccessible()) { - IFile file = p.getFile(uri); - - if (file.getLocation() != null) { - location = file.getLocation().toString(); - } - if (location == null && file.getLocationURI() != null) { - location = file.getLocationURI().toString(); - } - if (location == null) { - location = file.getFullPath().toString(); - } - } - } - if(location == null) { - location = URIHelper.normalize(uri, baseReference, getRootLocationString()); - } - return location; - } - - /** - * Perform the getLocationByURI action using the baseReference as the - * point of reference instead of the default for this resolver - * - * Note: currently resolveCrossProjectLinks is ignored in this - * implementation. - */ - public String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks) { - return getLocationByURI(uri, baseReference); - } - - /** - * - * @param path - * @param host - * @return String - */ - private String getPath(IPath path, String host) { - IPath newPath = path; - // They are potentially for only Windows operating system. - // a.) if path has a device, and if it begins with IPath.SEPARATOR, - // remove it - final String device = path.getDevice(); - if ((device != null) && (device.length() > 0)) { - if (device.charAt(0) == IPath.SEPARATOR) { - final String newDevice = device.substring(1); - newPath = path.setDevice(newDevice); - } - } - // b.) if it has a hostname, it is UNC name... Any java or eclipse api - // helps it ?? - if (path != null && host != null && host.length() != 0) { - IPath uncPath = new Path(host); - uncPath = uncPath.append(path); - newPath = uncPath.makeUNC(true); - } - return newPath.toString(); - } - - /** - * - * @param url - * @return String - */ - private String getPath(URL url) { - String ref = url.getRef() == null ? "" : "#" + url.getRef(); //$NON-NLS-1$ //$NON-NLS-2$ - String strPath = url.getFile() + ref; - IPath path; - if (strPath.length() == 0) { - path = Path.ROOT; - } - else { - path = new Path(strPath); - String query = null; - StringTokenizer parser = new StringTokenizer(strPath, "?"); //$NON-NLS-1$ - int tokenCount = parser.countTokens(); - if (tokenCount == 2) { - path = new Path((String) parser.nextElement()); - query = (String) parser.nextElement(); - } - if (query == null) { - parser = new StringTokenizer(path.toString(), "#"); //$NON-NLS-1$ - tokenCount = parser.countTokens(); - if (tokenCount == 2) { - path = new Path((String) parser.nextElement()); - } - } - } - return getPath(path, url.getHost()); - } - - public org.eclipse.core.resources.IProject getProject() { - return fProject; - } - - public org.eclipse.core.resources.IContainer getRootLocation() { - return fProject; - } - - protected String getRootLocationString() { - String location = null; - if (fProject == null) - return null; - if (fProject.getLocation() != null) { - location = fProject.getLocation().toString(); - } - if (location == null && fProject.getLocationURI() != null) { - location = fProject.getLocationURI().toString(); - } - if (location == null) { - location = fProject.getFullPath().toString(); - } - return location; - } - - public InputStream getURIStream(String uri) { - return null; - } - - // defect 244817 start - /** - * - * @param passedSpec - * @return boolean - */ - private boolean isFileURL(String passedSpec) { - if (passedSpec == null) { - return false; - } - final String spec = passedSpec.trim(); - if (spec.length() == 0) { - return false; - } - final int limit = spec.length(); - String newProtocol = null; - for (int index = 0; index < limit; index++) { - final char p = spec.charAt(index); - if (p == '/') { //$NON-NLS-1$ - break; - } - if (p == ':') { //$NON-NLS-1$ - newProtocol = spec.substring(0, index); - break; - } - } - return (newProtocol != null && newProtocol.compareToIgnoreCase("file") == 0); //$NON-NLS-1$ - } - - public void setFileBaseLocation(String newFileBaseLocation) { - fFileBaseLocation = newFileBaseLocation; - } - - public void setProject(IProject newProject) { - fProject = newProject; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ResourceUtil.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ResourceUtil.java deleted file mode 100644 index ab59ecbbc5..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ResourceUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -import org.eclipse.core.resources.IFile; -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.wst.sse.core.internal.provisional.IStructuredModel; - - -/** - * @deprecated - makes assumptions on behalf of the requester - */ -public class ResourceUtil { - - /** - * Obtains the IFile for a model - * - * @param model - * the model to use - * @return the IFile used to create the model, if it came from an IFile, - * null otherwise - */ - public static IFile getFileFor(IStructuredModel model) { - if (model == null) - return null; - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - IFile file = null; - IPath location = new Path(model.getBaseLocation()); - // if the path is not a path in the file system and there are at least - // 2 segments, it might be in the workspace - IFile[] files = root.findFilesForLocation(location); - if (files.length > 0) { - file = files[0]; - } - else if (location.segmentCount() > 1) { - // remember, this IFile isn't guaranteed to exist - file = root.getFile(location); - } - return file; - } - - /** - * Obtain IFiles from IStructuredModel (includes linkedResources) - * - * @return the corresponding files in the workspace, or an empty array if - * none - */ - public static IFile[] getFilesFor(IStructuredModel model) { - if (model == null) - return null; - - IFile[] files = null; - IPath location = new Path(model.getBaseLocation()); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - // if the path is not a path in the file system and there are at least - // 2 segments, it might be in the workspace - if (!location.toFile().exists() && location.segmentCount() > 1) { - // remember, this IFile isn't guaranteed to exist - files = new IFile[]{root.getFile(location)}; - } - else { - files = root.findFilesForLocation(location); - } - return files; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ScriptLanguageKeys.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ScriptLanguageKeys.java deleted file mode 100644 index 5d4d7aa7a5..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/ScriptLanguageKeys.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -/** - * Contains list of script languages and mime types - */ -public interface ScriptLanguageKeys { - - public static final String JAVA = "java"; //$NON-NLS-1$ - - public static final String[] JAVA_LANGUAGE_KEYS = new String[]{"java"}; //$NON-NLS-1$ - - public static final String JAVASCRIPT = "javascript"; //$NON-NLS-1$ - public static final String[] JAVASCRIPT_LANGUAGE_KEYS = {"javascript", //$NON-NLS-1$ - "javascript1.0", //$NON-NLS-1$ - "javascript1.1", //$NON-NLS-1$ - "javascript1.2", //$NON-NLS-1$ - "javascript1.3", //$NON-NLS-1$ - "javascript1.4", //$NON-NLS-1$ - "javascript1.5", //$NON-NLS-1$ - "javascript1.6", //$NON-NLS-1$ - "jscript", //$NON-NLS-1$ - "sashscript"}; //$NON-NLS-1$ - - public static final String[] JAVASCRIPT_MIME_TYPE_KEYS = {"text/javascript", //$NON-NLS-1$ - "text/jscript", //$NON-NLS-1$ - "text/sashscript"}; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Sorter.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Sorter.java deleted file mode 100644 index 41cdf33265..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Sorter.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - - -/** - * The SortOperation takes a collection of objects and returns a sorted - * collection of these objects. Concrete instances of this class provide the - * criteria for the sorting of the objects based on the type of the objects. - */ -public abstract class Sorter { - - /** - * Returns true iff elementTwo is 'greater than' elementOne. This is the - * 'ordering' method of the sort operation. Each subclass overrides this - * method with the particular implementation of the 'greater than' concept - * for the objects being sorted. If elementOne and elementTwo are - * equivalent in terms of their sorting order, this method must return - * 'false'. - */ - public abstract boolean compare(Object elementOne, Object elementTwo); - - /** - * Sort the objects in the array and return the array. - */ - private Object[] quickSort(Object[] array, int left, int right) { - int originalLeft = left; - int originalRight = right; - Object mid = array[(left + right) / 2]; - - do { - while (compare(array[left], mid)) - left++; - while (compare(mid, array[right])) - right--; - if (left <= right) { - Object tmp = array[left]; - array[left] = array[right]; - array[right] = tmp; - left++; - right--; - } - } while (left <= right); - - if (originalLeft < right) - array = quickSort(array, originalLeft, right); - if (left < originalRight) - array = quickSort(array, left, originalRight); - - return array; - } - - /** - * Return a new (quick)sorted array from this unsorted array. The original - * array is not modified. - */ - public Object[] sort(Object[] unSortedCollection) { - int size = unSortedCollection.length; - Object[] sortedCollection = new Object[size]; - - //copy the array so can return a new sorted collection - System.arraycopy(unSortedCollection, 0, sortedCollection, 0, size); - if (size > 1) - quickSort(sortedCollection, 0, size - 1); - - return sortedCollection; - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/TextUtilities.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/TextUtilities.java deleted file mode 100644 index 423fa49d4f..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/TextUtilities.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - - -/** - * Collection of text functions. - * @deprecated - the JFace class is public in 3.1 - */ -// This class was originally copied from org.eclipse.jface.text, and made -// public -public class TextUtilities { - /** - * Returns whether the text ends with one of the given search strings. - */ - public static boolean endsWith(String[] searchStrings, String text) { - for (int i = 0; i < searchStrings.length; i++) { - if (text.endsWith(searchStrings[i])) - return true; - } - return false; - } - - /** - * Returns the position in the string greater than offset of the longest - * matching search string. - */ - public static int[] indexOf(String[] searchStrings, String text, int offset) { - - int[] result = {-1, -1}; - - for (int i = 0; i < searchStrings.length; i++) { - int index = text.indexOf(searchStrings[i], offset); - if (index >= 0) { - - if (result[0] == -1) { - result[0] = index; - result[1] = i; - } else if (index < result[0]) { - result[0] = index; - result[1] = i; - } else if (index == result[0] && searchStrings[i].length() > searchStrings[result[1]].length()) { - result[0] = index; - result[1] = i; - } - } - } - - return result; - - } -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/URIResolver.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/URIResolver.java deleted file mode 100644 index e2259eb4fd..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/URIResolver.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - -import java.io.InputStream; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; - - -/** - * @deprecated - * - * Should use extensible URIResolver from org.eclipse.wst.common.uriresolver - * instead. - */ - -public interface URIResolver { - - String getFileBaseLocation(); - - /** - * Resolve the (possibly relative) URI acording to RFC1808 using the - * default file base location. Resolves resource references into absolute - * resource locations without ensuring that the resource actually exists. - */ - String getLocationByURI(String uri); - - /** - * Resolve the (possibly relative) URI acording to RFC1808 using the - * default file base location. Resolves resource references into absolute - * resource locations without ensuring that the resource actually exists. - * - * If resolveCrossProjectLinks is set to true, then this method will - * properly resolve the URI if it is a valid URI to another (appropriate) - * project. - */ - String getLocationByURI(String uri, boolean resolveCrossProjectLinks); - - /** - * Perform the getLocationByURI action using the baseReference as the - * point of reference instead of the default for this resolver - */ - String getLocationByURI(String uri, String baseReference); - - /** - * Perform the getLocationByURI action using the baseReference as the - * point of reference instead of the default for this resolver - * - * If resolveCrossProjectLinks is set to true, then this method will - * properly resolve the URI if it is a valid URI to another (appropriate) - * project. - */ - String getLocationByURI(String uri, String baseReference, boolean resolveCrossProjectLinks); - - IProject getProject(); - - IContainer getRootLocation(); - - /** - * Attempts to return a direct inputstream to the given URI which must be - * relative to the default point of reference. - * - */ - InputStream getURIStream(String uri); - - void setFileBaseLocation(String newLocation); - - void setProject(IProject newProject); - -} diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Utilities.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Utilities.java deleted file mode 100644 index 911c5e921c..0000000000 --- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/util/Utilities.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.core.internal.util; - - - -import java.io.BufferedInputStream; -import java.io.InputStream; - -import org.eclipse.wst.sse.core.internal.encoding.CodedIO; -import org.eclipse.wst.sse.core.internal.encoding.util.BufferedLimitedStream; - - - -public class Utilities { - - /** - * a common calculation in some of the parsing methods (e.g. in - * ContextRegion and IStructuredDocumentRegion) - */ - public static int calculateLengthDifference(String changes, int lengthToReplace) { - // determine the length by the text itself, or, if there is no text to - // insert (i.e. we are doing a delete) then calculate the length as - // a negative number to denote the amount to delete. - // For a straight insert, the selection Length will be zero. - int lengthDifference = 0; - if (changes == null) { - // the delete case - lengthDifference = 0 - lengthToReplace; - } - else { - lengthDifference = changes.length() - lengthToReplace; - } - if (Debug.debugStructuredDocument) { - System.out.println("lengthDifference: " + lengthDifference);//$NON-NLS-1$ - } - return lengthDifference; - } - - /** - * Returns true iff both parameters are not null and the object is within - * the array. Careful, this uses identity. Not good for basic strings. - */ - public static boolean contains(Object[] objectArray, Object object) { - boolean result = false; - // if object or objectArray is null, return false - if ((objectArray != null) && (object != null)) { - for (int i = 0; i < objectArray.length; i++) { - if (objectArray[i] == object) { - result = true; - break; - } - } - } - return result; - } - - public static boolean containsString(String[] objectArray, String object) { - boolean result = false; - // if object or objectArray is null, return false - if ((objectArray != null) && (object != null)) { - for (int i = 0; i < objectArray.length; i++) { - if (objectArray[i].equals(object)) { - result = true; - break; - } - } - } - return result; - } - - /** - * Ensures that an InputStream has mark/reset support, is readlimit is - * set, and that the stream is "limitable" (that is, reports "end of - * input" rather than allow going past mark). This is very specialized - * stream introduced to overcome - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67211. See also - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=68565 - */ - public static InputStream getLimitedStream(InputStream original) { - if (original == null) - return null; - if (original instanceof BufferedLimitedStream) - return original; - return new BufferedLimitedStream(original, CodedIO.MAX_BUF_SIZE); - } - - /** - * <p> - * Ensures that an InputStream has mark/reset support. - * </p> - * <p> - * It's vital that a BufferedInputStream <b>not</b> be wrapped in another - * BufferedInputStream as each can preemptively consume <i>n</i> bytes - * (e.g. 2048) from the parent stream before any requests are made. The - * cascading effect is that the second/inner BufferedInputStream can never - * rewind itself to the first <i>n</i> bytes since they were already - * consumed by its parent. - * </p> - */ - public static InputStream getMarkSupportedStream(InputStream original) { - if (original == null) - return null; - if (original.markSupported()) - return original; - InputStream buffered = new BufferedInputStream(original, CodedIO.MAX_BUF_SIZE); - buffered.mark(CodedIO.MAX_MARK_SIZE); - return buffered; - } - - /** - * Used for log/trace messages. Id is assumed to be some form of a - * filename. See IModelManager. - */ - public static String makeShortId(Object id) { - if (id == null) - id = "NOID";//$NON-NLS-1$ - String whole = id.toString(); - String part = whole.substring(whole.lastIndexOf("/") + 1); //$NON-NLS-1$ - return "..." + part; //$NON-NLS-1$ - } - - - /** - * Utilities constructor comment. - */ - public Utilities() { - super(); - } -} |