KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > browser > macosx > SafariBrowser


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.browser.macosx;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.StringTokenizer JavaDoc;
15
16 import org.eclipse.ui.internal.browser.browsers.DefaultBrowser;
17
18 public class SafariBrowser extends DefaultBrowser {
19     
20     public SafariBrowser(String JavaDoc id, String JavaDoc location, String JavaDoc parameters) {
21         super(id, location, parameters);
22         this.location = location;
23         this.parameters = parameters;
24     }
25
26     /**
27      * Creates the final command to launch.
28      *
29      * @param path
30      * @param url
31      * @return String[]
32      */

33     protected String JavaDoc[] prepareCommand(String JavaDoc path, String JavaDoc url) {
34         if (url != null && url.toLowerCase().startsWith("file:")) { //$NON-NLS-1$
35
url = url.substring(5);
36         }
37         
38         ArrayList JavaDoc tokenList = new ArrayList JavaDoc();
39         //Divide along quotation marks
40
StringTokenizer JavaDoc qTokenizer = new StringTokenizer JavaDoc(path.trim(),
41             "\"", true); //$NON-NLS-1$
42
boolean withinQuotation = false;
43         String JavaDoc quotedString = ""; //$NON-NLS-1$
44
while (qTokenizer.hasMoreTokens()) {
45             String JavaDoc curToken = qTokenizer.nextToken();
46             if (curToken.equals("\"")) { //$NON-NLS-1$
47
if (withinQuotation) {
48                     // quotes prevent launching on Unix 35673
49
tokenList.add(quotedString);
50                 } else {
51                     quotedString = ""; //$NON-NLS-1$
52
}
53                 withinQuotation = !withinQuotation;
54                 continue;
55             } else if (withinQuotation) {
56                 quotedString = curToken;
57                 continue;
58             } else {
59                 //divide unquoted strings along white space
60
StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(curToken.trim());
61                 while (parser.hasMoreTokens()) {
62                     tokenList.add(parser.nextToken());
63                 }
64             }
65         }
66         // substitute %1 by url
67
boolean substituted = false;
68         for (int i = 0; i < tokenList.size(); i++) {
69             String JavaDoc token = (String JavaDoc) tokenList.get(i);
70             String JavaDoc newToken = doSubstitutions(token, url);
71             if (newToken != null) {
72                 tokenList.set(i, newToken);
73                 substituted = true;
74             }
75         }
76         // add the url if not substituted already
77
if (!substituted)
78             tokenList.add(url);
79
80         String JavaDoc[] command = new String JavaDoc[tokenList.size()];
81         tokenList.toArray(command);
82         return command;
83     }
84 }
Popular Tags