Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
B2B XML Application: Step by Step , 27 of 32
To prevent over complicating the listing of examples in the section, "Running the B2B XML Application: Detailed Procedure", the XSL examples are listed separately.
<?xml version="1.0"?> <!-- | $Author: olediour@us $ | $Date: 04-May-2000 | xsl for html | $Revision: 1.1 $ +--> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output media-type="text/html" method="html" encoding="ISO-8859-1"/> <xsl:template match="/"> <html> <head> <title>Retail Application</title> </head> <body> <xsl:if test="//pageTitle"> <h2><xsl:value-of select="//pageTitle"/></h2> </xsl:if> <xsl:choose> <xsl:when test="loginResult"> <xsl:apply-templates select="loginResult"/> </xsl:when> <xsl:when test="index"> <xsl:apply-templates select="index"/> </xsl:when> <xsl:when test="inventory"> <xsl:apply-templates select="inventory"/> </xsl:when> <xsl:when test="order"> <xsl:apply-templates select="order"/> </xsl:when> <xsl:when test="placeOrder"> <xsl:apply-templates select="placeOrder"/> </xsl:when> <xsl:otherwise> <p align="center"> <h3>This kind of XML Document cannot be processed...</h3> </p> </xsl:otherwise> </xsl:choose> </body> </html> </xsl:template> <xsl:template match="loginResult"> <xsl:if test="ROWSET/ROW/unknown"> <table width="98%"> <tr> <td bgcolor="yellow" align="center"> <xsl:value-of select="ROWSET/ROW/unknown"/> is not allowed to log in !</td> </tr> </table> </xsl:if> <xsl:if test="ROWSET/ROW/NAME"> <p align="center"> <h2>Welcome <xsl:value-of select="ROWSET/ROW/NAME"/> !</h2> </p> <p align="center"> <a> <xsl:attribute name="href"> <xsl:value-of select="nextStep"/>?custId=<xsl:value-of select="ROWSET/ROW/ID"/> </xsl:attribute> Please enter the Mall ! </a> </p> </xsl:if> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="index"> <xsl:for-each select="form"> <center> <form> <xsl:attribute name="action"><xsl:value-of select="./@action"/></xsl:attribute> <xsl:attribute name="method"><xsl:value-of select="./@method"/></xsl:attribute> <xsl:if test="./field"> <table width="98%" border="1"> <xsl:for-each select="./field"> <tr> <td align="right"><xsl:value-of select="./@prompt"/></td> <td> <input> <xsl:choose> <xsl:when test="./@type = 'text'"> <xsl:attribute name="type">text</xsl:attribute> </xsl:when> </xsl:choose> <xsl:attribute name="name"> <xsl:value-of select="./@name"/></xsl:attribute> </input> </td> </tr> </xsl:for-each> </table> </xsl:if> <xsl:if test="./button"> <p> <xsl:for-each select="./button"> <input> <xsl:choose> <xsl:when test="./@type = 'submit'"> <xsl:attribute name="type">submit</xsl:attribute> </xsl:when> </xsl:choose> <xsl:attribute name="value"> <xsl:value-of select="./@label"/> </xsl:attribute> </input> </xsl:for-each> </p> </xsl:if> </form> </center> </xsl:for-each> </xsl:template> <xsl:template match="inventory"> <h2>This is the Mart content</h2> <table> <tr> <th>Prod #</th> <th>Product</th> <th>Price</th> <th>Supplied by</th> </tr> <xsl:for-each select="form/theMart/ROWSET/ROW"> <tr> <td><xsl:value-of select="ID"/></td> <td> <a> <xsl:attribute name="href"> <xsl:value-of select="../../../../form/@action"/>?custId=<xsl:value-of select="../../../../form/hiddenFields/custId"/>&prodId=<xsl:value-of select="ID"/> </xsl:attribute> <xsl:value-of select="DESCRIPTION"/> </a> </td> <td><xsl:value-of select="PRICE"/></td> <td><xsl:value-of select="NAME"/></td> </tr> </xsl:for-each> </table> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="order"> <center> <h2>Thank you <xsl:value-of select="CUST/NAME"/> for shopping with us !</h2> <hr/> <h2>Please enter the quantity</h2> <form action="placeOrder.xsql" method="post"> <input type="hidden" name="prodId"> <xsl:attribute name="value"> <xsl:value-of select="PROD/ID"/> </xsl:attribute> </input> <input type="hidden" name="custId"> <xsl:attribute name="value"> <xsl:value-of select="CUST/ID"/></xsl:attribute> </input> <table border="1"> <tr> <td colspan="2"><xsl:value-of select="PROD/DESCRIPTION"/> at $<xsl:value-of select="PROD/PRICE"/> each supplied by <xsl:value-of select="PROD/NAME"/></td> </tr> <tr> <td align="right">Quantity</td> <td><input type="text" name="qty"/></td> </tr> </table> <p><input type="submit" value="Place Order"/></p> </form> </center> <p> <a><xsl:attribute name="href"> <xsl:value-of select="returnHome"/> </xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="placeOrder"> <xsl:if test="operationResult"> <table width="98%"> <tr><td align="center"> <font color="navy"> <xsl:value-of select="operationResult/text()"/> </font></td></tr> <tr> <td align="center"> <xsl:for-each select="operationResult/nextStep"> <form method="post"> <xsl:attribute name="action"><xsl:value-of select="./@Action"/></xsl:attribute> <xsl:if test="prmList"> <xsl:for-each select="prmList/prm"> <input type="hidden"> <xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute> <xsl:attribute name="value"><xsl:value-of select="./@value"/></xsl:attribute> </input> </xsl:for-each> </xsl:if> <input type="submit"> <xsl:attribute name="value"><xsl:value-of select="./@Label"/></xsl:attribute> </input> </form> </xsl:for-each> </td> </tr> </table> </xsl:if> <xsl:if test="xsql-error"> <table width="98%"> <tr><td><xsl:value-of select="xsql-error/@action"/></td></tr> <tr><td><xsl:value-of select="xsql-error/statement"/></td></tr> <tr><td><xsl:value-of select="xsql-error/message"/></td></tr> </table> </xsl:if> <xsl:if test="operationProblem"> <table width="98%"> <tr> <td colspan="2" align="center"> <font color="red"><b><xsl:value-of select="operationProblem/text()"/></b></font> </td> </tr> <xsl:for-each select="operationProblem/parameters/*"> <tr> <td align="right"><xsl:value-of select="name()"/></td> <td align="left"><xsl:value-of select="."/></td> </tr> </xsl:for-each> </table> </xsl:if> <xsl:if test="bottomLinks"> <xsl:choose> <xsl:when test="operationResult"> </xsl:when> <xsl:otherwise> <p align="center"> <xsl:for-each select="bottomLinks/aLink"> [<a><xsl:attribute name="href"><xsl:value-of select="./@href"/></xsl:attribute><xsl:value-of select="."/></a>] </xsl:for-each> </p> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:choose> <xsl:when test="operationResult/nextStep"> </xsl:when> <xsl:otherwise> <xsl:if test="returnHome"> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
<?xml version="1.0"?> <!-- | $Author: olediour@us $ | $Date: 04-May-2000 | xsl for html (Palm Pilot, HandWeb browser) | $Revision: 1.1 $ +--> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output media-type="text/html" method="html" encoding="ISO-8859-1"/> <xsl:template match="/"> <html> <head> <title>Retail Application</title> </head> <body> <xsl:if test="//pageTitle"> <h2><xsl:value-of select="//pageTitle"/></h2> </xsl:if> <xsl:choose> <xsl:when test="loginResult"> <xsl:apply-templates select="loginResult"/> </xsl:when> <xsl:when test="index"> <xsl:apply-templates select="index"/> </xsl:when> <xsl:when test="inventory"> <xsl:apply-templates select="inventory"/> </xsl:when> <xsl:when test="order"> <xsl:apply-templates select="order"/> </xsl:when> <xsl:when test="placeOrder"> <xsl:apply-templates select="placeOrder"/> </xsl:when> <xsl:otherwise> <p align="center"> <h3>This kind of XML Document cannot be processed...</h3> </p> </xsl:otherwise> </xsl:choose> </body> </html> </xsl:template> <xsl:template match="loginResult"> <xsl:if test="ROWSET/ROW/unknown"> <table width="98%"> <tr><td bgcolor="yellow" align="center"><xsl:value-of select="ROWSET/ROW/unknown"/> is not allowed to log in !</td></tr> </table> </xsl:if> <xsl:if test="ROWSET/ROW/NAME"> <p align="center"> <h2>Welcome <xsl:value-of select="ROWSET/ROW/NAME"/> !</h2> </p> <p align="center"> <a> <xsl:attribute name="href"><xsl:value-of select="nextStep"/>?custId=<xsl:value-of select="ROWSET/ROW/ID"/></xsl:attribute> Please enter the Mall ! </a> </p> </xsl:if> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="index"> <xsl:for-each select="form"> <center> <form> <xsl:attribute name="action"><xsl:value-of select="./@action"/></xsl:attribute> <xsl:attribute name="method"><xsl:value-of select="./@method"/></xsl:attribute> <xsl:if test="./field"> <table width="98%" border="1"> <xsl:for-each select="./field"> <tr> <td align="right"><xsl:value-of select="./@prompt"/></td> <td> <input> <xsl:choose> <xsl:when test="./@type = 'text'"> <xsl:attribute name="type">text</xsl:attribute> </xsl:when> </xsl:choose> <xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute> </input> </td> </tr> </xsl:for-each> </table> </xsl:if> <xsl:if test="./button"> <p> <xsl:for-each select="./button"> <input> <xsl:choose> <xsl:when test="./@type = 'submit'"> <xsl:attribute name="type">submit</xsl:attribute> </xsl:when> </xsl:choose> <xsl:attribute name="value"><xsl:value-of select="./@label"/></xsl:attribute> </input> </xsl:for-each> </p> </xsl:if> </form> </center> </xsl:for-each> </xsl:template> <xsl:template match="inventory"> <h2>This is the Mart content</h2> <xsl:for-each select="form/theMart/ROWSET/ROW"> <xsl:value-of select="ID"/> <xsl:text> </xsl:text> <form method="post"> <xsl:attribute name="action"> <xsl:value-of select="../../../../form/@action"/> </xsl:attribute> <input type="hidden" name="custId"> <xsl:attribute name="value"><xsl:value-of select="../../../../form/hiddenFields/custId"/></xsl:attribute> </input> <input type="hidden" name="prodId"> <xsl:attribute name="value"><xsl:value-of select="ID"/></xsl:attribute> </input> <input type="submit"> <xsl:attribute name="value"><xsl:value-of select="DESCRIPTION"/></xsl:attribute> </input> </form> <xsl:text> @ $</xsl:text><xsl:value-of select="PRICE"/><xsl:text> each</xsl:text> <xsl:text> Supplied by </xsl:text><xsl:value-of select="NAME"/> <br/> </xsl:for-each> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="order"> <center> <h2>Thank you <xsl:value-of select="CUST/NAME"/> for shopping with us !</h2> <hr/> <h2>Please enter the quantity</h2> <form action="placeOrder.xsql" method="post"> <input type="hidden" name="prodId"> <xsl:attribute name="value"><xsl:value-of select="PROD/ID"/></xsl:attribute> </input> <input type="hidden" name="custId"> <xsl:attribute name="value"><xsl:value-of select="CUST/ID"/></xsl:attribute> </input> <p> <xsl:value-of select="PROD/DESCRIPTION"/> at $<xsl:value-of select="PROD/PRICE"/> each supplied by <xsl:value-of select="PROD/NAME"/> <br/> Quantity : <br/> <input type="text" name="qty"/> </p> <p><input type="submit" value="Place Order"/></p> </form> </center> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:template> <xsl:template match="placeOrder"> <xsl:if test="operationResult"> <center> <xsl:value-of select="operationResult/text()"/> <br/> <xsl:for-each select="operationResult/nextStep"> <form method="post"> <xsl:attribute name="action"><xsl:value-of select="./@Action"/></xsl:attribute> <xsl:if test="prmList"> <xsl:for-each select="prmList/prm"> <input type="hidden"> <xsl:attribute name="name"><xsl:value-of select="./@name"/></xsl:attribute> <xsl:attribute name="value"><xsl:value-of select="./@value"/></xsl:attribute> </input> </xsl:for-each> </xsl:if> <input type="submit"> <xsl:attribute name="value"><xsl:value-of select="./@Label"/></xsl:attribute> </input> </form> </xsl:for-each> </center> </xsl:if> <xsl:if test="operationProblem"> <table width="98%"> <tr><td align="center"><font color="red"><xsl:value-of select="operationProblem"/></font></td></tr> </table> </xsl:if> <xsl:if test="bottomLinks"> <xsl:choose> <xsl:when test="operationResult"> </xsl:when> <xsl:otherwise> <p align="center"> <xsl:for-each select="bottomLinks/aLink"> [<a><xsl:attribute name="href"><xsl:value-of select="./@href"/></xsl:attribute><xsl:value-of select="."/></a>] </xsl:for-each> </p> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:choose> <xsl:when test="operationResult/nextStep"> </xsl:when> <xsl:otherwise> <xsl:if test="returnHome"> <p> <a><xsl:attribute name="href"><xsl:value-of select="returnHome"/></xsl:attribute>Back to Login</a> </p> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
This script creates and manages the GUI and stylesheets used in the B2B XML application.
package B2BDemo.StyleSheetUtil; /** * @author Olivier LE DIOURIS - Partner Technical Services - Oracle Copr. */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; // needed for new CLOB and BLOB classes import oracle.sql.*; import oracle.jdbc.driver.*; import java.beans.*; import javax.swing.event.*; import B2BDemo.*; import B2BDemo.XMLUtil.*; public class GUInterface extends JFrame { private boolean lite = false; // Use O8iLite private boolean inserting = false; private final static int UPDATE = 1; private final static int INSERT = 2; private final static int ENTER_QUERY = 1; private final static int EXEC_QUERY = 2; int queryState = ENTER_QUERY; String sqlStmt = "Select APPFROM, " + " APPTO, " + " OP, " + " XSL " + "From styleSheets"; private static String connURL = AppCste.AQDBUrl; private static String userName = AppCste.AQuser; private static String password = AppCste.AQpswd; private Connection conn = null; private Vector recVect = null; int currRec = 0; XslRecord thisRecord = null; BorderLayout borderLayout1 = new BorderLayout(); JPanel jPanel1 = new JPanel(); JMenuBar menuBar1 = new JMenuBar(); JMenu menuFile = new JMenu(); JMenuItem menuFileExit = new JMenuItem(); JMenu menuHelp = new JMenu(); JMenuItem menuHelpAbout = new JMenuItem(); JLabel statusBar = new JLabel(); JToolBar toolBar = new JToolBar(); JButton buttonOpen = new JButton(); JButton buttonClose = new JButton(); JButton buttonHelp = new JButton(); ImageIcon imageOpen; ImageIcon imageClose; ImageIcon imageHelp; JPanel jPanel2 = new JPanel(); BorderLayout borderLayout2 = new BorderLayout(); JButton firstButton = new JButton(); JPanel jPanel3 = new JPanel(); JPanel jPanel4 = new JPanel(); BorderLayout borderLayout3 = new BorderLayout(); BorderLayout borderLayout4 = new BorderLayout(); JPanel jPanel5 = new JPanel(); JTextField fromAppValue = new JTextField(); JLabel fromApp = new JLabel(); JPanel jPanel6 = new JPanel(); BorderLayout borderLayout5 = new BorderLayout(); JLabel jLabel2 = new JLabel(); JScrollPane jScrollPane1 = new JScrollPane(); JTextArea XSLStyleSheet = new JTextArea(); JButton previousButton = new JButton(); JButton nextButton = new JButton(); JButton lastButton = new JButton(); JButton validateButton = new JButton(); GridLayout gridLayout1 = new GridLayout(); JLabel toApp = new JLabel(); JTextField toAppValue = new JTextField(); JLabel operationLabel = new JLabel(); JTextField opValue = new JTextField(); JButton newButton = new JButton(); JButton deleteButton = new JButton(); JButton queryButton = new JButton(); public GUInterface() { super(); try { jbInit(); buttonOpen.setIcon(imageOpen); buttonClose.setIcon(imageClose); buttonHelp.setIcon(imageHelp); } catch (Exception e) { e.printStackTrace(); } } private void getConnected() throws Exception { try { if (lite) { Class.forName("oracle.lite.poljdbc.POLJDBCDriver"); conn = DriverManager.getConnection("jdbc:Polite:POLite", "system", "manager"); } else { Class.forName ("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection (connURL, userName, password); } } catch (Exception e) { System.err.println("Get connected failed : " + e); throw e; } } private void jbInit() throws Exception { if (conn == null) { try { getConnected(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString(), "Connection", JOptionPane.ERROR_MESSAGE); System.exit(1); } } imageOpen = new ImageIcon(GUInterface.class.getResource("openfile.gif")); imageClose = new ImageIcon(GUInterface.class.getResource("closefile.gif")); imageHelp = new ImageIcon(GUInterface.class.getResource("help.gif")); this.setTitle("Style Sheets Management"); this.getContentPane().setLayout(borderLayout1); this.setSize(new Dimension(511, 526)); jPanel1.setLayout(borderLayout2); menuFile.setText("File"); menuFileExit.setText("Exit"); menuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fileExit_ActionPerformed(e); } }); menuHelp.setText("Help"); menuHelpAbout.setText("About"); menuHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { helpAbout_ActionPerformed(e); } }); statusBar.setText("Initializing..."); buttonOpen.setToolTipText("Open File"); buttonClose.setToolTipText("Validate modifications"); buttonHelp.setToolTipText("About Style Sheet Manager"); firstButton.setText("<<"); jPanel5.setLayout(gridLayout1); fromApp.setText("From Application :"); fromApp.setHorizontalAlignment(SwingConstants.RIGHT); jLabel2.setText("XSL Style Sheet"); previousButton.setText("<"); nextButton.setText(">"); lastButton.setText(">>"); validateButton.setText("Validate"); gridLayout1.setRows(4); toApp.setText("To Application : "); toApp.setHorizontalAlignment(SwingConstants.RIGHT); operationLabel.setText("Operation : "); operationLabel.setHorizontalAlignment(SwingConstants.RIGHT); jPanel6.setLayout(borderLayout5); jPanel4.setLayout(borderLayout4); jPanel3.setLayout(borderLayout3); menuFile.add(menuFileExit); menuBar1.add(menuFile); menuHelp.add(menuHelpAbout); menuBar1.add(menuHelp); this.setJMenuBar(menuBar1); this.getContentPane().add(statusBar, BorderLayout.SOUTH); toolBar.add(buttonOpen); toolBar.add(buttonClose); toolBar.add(buttonHelp); this.getContentPane().add(toolBar, BorderLayout.NORTH); this.getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.add(jPanel2, BorderLayout.SOUTH); jPanel2.add(queryButton, null); jPanel2.add(newButton, null); jPanel2.add(firstButton, null); jPanel2.add(previousButton, null); jPanel2.add(nextButton, null); jPanel2.add(lastButton, null); jPanel2.add(validateButton, null); jPanel2.add(deleteButton, null); jPanel1.add(jPanel3, BorderLayout.CENTER); jPanel3.add(jPanel4, BorderLayout.NORTH); jPanel3.add(jPanel5, BorderLayout.SOUTH); jPanel5.add(fromApp, null); jPanel5.add(fromAppValue, null); jPanel5.add(toApp, null); jPanel5.add(toAppValue, null); jPanel5.add(operationLabel, null); jPanel5.add(opValue, null); jPanel3.add(jPanel6, BorderLayout.CENTER); jPanel6.add(jLabel2, BorderLayout.NORTH); jPanel6.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(XSLStyleSheet, null); // statusBar.setText("Connected..."); // Building Vector of record. queryButton.setText("Enter Query"); queryButton.setActionCommand("query"); queryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { queryButton_actionPerformed(e); } }); buttonClose.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonClose_actionPerformed(e); } }); deleteButton.setText("Delete"); deleteButton.setToolTipText("Delete the current record"); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { deleteButton_actionPerformed(e); } }); newButton.setText("New"); newButton.setToolTipText("Create a new record"); newButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { newButton_actionPerformed(e); } }); validateButton.setToolTipText("Validate your modifications"); opValue.setEditable(false); toAppValue.setEditable(false); fromAppValue.setEditable(false); validateButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { validateButton_actionPerformed(e); } }); lastButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { lastButton_actionPerformed(e); } }); firstButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { firstButton_actionPerformed(e); } }); previousButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { previousButton_actionPerformed(e); } }); nextButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { nextButton_actionPerformed(e); } }); lastButton.setActionCommand("last"); lastButton.setToolTipText("Last record"); nextButton.setActionCommand("next"); nextButton.setToolTipText("Next record"); previousButton.setActionCommand("previous"); previousButton.setToolTipText("Previous record"); firstButton.setActionCommand("first"); firstButton.setToolTipText("First record"); // Execute query and build vector executeQuery(sqlStmt); updateStatusBar(); } void executeQuery(String theSqlStmt) { recVect = new Vector(); try { Statement stmt = conn.createStatement(); ResultSet rSet = stmt.executeQuery(theSqlStmt); CLOB clob = null; while (rSet.next()) { clob = ((OracleResultSet)rSet).getCLOB(4); String strLob = dumpClob(conn, clob); XslRecord xslRecord = new XslRecord(rSet.getString(1), rSet.getString(2), rSet.getString(3), strLob); recVect.addElement(xslRecord); } rSet.close(); stmt.close(); // Populate form with first record firstButton.setEnabled(false); previousButton.setEnabled(false); nextButton.setEnabled(false); lastButton.setEnabled(false); if (recVect.size() > 0) { currRec = 1; displayRecord(currRec); } if (recVect.size() > 1) { nextButton.setEnabled(true); lastButton.setEnabled(true); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString(), "Executing request", JOptionPane.ERROR_MESSAGE); System.exit(1); } } void displayRecord(int rnk) { XslRecord xslRecord = (XslRecord)recVect.elementAt(rnk-1); thisRecord = new XslRecord(xslRecord.FROM, xslRecord.TO, xslRecord.TASK, xslRecord.XSL); XSLStyleSheet.setText(xslRecord.XSL); fromAppValue.setText(xslRecord.FROM); toAppValue.setText(xslRecord.TO); opValue.setText(xslRecord.TASK); XSLStyleSheet.requestFocus(); XSLStyleSheet.setCaretPosition(0); // Buttons firstButton.setEnabled(false); previousButton.setEnabled(false); nextButton.setEnabled(false); lastButton.setEnabled(false); if (rnk > 1) { firstButton.setEnabled(true); previousButton.setEnabled(true); } if (rnk < recVect.size()) { nextButton.setEnabled(true); lastButton.setEnabled(true); } } void updateStatusBar() { statusBar.setText("Ready for " + recVect.size() + " records"); } private static String dumpClob(Connection conn, CLOB clob) throws Exception { String returnString = ""; OracleCallableStatement cStmt1 = (OracleCallableStatement) conn.prepareCall ("begin ? := dbms_lob.getLength (?); end;"); OracleCallableStatement cStmt2 = (OracleCallableStatement) conn.prepareCall ("begin dbms_lob.read (?, ?, ?, ?); end;"); cStmt1.registerOutParameter (1, Types.NUMERIC); cStmt1.setCLOB (2, clob); cStmt1.execute (); long length = cStmt1.getLong (1); long i = 0; int chunk = 80; while (i < length) { cStmt2.setCLOB (1, clob); cStmt2.setLong (2, chunk); cStmt2.registerOutParameter (2, Types.NUMERIC); cStmt2.setLong (3, i + 1); cStmt2.registerOutParameter (4, Types.VARCHAR); cStmt2.execute (); long read_this_time = cStmt2.getLong (2); returnString += cStmt2.getString (4); // System.out.print ("Read " + read_this_time + " chars: "); // System.out.println (string_this_time); i += read_this_time; } cStmt1.close (); cStmt2.close (); return returnString; } static void fillClob (Connection conn, CLOB clob, String str) throws SQLException { OracleCallableStatement cStmt = (OracleCallableStatement) conn.prepareCall ("begin dbms_lob.write (?, ?, ?, ?); end;"); int i = 0; int chunk = 80; int length = str.length(); long c, ii; System.out.println("Length: " + length + "\n" + str); while (i < length) { cStmt.setClob (1, clob); c = chunk; cStmt.setLong (2, c); ii = i + 1; cStmt.setLong (3, ii); cStmt.setString (4, str.substring(i, i + chunk)); cStmt.execute (); i += chunk; if (length - i < chunk) chunk = length - i; } cStmt.close (); } void fileExit_ActionPerformed(ActionEvent e) { if (conn != null) { try { conn.close(); } catch (Exception ex) {} } System.exit(0); } void helpAbout_ActionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(this, new GUInterface_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE); } void nextButton_actionPerformed(ActionEvent e) { checkRecordChange(); currRec++; displayRecord(currRec); } void previousButton_actionPerformed(ActionEvent e) { checkRecordChange(); currRec--; displayRecord(currRec); } void firstButton_actionPerformed(ActionEvent e) { checkRecordChange(); currRec = 1; displayRecord(currRec); } void lastButton_actionPerformed(ActionEvent e) { checkRecordChange(); currRec = recVect.size(); displayRecord(currRec); } void validateButton_actionPerformed(ActionEvent e) { validateRec(); } void validateRec() { thisRecord = new XslRecord(fromAppValue.getText(), toAppValue.getText(), opValue.getText(), XSLStyleSheet.getText()); if (saveChanges(thisRecord, (inserting?INSERT:UPDATE))) JOptionPane.showMessageDialog(null, "All right!"); } void deleteRec() { thisRecord = new XslRecord(fromAppValue.getText(), toAppValue.getText(), opValue.getText(), XSLStyleSheet.getText()); String sqlStmt = "delete styleSheets where fromApp = ? and " + " toApp = ? and " + " op = ?"; try { PreparedStatement pStmt = conn.prepareStatement(sqlStmt); pStmt.setString(1, thisRecord.FROM); pStmt.setString(2, thisRecord.TO); pStmt.setString(3, thisRecord.TASK); pStmt.execute(); conn.commit(); System.out.println("Deleted !"); pStmt.close(); // Delete from vector... recVect.removeElementAt(currRec - 1); updateStatusBar(); if (currRec >= recVect.size()) currRec--; displayRecord(currRec); JOptionPane.showMessageDialog(null, "All right!"); } catch (SQLException sqlE) { JOptionPane.showMessageDialog(null, sqlE.toString(), "Deleting record", JOptionPane.ERROR_MESSAGE); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString(), "Deleting record", JOptionPane.ERROR_MESSAGE); } } void checkRecordChange() { thisRecord = new XslRecord(fromAppValue.getText(), toAppValue.getText(), opValue.getText(), XSLStyleSheet.getText()); if (!thisRecord.equals((XslRecord)recVect.elementAt(currRec-1))) { int result = JOptionPane.showConfirmDialog(null, "Record has changed\nDo you want to save the modifications ?"); if (result == JOptionPane.YES_OPTION) { saveChanges(thisRecord, UPDATE); JOptionPane.showMessageDialog(null, "All right!"); } } } boolean saveChanges(XslRecord rec, int operation) { boolean ret = true; if (operation == this.UPDATE) { String theSqlStmt = "update styleSheets set xsl = ? where appFrom = ? and appTo = ? and op = ?"; try { PreparedStatement pStmt = conn.prepareStatement(theSqlStmt); pStmt.setString(1, rec.XSL); pStmt.setString(2, rec.FROM); pStmt.setString(3, rec.TO); pStmt.setString(4, rec.TASK); pStmt.execute(); conn.commit(); System.out.println("Updated !"); pStmt.close(); // Reinsert in vector... recVect.setElementAt(rec, currRec - 1); } catch (SQLException sqlE) { JOptionPane.showMessageDialog(null, sqlE.toString(), "Saving record", JOptionPane.ERROR_MESSAGE); ret = false; } } else { System.out.println("Inserting new record"); String sqlStmt = "insert into styleSheets " + " ( appFrom, " + " appTo, " + " op, " + " xsl " + " ) values " + " (?, ?, ?, ?)"; String sqlGetLob = "select xsl from styleSheets " + "where appFrom = ? and " + " appTo = ? and " + " op = ?"; try { PreparedStatement pStmt = conn.prepareStatement(sqlStmt); pStmt.setString(1, rec.FROM); pStmt.setString(2, rec.TO); pStmt.setString(3, rec.TASK); pStmt.setString(4, ""); // Null in the LOB, will be filled later pStmt.execute(); System.out.println("Inserted !"); pStmt.close(); PreparedStatement fillLOBStmt = conn.prepareStatement(sqlGetLob); fillLOBStmt.setString(1, rec.FROM); fillLOBStmt.setString(2, rec.TO); fillLOBStmt.setString(3, rec.TASK); ResultSet lobRSet = fillLOBStmt.executeQuery(); while (lobRSet.next()) { CLOB clob = ((OracleResultSet)lobRSet).getCLOB(1); fillClob(conn, clob, rec.XSL); } conn.commit(); // Add in vector... recVect.addElement(rec); currRec = recVect.size(); displayRecord(currRec); } catch (SQLException sqlE) { JOptionPane.showMessageDialog(null, sqlE.toString(), "Inserting record", JOptionPane.ERROR_MESSAGE); ret = false; } inserting = false; fromAppValue.setEditable(false); toAppValue.setEditable(false); opValue.setEditable(false); } updateStatusBar(); return ret; } void buttonClose_actionPerformed(ActionEvent e) { validateRec(); } void newButton_actionPerformed(ActionEvent e) { fromAppValue.setEditable(true); toAppValue.setEditable(true); opValue.setEditable(true); inserting = true; XSLStyleSheet.setText(""); fromAppValue.setText(""); toAppValue.setText(""); opValue.setText(""); } void deleteButton_actionPerformed(ActionEvent e) { deleteRec(); } void queryButton_actionPerformed(ActionEvent e) { if (queryState == ENTER_QUERY) { queryState = EXEC_QUERY; queryButton.setText("Execute Query"); fromAppValue.setEditable(true); toAppValue.setEditable(true); opValue.setEditable(true); XSLStyleSheet.setEditable(false); statusBar.setText("Entering query"); XSLStyleSheet.setText(""); fromAppValue.setText(""); toAppValue.setText(""); opValue.setText(""); newButton.setEnabled(false); firstButton.setEnabled(false); previousButton.setEnabled(false); nextButton.setEnabled(false); lastButton.setEnabled(false); validateButton.setEnabled(false); deleteButton.setEnabled(false); } else { queryState = ENTER_QUERY; queryButton.setText("Enter Query"); statusBar.setText("Executing query"); fromAppValue.setEditable(false); toAppValue.setEditable(false); opValue.setEditable(false); XSLStyleSheet.setEditable(true); newButton.setEnabled(true); firstButton.setEnabled(true); previousButton.setEnabled(true); nextButton.setEnabled(true); lastButton.setEnabled(true); validateButton.setEnabled(true); deleteButton.setEnabled(true); // Execute query String stmt = sqlStmt; boolean firstCondition = true; if (fromAppValue.getText().length() > 0) { stmt += ((firstCondition?" where ":" and ") + "fromApp like '" + fromAppValue.getText() + "' "); firstCondition = false; } if (toAppValue.getText().length() > 0) { stmt += ((firstCondition?" where ":" and ") + "toApp like '" + toAppValue.getText() + "' "); firstCondition = false; } if (opValue.getText().length() > 0) { stmt += ((firstCondition?" where ":" and ") + "op like '" + opValue.getText() + "' "); firstCondition = false; } executeQuery(stmt); updateStatusBar(); displayRecord(currRec); } } }
package B2BDemo.StyleSheetUtil; /** * @author Olivier LE DIOURIS - Partner Technical Services - Oracle Copr. */ import java.awt.*; import javax.swing.*; import javax.swing.border.*; import oracle.jdeveloper.layout.*; public class GUInterface_AboutBoxPanel1 extends JPanel { JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); GridBagLayout gridBagLayout1 = new GridBagLayout(); Border border1 = new EtchedBorder(); public GUInterface_AboutBoxPanel1() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jLabel1.setText("Stored Style Sheets management."); jLabel2.setText("Olivier LE DIOURIS"); jLabel3.setText("Copyright (c) 1999"); jLabel4.setText("Oracle Corp."); this.setLayout(gridBagLayout1); this.setBorder(border1); this.add(jLabel1, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5,5,0,5),0,0)); this.add(jLabel2, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,5,0,5),0,0)); this.add(jLabel3, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,5,0,5),0,0)); this.add(jLabel4, new GridBagConstraints2(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,5,5,5),0,0)); } }
package B2BDemo.StyleSheetUtil; /** * A grapical utility to manipulate the stylesheets stored in the database, * in the AQ Schema. The stylsheets will be used to transform the incoming * document into the outgoing one. * * @author Olivier LE DIOURIS - Partner Technical Services - Oracle Copr. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; //import oracle.bali.ewt.border.UIBorderFactory; //import oracle.bali.ewt.olaf.OracleLookAndFeel; public class GUIStylesheet { private static final boolean useBali = false; public GUIStylesheet() { Frame frame = new GUInterface(); //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width)/2, (screenSize.height - frameSize.height)/2); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); } public static void main(String[] args) { new GUIStylesheet(); } }
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|