From e835d87c06ad2db944a77ba63b719c5b23f59bd8 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Fri, 21 May 2010 01:41:13 +0000 Subject: [PATCH] Remove Java2HTML dependency. Use FishEye directly for Source code browsing git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@946850 13f79535-47bb-0310-9956-ffa450edef68 --- openjpa-examples/openbooks/build.xml | 42 +------ openjpa-examples/openbooks/index.html | 23 ++-- openjpa-examples/openbooks/run.xml | 10 +- .../jpa/tools/swing/SourceCodeViewer.java | 116 +++++------------- .../src/main/java/openbook/client/Demo.java | 39 +++++- 5 files changed, 83 insertions(+), 147 deletions(-) diff --git a/openjpa-examples/openbooks/build.xml b/openjpa-examples/openbooks/build.xml index 1250c1ef6..323d85890 100644 --- a/openjpa-examples/openbooks/build.xml +++ b/openjpa-examples/openbooks/build.xml @@ -74,15 +74,6 @@ - - - - - - - - @@ -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. - - *** 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. - @@ -171,8 +157,7 @@ clean, generate-canonical-model, compile, - enhance, - generate-html-source"> + enhance"> - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openjpa-examples/openbooks/index.html b/openjpa-examples/openbooks/index.html index 762d0e3a5..e8006f4c4 100644 --- a/openjpa-examples/openbooks/index.html +++ b/openjpa-examples/openbooks/index.html @@ -131,9 +131,6 @@ font-size:16px;
In JEE mode, OpenJPA library and JDBC drivers are configured in JEE server and hence variables in this file are irrelevant. -
  • Edit load.properties 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. @@ -159,11 +156,9 @@ font-size:16px;

    Run OpenBooks

    If you have built OpenBooks for JSE, then go to the target/openbooks directory.
    - Invoke the Ant script to populate the database.
    -   $ ant -f run.xml load -
    - Then invoke the Ant script to run OpenBooks
    -  $ ant -f run.xml run + Invoke the Ant script to run OpenBooks
    +   $ ant -f run.xml +
    If you have build OpenBooks for JEE, a Web Application Archive openbooks.war will be created in target/openbooks directory. You need to deploy openbooks.war @@ -172,5 +167,17 @@ font-size:16px;   http://<app server host>:<port>/openbooks/
    to access OpenBooks as an web application. +
    + +

    Populate OpenBooks Database

    + 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 load.properties + 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
    +   $ ant -f run.xml load + diff --git a/openjpa-examples/openbooks/run.xml b/openjpa-examples/openbooks/run.xml index 1bfb25309..6a25f9061 100644 --- a/openjpa-examples/openbooks/run.xml +++ b/openjpa-examples/openbooks/run.xml @@ -22,7 +22,7 @@ - + @@ -63,13 +63,5 @@ - - - - Runs OpenBooks demo application. - See index.html for instructions. - - - diff --git a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java index 168ad9823..39b28bac6 100644 --- a/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java +++ b/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java @@ -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.HTMLEditorKit; public class SourceCodeViewer extends JPanel implements ActionListener { private final JEditorPane _editor; private final JComboBox _bookmarks; - private Map _files = new TreeMap(); + private Map _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 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 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 JPanel implements ActionListener { 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); - } - - - } diff --git a/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java b/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java index 1e27159fb..e29e5f54b 100644 --- a/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java +++ b/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java @@ -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 implements Thread.UncaughtExceptionHandler { } 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 implements Thread.UncaughtExceptionHandler { 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 getAnchors() { + Map anchors = new TreeMap(); + 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"; + } + } /**