From 1fe8b86b9d7ad0e8e51cfb8abf71449bd7a193f3 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Fri, 27 Jan 2012 18:10:21 +0100 Subject: [PATCH] Started with the uploading of dependencies. --- Kieker.WebGUI/pom.xml | 49 ++- .../beans/DependencyUploadController.java | 17 +- .../kieker/webgui/common/FileManager.java | 59 ++- Kieker.WebGUI/src/main/webapp/WEB-INF/web.xml | 17 + Kieker.WebGUI/src/main/webapp/main.xhtml | 390 ++++++++++-------- 5 files changed, 316 insertions(+), 216 deletions(-) diff --git a/Kieker.WebGUI/pom.xml b/Kieker.WebGUI/pom.xml index fb62120a..21530be8 100644 --- a/Kieker.WebGUI/pom.xml +++ b/Kieker.WebGUI/pom.xml @@ -220,6 +220,16 @@ <scope>system</scope> <systemPath>${project.basedir}/lib/kieker-1.5-SNAPSHOT.jar</systemPath> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>commons-fileupload</groupId> + <artifactId>commons-fileupload</artifactId> + <version>1.2.1</version> + </dependency> </dependencies> <repositories> @@ -239,6 +249,13 @@ <version>8.1.0.RC1</version> <configuration> <scanIntervalSeconds>5</scanIntervalSeconds> + <connectors> + <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> + <port>8080</port> + <maxIdleTime>600000</maxIdleTime> <!-- 10 minutes in milliseconds! --> + <lowResourcesMaxIdleTime>600000</lowResourcesMaxIdleTime> + </connector> + </connectors> </configuration> </plugin> <plugin> @@ -261,31 +278,13 @@ <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> - <!--<plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.1</version> - <executions> - <execution> - <phase>validate</phase> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <outputDirectory>${endorsed.dir}</outputDirectory> - <silent>true</silent> - <artifactItems> - <artifactItem> - <groupId>javax</groupId> - <artifactId>javaee-endorsed-api</artifactId> - <version>6.0</version> - <type>jar</type> - </artifactItem> - </artifactItems> - </configuration> - </execution> - </executions> - </plugin>--> + <!--<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> + <version>2.1</version> <executions> <execution> <phase>validate</phase> <goals> + <goal>copy</goal> </goals> <configuration> <outputDirectory>${endorsed.dir}</outputDirectory> + <silent>true</silent> <artifactItems> <artifactItem> <groupId>javax</groupId> + <artifactId>javaee-endorsed-api</artifactId> <version>6.0</version> <type>jar</type> + </artifactItem> </artifactItems> </configuration> </execution> </executions> + </plugin> --> </plugins> </build> diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/DependencyUploadController.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/DependencyUploadController.java index ff5fc66c..cb8756be 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/DependencyUploadController.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/DependencyUploadController.java @@ -3,7 +3,7 @@ package kieker.webgui.beans; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; -import kieker.analysis.model.analysisMetaModel.MIProject; +import kieker.webgui.common.FileManager; import org.primefaces.model.UploadedFile; @@ -14,27 +14,20 @@ import org.primefaces.model.UploadedFile; @ManagedBean @SessionScoped public class DependencyUploadController { - private UploadedFile file; - private MIProject project; - - public MIProject getProject() { - return project; - } - - public void setProject(MIProject project) { - this.project = project; - } public UploadedFile getFile() { + System.out.println(file); return file; } public void setFile(UploadedFile file) { + System.out.println(file); this.file = file; } public void upload() { - + System.out.println(file); + FileManager.getInstance().uploadDependency(file); } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/FileManager.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/FileManager.java index ba318826..4176a282 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/FileManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/FileManager.java @@ -1,10 +1,15 @@ package kieker.webgui.common; import java.io.File; -import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import org.primefaces.model.UploadedFile; + import kieker.analysis.AnalysisController; import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.common.logging.Log; @@ -25,6 +30,7 @@ public final class FileManager { private static final String PROJECT_DIR = ROOT_DIR + File.separator + "projects"; private static final String LIB_DIR = ROOT_DIR + File.separator + "libraries"; private static final String EXTENSION = ".xml"; + private static final int BUF_SIZE = 1024; private static final FileManager instance = new FileManager(); private FileManager() { @@ -133,6 +139,57 @@ public final class FileManager { return resultList; } + /** + * This method uploads a given file as a new dependency. The file is stored within the lib-directory of this application. If a file with the same name does + * already exist, it will be replaces. + * + * @param file + * The file to be uploaded. + * @return true iff the file has been uploaded successfully. + */ + public boolean uploadDependency(final UploadedFile file) { + System.out.println(file); + final File depFile = new File(LIB_DIR, file.getFileName()); + + InputStream in = null; + OutputStream out = null; + try { + /* Get the streams. */ + in = file.getInputstream(); + out = new FileOutputStream(depFile); + final byte buf[] = new byte[BUF_SIZE]; + int count; + + /* Transfer the file. */ + while ((count = in.read(buf)) != -1) { + out.write(buf, 0, count); + } + + } catch (final IOException ex) { + FileManager.LOG.error("Could not transfer file '" + file.getFileName() + "'"); + return false; + } finally { + /* Try to make sure that the streams will be closed. */ + try { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } + } catch (IOException ex) { + // Ignore + } + } + + return true; + } + + /** + * Delivers the only instance of this class. + * + * @return The singleton instance of this class. + */ public static FileManager getInstance() { return instance; } diff --git a/Kieker.WebGUI/src/main/webapp/WEB-INF/web.xml b/Kieker.WebGUI/src/main/webapp/WEB-INF/web.xml index 94c40203..8d8de186 100644 --- a/Kieker.WebGUI/src/main/webapp/WEB-INF/web.xml +++ b/Kieker.WebGUI/src/main/webapp/WEB-INF/web.xml @@ -1,30 +1,37 @@ <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> + <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> + <context-param> <param-name>primefaces.THEME</param-name> <param-value>#{currentThemeBean.theme}</param-value> </context-param> + <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> + <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> + <session-config> <session-timeout> 30 </session-timeout> </session-config> + <welcome-file-list> <welcome-file>faces/main.xhtml</welcome-file> </welcome-file-list> + <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> @@ -41,4 +48,14 @@ <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> + + <filter> + <filter-name>PrimeFaces FileUpload Filter</filter-name> + <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>PrimeFaces FileUpload Filter</filter-name> + <servlet-name>Faces Servlet</servlet-name> + </filter-mapping> </web-app> diff --git a/Kieker.WebGUI/src/main/webapp/main.xhtml b/Kieker.WebGUI/src/main/webapp/main.xhtml index e70cbabd..cf47bba6 100644 --- a/Kieker.WebGUI/src/main/webapp/main.xhtml +++ b/Kieker.WebGUI/src/main/webapp/main.xhtml @@ -1,183 +1,217 @@ <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" - xmlns:h="http://java.sun.com/jsf/html" - xmlns:f="http://java.sun.com/jsf/core" - xmlns:p="http://primefaces.org/ui" > - - <f:view contentType="text/html"> - <h:head> - <title>Kieker.WebGUI</title> - <link rel="stylesheet" title="Standard-Stylesheet" type="text/css" href="main.css" /> - </h:head> - - <h:body> - <!-- This is the layout for the whole page. --> - <p:layout fullPage="true"> - - <!-- This is the top unit within the layout and is used for the menu bar. --> - <p:layoutUnit position="north" size="60" collapsible="false"> - <h:form> - <p:menubar> - <p:submenu label="File"> - <p:menuitem value="New Project" onclick="NewProjectDialog.show();" ajax="true" update="ProjectsList"/> - <p:menuitem value="Save Project" ajax="true" /> - <p:menuitem value="Set as Main Project" ajax="true" /> - <p:separator/> - <p:menuitem value="Delete Project" ajax="true" /> - <p:menuitem value="Reset Project" ajax="true" /> - <p:separator/> - <p:menuitem value="Add Dependency" ajax="true" onclick="DependenciesUploadDialog.show();"/> - <p:menuitem value="Delete Dependency" ajax="true" /> - <p:separator/> - <p:menuitem value="Settings" onclick="SettingsDialog.show();" ajax="true"/> - </p:submenu> - - <p:submenu label="Help"> - <p:menuitem value="About..." onclick="AboutDialog.show();"/> - </p:submenu> - - </p:menubar> - - </h:form> - </p:layoutUnit> - - <!-- The following layout is at the left side of the page and shows the available projects. --> - <p:layoutUnit header="Projects" collapsible="true" position="west" size="200" resizable="true" minSize="100"> - <h:form id="ProjectsList"> - <p:tree selection="#{selectedProjectBean.selectedNode}" id="ProjectsListTree" selectionMode="single" style="width: auto" value="#{availableProjectsBean.projectsRoot}" var="node" > - <p:treeNode type="project"> - <h:outputText style="font-weight: #{selectedProjectBean.getFontWeight(node)}" value="#{node}"> - <f:converter converterId="kieker.webgui.converter.MIProjectToStringConverter"/> - </h:outputText> - </p:treeNode> - <p:treeNode type="dependencies"> - <h:outputText value="#{node}"/> - </p:treeNode> - <p:treeNode type="usedPlugins"> - <h:outputText value="#{node}"/> - </p:treeNode> - </p:tree> - - <p:contextMenu for="ProjectsListTree" nodeType="project"> - <p:menuitem value="New Project" onclick="NewProjectDialog.show();" ajax="true" update="ProjectsList"/> - <p:menuitem value="Save Project" ajax="true" /> - <p:menuitem value="Set as Main Project" ajax="true" action="#{selectedProjectBean.setMainProject(selectedProjectBean.getSelectedProject())}" update="ProjectsListTree"/> - <p:separator/> - <p:menuitem value="Delete Project" ajax="true" /> - <p:menuitem value="Reset Project" ajax="true" /> - </p:contextMenu> - <p:contextMenu for="ProjectsListTree" nodeType="dependencies"> - <p:menuitem value="Add Dependency" ajax="true" onclick="DependenciesUploadDialog.show();"/> - <p:menuitem value="Delete Dependency" ajax="true" /> - </p:contextMenu> - <p:contextMenu for="ProjectsListTree" nodeType="usedPlugins"> - - </p:contextMenu> - </h:form> - - </p:layoutUnit> - - <!-- The following layout unit is within the center and used for the graph. --> - <p:layoutUnit position="center"> - </p:layoutUnit> - - <!-- The following layout unit is located at the bottom and will be used for properties. --> - <p:layoutUnit position="south" size="150" header="Properties" resizable="true" collapsible="true"> - <p:dataTable id="carList"> - - - <p:column headerText="Key" style="width:125px"> - <p:cellEditor> - <f:facet name="output"> - <h:outputText value="" /> - </f:facet> - <f:facet name="input"> - <p:inputText value="" style="width:100%"/> - </f:facet> - </p:cellEditor> - </p:column> - - <p:column headerText="Value" style="width:125px"> - <p:cellEditor> - <f:facet name="output"> - <h:outputText value="" /> - </f:facet> - <f:facet name="input"> - <p:inputText value="" style="width:100%" label="Year"/> - </f:facet> - </p:cellEditor> - </p:column> - - <p:column headerText="Options" style="width:50px"> - <p:rowEditor /> - </p:column> - - </p:dataTable> - </p:layoutUnit> - - <!-- The following layout unit is located at the right side of the page and is used as a tool palette. It shows the available plugins etc. --> - <p:layoutUnit position="east" size="200" header="Tool Palette" resizable="true" collapsible="true"> - <p:tree style="width: auto" value="#{availablePluginsBean.availablePluginsRoot}" var="node" > - <p:treeNode > - <h:outputText value="#{node}"/> - </p:treeNode> - </p:tree> - </p:layoutUnit> - </p:layout> - - </h:body> - - <!-- This is the about-dialog. --> - <p:dialog header="About..." resizable="false" modal="true" widgetVar="AboutDialog"> - <h:outputText value="Kieker.WebGUI"/><br/><br/> - <h:outputText value="Version: 1.0-SNAPSHOT"/><br/> - <h:outputText value="Copyright (c) 2012 Kieker Project"/> <br/><br/> - <a href="http://www.kieker-monitoring.net/">http://www.kieker-monitoring.net/</a> - </p:dialog> - - <!-- This is the dialog to create a new project. --> - <p:dialog id="NewProjectDialog" header="New Project" resizable="false" modal="true" widgetVar="NewProjectDialog" > - <p:ajax event="close" update="NewProjectDialog" listener="#{stringBean.clear()}" /> - - <h:form> - <h:outputText value="Please enter the name of the new project: " /><br/><br/> - <center> - <p:inputText id="NewProjectInput" style="width: 90%" value="#{stringBean.string}" /><br/><br/> - <p:commandButton value="Submit" action="#{availableProjectsBean.addProject(stringBean.string)}" update="ProjectsList" oncomplete="NewProjectDialog.hide();"/> - </center> - </h:form> - </p:dialog> - - <!-- This is the dialog for settings and properties. --> - <p:dialog id="SettingsDialog" header="Settings" resizable="false" modal="true" widgetVar="SettingsDialog"> - <h:form> - <h:panelGrid columns="2" cellpadding="10"> - <h:outputText value="Look and Feel:" /> - <p:themeSwitcher value="#{currentThemeBean.theme}" style="width:150px" effect="fade" > - <f:selectItem itemLabel="Choose Theme" itemValue="" /> - <f:selectItems value="#{themeSwitcherBean.themes}" /> - </p:themeSwitcher> - </h:panelGrid> - <center> - <p:commandButton value="Okay" oncomplete="SettingsDialog.hide();"/> - </center> - </h:form> - </p:dialog> - - <!-- This is the dialog for uploading dependencies. --> - <p:dialog id="DependenciesUploadDialog" header="Add Dependency" resizable="false" modal="true" widgetVar="DependenciesUploadDialog"> - <h:form> - <p:fileUpload value="#{dependencyUploadController.file}" mode="simple"/><br/><br/> - <center> - <p:commandButton value="Submit" ajax="true" - update="ProjectsList" - actionListener="#{dependencyUploadController.upload}" - oncomplete="DependenciesUploadDialog.hide();"/> - </center> - - </h:form> - </p:dialog> - </f:view> + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:p="http://primefaces.org/ui"> + +<f:view contentType="text/html"> + <h:head> + <title>Kieker.WebGUI</title> + <link rel="stylesheet" title="Standard-Stylesheet" type="text/css" + href="main.css" /> + </h:head> + + <h:body> + <!-- This is the layout for the whole page. --> + <p:layout fullPage="true"> + + <!-- This is the top unit within the layout and is used for the menu bar. --> + <p:layoutUnit position="north" size="60" collapsible="false"> + <h:form> + <p:menubar> + <p:submenu label="File"> + <p:menuitem value="New Project" + onclick="NewProjectDialog.show();" ajax="true" + update="ProjectsList" /> + <p:menuitem value="Save Project" ajax="true" /> + <p:menuitem value="Set as Main Project" ajax="true" /> + <p:separator /> + <p:menuitem value="Delete Project" ajax="true" /> + <p:menuitem value="Reset Project" ajax="true" /> + <p:separator /> + <p:menuitem value="Add Dependency" ajax="true" + onclick="DependenciesUploadDialog.show();" /> + <p:menuitem value="Delete Dependency" ajax="true" /> + <p:separator /> + <p:menuitem value="Settings" onclick="SettingsDialog.show();" + ajax="true" /> + </p:submenu> + + <p:submenu label="Help"> + <p:menuitem value="About..." onclick="AboutDialog.show();" /> + </p:submenu> + + </p:menubar> + + </h:form> + </p:layoutUnit> + + <!-- The following layout is at the left side of the page and shows the available projects. --> + <p:layoutUnit header="Projects" collapsible="true" position="west" + size="200" resizable="true" minSize="100"> + <h:form id="ProjectsList"> + <p:tree selection="#{selectedProjectBean.selectedNode}" + id="ProjectsListTree" selectionMode="single" style="width: auto" + value="#{availableProjectsBean.projectsRoot}" var="node"> + <p:treeNode type="project"> + <h:outputText + style="font-weight: #{selectedProjectBean.getFontWeight(node)}" + value="#{node}"> + <f:converter + converterId="kieker.webgui.converter.MIProjectToStringConverter" /> + </h:outputText> + </p:treeNode> + <p:treeNode type="dependencies"> + <h:outputText value="#{node}" /> + </p:treeNode> + <p:treeNode type="usedPlugins"> + <h:outputText value="#{node}" /> + </p:treeNode> + </p:tree> + + <p:contextMenu for="ProjectsListTree" nodeType="project"> + <p:menuitem value="New Project" onclick="NewProjectDialog.show();" + ajax="true" update="ProjectsList" /> + <p:menuitem value="Save Project" ajax="true" /> + <p:menuitem value="Set as Main Project" ajax="true" + action="#{selectedProjectBean.setMainProject(selectedProjectBean.getSelectedProject())}" + update="ProjectsListTree" /> + <p:separator /> + <p:menuitem value="Delete Project" ajax="true" /> + <p:menuitem value="Reset Project" ajax="true" /> + </p:contextMenu> + <p:contextMenu for="ProjectsListTree" nodeType="dependencies"> + <p:menuitem value="Add Dependency" ajax="true" + onclick="DependenciesUploadDialog.show();" /> + <p:menuitem value="Delete Dependency" ajax="true" /> + </p:contextMenu> + <p:contextMenu for="ProjectsListTree" nodeType="usedPlugins"> + + </p:contextMenu> + </h:form> + + </p:layoutUnit> + + <!-- The following layout unit is within the center and used for the graph. --> + <p:layoutUnit position="center"> + </p:layoutUnit> + + <!-- The following layout unit is located at the bottom and will be used for properties. --> + <p:layoutUnit position="south" size="150" header="Properties" + resizable="true" collapsible="true"> + <p:dataTable id="carList"> + + + <p:column headerText="Key" style="width:125px"> + <p:cellEditor> + <f:facet name="output"> + <h:outputText value="" /> + </f:facet> + <f:facet name="input"> + <p:inputText value="" style="width:100%" /> + </f:facet> + </p:cellEditor> + </p:column> + + <p:column headerText="Value" style="width:125px"> + <p:cellEditor> + <f:facet name="output"> + <h:outputText value="" /> + </f:facet> + <f:facet name="input"> + <p:inputText value="" style="width:100%" label="Year" /> + </f:facet> + </p:cellEditor> + </p:column> + + <p:column headerText="Options" style="width:50px"> + <p:rowEditor /> + </p:column> + + </p:dataTable> + </p:layoutUnit> + + <!-- The following layout unit is located at the right side of the page and is used as a tool palette. It shows the available plugins etc. --> + <p:layoutUnit position="east" size="200" header="Tool Palette" + resizable="true" collapsible="true"> + <p:tree style="width: auto" + value="#{availablePluginsBean.availablePluginsRoot}" var="node"> + <p:treeNode> + <h:outputText value="#{node}" /> + </p:treeNode> + </p:tree> + </p:layoutUnit> + </p:layout> + + </h:body> + + <!-- This is the about-dialog. --> + <p:dialog header="About..." resizable="false" modal="true" + widgetVar="AboutDialog"> + <h:outputText value="Kieker.WebGUI" /> + <br /> + <br /> + <h:outputText value="Version: 1.0-SNAPSHOT" /> + <br /> + <h:outputText value="Copyright (c) 2012 Kieker Project" /> + <br /> + <br /> + <a href="http://www.kieker-monitoring.net/">http://www.kieker-monitoring.net/</a> + </p:dialog> + + <!-- This is the dialog to create a new project. --> + <p:dialog id="NewProjectDialog" header="New Project" resizable="false" + modal="true" widgetVar="NewProjectDialog"> + <p:ajax event="close" update="NewProjectDialog" + listener="#{stringBean.clear()}" /> + + <h:form> + <h:outputText value="Please enter the name of the new project: " /> + <br /> + <br /> + <center> + <p:inputText id="NewProjectInput" style="width: 90%" + value="#{stringBean.string}" /> + <br /> <br /> + <p:commandButton value="Submit" + action="#{availableProjectsBean.addProject(stringBean.string)}" + update="ProjectsList" oncomplete="NewProjectDialog.hide();" /> + </center> + </h:form> + </p:dialog> + + <!-- This is the dialog for settings and properties. --> + <p:dialog id="SettingsDialog" header="Settings" resizable="false" + modal="true" widgetVar="SettingsDialog"> + <h:form> + <h:panelGrid columns="2" cellpadding="10"> + <h:outputText value="Look and Feel:" /> + <p:themeSwitcher value="#{currentThemeBean.theme}" + style="width:150px" effect="fade"> + <f:selectItem itemLabel="Choose Theme" itemValue="" /> + <f:selectItems value="#{themeSwitcherBean.themes}" /> + </p:themeSwitcher> + </h:panelGrid> + <center> + <p:commandButton value="Okay" oncomplete="SettingsDialog.hide();" /> + </center> + </h:form> + </p:dialog> + + <!-- This is the dialog for uploading dependencies. --> + <p:dialog id="DependenciesUploadDialog" header="Add Dependency" + resizable="false" modal="true" widgetVar="DependenciesUploadDialog"> + + <h:form enctype="multipart/form-data"> + <p:fileUpload value="#{dependencyUploadController.file}" mode="simple" /> + + <p:commandButton value="Submit" ajax="false" + actionListener="#{dependencyUploadController.upload}" /> + </h:form> + + </p:dialog> + +</f:view> </html> -- GitLab