[weld-commits] Weld SVN: r5847 - in examples/trunk/jsf/pastecode: ejb/src/main/java/org/jboss/weld/examples/pastecode/session and 3 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Tue Feb 16 10:34:38 EST 2010


Author: mgencur at redhat.com
Date: 2010-02-16 10:34:37 -0500 (Tue, 16 Feb 2010)
New Revision: 5847

Added:
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java
   examples/trunk/jsf/pastecode/ejb/src/main/resources/data.sql
Modified:
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/DataBean.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HistoryBean.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
   examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java
   examples/trunk/jsf/pastecode/war/src/main/java/org/jboss/weld/examples/pastecode/DownloadServlet.java
   examples/trunk/jsf/pastecode/war/src/main/webapp/home.xhtml
Log:
bean for populating database and licences

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;
@@ -52,6 +73,7 @@
       this.text = "";
       this.user = "";
       this.hash = null;
+      this.datetime = null;
    }
 
    @Temporal(TemporalType.TIMESTAMP)
@@ -111,26 +133,4 @@
    {
       this.user = user;
    }
-
-//   public Object clone()
-//   {
-//      Code c = null;
-//      try
-//      {
-//         c = (Code) super.clone();
-//         c.setDatetime(this.datetime);
-//         c.setHash(this.hash);
-//         c.setId(this.id);
-//         c.setLanguage(this.language);
-//         c.setNote(this.note);
-//         c.setText(this.text);
-//         c.setUser(this.user);
-//      }
-//      catch (CloneNotSupportedException e)
-//      {
-//         e.printStackTrace();
-//      }
-//      return c;
-//   }
-
 }
\ No newline at end of file

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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.ejb.Local;

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;
@@ -42,7 +63,11 @@
    public String addCode(Code code, boolean secured)
    {
       String result;
-      code.setDatetime(Calendar.getInstance().getTime());
+      if (code.getDatetime() == null)
+      {
+         code.setDatetime(Calendar.getInstance().getTime());
+      }
+
       if (code.getUser().trim().isEmpty())
       {
          code.setUser("Anonymous");
@@ -70,7 +95,7 @@
          result = new Integer(code.getId()).toString();
       }
 
-      //System.out.println("Result: " + result);
+      // System.out.println("Result: " + result);
 
       return result;
    }
@@ -123,7 +148,6 @@
       return codes;
    }
 
-
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public List<Code> allCodes()
    {
@@ -131,11 +155,11 @@
       List<Code> 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
+    * 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<Code> searchCodes(Code code, int page, QueryInfo info)
@@ -167,7 +191,8 @@
       {
          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
+         date2.setTime(code.getDatetime().getTime() + 24 * 60 * 60 * 1000); // +1
+         // day
 
          String formattedDate1 = formatter.format(code.getDatetime());
          String formattedDate2 = formatter.format(date2);

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/DataBean.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/DataBean.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/DataBean.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HashComputer.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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 org.jboss.weld.examples.pastecode.model.Code;

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/History.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/History.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/History.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HistoryBean.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HistoryBean.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/HistoryBean.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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.inject.*;

Added: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java	                        (rev 0)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/PopulateDatabaseBean.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -0,0 +1,116 @@
+/*
+ * 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.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.inject.Inject;
+import org.jboss.weld.examples.pastecode.model.Code;
+import com.sun.org.apache.xml.internal.serialize.LineSeparator;
+
+/**
+ * This bean only populates database with preformatted data. This is due to need
+ * for Hypersonic database which doesn't allow multi-line inserts. Hypersonic
+ * database is embedded in JBoss AS and so there is no need to configure any
+ * external database to run this example.
+ * 
+ */
+ at ApplicationScoped
+ at Named("database")
+public class PopulateDatabaseBean
+{
+
+   private @Inject
+   Instance<CodeEAO> eaoIn;
+   private CodeEAO eao;
+   private boolean secured = false;
+   private static final String file = "data.sql";
+   private boolean populated = false;
+
+   public PopulateDatabaseBean()
+   {
+   }
+
+   public void populate()
+   {
+      if (populated)
+      {
+         return;
+      }
+
+      eao = eaoIn.get();
+
+      try
+      {
+         String fileContent = readFileData(file);
+         StringTokenizer st = new StringTokenizer(fileContent, "'");
+         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+         while (st.countTokens() > 1)
+         {
+            Code c = new Code();
+            st.nextToken();
+            c.setDatetime(formatter.parse(st.nextToken()));
+            st.nextToken();
+            c.setLanguage(st.nextToken());
+            st.nextToken();
+            c.setNote(st.nextToken());
+            st.nextToken();
+            c.setUser(st.nextToken());
+            st.nextToken();
+            c.setText(st.nextToken());
+
+            eao.addCode(c, secured);
+         }
+
+      }
+      catch (Exception e)
+      {
+         System.err.println("Unable to read all records from " + file + " file");
+      }
+
+      populated = true;
+   }
+
+   private String readFileData(String fileName) throws IOException
+   {
+      InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName);
+      BufferedReader br = new BufferedReader(new InputStreamReader(is));
+
+      String radek;
+      StringBuffer sb = new StringBuffer();
+
+      while ((radek = br.readLine()) != null)
+      {
+         sb.append(radek).append(LineSeparator.Web);
+      }
+
+      return new String(sb);
+   }
+}

Modified: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/QueryInfo.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;
@@ -49,7 +70,7 @@
       else
       {
          this.setStartIndex(0);
-         this.setEndIndex((numLinks > this.pagesCount) ? this.pagesCount : numLinks); 
+         this.setEndIndex((numLinks > this.pagesCount) ? this.pagesCount : numLinks);
       }
 
       if (this.page + (numLinks / 2) >= this.pagesCount)

Added: examples/trunk/jsf/pastecode/ejb/src/main/resources/data.sql
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/resources/data.sql	                        (rev 0)
+++ examples/trunk/jsf/pastecode/ejb/src/main/resources/data.sql	2010-02-16 15:34:37 UTC (rev 5847)
@@ -0,0 +1,530 @@
+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',
+'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',
+'a.GlobalOrangeButton span {
+background: transparent url(http://media-sprout.com/tutorials/web/CSSSprit-SlideButton/images/button_left_orange.png) no-repeat 0 0;
+display: block;
+line-height: 22px;
+padding: 7px 0 5px 18px;
+color: #fff;
+}
+');
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (4, '2009-02-02 01:01:01', 'js', ' ', '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',
+'<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',
+'var myArray = ["one", "two", "three"];
+
+// console.log( myArray ) => ["one", "two", "three"]
+
+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',
+'function randRange(data) {
+       var newTime = data[Math.floor(data.length * Math.random())];
+       return newTime;
+}
+
+function toggleSomething() {
+       var timeArray = new Array(200, 300, 150, 250, 2000, 3000, 1000, 1500);
+
+       // do stuff, happens to use jQuery here (nothing else does)
+       $("#box").toggleClass("visible");
+
+       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',
+'public List<code> recentcodes()
+    {
+    	Query q = em.createQuery("SELECT c FROM code c WHERE hash=null ORDER BY datetime DESC ");
+    	q.setMaxResults(MAX_codeS);
+    	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',
+' 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',
+'public List findAll() throws DataAccessLayerException{
+        List events = null;
+        try {
+            startOperation();
+            Query query = session.createQuery("from Event");
+            events =  query.list();
+            tx.commit();
+        } catch (HibernateException e) {
+            handleException(e);
+        } finally {
+            HibernateFactory.close(session);
+        }
+        return events;
+    }
+');
+insert into code (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 {
+            startOperation();
+            event = (Event) session.load(Event.class, id);
+            tx.commit();
+        } catch (HibernateException e) {
+            handleException(e);
+        } finally {
+            HibernateFactory.close(session);
+        }
+        return event;
+    }');
+insert into code (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();
+            session.delete(event);
+            tx.commit();
+        } catch (HibernateException e) {
+            handleException(e);
+        } finally {
+            HibernateFactory.close(session);
+        }
+    }');
+insert into code (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();
+            session.save(event);
+            tx.commit();
+        } catch (HibernateException e) {
+            handleException(e);
+        } finally {
+            HibernateFactory.close(session);
+        }
+    }');
+insert into code (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.
+     $daysOfWeek = array(S,M,T,W,T,F,S);
+
+     // What is the first day of the month in question?
+     $firstDayOfMonth = mktime(0,0,0,$month,1,$year);
+
+     // 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',
+'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',
+'<?php
+
+function getTwitterStatus($userid){
+$url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1";
+
+$xml = simplexml_load_file($url) or die("could not connect");
+
+       foreach($xml->status as $status){
+       $text = $status->text;
+       }
+       echo $text;
+ }
+
+//my user id kenrick1991
+getTwitterStatus("kenrick1991");
+
+?>');
+insert into code (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',
+'function findexts ($filename) {
+
+       $filename = strtolower($filename) ;
+
+       $exts = split("[/\\.]", $filename) ;
+
+       $n = count($exts)-1;
+
+       $exts = $exts[$n];
+
+       return $exts;
+
+}');
+insert into code (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',
+'import java.util.*;
+
+import org.hibernate.*;
+import org.hibernate.criterion.*;
+
+public class Main {
+  
+  
+  public static void main(String[] args) {
+    HibernateUtil.setup("create table EVENTS ( uid int, name VARCHAR, start_Date date, duration int);");
+    
+    // hibernate code start
+
+
+        SimpleEventDao eventDao = new SimpleEventDao();
+        Event event = new Event();
+        event.setName("Create an Event");
+
+        eventDao.create(event);
+        
+        Event foundEvent = eventDao.find(/*event.getId()*/1L);
+
+        System.out.println(foundEvent.getName());
+        
+
+        HibernateUtil.checkData("select uid, name from events");        
+    // hibernate code end
+  }
+  
+}');
+insert into code (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;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.TransferHandler;
+
+public class DropModeON {
+  public static void main(String[] args) {
+    JPanel north = new JPanel();
+    north.add(new JLabel("Drag from here:"));
+    JTextField field = new JTextField(10);
+    field.setDragEnabled(true); 
+    north.add(field);
+
+    final DefaultListModel listModel = new DefaultListModel();
+    listModel.addElement("first");
+    listModel.addElement("second");
+    final JList list = new JList(listModel);
+    list.setDragEnabled(true);
+
+    list.setTransferHandler(new TransferHandler() {
+      public boolean canImport(TransferHandler.TransferSupport support) {
+        if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+          return false;
+        }
+        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
+        if (dl.getIndex() == -1) {
+          return false;
+        } else {
+          return true;
+        }
+      }');
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (22, '2009-02-15 01:01:01', 'java', ' ', 'martin',
+'@Entity
+public class Address {
+    @Id
+    private int id;
+    private String street;
+    private String city;
+    private String state;
+    private String zip;
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public String getStreet() {
+        return street;
+    }
+    
+    public void setStreet(String address) {
+        this.street = address;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+    public String toString() {
+        return "Address id: " + getId() + 
+               ", street: " + getStreet() +
+               ", city: " + getCity() +
+               ", state: " + getState() +
+               ", zip: " + getZip();
+    }
+
+}');
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (23, '2009-02-18 01:01:01', 'java', ' ', 'graham',
+'import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+public class ProfessorService {
+  protected EntityManager em;
+
+  public ProfessorService(EntityManager em) {
+    this.em = em;
+  }
+
+  public List findWithAlias() {
+    Query query = em.createNativeQuery(
+        "SELECT emp.emp_id AS emp_id, name, salary, manager_id, dept_id, address_id, "
+            + "address.id, street, city, state, zip " + "FROM emp, address "
+            + "WHERE address_id = id", "ProfessorWithAddressColumnAlias");
+    return query.getResultList();
+  }
+
+}');
+insert into code (ID, DATETIME, LANGUAGE, NOTE, USER, TEXT) values (24, '2009-02-19 01:01:01', 'java', ' ', 'crazyman',
+'@Entity
+public class Department {
+  @Id
+  @GeneratedValue(strategy = GenerationType.IDENTITY)
+  private int id;
+
+  private String name;
+
+  public int getId() {
+    return id;
+  }
+
+  public void setId(int id) {
+    this.id = id;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String deptName) {
+    this.name = deptName;
+  }
+
+  public String toString() {
+    return "Department id: " + getId() + ", name: " + getName();
+  }
+}
+');
+insert into code (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;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+
+public class JPAUtil {
+  Statement st;
+  
+  public JPAUtil() throws Exception{
+    Class.forName("org.hsqldb.jdbcDriver");
+    System.out.println("Driver Loaded.");
+    String url = "jdbc:hsqldb:data/tutorial";
+
+    Connection conn = DriverManager.getConnection(url, "sa", "");
+    System.out.println("Got Connection.");
+    st = conn.createStatement();
+  }
+  public void executeSQLCommand(String sql) throws Exception {
+    st.executeUpdate(sql);
+  }
+  public void checkData(String sql) throws Exception {
+    ResultSet rs = st.executeQuery(sql);
+    ResultSetMetaData metadata = rs.getMetaData();
+
+    for (int i = 0; i < metadata.getColumnCount(); i++) {
+      System.out.print("\t"+ metadata.getColumnLabel(i + 1)); 
+    }
+    System.out.println("\n----------------------------------");
+
+    while (rs.next()) {
+      for (int i = 0; i < metadata.getColumnCount(); i++) {
+        Object value = rs.getObject(i + 1);
+        if (value == null) {
+          System.out.print("\t       ");
+        } else {
+          System.out.print("\t"+value.toString().trim());
+        }
+      }
+      System.out.println("");
+    }
+  }
+}');
+
+insert into code (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;
+
+import javax.ejb.Stateful;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.io.Serializable;
+import javax.ejb.EJBContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.*;
+import org.jboss.weld.examples.pastie.model.code;
+import javax.inject.*;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+
+/**
+ * Session Bean implementation class HistoryBean
+ */
+
+ at SessionScoped
+ at Named("history")
+ at Stateful
+public class HistoryBean implements History, Serializable
+{
+    
+	private static final long serialVersionUID = 20L;
+
+	transient @Inject codeEAO eao;
+	
+	transient private @Inject PastieUtils utils;
+	
+	//transient private @Inject QueryInfo info;
+	
+	private QueryInfo info;
+	
+	
+
+	private List<code> codes;
+	
+	private boolean firstAccess = true;
+	
+	private int TRIMMED_TEXT_LEN = 150; 
+	
+	private code searchItem;
+	
+	private int page = 0;
+	
+
+
+	public HistoryBean()	
+    {
+    }
+	
+	@PostConstruct
+	public void initialize()
+	{
+		this.searchItem = new code();
+		this.info = new QueryInfo();
+	}
+    
+    public List<code> getcodes() 
+    {
+  	   return this.codes;  
+    }
+    
+    public void loadcode()
+    {
+    	if (firstAccess)
+    	{
+	    	this.codes = eao.allcodes();
+	        
+	        for(int i=0; i!=this.codes.size();i++)
+	        {
+	     	   String s = this.codes.get(i).getText();
+	     	   //this.codes.get(i).setText(s.substring(0, s.length() > TRIMMED_TEXT_LEN ? TRIMMED_TEXT_LEN : s.length()));
+	        }   
+	        firstAccess = false;
+    	}
+    }
+    
+    public void setcodes(List<code> codes) {
+		this.codes = codes;
+	}    
+    
+    @Produces @Named("searchItem")
+	public code getSearchItem() {
+		return searchItem;
+	}
+
+	public void setSearchItem(code searchItem) {
+		this.searchItem = searchItem;
+	}
+	
+	public String search()
+	{
+		this.codes = eao.searchcodes(this.searchItem, this.page, this.info);
+		
+		return "history";
+	}
+	
+
+	public int getPage() {
+		return page;
+	}
+
+	public void setPage(int page) {
+		this.page = page;
+	}
+	
+	
+	public QueryInfo getInfo() {
+		return info;
+	}
+
+	public void setInfo(QueryInfo info) {
+		this.info = info;
+	}
+    
+}
+')

Modified: examples/trunk/jsf/pastecode/war/src/main/java/org/jboss/weld/examples/pastecode/DownloadServlet.java
===================================================================
--- examples/trunk/jsf/pastecode/war/src/main/java/org/jboss/weld/examples/pastecode/DownloadServlet.java	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/war/src/main/java/org/jboss/weld/examples/pastecode/DownloadServlet.java	2010-02-16 15:34:37 UTC (rev 5847)
@@ -1,3 +1,24 @@
+/*
+ * 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;
 
 import java.io.*;

Modified: examples/trunk/jsf/pastecode/war/src/main/webapp/home.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/war/src/main/webapp/home.xhtml	2010-02-16 13:12:39 UTC (rev 5846)
+++ examples/trunk/jsf/pastecode/war/src/main/webapp/home.xhtml	2010-02-16 15:34:37 UTC (rev 5847)
@@ -6,6 +6,12 @@
     xmlns:s="http://jboss.com/products/seam/taglib">
   
   <ui:composition template="template.xhtml">
+   	<ui:define name="viewMetadata">
+       <f:metadata>
+       		<f:event type="preRenderView" listener="#{database.populate}"/>
+       </f:metadata>      
+    </ui:define> 
+   	
    	<ui:define name="mainarea">
    		<div style="width: 100%; padding: 7px;">
 	   		



More information about the weld-commits mailing list