From: khartlage Date: Sat, 28 Jun 2003 12:52:22 +0000 (+0000) Subject: Remove String#replaceAll() with StringUtil#replaceAll() for 1.3 compatibility X-Git-Url: http://secure.phpeclipse.com?hp=6652e3925e57f8b2da09c22577610835aefd9c29 Remove String#replaceAll() with StringUtil#replaceAll() for 1.3 compatibility --- diff --git a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java index 488ca10..34b50ff 100644 --- a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java +++ b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java @@ -9,6 +9,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.StringTokenizer; +import net.sourceforge.phpdt.internal.ui.util.StringUtil; + import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -286,7 +288,7 @@ public IFile createNewFile(String fileName) { String insert = (String)inserts.get(i); String replace = (String)names.get(i); - buffer = buffer.replaceAll(insert, replace.toLowerCase()); + buffer = StringUtil.replaceAll(buffer, insert, replace.toLowerCase()); try { ps = new PipedOutputStream(); is = new PipedInputStream(ps); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java index 737d557..9ff6c61 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/externaltools/variable/UrlExpander.java @@ -6,7 +6,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.jface.preference.IPreferenceStore; /** - * Expands a variable into the last opened PHP file + * Expands a variable into a localhost/documentRoot URL string *

* This class is not intended to be extended by clients. *

@@ -21,7 +21,7 @@ public class UrlExpander extends ResourceExpander { //implements IVariableTextEx } /** - * Returns a string representation of the path to a file or directory + * Returns a string representation to a localhost/documentRoot URL * for the given variable tag and value or null. * * @see IVariableTextExpander#getText(String, String, ExpandVariableContext) @@ -32,7 +32,6 @@ public class UrlExpander extends ResourceExpander { //implements IVariableTextEx IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); String localhostURL = path.toString(); String lowerCaseFileName = localhostURL.toLowerCase(); - // fileName = "http://localhost"+fileName.replaceAll("c:", ""); String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); documentRoot = documentRoot.replace('\\', '/'); documentRoot = documentRoot.toLowerCase(); @@ -40,8 +39,6 @@ public class UrlExpander extends ResourceExpander { //implements IVariableTextEx if (lowerCaseFileName.startsWith(documentRoot)) { localhostURL = localhostURL.substring(documentRoot.length()); localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF)+ localhostURL; - System.out.println(localhostURL); - // localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF)+ localhostURL;// + localhostURL.replaceAll(documentRoot, ""); } return localhostURL; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StringUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StringUtil.java new file mode 100644 index 0000000..8ade751 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/StringUtil.java @@ -0,0 +1,33 @@ +/* + * Created on 28.06.2003 + * + */ +package net.sourceforge.phpdt.internal.ui.util; + +/** + * some string utilities + * + */ +public class StringUtil { + + /** + * Replace each substring of str which matches findStr with replaceStr + * + * @param str the string the substrings should be replaced in + * @param findStr the substring to be replaced + * @param replaceStr the replacement + * @return the resultstring + */ + public static final String replaceAll(String str, String findStr, String replaceStr) { + StringBuffer buf = new StringBuffer(); + + int lastindex = 0; + int indexOf = 0; + while ((indexOf=str.indexOf(findStr, lastindex)) != -1) { + buf.append(str.substring(lastindex, indexOf)).append(replaceStr); + lastindex = indexOf + findStr.length(); + } + buf.append(str.substring(lastindex)); + return buf.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index 18b7858..3fbcb11 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -88,24 +88,6 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { // single file: IFile file = (IFile) resource; String localhostURL; -// IPath path = file.getFullPath(); -// -// String localhostURL = file.getLocation().toString(); -// String lowerCaseFileName = localhostURL.toLowerCase(); -// // fileName = "http://localhost"+fileName.replaceAll("c:", ""); -// String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); -// documentRoot = documentRoot.replace('\\', '/'); -// documentRoot = documentRoot.toLowerCase(); -// -// if (lowerCaseFileName.startsWith(documentRoot)) { -// localhostURL = localhostURL.substring(documentRoot.length()); -// } else { -// MessageDialog.openInformation(shell, "Wrong DocumentRoot", "Adjust DocumentRoot: " + documentRoot); -// return; -// } -// -// localhostURL = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL.replaceAll(documentRoot, ""); - if ((localhostURL=getLocalhostURL(store, (IFile) resource)) == null) { MessageDialog.openInformation(shell, "Couldn't create localhost URL", "Please configure your localhost and documentRoot"); return; @@ -154,7 +136,6 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { String localhostURL = file.getLocation().toString(); String lowerCaseFileName = localhostURL.toLowerCase(); - // fileName = "http://localhost"+fileName.replaceAll("c:", ""); String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); documentRoot = documentRoot.replace('\\', '/'); documentRoot = documentRoot.toLowerCase(); @@ -165,7 +146,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { return null; } - return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL.replaceAll(documentRoot, ""); + return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL; } diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java index 25183f6..3414145 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java @@ -19,6 +19,7 @@ import net.sourceforge.phpdt.internal.compiler.ast.*; import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; +import net.sourceforge.phpdt.internal.ui.util.StringUtil; /** * A new php parser. @@ -192,9 +193,9 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon Hashtable attributes = new Hashtable(); - current = current.replaceAll("\n", ""); - current = current.replaceAll("", ""); - current = current.replaceAll("", ""); + current = StringUtil.replaceAll(current, "\n", ""); + current = StringUtil.replaceAll(current, "", ""); + current = StringUtil.replaceAll(current, "", ""); MarkerUtilities.setMessage(attributes, current); if (current.indexOf(PARSE_ERROR_STRING) != -1) diff --git a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java index 3962da9..ed690b0 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java @@ -1,16 +1,18 @@ package test; +import java.text.MessageFormat; +import java.util.Hashtable; + +import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; +import net.sourceforge.phpdt.internal.ui.util.StringUtil; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.texteditor.MarkerUtilities; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; -import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; - -import java.text.MessageFormat; -import java.util.Hashtable; /** * The superclass for our PHP parsers. @@ -36,13 +38,11 @@ public abstract class PHPParserSuperclass { final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); final String filename = file.getLocation().toString(); - final String[] arguments = {filename}; - final MessageFormat form = - new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); + final String[] arguments = { filename }; + final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); final String command = form.format(arguments); - final String parserResult = - PHPStartApacheAction.getParserOutput(command, "External parser: "); + final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); try { // parse the buffer to find the errors and warnings @@ -56,8 +56,7 @@ public abstract class PHPParserSuperclass { * @param output the external parser output * @param file the file that was parsed. */ - protected static void createMarkers(final String output, final IFile file) - throws CoreException { + protected static void createMarkers(final String output, final IFile file) throws CoreException { // delete all markers file.deleteMarkers(IMarker.PROBLEM, false, 0); @@ -79,16 +78,14 @@ public abstract class PHPParserSuperclass { } } - private static void scanLine(final String output, final IFile file, final int indx, final int brIndx) - throws CoreException { + private static void scanLine(final String output, final IFile file, final int indx, final int brIndx) throws CoreException { String current; // String outLineNumberString; never used final StringBuffer lineNumberBuffer = new StringBuffer(10); char ch; current = output.substring(indx, brIndx); - if (current.indexOf(PARSE_WARNING_STRING) != -1 - || current.indexOf(PARSE_ERROR_STRING) != -1) { + if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { final int onLine = current.indexOf("on line "); if (onLine != -1) { lineNumberBuffer.delete(0, lineNumberBuffer.length()); @@ -103,17 +100,15 @@ public abstract class PHPParserSuperclass { final Hashtable attributes = new Hashtable(); - current = current.replaceAll("\n", ""); - current = current.replaceAll("", ""); - current = current.replaceAll("", ""); + current = StringUtil.replaceAll(current, "\n", ""); + current = StringUtil.replaceAll(current, "", ""); + current = StringUtil.replaceAll(current, "", ""); MarkerUtilities.setMessage(attributes, current); if (current.indexOf(PARSE_ERROR_STRING) != -1) attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); else if (current.indexOf(PARSE_WARNING_STRING) != -1) - attributes.put( - IMarker.SEVERITY, - new Integer(IMarker.SEVERITY_WARNING)); + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); else attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); MarkerUtilities.setLineNumber(attributes, lineNumber); @@ -153,26 +148,27 @@ public abstract class PHPParserSuperclass { * {@link PHPParserSuperclass#INFO},{@link PHPParserSuperclass#WARNING}),{@link PHPParserSuperclass#TASK}) * @throws CoreException an exception throwed by the MarkerUtilities */ - public static void setMarker(final IFile file, - final String message, - final int charStart, - final int charEnd, - final int errorLevel) - throws CoreException { + public static void setMarker( + final IFile file, + final String message, + final int charStart, + final int charEnd, + final int errorLevel) + throws CoreException { if (file != null) { final Hashtable attributes = new Hashtable(); MarkerUtilities.setMessage(attributes, message); switch (errorLevel) { - case ERROR: + case ERROR : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); break; - case WARNING: + case WARNING : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); break; - case INFO: + case INFO : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); break; - case TASK: + case TASK : attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); break; } @@ -191,27 +187,23 @@ public abstract class PHPParserSuperclass { * {@link PHPParserSuperclass#INFO},{@link PHPParserSuperclass#WARNING}) * @throws CoreException an exception throwed by the MarkerUtilities */ - public static void setMarker(final IFile file, - final String message, - final int line, - final int errorLevel, - final String location) - throws CoreException { + public static void setMarker(final IFile file, final String message, final int line, final int errorLevel, final String location) + throws CoreException { if (file != null) { String markerKind = IMarker.PROBLEM; final Hashtable attributes = new Hashtable(); MarkerUtilities.setMessage(attributes, message); switch (errorLevel) { - case ERROR: + case ERROR : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); break; - case WARNING: + case WARNING : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); break; - case INFO: + case INFO : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); break; - case TASK: + case TASK : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); markerKind = IMarker.TASK; break; @@ -233,27 +225,28 @@ public abstract class PHPParserSuperclass { * @param location the location of the error * @throws CoreException an exception throwed by the MarkerUtilities */ - public static void setMarker(final IFile file, - final String message, - final int charStart, - final int charEnd, - final int errorLevel, - final String location) - throws CoreException { + public static void setMarker( + final IFile file, + final String message, + final int charStart, + final int charEnd, + final int errorLevel, + final String location) + throws CoreException { if (file != null) { final Hashtable attributes = new Hashtable(); MarkerUtilities.setMessage(attributes, message); switch (errorLevel) { - case ERROR: + case ERROR : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); break; - case WARNING: + case WARNING : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); break; - case INFO: + case INFO : attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); break; - case TASK: + case TASK : attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK)); break; }