001: /*
002: * WebSphinx web-crawling toolkit
003: *
004: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
020: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
022: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
023: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: *
031: */
032:
033: package websphinx.workbench;
034:
035: import java.applet.*;
036: import java.awt.*;
037: import java.net.URL;
038: import websphinx.Crawler;
039: import websphinx.Tagexp;
040: import rcm.awt.PopupDialog;
041:
042: public class WorkbenchApplet extends Applet {
043:
044: Workbench workbench;
045:
046: public Workbench makeWorkbench() {
047: String openURL = getParameter("open");
048: String newClassname = getParameter("new");
049:
050: try {
051: if (openURL != null)
052: return new Workbench(
053: new URL(getDocumentBase(), openURL));
054: else if (newClassname != null)
055: return new Workbench((Crawler) Class.forName(
056: newClassname).newInstance());
057: else
058: return new Workbench();
059: } catch (Exception e) {
060: PopupDialog.warn(null, "Error", e.toString());
061: throw new Error(e.toString());
062: }
063: }
064:
065: public void init() {
066: super .init();
067:
068: String targetName = getParameter("target");
069: if (targetName != null)
070: Context.setApplet(this , targetName);
071: else
072: Context.setApplet(this );
073:
074: workbench = makeWorkbench();
075:
076: String param;
077: if ((param = getParameter("advanced")) != null)
078: workbench.setAdvancedMode(isTrue(param));
079:
080: /*
081: if ((param = getParameter ("graph")) != null)
082: workbench.setGraphVisible (isTrue (param));
083:
084: if ((param = getParameter ("statistics")) != null)
085: workbench.setStatisticsVisible (isTrue (param));
086:
087: if ((param = getParameter ("log")) != null)
088: workbench.setLoggerVisible (isTrue (param));
089: */
090:
091: Crawler crawler = workbench.getCrawler();
092:
093: String action = getParameter("action");
094: if (action != null) {
095: String filename = getParameter("filename");
096: String pattern = getParameter("pattern");
097:
098: if (action.equalsIgnoreCase("concatenate"))
099: crawler.setAction(new ConcatAction(filename, true));
100: else if (action.equalsIgnoreCase("save"))
101: crawler.setAction(new MirrorAction(filename, true));
102: else if (action.equalsIgnoreCase("visualize")) {
103: crawler.setAction(null);
104: //workbench.setGraphVisible (true);
105: } else if (action.equalsIgnoreCase("extract"))
106: crawler.setAction(new ExtractAction(
107: new Tagexp(pattern), true, filename, false));
108: else if (action.equalsIgnoreCase("none"))
109: crawler.setAction(null);
110: else
111: throw new RuntimeException("unknown action: " + action);
112: }
113:
114: String urls = getParameter("urls");
115: if (urls != null)
116: try {
117: crawler.setRootHrefs(urls);
118: } catch (java.net.MalformedURLException e) {
119: throw new RuntimeException(e.toString());
120: }
121:
122: String domain = getParameter("domain");
123: if (domain != null) {
124: if (domain.equalsIgnoreCase("server"))
125: crawler.setDomain(Crawler.SERVER);
126: else if (domain.equalsIgnoreCase("subtree"))
127: crawler.setDomain(Crawler.SUBTREE);
128: else
129: crawler.setDomain(Crawler.WEB);
130: }
131:
132: String type = getParameter("type");
133: if (type != null) {
134: if (type.equalsIgnoreCase("images+hyperlinks"))
135: crawler.setLinkType(Crawler.HYPERLINKS_AND_IMAGES);
136: else if (type.equalsIgnoreCase("all"))
137: crawler.setLinkType(Crawler.ALL_LINKS);
138: else
139: crawler.setLinkType(Crawler.WEB);
140: }
141:
142: String depth = getParameter("depth");
143: if (depth != null)
144: crawler.setMaxDepth(Integer.parseInt(depth));
145:
146: String dfs = getParameter("depthfirst");
147: if (dfs != null)
148: crawler.setDepthFirst(isTrue(dfs));
149:
150: workbench.setCrawler(crawler);
151:
152: setLayout(new BorderLayout());
153: add("Center", workbench);
154: }
155:
156: private static boolean isTrue(String s) {
157: return s != null
158: && (s.equalsIgnoreCase("on") || s.equalsIgnoreCase("1")
159: || s.equalsIgnoreCase("yes") || s
160: .equalsIgnoreCase("true"));
161: }
162: }
|