Author: pete.muir(a)jboss.org
Date: 2010-06-16 09:35:18 -0400 (Wed, 16 Jun 2010)
New Revision: 6441
Added:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/AccessLog.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/Language.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
Removed:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/LargeCodeLog.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Code.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeBean.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Data.java
Modified:
examples/trunk/jsf/pastecode/
examples/trunk/jsf/pastecode/pom.xml
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LargeCodeDecorator.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java
examples/trunk/jsf/pastecode/src/main/resources/data.sql
examples/trunk/jsf/pastecode/src/main/webapp/
examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/
examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/web.xml
examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
examples/trunk/jsf/pastecode/src/main/webapp/history.xhtml
examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml
Log:
large number of updates to example, possibly not working right now 100% ;-)
Property changes on: examples/trunk/jsf/pastecode
___________________________________________________________________
Name: svn:ignore
+ target
.classpath
.settings
.project
Modified: examples/trunk/jsf/pastecode/pom.xml
===================================================================
--- examples/trunk/jsf/pastecode/pom.xml 2010-06-16 10:26:18 UTC (rev 6440)
+++ examples/trunk/jsf/pastecode/pom.xml 2010-06-16 13:35:18 UTC (rev 6441)
@@ -1,74 +1,80 @@
<?xml version="1.0"?>
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
-
+
<parent>
<groupId>org.jboss.weld.examples</groupId>
<artifactId>weld-examples-parent</artifactId>
<version>1.0.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
-
+
<groupId>org.jboss.weld.examples.jsf.pastecode</groupId>
<artifactId>weld-jsf-pastecode</artifactId>
<packaging>war</packaging>
<name>Weld Examples: PasteCode</name>
-
+
<dependencies>
-
+
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
<classifier>jdk15</classifier>
</dependency>
-
+
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
-
+
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.jboss.ejb3</groupId>
- <artifactId>jboss-ejb3_1</artifactId>
- <version>1.0.8-alpha-1</version>
+ <artifactId>jboss-ejb3-api</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
@@ -79,49 +85,51 @@
</exclusion>
</exclusions>
</dependency>
-
+
</dependencies>
-
+
<build>
<finalName>weld-pastecode</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
-
<warSourceExcludes>WEB-INF/classes/**,WEB-INF/lib/**</warSourceExcludes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>com.pyx4j</groupId>
- <artifactId>maven-junction-plugin</artifactId>
- <executions>
- <execution>
- <id>unlink</id>
- <phase>clean</phase>
- <goals>
- <goal>unlink</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <links>
- <!-- link src/main/webapp -> war/ for IDEs -->
- <link>
- <dst>${basedir}/war</dst>
- <src>${basedir}/src/main/webapp</src>
- </link>
- </links>
- </configuration>
- </plugin>
- </plugins>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+
<warSourceExcludes>WEB-INF/classes/**,WEB-INF/lib/**</warSourceExcludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.pyx4j</groupId>
+ <artifactId>maven-junction-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unlink</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>unlink</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <links>
+ <!-- link src/main/webapp -> war/ for IDEs -->
+ <link>
+ <dst>${basedir}/war</dst>
+ <src>${basedir}/src/main/webapp</src>
+ </link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
</build>
-
- <!-- <scm>
+
+ <!--
+ <scm>
<
connection>scm:svn:http://anonsvn.jboss.org/repos/weld/examples/trunk/...
<
developerConnection>scm:svn:https://svn.jboss.org/repos/weld/examples/...
-
<
url>http://fisheye.jboss.org/browse/weld/examples/trunk/jsf/pastecode&...
- </scm> -->
-
+
<
url>http://fisheye.jboss.org/browse/weld/examples/trunk/jsf/pastecode&...
+ </scm>
+ -->
+
</project>
Copied:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/AccessLog.java
(from rev 6434,
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/LargeCodeLog.java)
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/AccessLog.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/AccessLog.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.model;
+
+import static javax.persistence.GenerationType.AUTO;
+
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+public class AccessLog
+{
+
+ @Id @GeneratedValue(strategy = AUTO)
+ private int id;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date datetime;
+
+ @ManyToOne
+ private CodeFragment codeFragment;
+
+ private String access;
+
+ public AccessLog(CodeFragment codeFragment, Date dateTime, String access)
+ {
+ this.codeFragment = codeFragment;
+ this.datetime = dateTime;
+ this.access = access;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ public CodeFragment getCodeFragment()
+ {
+ return codeFragment;
+ }
+
+ public void setCodeFragment(CodeFragment codeFragment)
+ {
+ this.codeFragment = codeFragment;
+ }
+
+ public String getAccess()
+ {
+ return access;
+ }
+
+ public void setAccess(String access)
+ {
+ this.access = access;
+ }
+
+ public Date getDatetime()
+ {
+ return this.datetime;
+ }
+
+ public void setDatetime(Date datetime)
+ {
+ this.datetime = datetime;
+ }
+
+}
Copied:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
(from rev 6434,
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeEntity.java)
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/CodeFragment.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.model;
+
+import static javax.persistence.GenerationType.AUTO;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.OneToMany;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ * The entity class for the pasted code "fragment". This is the main entity
+ * class in the application.
+ */
+@Entity
+public class CodeFragment
+{
+
+ @Id
+ @GeneratedValue(strategy = AUTO)
+ @Column(name = "id")
+ private int id;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date datetime;
+
+ @Enumerated(EnumType.STRING)
+ private Language language;
+
+ @Lob
+ private String note;
+
+ @Lob
+ private String text;
+
+ private String user;
+
+ private String hash;
+
+ @OneToMany(mappedBy = "codeFragment", cascade = CascadeType.REMOVE)
+ List<AccessLog> largeCodeFragmentAccessLog;
+
+ public CodeFragment()
+ {
+ this.note = "";
+ this.text = "";
+ this.user = "";
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ public String getHash()
+ {
+ return hash;
+ }
+
+ public void setHash(String hash)
+ {
+ this.hash = hash;
+ }
+
+ public Date getDatetime()
+ {
+ return this.datetime;
+ }
+
+ public void setDatetime(Date datetime)
+ {
+ this.datetime = datetime;
+ }
+
+ public Language getLanguage()
+ {
+ return language;
+ }
+
+ public void setLanguage(Language language)
+ {
+ this.language = language;
+ }
+
+ public String getNote()
+ {
+ return this.note;
+ }
+
+ public void setNote(String note)
+ {
+ this.note = note;
+ }
+
+ public String getText()
+ {
+ return this.text;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+
+ public String getUser()
+ {
+ return this.user;
+ }
+
+ public void setUser(String user)
+ {
+ this.user = user;
+ }
+
+ public List<AccessLog> getLargeCodeFragmentAccessLog()
+ {
+ return largeCodeFragmentAccessLog;
+ }
+
+ public void setLargeCodeFragmentAccessLog(List<AccessLog>
largeCodeFragmentAccessLog)
+ {
+ this.largeCodeFragmentAccessLog = largeCodeFragmentAccessLog;
+ }
+}
\ No newline at end of file
Added:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/Language.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/Language.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/Language.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package org.jboss.weld.examples.pastecode.model;
+
+
+public enum Language
+{
+
+ TEXT("txt", "Plain text", "text" ),
+ AS3("as3", "AS3", "as3" ),
+ BASH("sh", "Bash", "bash"),
+ CSHARP("cs", "C#", "csharp"),
+ COLD_FUSION("cf", "Cold Fusion", "coldfusion"),
CPLUSPLUS("cpp", "C++", "cpp"),
+ CSS("css", "CSS", "css"),
+ DELPHI("pas", "Delphi", "pas"),
+ DIFF("diff", "Diff", "diff"), ERLANG("erl",
"Erlang", "erl"),
+ GROOVY("groovy", "Groovy", "groovy"),
+ JAVASCRIPT("js", "JavaScript", "js"),
+ JAVA("java", "Java", "java"),
+ JAVAFX("fx", "JavaFX", "javafx"),
+ PERL("perl", "Perl", "perl"),
+ PHP("php", "PHP", "php"),
+ POWER_SHELL("ps1", "Power Shell", "powershell"),
+ PYTHON("py", "Python", "py"),
+ RUBY("rb", "Ruby", "rb"),
+ SCALA("scl", "Scala", "scala"),
+ SQL("sql", "Sql", "sql"),
+ VISUAL_BASIC("vb", "Visual Basic", "vb"),
+ XML("xml", "XML", "xml");
+
+ private final String extension;
+ private final String name;
+ private final String brush;
+
+ Language(String extension, String name, String brush)
+ {
+ this.extension = extension;
+ this.name = name;
+ this.brush = brush;
+ }
+
+ public String getBrush()
+ {
+ return brush;
+ }
+
+ public String getExtension()
+ {
+ return extension;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
\ No newline at end of file
Property changes on:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/Language.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/LargeCodeLog.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/LargeCodeLog.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/model/LargeCodeLog.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.model;
-
-import java.io.Serializable;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.persistence.GenerationType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Column;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import java.util.Date;
-
-@Entity
-@Table(name = "largecodelog")
-public class LargeCodeLog implements Serializable
-{
- private static final long serialVersionUID = 1L;
- private int id;
- private Date datetime;
- private int codeId;
- private String access;
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "id")
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public LargeCodeLog(int codeId, Date dateTime, String access)
- {
- this.codeId = codeId;
- this.datetime = dateTime;
- this.access = access;
- }
-
- public int getCodeId()
- {
- return codeId;
- }
-
- public void setCodeId(int codeId)
- {
- this.codeId = codeId;
- }
-
- public String getAccess()
- {
- return access;
- }
-
- public void setAccess(String access)
- {
- this.access = access;
- }
-
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name = "datetime")
- public Date getDatetime()
- {
- return this.datetime;
- }
-
- public void setDatetime(Date datetime)
- {
- this.datetime = datetime;
- }
-
-}
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/servlets/DownloadServlet.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,35 +21,38 @@
*/
package org.jboss.weld.examples.pastecode.servlets;
-import java.io.*;
+import java.io.IOException;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-import org.jboss.weld.examples.pastecode.session.Code;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+import org.jboss.weld.examples.pastecode.session.CodeFragmentManager;
+
public class DownloadServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Inject
- Instance<Code> eaoIn;
- Code eao;
+ Instance<CodeFragmentManager> eaoIn;
+ CodeFragmentManager eao;
public DownloadServlet()
{
}
+ @Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
{
this.eao = eaoIn.get();
- String id = (String) request.getParameter("id");
- CodeEntity c = eao.getCode(id);
+ String id = request.getParameter("id");
+ CodeFragment c = eao.getCodeFragment(id);
String fileName = c.getUser() + "." + c.getLanguage();
String txt = c.getText();
Deleted:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Code.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Code.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Code.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import java.util.List;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-
-public interface Code
-{
- public String addCode(CodeEntity code, boolean secured);
-
- public CodeEntity getCode(String id);
-
- public List<CodeEntity> recentCodes();
-
- public List<CodeEntity> searchCodes(CodeEntity code, int page, QueryInfo info);
-}
Deleted:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeBean.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeBean.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeBean.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -1,211 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import java.security.NoSuchAlgorithmException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import javax.annotation.Resource;
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.persistence.*;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-import javax.inject.*;
-import java.util.*;
-
-/**
- * Session Bean implementation class CodeEAOBean
- */
-@Stateless
-@Named("codeEAOBean")
-public class CodeBean implements Code
-{
-
- @PersistenceContext(unitName = "pastecodeDatabase")
- private EntityManager em;
-
- @Resource
- EJBContext ctx;
-
- @Inject
- private HashComputer hashComp;
-
- private int MAX_CODES = 7;
-
- private int PAGE_SIZE = 2;
-
- public CodeBean()
- {
- }
-
- public String addCode(CodeEntity code, boolean secured)
- {
- String result;
- if (code.getDatetime() == null)
- {
- code.setDatetime(Calendar.getInstance().getTime());
- }
-
- if (code.getUser().trim().isEmpty())
- {
- code.setUser("Anonymous");
- }
-
- /* compute hash value and return it if secured flag has been set */
- if (secured)
- {
- try
- {
- String hashValue = hashComp.getHashValue(code);
- code.setHash(hashValue);
- result = hashValue;
- em.persist(code);
- }
- catch (NoSuchAlgorithmException e)
- {
- e.printStackTrace();
- return null;
- }
- }
- else
- {
- em.persist(code);
- result = new Integer(code.getId()).toString();
- }
-
- // System.out.println("Result: " + result);
-
- return result;
- }
-
- public CodeEntity getCode(String id)
- {
- boolean secured = true;
-
- try
- {
- Integer.parseInt(id);
- secured = false; /*
- * if it is possible to convert to number -> not
- * secured, otherwise -> secured
- */
- }
- catch (NumberFormatException e)
- {
- }
-
- if (secured)
- {
- Query q = em.createQuery("SELECT c FROM CodeEntity c WHERE hash =
:hash");
- q.setParameter("hash", id);
- return (CodeEntity) q.getSingleResult();
- }
- else
- {
- CodeEntity c = em.find(CodeEntity.class, Integer.parseInt(id));
- /*
- * if somebody is trying to guess Id of secured code paste he cannot
- * pass
- */
- if (c.getHash() == null)
- {
- return c;
- }
- else
- {
- throw new EJBException("Access denied");
- }
- }
- }
-
- public List<CodeEntity> recentCodes()
- {
- Query q = em.createQuery("SELECT c FROM CodeEntity c WHERE hash=null ORDER BY
datetime DESC ");
- q.setMaxResults(MAX_CODES);
- List<CodeEntity> codes = q.getResultList();
- return codes;
- }
-
- /**
- * getting codes from database needs new transaction so that we can further
- * modify returned Codes without affecting database (when we call this
- * function from another session bean
- */
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public List<CodeEntity> searchCodes(CodeEntity code, int page, QueryInfo info)
- {
- StringBuilder sb = new StringBuilder();
-
- String delim = "";
- if (!code.getUser().trim().equals(""))
- {
- sb.append("c.user = \'" + code.getUser().trim().toLowerCase() +
"\'");
- delim = " AND";
- }
- if (!code.getLanguage().trim().equals(""))
- {
- sb.append(delim).append(" c.language = \'" +
code.getLanguage().trim().toLowerCase() + "\'");
- delim = " AND";
- }
- if (!code.getNote().trim().equals(""))
- {
- sb.append(delim).append(" c.note LIKE \'%" +
code.getNote().trim().toLowerCase() + "%\'");
- delim = " AND";
- }
- if (!code.getText().trim().equals(""))
- {
- sb.append(delim).append(" c.text LIKE \'%" +
code.getText().toLowerCase() + "%\'");
- delim = " AND";
- }
- if (code.getDatetime() != null)
- {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd
HH-mm-ss");
- Date date2 = new Date();
- date2.setTime(code.getDatetime().getTime() + 24 * 60 * 60 * 1000); // +1
- // day
-
- String formattedDate1 = formatter.format(code.getDatetime());
- String formattedDate2 = formatter.format(date2);
-
- sb.append(delim).append(" c.datetime between \'" + formattedDate1
+ "\' and \'" + formattedDate2 + "\'");
- delim = " AND";
- }
-
- if (sb.toString().length() == 0)
- sb.append("1 = \'1\'");
-
- Query q = em.createQuery("SELECT c FROM CodeEntity c WHERE hash=null AND
" + sb.toString() + " ORDER BY datetime DESC");
- int allRecords = q.getResultList().size();
- q.setFirstResult(page * PAGE_SIZE);
- q.setMaxResults(PAGE_SIZE);
- List<CodeEntity> codes = q.getResultList();
-
- info.setPage(page);
- info.setRecordsCount(allRecords);
- info.setPagesCount(allRecords / PAGE_SIZE);
-
- return codes;
- }
-}
Copied:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java
(from rev 6434,
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Code.java)
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManager.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.session;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
+@Local
+public interface CodeFragmentManager
+{
+ public String addCodeFragment(CodeFragment code, boolean privateFragment);
+
+ public CodeFragment getCodeFragment(String id);
+
+ public List<CodeFragment> getRecentCodeFragments();
+
+ public List<CodeFragment> searchCodeFragments(CodeFragment code, int page,
QueryInfo info);
+}
Copied:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
(from rev 6434,
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeBean.java)
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.session;
+
+import java.security.NoSuchAlgorithmException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
+@Stateless
+public class CodeFragmentManagerImpl implements CodeFragmentManager
+{
+
+ // The number of code fragments to return in our recentCodeFragments query
+ private static int MAX_RECENT_FRAGMENTS = 7;
+
+ // The number of code fragments to display per page
+ private static int PAGE_SIZE = 2;
+
+ @PersistenceContext(unitName = "pastecodeDatabase")
+ private EntityManager entityManager;
+
+ @Inject
+ private HashComputer hashComputer;
+
+ public String addCodeFragment(CodeFragment code, boolean privateFragment)
+ {
+ // Set the defaults
+ if (code.getDatetime() == null)
+ {
+ code.setDatetime(Calendar.getInstance().getTime());
+ }
+
+ if (code.getUser().trim().isEmpty())
+ {
+ code.setUser("Anonymous");
+ }
+
+ // compute hash value and return it if private flag has been set
+ if (privateFragment)
+ {
+ try
+ {
+ String hashValue = hashComputer.getHashValue(code);
+ code.setHash(hashValue);
+ entityManager.persist(code);
+ return hashValue;
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ // just return a non-hashed id
+ else
+ {
+ entityManager.persist(code);
+ return new Integer(code.getId()).toString();
+ }
+ }
+
+ public CodeFragment getCodeFragment(String id)
+ {
+ // If it's not an integer, it's a hash!
+ if (!isInteger(id))
+ {
+ Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
hash = :hash");
+ query.setParameter("hash", id);
+
+ @SuppressWarnings("unchecked")
+ List<CodeFragment> fragments = query.getResultList();
+
+ if (fragments.size() == 0)
+ {
+ throw new RuntimeException("No such fragment!");
+ }
+ else
+ {
+ return fragments.get(0);
+ }
+ }
+ else
+ {
+ CodeFragment c = entityManager.find(CodeFragment.class, Integer.parseInt(id));
+ if (c == null)
+ {
+ throw new RuntimeException("No such fragment!");
+ }
+ // If no hash was set, then this is not a private fragment, return it!
+ if (c.getHash() == null)
+ {
+ return c;
+ }
+ else
+ {
+ throw new RuntimeException("Access denied!");
+ }
+ }
+ }
+
+ private static boolean isInteger(String string)
+ {
+ try
+ {
+ Integer.parseInt(string);
+ return true;
+ }
+ catch (NumberFormatException e)
+ {
+ return false;
+ }
+ }
+
+ public List<CodeFragment> getRecentCodeFragments()
+ {
+ Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
hash=null ORDER BY datetime DESC ");
+ query.setMaxResults(MAX_RECENT_FRAGMENTS);
+
+ @SuppressWarnings("unchecked")
+ List<CodeFragment> codes = query.getResultList();
+
+ return codes;
+ }
+
+ /**
+ * getting codes from database needs new transaction so that we can further
+ * modify returned Codes without affecting database (when we call this
+ * function from another session bean
+ */
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public List<CodeFragment> searchCodeFragments(CodeFragment code, int page,
QueryInfo info)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ String delim = "";
+ if (!code.getUser().trim().equals(""))
+ {
+ sb.append("c.user = \'" + code.getUser().trim().toLowerCase() +
"\'");
+ delim = " AND";
+ }
+ if (code.getLanguage() != null)
+ {
+ sb.append(delim).append(" c.language = \'" +
code.getLanguage().name() + "\'");
+ delim = " AND";
+ }
+ if (!code.getNote().trim().equals(""))
+ {
+ sb.append(delim).append(" c.note LIKE \'%" +
code.getNote().trim().toLowerCase() + "%\'");
+ delim = " AND";
+ }
+ if (!code.getText().trim().equals(""))
+ {
+ sb.append(delim).append(" c.text LIKE \'%" +
code.getText().toLowerCase() + "%\'");
+ delim = " AND";
+ }
+ if (code.getDatetime() != null)
+ {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd
HH-mm-ss");
+ Date date2 = new Date();
+ date2.setTime(code.getDatetime().getTime() + 24 * 60 * 60 * 1000); // +1
+ // day
+
+ String formattedDate1 = formatter.format(code.getDatetime());
+ String formattedDate2 = formatter.format(date2);
+
+ sb.append(delim).append(" c.datetime between \'" + formattedDate1
+ "\' and \'" + formattedDate2 + "\'");
+ delim = " AND";
+ }
+
+ if (sb.toString().length() == 0)
+ sb.append("1 = \'1\'");
+
+ Query q = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE
hash=null AND " + sb.toString() + " ORDER BY datetime DESC");
+ int allRecords = q.getResultList().size();
+ q.setFirstResult(page * PAGE_SIZE);
+ q.setMaxResults(PAGE_SIZE);
+ List<CodeFragment> codes = q.getResultList();
+
+ info.setPage(page);
+ info.setRecordsCount(allRecords);
+ info.setPagesCount(allRecords / PAGE_SIZE);
+
+ return codes;
+ }
+}
Deleted:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Data.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Data.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Data.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Named;
-import java.io.Serializable;
-import javax.faces.model.SelectItem;
-import javax.enterprise.inject.Produces;
-import java.util.List;
-import java.util.ArrayList;
-
-@ApplicationScoped
-@Named("dataBean")
-public class Data implements Serializable
-{
- private static final long serialVersionUID = 991300443278089016L;
-
- private int LANG_EXTENSION = 0; // e.g. txt
- private int LANG_NAME = 1; // e.g. Plain text
- private int LANG_BRUSH = 2; // e.g. text
- private String languages[][] = { { "txt", "Plain text",
"text" }, { "as3", "AS3", "as3" }, {
"sh", "Bash", "bash" }, { "cs", "C#",
"csharp" }, { "cf", "Cold Fusion", "coldfusion" },
{ "cpp", "C++", "cpp" }, { "css", "CSS",
"css" }, { "pas", "Delphi", "pas" }, {
"diff", "Diff", "diff" }, { "erl",
"Erlang", "erl" }, { "groovy", "Groovy",
"groovy" }, { "js", "JavaScript", "js" }, {
"java", "Java", "java" }, { "fx",
"JavaFX", "javafx" }, { "perl", "Perl",
"perl" }, { "php", "PHP", "php" }, {
"ps1", "Power Shell", "powershell" }, { "py",
"Python", "py" }, { "rb", "Ruby", "rb"
}, { "scl", "Scala", "scala" }, { "sql",
"Sql", "sql" }, { "vb", "Visual Basic",
"vb" }, { "xml", "XML", "xml" } };
- private String themes[] = { "Default Theme", "Django Theme",
"Eclipse Theme", "Emacs Theme", "Midnight Theme", "Dark
Theme" };
-
- public Data()
- {
- }
-
- @Produces
- @Named("languageItems")
- public List<SelectItem> getLanguageItems()
- {
- List<SelectItem> items = new ArrayList<SelectItem>();
- for (int i = 0; i != languages.length; i++)
- {
- items.add(new SelectItem(languages[i][LANG_EXTENSION],
languages[i][LANG_NAME]));
- }
- return items;
- }
-
- @Produces
- @Named("themeItems")
- public List<SelectItem> getThemeItems()
- {
- List<SelectItem> items = new ArrayList<SelectItem>();
- for (int i = 0; i != themes.length; i++)
- {
- items.add(new SelectItem(themes[i]));
- }
- return items;
- }
-
- public String getBrush(String language)
- {
- for (int i = 0; i != languages.length; i++)
- {
- if (languages[i][LANG_EXTENSION].equals(language))
- return languages[i][LANG_BRUSH];
- }
- return languages[0][LANG_BRUSH];
- }
-}
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,17 +21,16 @@
*/
package org.jboss.weld.examples.pastecode.session;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
+import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.security.MessageDigest;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
+// TODO @Stateless
public class HashComputer
{
- public HashComputer()
- {
- }
- public String getHashValue(CodeEntity code) throws NoSuchAlgorithmException
+ public String getHashValue(CodeFragment code) throws NoSuchAlgorithmException
{
String hashValue;
MessageDigest md = MessageDigest.getInstance("SHA-1");
@@ -43,15 +42,27 @@
private String asHex(byte buf[])
{
- StringBuffer strBuf = new StringBuffer(buf.length * 2);
+ StringBuilder strBuf = new StringBuilder(buf.length * 2);
+ // make sure it contains a letter!
+ strBuf.append("h");
+
for (int i = 0; i < buf.length; i++)
{
- if (((int) buf[i] & 0xff) < 0x10)
+ if ((buf[i] & 0xff) < 0x10)
+ {
strBuf.append("0");
- strBuf.append(Long.toString((int) buf[i] & 0xff, 16));
+ strBuf.append(Long.toString(buf[i] & 0xff, 16));
+ }
}
+ if (strBuf.length() <= 6)
+ {
+ while (strBuf.length() <= 6)
+ {
+ strBuf.append("0");
+ }
+ }
+ return strBuf.toString().substring(0, 6);
+ }
- return strBuf.toString();
- }
}
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/History.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,85 +21,75 @@
*/
package org.jboss.weld.examples.pastecode.session;
-import java.util.List;
-import javax.ejb.Stateful;
-import javax.annotation.PostConstruct;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-import javax.inject.Named;
-import javax.inject.Inject;
import java.io.Serializable;
+import java.util.List;
+
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
/**
* Session Bean implementation class HistoryBean
*/
@SessionScoped
@Named("history")
-@Stateful
+//TODO @Stateful
public class History implements Serializable
{
private static final long serialVersionUID = 20L;
+
+ // The max length of the snippet we show
+ private static int TRIMMED_TEXT_LEN = 120;
- transient @Inject
- Code eao;
+ @Inject
+ private CodeFragmentManager codeFragmentManager;
private QueryInfo info;
- private List<CodeEntity> codes;
+ private List<CodeFragment> codes;
- private int TRIMMED_TEXT_LEN = 120;
+ // The Search we are conducting
+ private final CodeFragment codeFragmentPrototype;
- private CodeEntity searchItem;
-
private int page = 0;
public History()
{
+ this.codeFragmentPrototype = new CodeFragment();
}
- @PostConstruct
- public void initialize()
+ public List<CodeFragment> getCodes()
{
- this.searchItem = new CodeEntity();
- // this.info = new QueryInfo();
- }
-
- public List<CodeEntity> getCodes()
- {
return this.codes;
}
- public void setCodes(List<CodeEntity> codes)
+ @Produces @Named
+ public CodeFragment getCodeFragmentPrototype()
{
- this.codes = codes;
+ return codeFragmentPrototype;
}
- @Produces
- @Named("searchItem")
- public CodeEntity getSearchItem()
- {
- return searchItem;
- }
-
- public void setSearchItem(CodeEntity searchItem)
- {
- this.searchItem = searchItem;
- }
-
+ //Start a *new* search!
public String newSearch()
{
this.page = 0;
return "history";
}
+ // Do the search, called as a "page action"
public String search()
{
this.info = new QueryInfo();
this.codes = null;
- this.codes = eao.searchCodes(this.searchItem, this.page, this.info);
+
+ // Perform a seach
+
+ this.codes = codeFragmentManager.searchCodeFragments(this.codeFragmentPrototype,
this.page, this.info);
for (int i = 0; i != this.codes.size(); i++)
{
Copied:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java
(from rev 6434,
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Data.java)
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LanguageManager.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.session;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+import org.jboss.weld.examples.pastecode.model.Language;
+
+public class LanguageManager
+{
+
+ @Produces
+ @Named
+ public Language[] getLanguages()
+ {
+ return Language.values();
+ }
+
+}
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LargeCodeDecorator.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LargeCodeDecorator.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/LargeCodeDecorator.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -22,6 +22,7 @@
package org.jboss.weld.examples.pastecode.session;
import java.util.Date;
+
import javax.annotation.Resource;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
@@ -31,10 +32,11 @@
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-import org.jboss.weld.examples.pastecode.model.LargeCodeLog;
import javax.transaction.UserTransaction;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+import org.jboss.weld.examples.pastecode.model.AccessLog;
+
/**
* This Decorator performs logging of information about large
* transactions. A transaction is large if the pasted code has
@@ -47,10 +49,10 @@
*/
@Decorator
@TransactionManagement(TransactionManagementType.BEAN)
-public abstract class LargeCodeDecorator implements Code
+public abstract class LargeCodeDecorator implements CodeFragmentManager
{
/* injecting Delagation point - mandatory */
- @Inject @Delegate @Any Code eao;
+ @Inject @Delegate @Any CodeFragmentManager eao;
@PersistenceContext(unitName = "pastecodeDatabase")
private EntityManager em;
@@ -59,10 +61,10 @@
private long LARGE_CODE = 65536;
- public String addCode(CodeEntity code, boolean secured)
+ public String addCodeFragment(CodeFragment code, boolean secured)
{
- String codeId = eao.addCode(code, secured);
+ String codeId = eao.addCodeFragment(code, secured);
if (code.getText().length() > LARGE_CODE)
{
@@ -70,7 +72,7 @@
{
ut.begin();
em.joinTransaction();
- em.persist(new LargeCodeLog(code.getId(), code.getDatetime(),
"w")); //writing large code
+ em.persist(new AccessLog(code, code.getDatetime(), "w")); //writing
large code
ut.commit();
}
catch(Exception e)
@@ -89,9 +91,9 @@
return codeId;
}
- public CodeEntity getCode(String id)
+ public CodeFragment getCodeFragment(String id)
{
- CodeEntity code = eao.getCode(id);
+ CodeFragment code = eao.getCodeFragment(id);
if (code.getText().length() > LARGE_CODE)
{
@@ -99,7 +101,7 @@
{
ut.begin();
em.joinTransaction();
- em.persist(new LargeCodeLog(code.getId(), new Date(), "r"));
//reading large code
+ em.persist(new AccessLog(code, new Date(), "r")); //reading large
code
ut.commit();
}
catch(Exception e)
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,17 +21,21 @@
*/
package org.jboss.weld.examples.pastecode.session;
-import javax.inject.*;
+import java.util.List;
+
import javax.annotation.PostConstruct;
import javax.ejb.EJBException;
-import javax.enterprise.inject.*;
-import org.jboss.weld.examples.pastecode.model.*;
-import java.util.List;
+import javax.enterprise.inject.Model;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
@Model
public class Paster
{
- private CodeEntity code;
+ private CodeFragment code;
private String codeId;
@@ -41,9 +45,9 @@
private boolean secured = false;
- @Inject Data data;
+ @Inject LanguageManager data;
- transient @Inject Code eao;
+ transient @Inject CodeFragmentManager eao;
public Paster()
{
@@ -52,37 +56,37 @@
@PostConstruct
public void postConstruct()
{
- this.code = new CodeEntity();
+ this.code = new CodeFragment();
this.theme = "shThemeDefault.css";
}
public String paste()
{
- this.codeId = eao.addCode(code, secured);
+ this.codeId = eao.addCodeFragment(code, secured);
return "success";
}
/* used for access from jsf page */
@Produces
@Named("code")
- public CodeEntity getPasterCodeInstance()
+ public CodeFragment getPasterCodeInstance()
{
return this.code;
}
public void loadCode()
{
- this.code = eao.getCode(codeId);
+ this.code = eao.getCodeFragment(codeId);
if (this.code == null)
throw new EJBException("Could not read entity with given id value");
- this.brush = data.getBrush(this.code.getLanguage());
+ this.brush = this.code.getLanguage().getBrush();
}
- public List<CodeEntity> getCodes()
+ public List<CodeFragment> getCodes()
{
- return eao.recentCodes();
+ return eao.getRecentCodeFragments();
}
public String getCodeId()
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,19 +21,21 @@
*/
package org.jboss.weld.examples.pastecode.session;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Named;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import javax.enterprise.inject.Instance;
import java.text.SimpleDateFormat;
import java.util.StringTokenizer;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
import javax.inject.Inject;
-import org.jboss.weld.examples.pastecode.model.CodeEntity;
-import com.sun.org.apache.xml.internal.serialize.LineSeparator;
+import javax.inject.Named;
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+import org.jboss.weld.examples.pastecode.model.Language;
+
/**
* This bean only populates database with preformatted data. This is due to need
* for Hypersonic database which doesn't allow multi-line inserts. Hypersonic
@@ -41,14 +43,15 @@
* external database to run this example.
*
*/
+// TODO Make into an EJB Singleton which executes at startup
@ApplicationScoped
@Named("database")
public class PopulateDatabaseBean
{
- private @Inject
- Instance<Code> eaoIn;
- private Code eao;
+ @Inject
+ private Instance<CodeFragmentManager> eaoIn;
+ private CodeFragmentManager eao;
private boolean secured = false;
private static final String file = "data.sql";
private boolean populated = false;
@@ -74,11 +77,11 @@
while (st.countTokens() > 1)
{
- CodeEntity c = new CodeEntity();
+ CodeFragment c = new CodeFragment();
st.nextToken();
c.setDatetime(formatter.parse(st.nextToken()));
st.nextToken();
- c.setLanguage(st.nextToken());
+ c.setLanguage(Language.valueOf(st.nextToken()));
st.nextToken();
c.setNote(st.nextToken());
st.nextToken();
@@ -86,7 +89,7 @@
st.nextToken();
c.setText(st.nextToken());
- eao.addCode(c, secured);
+ eao.addCodeFragment(c, secured);
}
}
@@ -108,7 +111,7 @@
while ((radek = br.readLine()) != null)
{
- sb.append(radek).append(LineSeparator.Web);
+ sb.append(radek).append("\n");
}
return new String(sb);
Modified:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java 2010-06-16
10:26:18 UTC (rev 6440)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -21,11 +21,12 @@
*/
package org.jboss.weld.examples.pastecode.session;
+import java.util.ArrayList;
import java.util.List;
-import java.util.ArrayList;
public class QueryInfo
{
+
private int recordsCount = 0;
private int pagesCount = 0;
private int numLinks = 8;
Added:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,25 @@
+package org.jboss.weld.examples.pastecode.session;
+
+public enum Theme
+{
+
+ DEFAULT("Default Theme"),
+ DJANGO( "Django Theme"),
+ ECLIPSE("Eclipse Theme"),
+ EMACS("Emacs Theme"),
+ MIDNIGHT("Midnight Theme"),
+ DARK("Dark Theme");
+
+ private final String name;
+
+ private Theme(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+}
Property changes on:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Theme.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
===================================================================
---
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
(rev 0)
+++
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java 2010-06-16
13:35:18 UTC (rev 6441)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.session;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+@ApplicationScoped
+public class ThemeManager
+{
+
+ // The supported themes
+ private final List<String> THEMES = new ArrayList<String>();
+
+ @SuppressWarnings("unused")
+ @PostConstruct
+ private void populateThemes()
+ {
+ for (Theme theme : Theme.values())
+ {
+ THEMES.add(theme.getName());
+ }
+ }
+
+ @Produces @Named
+ public List<String> getThemes()
+ {
+ return Collections.unmodifiableList(THEMES);
+ }
+
+}
Property changes on:
examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/ThemeManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: examples/trunk/jsf/pastecode/src/main/resources/data.sql
===================================================================
--- examples/trunk/jsf/pastecode/src/main/resources/data.sql 2010-06-16 10:26:18 UTC (rev
6440)
+++ examples/trunk/jsf/pastecode/src/main/resources/data.sql 2010-06-16 13:35:18 UTC (rev
6441)
@@ -1,14 +1,14 @@
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (1, '2010-01-01
01:01:01', 'css', ' ', 'martin',
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (1, '2010-01-01
01:01:01', 'CSS', ' ', 'martin',
'div {
min-height: 500px;
height:auto !important;
height: 500px;
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (2, '2009-01-02
01:01:01', 'css', ' ', 'peter',
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (2, '2009-01-02
01:01:01', 'CSS', ' ', 'peter',
'div {
height: expression( this.scrollHeight < 501 ? "500px" : "auto"
);
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (3, '2009-02-02
01:01:01', 'css', ' ', 'peter',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (3,
'2009-02-02 01:01:01', 'CSS', ' ', 'peter',
'a.GlobalOrangeButton span {
background: transparent
url(http://media-sprout.com/tutorials/web/CSSSprit-SlideButton/images/but...
no-repeat 0 0;
display: block;
@@ -17,19 +17,19 @@
color: #fff;
}
');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (4, '2009-02-02
01:01:01', 'js', ' ', 'john',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (4,
'2009-02-02 01:01:01', 'JAVASCRIPT', ' ', 'john',
'var newPathname = "";
for ( i = 0; i pathArray.length; i++ ) {
newPathname += "/";
newPathname += pathArray[i];
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (5, '2009-02-03
01:01:01', 'js', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (5,
'2009-02-03 01:01:01', 'JAVASCRIPT', ' ', 'graham',
'<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (6, '2009-02-04
01:01:01', 'js', ' ', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (6,
'2009-02-04 01:01:01', 'JAVASCRIPT', ' ', 'martin',
'var myArray = ["one", "two", "three"];
// console.log( myArray ) => ["one", "two", "three"]
@@ -37,7 +37,7 @@
myArray.length = 0;
// console.log( myArray ) => []');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (7, '2009-02-04
01:01:01', 'js', ' ', 'crazyman',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (7,
'2009-02-04 01:01:01', 'JAVASCRIPT', ' ', 'crazyman',
'function randRange(data) {
var newTime = data[Math.floor(data.length * Math.random())];
return newTime;
@@ -52,7 +52,7 @@
clearInterval(timer);
timer = setInterval(toggleSomething, randRange(timeArray));
');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (8, '2009-02-05
01:01:01', 'java', ' ', 'peter',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (8,
'2009-02-05 01:01:01', 'JAVA', ' ', 'peter',
'public List<code> recentcodes()
{
Query q = em.createQuery("SELECT c FROM code c WHERE hash=null ORDER BY
datetime DESC ");
@@ -60,12 +60,12 @@
List<code> codes = q.getResultList();
return codes;
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (9, '2009-02-05
01:01:01', 'java', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (9,
'2009-02-05 01:01:01', 'JAVA', ' ', 'graham',
' private void startOperation() throws HibernateException {
session = HibernateFactory.openSession();
tx = session.beginTransaction();
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (10, '2009-01-06
01:01:01', 'java', ' ', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (10,
'2009-01-06 01:01:01', 'JAVA', ' ', 'martin',
'public List findAll() throws DataAccessLayerException{
List events = null;
try {
@@ -81,7 +81,7 @@
return events;
}
');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (11, '2009-02-06
01:01:01', 'java', ' ', 'crazyman',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (11,
'2009-02-06 01:01:01', 'JAVA', ' ', 'crazyman',
'public Event find(Long id) throws DataAccessLayerException {
Event event = null;
try {
@@ -95,7 +95,7 @@
}
return event;
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (12, '2009-01-07
01:01:01', 'java', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (12,
'2009-01-07 01:01:01', 'JAVA', ' ', 'graham',
' public void delete(Event event) throws DataAccessLayerException {
try {
startOperation();
@@ -107,7 +107,7 @@
HibernateFactory.close(session);
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (13, '2009-01-08
01:01:01', 'java', ' ', 'peter',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (13,
'2009-01-08 01:01:01', 'JAVA', ' ', 'peter',
'public void create(Event event) throws DataAccessLayerException {
try {
startOperation();
@@ -119,7 +119,7 @@
HibernateFactory.close(session);
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (14, '2009-01-09
01:01:01', 'php', ' ', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (14,
'2009-01-09 01:01:01', 'PHP', ' ', 'martin',
'function build_calendar($month,$year,$dateArray) {
// Create array containing abbreviations of days of week.
@@ -131,12 +131,12 @@
// How many days does this month contain?
$numberDays = date(t,$firstDayOfMonth);
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (15, '2009-01-10
01:01:01', 'php', ' ', 'john',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (15,
'2009-01-10 01:01:01', 'PHP', ' ', 'john',
'if ( !empty($_SERVER[HTTP_X_REQUESTED_WITH]) &&
strtolower($_SERVER[HTTP_X_REQUESTED_WITH]) == xmlhttprequest )
{
# Ex. check the query and serve requested data
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (16, '2009-01-11
01:01:01', 'php', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (16,
'2009-01-11 01:01:01', 'PHP', ' ', 'graham',
'<?php
function getTwitterStatus($userid){
@@ -154,11 +154,11 @@
getTwitterStatus("kenrick1991");
?>');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (17, '2009-01-11
01:01:01', 'php', ' ', 'peter',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (17,
'2009-01-11 01:01:01', 'PHP', ' ', 'peter',
'<?php
header( Location:
http://www.yoursite.com/new_page.html ) ;
?>');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (18, '2009-01-12
01:01:01', 'php', ' ', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (18,
'2009-01-12 01:01:01', 'PHP', ' ', 'martin',
'function findexts ($filename) {
$filename = strtolower($filename) ;
@@ -172,14 +172,14 @@
return $exts;
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (19, '2009-01-12
01:01:01', 'php', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (19,
'2009-01-12 01:01:01', 'PHP', ' ', 'graham',
'function fileRead($file){
$lines = file($file);
foreach ($lines as $line_num => $line) {
echo $line, </br>;
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (20, '2009-02-12
01:01:01', 'java', ' ', 'peter',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (20,
'2009-02-12 01:01:01', 'JAVA', ' ', 'peter',
'import java.util.*;
import org.hibernate.*;
@@ -210,7 +210,7 @@
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (21, '2009-02-16
01:01:01', 'java', ' ', 'crazyman',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (21,
'2009-02-16 01:01:01', 'JAVA', ' ', 'crazyman',
'import javax.swing.DefaultListModel;
import javax.swing.DropMode;
import javax.swing.JComboBox;
@@ -248,7 +248,7 @@
return true;
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (22, '2009-02-15
01:01:01', 'java', ' ', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (22,
'2009-02-15 01:01:01', 'JAVA', ' ', 'martin',
'@Entity
public class Address {
@Id
@@ -306,7 +306,7 @@
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (23, '2009-02-18
01:01:01', 'java', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (23,
'2009-02-18 01:01:01', 'JAVA', ' ', 'graham',
'import java.util.List;
import javax.persistence.EntityManager;
@@ -328,7 +328,7 @@
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (24, '2009-02-19
01:01:01', 'java', ' ', 'crazyman',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (24,
'2009-02-19 01:01:01', 'JAVA', ' ', 'crazyman',
'@Entity
public class Department {
@Id
@@ -358,7 +358,7 @@
}
}
');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (25, '2009-02-01
01:01:01', 'java', ' ', 'graham',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (25,
'2009-02-01 01:01:01', 'JAVA', ' ', 'graham',
'import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -404,7 +404,7 @@
}
}');
-insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (26, '2009-02-01
01:01:01', 'java', 'Some note', 'martin',
+insert into CodeFragment (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (26,
'2009-02-01 01:01:01', 'JAVA', 'Some note', 'martin',
'package org.jboss.weld.examples.pastie.session;
import java.util.List;
Property changes on: examples/trunk/jsf/pastecode/src/main/webapp
___________________________________________________________________
Name: svn:ignore
+ META-INF
Property changes on: examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF
___________________________________________________________________
Name: svn:ignore
+ lib
Modified: examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/web.xml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/web.xml 2010-06-16 10:26:18 UTC
(rev 6440)
+++ examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/web.xml 2010-06-16 13:35:18 UTC
(rev 6441)
@@ -1,55 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
-<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- version="2.5">
-
- <display-name>Weld PasteCode example</display-name>
-<!-- <distributable />-->
-
- <context-param>
- <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
- <param-value>.xhtml</param-value>
- </context-param>
-
- <session-config>
- <session-timeout>10</session-timeout>
- </session-config>
-
- <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>*.jsf</url-pattern>
- <url-pattern>/faces/*</url-pattern>
- </servlet-mapping>
-
- <filter>
- <filter-name>UrlRewriteFilter</filter-name>
-
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
- </filter>
-
- <filter-mapping>
- <filter-name>UrlRewriteFilter</filter-name>
- <url-pattern>/*</url-pattern>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- </filter-mapping>
-
- <servlet>
- <description></description>
- <display-name>DownloadServlet</display-name>
- <servlet-name>DownloadServlet</servlet-name>
-
<servlet-class>org.jboss.weld.examples.pastecode.servlets.DownloadServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>DownloadServlet</servlet-name>
- <url-pattern>/download</url-pattern>
- </servlet-mapping>
-
-</web-app>
+<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
+ <display-name>Weld PasteCode example</display-name>
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+ <session-config>
+ <session-timeout>10</session-timeout>
+ </session-config>
+ <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>*.jsf</url-pattern>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+ <filter>
+ <filter-name>UrlRewriteFilter</filter-name>
+
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>UrlRewriteFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ </filter-mapping>
+ <servlet>
+ <description></description>
+ <display-name>DownloadServlet</display-name>
+ <servlet-name>DownloadServlet</servlet-name>
+
<servlet-class>org.jboss.weld.examples.pastecode.servlets.DownloadServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>DownloadServlet</servlet-name>
+ <url-pattern>/download</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Modified: examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml 2010-06-16 10:26:18 UTC
(rev 6440)
+++ examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml 2010-06-16 13:35:18 UTC
(rev 6441)
@@ -42,7 +42,7 @@
<h:panelGroup>
<h:outputLabel for="theme" value="Choose theme: "/>
<h:selectOneMenu id="theme" value="#{paster.theme}"
onchange="chooseStyle(this.value);"> <!-- this.form.submit() -->
- <f:selectItems value="#{dataBean.themeItems}"/>
+ <f:selectItems value="#{themes}"/>
</h:selectOneMenu>
<a href="download?id=#{code.hash == null ? code.id : code.hash}"
style="text-decoration: none;"><input type="button"
value="Download file" /></a>
</h:panelGroup>
Modified: examples/trunk/jsf/pastecode/src/main/webapp/history.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/history.xhtml 2010-06-16 10:26:18 UTC
(rev 6440)
+++ examples/trunk/jsf/pastecode/src/main/webapp/history.xhtml 2010-06-16 13:35:18 UTC
(rev 6441)
@@ -1,98 +1,95 @@
<!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:ui="http://java.sun.com/jsf/facelets"
-
xmlns:h="http://java.sun.com/jsf/html"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:s="http://jboss.com/products/seam/taglib">
-
- <ui:composition template="template.xhtml">
- <ui:define name="viewMetadata">
- <f:metadata>
- <f:viewParam name="page" value="#{history.page}"/>
- <f:event type="preRenderView"
listener="#{history.search}"/>
- </f:metadata>
- </ui:define>
-
- <ui:define name="themes">
- </ui:define>
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:s="http://jboss.com/products/seam/taglib">
- <ui:define name="mainarea">
- <div style="width: 100%; padding: 7px;">
-
- <div id="paging" style="width:98%; border-width:0px;
background-color:#C1C1E8;"> <!-- height: 40px; -->
- <ui:include src="pagination.xhtml"></ui:include>
- </div>
- <br/>
- <h:dataTable value="#{history.codes}" var="varcode"
width="99%">
- <h:column>
- <div id="searched">
- <h:panelGroup >
- <h:outputLabel for="user" value="User: "/>
- <h:outputLink id="user" value="#{
varcode.id}"> <!-- display.jsf?id= -->
- <h:outputText
value="#{varcode.user}"></h:outputText>
- </h:outputLink>
- </h:panelGroup>
-
- <h:panelGroup>
- <h:outputLabel for="language" value="Language:
"/>
- <h:outputText id="language" value="#{
varcode.language}"></h:outputText>
- </h:panelGroup>
-
- <h:panelGroup>
- <h:outputLabel for="datetime" value="Date:
"/>
- <h:outputText id="datetime" value="#{
varcode.datetime}">
- <f:convertDateTime type="both"
pattern="yyyy-MM-dd HH:mm:ss"/>
- </h:outputText>
- </h:panelGroup>
- </div>
- <br/>
- <h:outputText value="Code (truncated): "/>
- <div style="height:100px; width:99%; border: 1px solid #7F7F7F;
overflow: auto; padding: 1px;">
- <pre>#{varcode.text}</pre>
- </div>
- <br/>
- <br/>
- </h:column>
- </h:dataTable>
- <br/>
- <div id="paging" style="width:98%; border-width:0px;
background-color:#C1C1E8;"> <!-- height: 40px; -->
- <ui:include src="pagination.xhtml"></ui:include>
- </div>
- </div>
-
- </ui:define>
-
- <ui:define name="rightmenu">
-
- <div id="rightmenuhead" style="width:350px;">
- <strong>Search:</strong>
- </div>
-
- <div id="rightmenubody" style="width:350px;">
-
- <h:panelGrid cellpadding="0" cellspacing="0"
columns="2" width="100%">
- <h:outputLabel for="user"
value="User:"></h:outputLabel>
- <h:inputText id="user" maxlength="30"
style="width:97%;" value="#{searchItem.user}"/>
- <h:outputLabel for="language"
value="Language:"></h:outputLabel>
- <h:inputText id="language" maxlength="30"
style="width:97%;" value="#{searchItem.language}"/>
- <h:outputLabel for="note"
value="Note:"></h:outputLabel>
- <h:inputText id="note" maxlength="30"
style="width:97%;" value="#{searchItem.note}"/>
- <h:outputLabel for="pasteDate" value="Date: "/>
- <h:inputText value="#{searchItem.datetime}"
id="pasteDate" style="width:97%;" alt="yyyy-mm-dd"
title="yyyy-mm-dd"
- converterMessage="Enter date formatted as yyyy-mm-dd !" >
- <f:convertDateTime type="date"
pattern="yyyy-MM-dd"/>
- </h:inputText>
- <h:outputLabel for="code" value="Code:"
style="width:100%;"></h:outputLabel>
- <h:inputTextarea id="code" maxlength="30"
rows="2" style="width:97%;" value="#{searchItem.text}"/>
- </h:panelGrid>
- <div style="width:100%;text-align:right;">
- <h:commandButton value="Search"
action="#{history.newSearch}"/>
- </div>
- <br/>
- <h:message for="pasteDate"/>
- </div>
-
- </ui:define>
-
- </ui:composition>
+<ui:composition template="template.xhtml">
+ <ui:define name="viewMetadata">
+ <f:metadata>
+ <f:viewParam name="page" value="#{history.page}" />
+ <f:event type="preRenderView" listener="#{history.search}"
/>
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="themes">
+ </ui:define>
+
+ <ui:define name="mainarea">
+ <div style="width: 100%; padding: 7px;">
+
+ <div id="paging"
+ style="width: 98%; border-width: 0px; background-color: #C1C1E8;">
+ <!-- height: 40px; --> <ui:include
src="pagination.xhtml"></ui:include>
+ </div>
+ <br />
+ <h:dataTable value="#{history.codes}" var="codeFragment"
width="99%">
+ <h:column>
+ <div id="searched"><h:panelGroup>
+ <h:outputLabel for="user" value="User: " />
+ <h:outputLink id="user" value="#{codeFragment.id}">
+ <!-- display.jsf?id= -->
+ <h:outputText value="#{codeFragment.user}"></h:outputText>
+ </h:outputLink>
+ </h:panelGroup> <h:panelGroup>
+ <h:outputLabel for="language" value="Language: " />
+ <h:outputText id="language"
value="#{codeFragment.language.name}"></h:outputText>
+ </h:panelGroup> <h:panelGroup>
+ <h:outputLabel for="datetime" value="Date: " />
+ <h:outputText id="datetime"
value="#{codeFragment.datetime}">
+ <f:convertDateTime type="both" pattern="yyyy-MM-dd HH:mm:ss"
/>
+ </h:outputText>
+ </h:panelGroup></div>
+ <br />
+ <h:outputText value="Code (truncated): " />
+ <div
+ style="height: 100px; width: 99%; border: 1px solid #7F7F7F; overflow: auto;
padding: 1px;">
+ <pre>#{codeFragment.text}</pre></div>
+ <br />
+ <br />
+ </h:column>
+ </h:dataTable> <br />
+ <div id="paging"
+ style="width: 98%; border-width: 0px; background-color: #C1C1E8;">
+ <!-- height: 40px; --> <ui:include
src="pagination.xhtml"></ui:include>
+ </div>
+ </div>
+
+ </ui:define>
+
+ <ui:define name="rightmenu">
+
+ <div id="rightmenuhead" style="width:
350px;"><strong>Search:</strong>
+ </div>
+
+ <div id="rightmenubody" style="width:
350px;"><h:panelGrid
+ cellpadding="0" cellspacing="0" columns="2"
width="100%">
+ <h:outputLabel for="user"
value="User:"></h:outputLabel>
+ <h:inputText id="user" maxlength="30"
style="width:97%;"
+ value="#{codeFragmentPrototype.user}" />
+ <h:outputLabel for="language"
value="Language:"></h:outputLabel>
+ <h:inputText id="language" maxlength="30"
style="width:97%;"
+ value="#{codeFragmentPrototype.language}" />
+ <h:outputLabel for="note"
value="Note:"></h:outputLabel>
+ <h:inputText id="note" maxlength="30"
style="width:97%;"
+ value="#{codeFragmentPrototype.note}" />
+ <h:outputLabel for="pasteDate" value="Date: " />
+ <h:inputText value="#{codeFragmentPrototype.datetime}"
id="pasteDate"
+ style="width:97%;" alt="yyyy-mm-dd" title="yyyy-mm-dd"
+ converterMessage="Enter date formatted as yyyy-mm-dd !">
+ <f:convertDateTime type="date" pattern="yyyy-MM-dd" />
+ </h:inputText>
+ <h:outputLabel for="code" value="Code:"
style="width:100%;"></h:outputLabel>
+ <h:inputTextarea id="code" maxlength="30" rows="2"
style="width:97%;"
+ value="#{codeFragmentPrototype.text}" />
+ </h:panelGrid>
+ <div style="width: 100%; text-align: right;"><h:commandButton
+ value="Search" action="#{history.newSearch}" /></div>
+ <br />
+ <h:message for="pasteDate" /></div>
+
+ </ui:define>
+
+</ui:composition>
</html>
Modified: examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml 2010-06-16 10:26:18 UTC (rev
6440)
+++ examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml 2010-06-16 13:35:18 UTC (rev
6441)
@@ -24,7 +24,7 @@
<h:panelGroup>
<h:outputLabel for="language" value="Language: "/>
<h:selectOneMenu id="language"
value="#{code.language}">
- <f:selectItems value="#{dataBean.languageItems}"/>
+ <f:selectItems value="#{languages}" var="language"
itemLabel="#{language.name}" itemValue="#{language.extension}" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup style="text-align:right;">