openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r946850 - in /openjpa/trunk/openjpa-examples/openbooks: build.xml index.html run.xml src/main/java/jpa/tools/swing/SourceCodeViewer.java src/main/java/openbook/client/Demo.java
Date Fri, 21 May 2010 01:41:13 GMT
Author: ppoddar
Date: Fri May 21 01:41:13 2010
New Revision: 946850

URL: http://svn.apache.org/viewvc?rev=946850&view=rev
Log:
Remove Java2HTML dependency. Use FishEye directly for Source code browsing

Modified:
    openjpa/trunk/openjpa-examples/openbooks/build.xml
    openjpa/trunk/openjpa-examples/openbooks/index.html
    openjpa/trunk/openjpa-examples/openbooks/run.xml
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java

Modified: openjpa/trunk/openjpa-examples/openbooks/build.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/build.xml?rev=946850&r1=946849&r2=946850&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/build.xml (original)
+++ openjpa/trunk/openjpa-examples/openbooks/build.xml Fri May 21 01:41:13 2010
@@ -74,15 +74,6 @@
 		</fileset>
 	</path>
 	
-	<path id="java2html.classpath"
-		description="Classpath for generating HTML version of source code using Java2HTML library">
-		<pathelement location="${rsrc.dir}" />
-		<fileset dir="${java2html.lib}">
-			<include name="*.jar" />
-		</fileset>
-	</path>
-
-	
 	<fileset id="canonical.metamodel" dir="${src.dir}" 
 		description="Set of *.java files generated for static, cannonical domain model">
 		<include name="**/*_.java"/>
@@ -113,11 +104,6 @@
 		   The directory for OpenJPA libraries can not be located at ${openjpa.lib}. 
 		   Make sure openjpa.lib property value is correct in build.properties file.	
 		</fail>
-		<available file="${java2html.lib}" property="java2html.exists"/>
-		<fail unless="java2html.exists">*** Error:
-		   The directory for Java2HTML libraries can not be located at ${java2html.lib}. 
-		   Make sure java2html.lib property value is correct in build.properties file.	
-		</fail>
 		<condition property="build.mode.is.valid">
 			<or>
 				<equals arg1="${build.mode}" arg2="jse" casesensitive="false" trim="true"/>
@@ -171,8 +157,7 @@
 	             clean,
 				 generate-canonical-model,
 				 compile,
-				 enhance,
-				 generate-html-source">
+				 enhance">
 		<subant antfile="build.${build.mode}.xml" 
 			target="package" 
 			inheritrefs="true" 
@@ -180,29 +165,4 @@
 			buildpath="${basedir}"/>
 	</target>
 	
-	<target name="generate-html-source" if="java2html.exists"
-		description="Generates HTML Source Code using Java2HTML utility">
-		<delete dir="${generated.html.dir}" failonerror="false"/>
-		<mkdir dir="${generated.html.dir}"/>
-		<java classname="de.java2html.Java2Html" fork="true">
-			<classpath refid="java2html.classpath"/>
-			<arg value="-srcdir"/>
-			<arg value="${src.dir}"/>
-			<arg value="-targetdir"/>
-			<arg value="${generated.html.dir}"/>
-			<arg value="-style"/>
-			<arg value="Eclipse"/>
-		</java>
-		<java classname="de.java2html.Java2Html" fork="true">
-			<classpath refid="java2html.classpath"/>
-			<arg value="-srcdir"/>
-			<arg value="${generated.src.dir}"/>
-			<arg value="-targetdir"/>
-			<arg value="${generated.html.dir}"/>
-			<arg value="-style"/>
-			<arg value="Eclipse"/>
-		</java>
-		<replace dir="${generated.html.dir}" token="10pt" value="14pt">
-	    </replace>
-    </target>	
 </project>

Modified: openjpa/trunk/openjpa-examples/openbooks/index.html
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/index.html?rev=946850&r1=946849&r2=946850&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/index.html (original)
+++ openjpa/trunk/openjpa-examples/openbooks/index.html Fri May 21 01:41:13 2010
@@ -131,9 +131,6 @@ font-size:16px;
       <br>
       In JEE mode, OpenJPA library and JDBC drivers are configured in JEE server and hence
variables in
       this file are irrelevant.  
-      <LI>Edit <A HREF="load.properties"><code>load.properties</code></A>
to specify load parameters such as number of 
-      Books etc. OpenBooks uses this data to populate a database with some sample data.
-      This example file has some typical values. If you are satisfied with it, you can leave
them as it is.
     </OL> 
     
     
@@ -159,11 +156,9 @@ font-size:16px;
 <h2><A name="Run">Run OpenBooks</A></h2> 
     If you have built OpenBooks for JSE, then go to the <code>target/openbooks</code>
directory. 
     <br>
-    Invoke the Ant script to populate the database.<br>
-    &nbsp;&nbsp;<code>$ ant -f run.xml load</code>
-    <br>
-    Then invoke the Ant script to run OpenBooks<br>
-    &nbsp;<code>$ ant -f run.xml run</code>
+    Invoke the Ant script to run OpenBooks<br>
+    &nbsp;&nbsp;<code>$ ant -f run.xml</code>
+    
  <hr>
     If you have build OpenBooks for JEE, a Web Application Archive <code>openbooks.war</code>
will be
     created in <code>target/openbooks</code> directory. You need to deploy <code>openbooks.war</code>
@@ -172,5 +167,17 @@ font-size:16px;
     &nbsp;&nbsp;<code>http://&lt;app server host&gt;:&lt;port&gt;/openbooks/</code>
     <br>
     to access OpenBooks as an web application.
+<hr>
+    
+<h2><A name="Seed">Populate OpenBooks Database</A></h2> 
+    OpenBooks checks for existing data at first connection to the database.
+    If the database is empty, the schema is defined and populated with initial data.
+    However, you can explicitly populate the database in JSE build. 
+    Edit <A HREF="load.properties"><code>load.properties</code></A>

+    to specify load parameters such as number of Books etc. OpenBooks uses this data to populate
a database 
+    with some sample data. This example file has some typical values. If you are satisfied
with it, 
+    you can leave them as it is. Then invoke the Ant script<br>
+    &nbsp;&nbsp;<code>$ ant -f run.xml load</code>
+    
 </body>
 </html>

Modified: openjpa/trunk/openjpa-examples/openbooks/run.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/run.xml?rev=946850&r1=946849&r2=946850&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/run.xml (original)
+++ openjpa/trunk/openjpa-examples/openbooks/run.xml Fri May 21 01:41:13 2010
@@ -22,7 +22,7 @@
 <!--               Ant script for running OpenBooks                         -->
 <!--                                                                        -->
 <!-- ====================================================================== -->
-<project name="OpenBooks" default="info">
+<project name="OpenBooks" default="run">
 	<property file="run.properties"/>
 	<property name="jpa.provider" value="openjpa" />
 	<property name="load.properties" value="load.properties" />
@@ -63,13 +63,5 @@
 			<classpath refid="run.classpath" />
 		</java>
 	</target>
-
-        <target name="info" depends="check-env">
-                <echo>
-                        Runs OpenBooks demo application.
-                        See index.html for instructions.
-                </echo>
-        </target>
-
 </project>	
 

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java?rev=946850&r1=946849&r2=946850&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
(original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
Fri May 21 01:41:13 2010
@@ -15,32 +15,25 @@ package jpa.tools.swing;
 
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
+import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
 
 import javax.swing.Box;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JComboBox;
 import javax.swing.JEditorPane;
-import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
-import javax.swing.text.html.HTMLDocument;
-import javax.swing.text.html.HTMLEditorKit;
 
 
 /**
  * A viewer for source code.
- * The input to this viewer is a set of *.html file names which may or may not have anchors.
+ * The input to this viewer is a root URL and set of anchors.
+ * The viewer shows the anchors in a combo-box and displays the
+ * corresponding HTML in the main editor. 
  * 
  * @author Pinaki Poddar
  *
@@ -49,32 +42,28 @@ import javax.swing.text.html.HTMLEditorK
 public class SourceCodeViewer extends JPanel implements ActionListener {
     private final JEditorPane _editor;
     private final JComboBox   _bookmarks;
-    private Map<String, File> _files = new TreeMap<String, File>();
+    private Map<String, String> _anchors;
+    private String _root;
     
-    public SourceCodeViewer(String dir) {
+    /**
+     * Create a Source Code Viewer for a set of anchors.
+     * @param root the root url 
+     * @param anchors the key is a visible text and value is the URL
+     * relative to the root.
+     */
+    public SourceCodeViewer(String root, Map<String,String> anchors) {
         super(true);
         setLayout(new BorderLayout());
         
-        
+        _anchors = anchors;
+        _root = root;
         _editor = new JEditorPane();
-        _editor.setEditorKit(new HTMLEditorKit());
+        _editor.setContentType("text/html");
+        _editor.setFont(new Font("Courier New", Font.PLAIN, 16));
         _editor.setEditable(false);
         
-        File root = getFile(dir);
-        if (root != null) {
-            List<File> files = new FileScanner("html", true).scan(root);
-            for (File f : files) {
-                String fileName = f.getAbsolutePath();
-                String key = fileName.substring(
-                        root.getAbsolutePath().length()+1, 
-                        fileName.length()- "html".length()-1)
-                        .replace(File.separatorChar,'.');
-                _files.put(key, f);
-            }
-        }
-        
         DefaultComboBoxModel model = new DefaultComboBoxModel();
-        for (String key : _files.keySet()) {
+        for (String key : anchors.keySet()) {
             model.addElement(key);
         }
         _bookmarks = new JComboBox(model);
@@ -86,73 +75,26 @@ public class SourceCodeViewer extends JP
         add(new JScrollPane(_editor), BorderLayout.CENTER);
         JPanel topPanel = new JPanel();
         ((FlowLayout)topPanel.getLayout()).setAlignment(FlowLayout.LEADING);
-        topPanel.add(new JLabel("Select File "));
+        topPanel.add(new JLabel("Go to "));
         topPanel.add(_bookmarks);
         topPanel.add(Box.createHorizontalGlue());
         add(topPanel, BorderLayout.NORTH);
+        
+        if (_anchors != null && !_anchors.isEmpty())
+           showPage(_anchors.keySet().iterator().next());
     }
-    
-    
    
     public void actionPerformed(ActionEvent e) {
-        String name = (String)_bookmarks.getSelectedItem();
+        String anchor = (String)_bookmarks.getSelectedItem();
+        showPage(anchor);
+    }
+    
+    private void showPage(String anchor) {
         try {
-            HTMLDocument doc = new HTMLDocument();
-            _editor.read(new FileInputStream(_files.get(name)), doc);
+            _editor.setPage(_root + _anchors.get(anchor));
         } catch (Exception ex) {
             ex.printStackTrace();
         }
+        
     }
-    
-    /**
-     * Check the given string for a matching file. The string is first
-     * tested to see if it is an existing file path. If it does not
-     * represent an existing file, it is checked as a resource name of a
-     * file. 
-     * @param name the file path or resource name
-     */
-    private File getFile(String name) {
-        if (name == null)
-            return null;
-
-        File file = new File(name);
-        if (file.exists())
-            return file;
-
-        URL url = Thread.currentThread().getContextClassLoader().getResource(name); 
-        if (url == null) {
-            url = getClass().getClassLoader().getResource(name);
-        }
-        if (url != null) {
-            String urlFile = url.getFile();
-            if (urlFile != null) {
-                File rsrc = new File(URLDecoder.decode(urlFile));
-                if (rsrc.exists())
-                    return rsrc;
-            }
-        }
-
-        return null;
-    }
-
-    
-    InputStream getResource(String resource) {
-        InputStream stream = getClass().getResourceAsStream(resource);
-        if (stream == null) {
-            stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
-        }
-        return stream;
-    }
-    
-    public static void main(String[] args) throws Exception {
-        SourceCodeViewer viewer = new SourceCodeViewer(args.length == 0 ? "source" : args[0]);
-        JFrame frame = new JFrame("Source Code Viewer");
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        frame.getContentPane().add(viewer);
-        frame.pack();
-        frame.setVisible(true);
-    }
-    
-    
-
 }

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java?rev=946850&r1=946849&r2=946850&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java Fri May
21 01:41:13 2010
@@ -21,11 +21,14 @@ import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
+import java.io.IOException;
 import java.io.PrintStream;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.concurrent.TimeUnit;
 
 import javax.swing.AbstractAction;
@@ -35,6 +38,7 @@ import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JDialog;
+import javax.swing.JEditorPane;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JScrollPane;
@@ -47,6 +51,7 @@ import javax.swing.SwingUtilities;
 import javax.swing.SwingWorker;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
+import javax.swing.text.html.HTMLEditorKit;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeCellRenderer;
 
@@ -61,7 +66,12 @@ import jpa.tools.swing.ScrollingTextPane
 import jpa.tools.swing.SourceCodeViewer;
 import jpa.tools.swing.StatusBar;
 import jpa.tools.swing.SwingHelper;
+import openbook.domain.Author;
+import openbook.domain.Book;
 import openbook.domain.Customer;
+import openbook.domain.Inventory;
+import openbook.domain.LineItem;
+import openbook.domain.PurchaseOrder;
 import openbook.server.OpenBookService;
 import openbook.server.ServiceFactory;
 import openbook.util.PropertyHelper;
@@ -414,7 +424,9 @@ public class Demo extends JFrame impleme
     }
     
     public class ViewSourceAction extends OpenBookAction {
-        SourceCodeViewer _sourceViewer;
+        private SourceCodeViewer _sourceViewer;
+        private static final String SRC_ROOT = "http://fisheye6.atlassian.com/browse/~raw,r=HEAD/openjpa/"
+
+                                               "trunk/openjpa-examples/openbooks/src/main/java/";
         
         public ViewSourceAction(String name, String iconLocation, String tooltip) {
             super(name, iconLocation, tooltip);
@@ -422,11 +434,34 @@ public class Demo extends JFrame impleme
         
         public void actionPerformed(ActionEvent e) {
             if (_sourceViewer == null) {
-                _sourceViewer = new SourceCodeViewer("source");
+                String root = PropertyHelper.getString(_config, "openbook.source.url",  SRC_ROOT);
+                _sourceViewer = new SourceCodeViewer(root, getAnchors());
             }
             showTab(_tabbedPane, "Source Code", _sourceViewer);
         }
         
+        Map<String, String> getAnchors() {
+            Map<String,String> anchors = new TreeMap<String, String>();
+            anchors.put("domain.Book",      toJavaFilePath(Book.class));
+            anchors.put("domain.Author",    toJavaFilePath(Author.class));
+            anchors.put("domain.Customer",  toJavaFilePath(Customer.class));
+            anchors.put("domain.Inventory", toJavaFilePath(Inventory.class));
+            anchors.put("domain.PurchaseOrder", toJavaFilePath(PurchaseOrder.class));
+            anchors.put("domain.LineItem", toJavaFilePath(LineItem.class));
+            
+            anchors.put("OpenBooks Service", toJavaFilePath(OpenBookService.class));
+            anchors.put("Generic Persistence Service", "openbook/server/PersistenceService.java");
+            anchors.put("OpenBooks Service Implementation", "openbook/server/OpenBookServiceImpl.java");
+            
+            anchors.put("clinet.Buy Book", toJavaFilePath(BuyBookPage.class));
+            
+            return anchors;
+        }
+        
+        private String toJavaFilePath(Class<?> cls) {
+            return cls.getName().replace('.', '/') + ".java";
+        }
+        
     }
     
     /**



Mime
View raw message