You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/05/07 16:29:49 UTC

svn commit: r535882 - in /felix/sandbox/donsez/shell.gui.scriptplugin: ./ doc/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/shell/ src/main/java/org/apache/fel...

Author: donsez
Date: Mon May  7 07:29:47 2007
New Revision: 535882

URL: http://svn.apache.org/viewvc?view=rev&rev=535882
Log:
creation of shell.gui.scriptplugin

Added:
    felix/sandbox/donsez/shell.gui.scriptplugin/
    felix/sandbox/donsez/shell.gui.scriptplugin/doc/
    felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/doc/shell.gui.scriptplugin.png   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java   (with props)
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/
    felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml   (with props)

Added: felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt Mon May  7 07:29:47 2007
@@ -0,0 +1,6 @@
+shell.gui.scriptplugin TODO LIST
+--------------------------------
+
+* implements the script saving
+* ...
+

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/doc/TODOLIST.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt Mon May  7 07:29:47 2007
@@ -0,0 +1,9 @@
+install file:E:\Felix-Dist\felix-svn\trunk\javax.servlet\target\javax.servlet-0.9.0-incubator-SNAPSHOT.jar
+install file:E:\Felix-Dist\felix-svn\trunk\org.osgi.compendium\target\org.osgi.compendium-0.9.0-incubator-SNAPSHOT.jar
+start file:E:\Felix-Dist\felix-svn\trunk\scr\target\org.apache.felix.scr-0.9.0-incubator-SNAPSHOT.jar
+
+
+start file:E:\Felix-Dist\felix-svn\trunk\shell.gui\target\org.apache.felix.shell.gui-0.9.0-incubator-SNAPSHOT.jar
+start file:E:\Felix-Dist\felix-svn\trunk\shell.gui.plugin\target\org.apache.felix.shell.gui.plugin-0.9.0-incubator-SNAPSHOT.jar
+start file:F:\osgi\felix-sandbox-donsez\shell.gui.scriptplugin\target\org.apache.felix.shell.gui.scriptplugin-0.9.0-incubator-SNAPSHOT.jar
+

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/doc/script.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/doc/shell.gui.scriptplugin.png
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/doc/shell.gui.scriptplugin.png?view=auto&rev=535882
==============================================================================
Binary file - no diff available.

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/doc/shell.gui.scriptplugin.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml Mon May  7 07:29:47 2007
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+	<properties>
+		<repositoryLocation>http://www-adele.imag.fr/users/Didier.Donsez/dev/felix/sandbox/</repositoryLocation>
+		<description>A plugin for the ShellGUI bundle to script commands./</description>
+	</properties>  
+
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.9.0-incubator-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Shell GUI Script Plugin</name>
+  <artifactId>org.apache.felix.shell.gui.scriptplugin</artifactId>
+  <description>${description}</description>
+
+    <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.shell</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.bundlerepository</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.shell.gui</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.scr</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+	  	<!--
+			docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html
+			and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html
+		-->
+		
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Bundle-Description>${description}</Bundle-Description>
+
+            <Private-Package>${pom.artifactId}.*</Private-Package>
+            <Import-Package>*</Import-Package>
+	    	    
+            <Export-Service>org.apache.felix.shell.gui.Plugin</Export-Service>
+            <Import-Service>org.apache.felix.shell.ShellService</Import-Service>
+	    
+            <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</Bundle-DocURL>
+            <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</Bundle-Url>
+            <Bundle-Source>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
+
+            <Service-Component>OSGI-INF/component.xml</Service-Component>
+	    
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <!--
+  <repositories>
+    <repository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </repository>
+
+  </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>apache.m2.incubator</id>
+      <name>Apache M2 Incubator Repository</name>
+      <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+    </pluginRepository>
+  </pluginRepositories>
+  -->
+</project>
+
+

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java Mon May  7 07:29:47 2007
@@ -0,0 +1,195 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.shell.gui.scriptplugin;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.StringTokenizer;
+
+import org.apache.felix.shell.ShellService;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class RunImpl {
+
+	//member variables
+	private ShellService shellService = null;
+
+	// boolean variables for the run command options 
+	public boolean[] m_eps = new boolean[3];
+	public final int STOP_ID = 0;
+	public final int ECHO_ID = 1;
+	public final int PROMPT_ID = 2;
+
+	public void bindShellService(ShellService ref) {
+		shellService = ref;
+	}
+
+	public void unbindShellService(ShellService ref) {
+		shellService = null;
+	}
+
+	// private methods	
+	private void trace(String msg) {
+		if (true)
+			System.out.println(msg);
+	}
+	
+	/**
+	 *  prints a slightly superfluous help message on second 
+	 *               console method is never called, but could be used for
+	 *               a help button
+	 *
+	 * @param out
+	 */
+	public void printUsage(PrintStream out) {
+		out.println(" Load a script text file:");
+		out.println("    file:[path] or http://[path]");
+		out.println("press LOAD to view script");
+		out.println("edit script, then press RUN to execute script");
+		out.println("lower window will show the output");
+		out.println("RUN-options:");
+		out.println("e   - echo commands.");
+		out.println("p   - prompt each command.");
+		out.println("s   - stop on error.");
+		return;
+	}
+
+	/**
+	 *  loads a script from file or the "interweb"
+	 *
+	 * @param out
+	 * @param err
+	 */
+	public void loadScript(PrintStream out, PrintStream err, URL url) {
+
+		URLConnection urlcnx;
+		BufferedReader br;
+		try {
+			urlcnx = url.openConnection();
+			br =
+				new BufferedReader(
+					new InputStreamReader(urlcnx.getInputStream()));
+			String line = new String();
+			boolean moreLines = true;
+			while (moreLines) {
+				line = (String) br.readLine();
+				if (line != null) {
+					out.println(line);
+				} else {
+					moreLines = false;
+				}
+			}
+
+		} catch (IOException ioe) {
+			ioe.printStackTrace(err);
+			err.flush();
+			return;
+		}
+	}
+
+	/**
+	 *  slightly adapted execute method of the run command
+	 *               implementation
+	 *
+	 * @param  s
+	 * @param  out
+	 * @param  err
+	 */
+	public void execute(String s, PrintStream out, PrintStream err) {
+
+		BufferedReader br = new BufferedReader(new java.io.StringReader(s));
+		boolean stopOnError = m_eps[STOP_ID];
+		boolean echoCommand = m_eps[ECHO_ID];
+		boolean prompt = m_eps[PROMPT_ID];
+
+		if (shellService == null) {
+			err.println("No ShellService available !");
+			err.flush();
+			return;
+		}
+
+		ByteArrayOutputStream baerr = new ByteArrayOutputStream();
+		PrintStream pbaerr = new PrintStream(baerr);
+
+		try {
+			String commandLine;
+			while ((commandLine = br.readLine()) != null) {
+				commandLine = commandLine.trim();
+				if (commandLine.equals(""))
+					continue;
+
+				if (prompt)
+					out.print("-->");
+				if (echoCommand)
+					out.print(commandLine);
+				if (prompt || echoCommand)
+					out.println();
+
+				if (commandLine.startsWith("rem")
+					|| commandLine.startsWith("#")) {
+					out.println(commandLine);
+					out.flush();
+					continue;
+				}
+				if (commandLine.startsWith("wait")) {
+					StringTokenizer sto = new StringTokenizer(commandLine);
+					sto.nextToken();
+					if (sto.hasMoreTokens()) {
+						String waitingTimeStr = sto.nextToken();
+						int waitingTime = Integer.parseInt(waitingTimeStr);
+						try {
+							Thread.sleep(waitingTime * 1000);
+						} catch (InterruptedException e1) {
+						}
+					}
+					continue;
+				}
+				shellService.executeCommand(commandLine, out, pbaerr);
+				pbaerr.flush();
+				byte[] ba = baerr.toByteArray();
+				if (ba.length != 0) {
+					err.println(new String(ba));
+					err.flush();
+					if (stopOnError)
+						break;
+					baerr.reset();
+				}
+			}
+		} catch (IOException ioe) {
+			ioe.printStackTrace(err);
+			err.flush();
+			return;
+		} catch (Exception e) {
+			e.printStackTrace(err);
+			err.flush();
+			return;
+		} finally {
+			if (br != null)
+				try {
+					br.close();
+				} catch (IOException e) {
+				}
+		}
+	}
+}

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/RunImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java Mon May  7 07:29:47 2007
@@ -0,0 +1,35 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.shell.gui.scriptplugin;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface Script {
+	/**
+	 *  displays output and error messages on second console
+	 * @param text
+	 */
+	public void addText(String text);
+
+	/**
+	 * displays loaded text file on first console
+	 *
+	 * @param text
+	 */
+	public void loadText(String text);
+}

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/Script.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java Mon May  7 07:29:47 2007
@@ -0,0 +1,45 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.shell.gui.scriptplugin;
+
+import java.io.OutputStream;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+class ScriptLoadStream extends OutputStream {
+	private Script m_script;
+
+	public ScriptLoadStream(Script script) {
+		m_script = script;
+	}
+
+	public void write(byte[] b) {
+		String tmp = new String(b);
+		m_script.loadText(tmp);
+	}
+
+	public void write(byte[] b, int off, int len) {
+		String tmp = new String(b, off, len);
+		m_script.loadText(tmp);
+	}
+
+	public void write(int b) {
+		byte[] ba = {(byte) b };
+		m_script.loadText(new String(ba));
+	}
+}

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptLoadStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java Mon May  7 07:29:47 2007
@@ -0,0 +1,353 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.shell.gui.scriptplugin;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollBar;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import org.apache.felix.shell.ShellService;
+import org.apache.felix.shell.gui.Plugin;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ScriptPlugin extends JPanel implements Plugin, Script {
+	/**
+	 * default serial id
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private RunImpl m_impl = null;
+
+	private JTextField m_urlField = null;
+	private JButton m_loadScriptButton = null;
+	private JButton m_saveScriptButton = null;
+	private JButton m_clearScriptButton = null;
+
+	// displays loaded scripts
+	private JTextArea m_scriptArea = null;
+
+	//displays the result of the executed commands
+	private JTextArea m_outputArea = null;
+
+	private PrintStream m_out = null;
+	private PrintStream m_load = null;
+
+	private JButton m_clearOutputButton = null;
+	private JCheckBox m_echoBox = null;
+	private JCheckBox m_promptBox = null;
+	private JCheckBox m_stopBox = null;
+	private JButton m_runButton = null;
+
+	private JScrollPane m_scroll = null;
+	private JScrollPane m_scroll2 = null;
+
+	public ScriptPlugin() {
+		m_impl=new RunImpl();
+	}
+
+	public void activate(ComponentContext componentContext) {
+		m_out = new PrintStream(new ScriptStream(this));
+		m_load = new PrintStream(new ScriptLoadStream(this));
+		initialize();
+	}
+	
+    // Plugin interface methods.
+
+	/**
+	 * @see org.apache.felix.shellgui.Plugin#getName()
+	 */
+    public String getName()
+    {
+        return "Script";    
+    }
+    
+	/**
+	 * @see org.apache.felix.shellgui.Plugin#getGUI()
+	 */
+    public Component getGUI()
+    {
+        return this;
+    }
+    
+    // SCR CALLBACK METHOD
+	
+	public void bindShellService(ShellService ref) {
+		m_impl.bindShellService(ref);
+	}
+
+	public void unbindShellService(ShellService ref) {
+		m_impl.unbindShellService(ref);
+	}
+
+    // Implementation.
+
+	/**
+	 * create user interface components
+	 *
+	 */
+	private void initialize() {
+		setLayout(new BorderLayout());
+		JPanel loadJPanel=new JPanel();
+		add(loadJPanel, BorderLayout.NORTH);
+		loadJPanel.add(new JLabel("URL"));
+		loadJPanel.add(m_urlField = new JTextField(20));
+		loadJPanel.add(m_loadScriptButton = new JButton("Load"));
+		loadJPanel.add(m_saveScriptButton = new JButton("Save"));
+		loadJPanel.add(m_clearScriptButton = new JButton("Clear"));
+		m_loadScriptButton.setMnemonic('l');
+		m_saveScriptButton.setMnemonic('s');
+
+
+		JPanel centerJPanel=new JPanel();
+		centerJPanel.setLayout(new GridLayout(2,1));
+		add(centerJPanel,BorderLayout.CENTER);
+		
+		
+		centerJPanel.add(m_scroll = new JScrollPane(m_scriptArea = new JTextArea())/*,BorderLayout.NORTH*/);
+		m_scriptArea.setFont(new java.awt.Font("Monospaced", 0, 12));
+		m_scriptArea.setLineWrap(true);
+		m_scriptArea.setAutoscrolls(true);
+		m_scriptArea.setEnabled(true);
+		m_scriptArea.setEditable(true);
+		m_scriptArea.setFont(new Font("Monospaced", 0, 12));
+		m_scroll.setAutoscrolls(true);
+
+		centerJPanel.add(m_scroll2 = new JScrollPane(m_outputArea = new JTextArea())/*,BorderLayout.SOUTH*/);
+		m_outputArea.setFont(new java.awt.Font("Monospaced", 0, 12));
+		m_outputArea.setLineWrap(true);
+		m_outputArea.setAutoscrolls(true);
+		m_outputArea.setEnabled(true);
+		m_outputArea.setEditable(false);
+		m_outputArea.setFont(new Font("Monospaced", 0, 12));
+		m_scroll2.setAutoscrolls(true);
+
+		add(createButtonPanel(), BorderLayout.SOUTH);
+
+		// Set table scroll pane to reasonable size.
+		m_scroll.setPreferredSize(new Dimension(50, 50));
+		m_scriptArea.setMinimumSize(new Dimension(0, 0));
+
+		m_scroll2.setPreferredSize(new Dimension(50, 50));
+		m_outputArea.setMinimumSize(new Dimension(0, 0));
+
+		createEventListeners();
+	}
+	/**
+	 * @return Jpanel
+	 */
+	private JPanel createButtonPanel() {
+		JPanel panel2 = new JPanel();
+		panel2.add(m_echoBox = new JCheckBox("Echo"));
+		m_echoBox.setSelected(true);
+		panel2.add(m_promptBox = new JCheckBox("Prompt"));
+		m_promptBox.setSelected(true);
+		panel2.add(m_stopBox = new JCheckBox("Stop"));
+		panel2.add(m_runButton = new JButton("Run"));
+		m_stopBox.setSelected(true);
+		panel2.add(m_clearOutputButton = new JButton("Clear"));
+		m_clearOutputButton.setMnemonic('C');
+		m_runButton.setMnemonic('R');
+		boolean[] setOptions = { true, true, true };
+		m_impl.m_eps = setOptions;
+		return panel2;
+	}
+
+	/**
+	 * create action listeners for the three buttons
+	 */
+	private void createEventListeners() {
+
+		m_loadScriptButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				//m_impl.printUsage(m_out);
+				String urlstr = m_urlField.getText();
+
+				if (urlstr.length() > 0) {
+					try {
+						//m_impl.loadScript(m_load, m_out, urlstr);
+						URL url;
+						url = new URL(m_urlField.getText());
+						m_impl.loadScript(m_load, m_out, url);
+					} catch (MalformedURLException e) {
+						JOptionPane.showMessageDialog(
+							JOptionPane.getFrameForComponent(ScriptPlugin.this),
+							e.getMessage(),
+							"URL NOT VALID",
+							JOptionPane.ERROR_MESSAGE);
+					}
+				}
+			}
+
+		});
+
+		m_saveScriptButton.addActionListener(new SaveActionListener(this));
+				
+		m_clearScriptButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				m_scriptArea.setText(" ");
+				m_urlField.setText(" ");
+			}
+		});
+
+		
+		m_clearOutputButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				m_outputArea.setText(" ");
+				m_echoBox.setSelected(true);
+				m_promptBox.setSelected(true);
+				m_stopBox.setSelected(true);
+				boolean[] setOptions = { true, true, true };
+				m_impl.m_eps = setOptions;
+			}
+		});
+
+		// executes script displayed in the first window
+		m_runButton.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent event) {
+				String s = m_scriptArea.getText();
+				m_impl.execute(s, m_out, m_out);
+			}
+		});
+
+		//add item listeners for the check boxes
+		m_promptBox.addItemListener(new ItemListener() {
+			public void itemStateChanged(ItemEvent e) {
+				if (e.getStateChange() == ItemEvent.SELECTED) {
+					m_impl.m_eps[m_impl.PROMPT_ID] = true;
+				} else {
+					m_impl.m_eps[m_impl.PROMPT_ID] = false;
+				}
+			}
+		});
+
+		m_stopBox.addItemListener(new ItemListener() {
+			public void itemStateChanged(ItemEvent e) {
+				if (e.getStateChange() == ItemEvent.SELECTED) {
+					m_impl.m_eps[m_impl.STOP_ID] = true;
+				} else {
+					m_impl.m_eps[m_impl.STOP_ID] = false;
+				}
+			}
+		});
+
+		m_echoBox.addItemListener(new ItemListener() {
+			public void itemStateChanged(ItemEvent e) {
+				if (e.getStateChange() == ItemEvent.SELECTED) {
+					m_impl.m_eps[m_impl.ECHO_ID] = true;
+				} else {
+					m_impl.m_eps[m_impl.ECHO_ID] = false;
+				}
+			}
+		});
+	}
+
+	
+	class SaveActionListener implements ActionListener {
+		private Component parent;
+		public SaveActionListener(Component parent) {
+			this.parent=parent;
+		}
+
+		public void actionPerformed(ActionEvent event) {
+			JFileChooser chooser = new JFileChooser();
+			// Note: source for ExampleFileFilter can be found in FileChooserDemo,
+			// under the demo/jfc directory in the JDK
+			// and in http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
+			/*
+			    ExampleFileFilter filter = new ExampleFileFilter();
+			    filter.addExtension("txt");
+			    filter.setDescription("Script");
+			    chooser.setFileFilter(filter);
+			 */
+
+			int returnVal = chooser.showOpenDialog(parent);
+			if(returnVal == JFileChooser.APPROVE_OPTION) {
+				System.out.println("You chose to save the script in this file: "
+					+chooser.getSelectedFile().getName()
+					+ " in "
+					+chooser.getCurrentDirectory().getName()
+					);
+				System.err.println("However, this function is not implemented");
+			}		
+		}
+	}
+	
+	/**
+	 * displays output and error messages on second console
+	 *
+	 * @param  text
+	 */
+	public void addText(String text) {
+		m_outputArea.append(text);
+		if (m_outputArea.isDisplayable()) {
+			try {
+				//Scroll to end of window
+				m_outputArea.setCaretPosition(Integer.MAX_VALUE);
+			} catch (Exception e) {
+			} // Just for safety
+		}
+		validate();
+		JScrollBar sb = m_scroll2.getVerticalScrollBar();
+		if ((sb != null) && (sb.isVisible())) {
+			sb.setValue(Integer.MAX_VALUE);
+		}
+	}
+
+	/**
+	 *  displays loaded text file on first console
+	 *
+	 * @param text
+	 */
+	public void loadText(String text) {
+		m_scriptArea.append(text);
+		if (m_scriptArea.isDisplayable()) {
+			try {
+				//Scroll to end of window
+				m_scriptArea.setCaretPosition(Integer.MAX_VALUE);
+			} catch (Exception e) {
+			} // Just for safety
+		}
+		validate();
+		JScrollBar sb = m_scroll.getVerticalScrollBar();
+		if ((sb != null) && (sb.isVisible())) {
+			sb.setValue(Integer.MAX_VALUE);
+		}
+	}
+}

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java Mon May  7 07:29:47 2007
@@ -0,0 +1,51 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.shell.gui.scriptplugin;
+
+import java.io.*;
+
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+class ScriptStream extends OutputStream
+{
+    private Script m_script;
+
+    public ScriptStream(Script script)
+    {
+        m_script = script;
+    }
+
+    public void write(byte[] b)
+    {
+        String tmp = new String(b);
+        m_script.addText(tmp);
+    }
+
+    public void write(byte[] b, int off, int len)
+    {
+        String tmp = new String(b, off, len);
+        m_script.addText(tmp);
+    }
+
+    public void write(int b)
+    {
+        byte[] ba = { (byte) b };
+        m_script.addText(new String(ba));
+    }
+}

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/java/org/apache/felix/shell/gui/scriptplugin/ScriptStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml?view=auto&rev=535882
==============================================================================
--- felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml (added)
+++ felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml Mon May  7 07:29:47 2007
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+-->
+<component name="shell.gui.scriptplugin" > <!-- immediate="yes" -->
+  <!-- xmlns="http://www.osgi.org/xmlns/scr/v1.0.0" -->
+	<implementation class="org.apache.felix.shell.gui.scriptplugin.ScriptPlugin"/>
+	
+	<service>
+		<provide interface="org.apache.felix.shell.gui.Plugin"/>
+	</service>
+
+	<reference name="SHELL"
+		interface="org.apache.felix.shell.ShellService"
+		cardinality="1..1"
+		policy="static"
+		bind="bindShellService"
+		unbind="unbindShellService"
+	/>
+</component>

Propchange: felix/sandbox/donsez/shell.gui.scriptplugin/src/main/resources/OSGI-INF/component.xml
------------------------------------------------------------------------------
    svn:eol-style = native