Source Code Cross Referenced for LoadXMLAction.java in  » Database-Client » SQL-Profiler » org » jahia » sqlprofiler » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQL Profiler » org.jahia.sqlprofiler.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The Apache Software Foundation. All rights reserved.
003:         *
004:         * This software is published under the terms of the Apache Software
005:         * License version 1.1, a copy of which has been included with this
006:         * distribution in the APACHE.txt file.  */
007:        package org.jahia.sqlprofiler.gui;
008:
009:        import java.awt.event.ActionEvent;
010:        import java.io.File;
011:        import java.io.IOException;
012:        import java.io.StringReader;
013:        import javax.swing.AbstractAction;
014:        import javax.swing.JFileChooser;
015:        import javax.swing.JFrame;
016:        import javax.swing.JOptionPane;
017:        import javax.xml.parsers.ParserConfigurationException;
018:        import javax.xml.parsers.SAXParserFactory;
019:        import org.apache.log4j.Category;
020:        import org.xml.sax.InputSource;
021:        import org.xml.sax.SAXException;
022:        import org.xml.sax.XMLReader;
023:
024:        /**
025:         * Encapsulates the action to load an XML file.
026:         *
027:         * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
028:         * @version 1.0
029:         */
030:        class LoadXMLAction extends AbstractAction {
031:            /** use to log messages **/
032:            private static final Category LOG = Category
033:                    .getInstance(LoadXMLAction.class);
034:
035:            /** the parent frame **/
036:            private final JFrame mParent;
037:
038:            /**
039:             * the file chooser - configured to allow only the selection of a
040:             * single file.
041:             */
042:            private final JFileChooser mChooser = new JFileChooser();
043:            {
044:                mChooser.setMultiSelectionEnabled(false);
045:                mChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
046:            }
047:
048:            /** parser to read XML files **/
049:            private final XMLReader mParser;
050:            /** the content handler **/
051:            private final XMLFileHandler mHandler;
052:
053:            /**
054:             * Creates a new <code>LoadXMLAction</code> instance.
055:             *
056:             * @param aParent the parent frame
057:             * @param aModel the model to add events to
058:             * @exception SAXException if an error occurs
059:             * @throws ParserConfigurationException if an error occurs
060:             */
061:            LoadXMLAction(JFrame aParent, LoggerTableModel aModel)
062:                    throws SAXException, ParserConfigurationException {
063:                mParent = aParent;
064:                mHandler = new XMLFileHandler(aModel);
065:                mParser = SAXParserFactory.newInstance().newSAXParser()
066:                        .getXMLReader();
067:                mParser.setContentHandler(mHandler);
068:            }
069:
070:            /**
071:             * Prompts the user for a file to load events from.
072:             * @param aIgnore an <code>ActionEvent</code> value
073:             */
074:            public void actionPerformed(ActionEvent aIgnore) {
075:                LOG.info("load file called");
076:                if (mChooser.showOpenDialog(mParent) == JFileChooser.APPROVE_OPTION) {
077:                    LOG.info("Need to load a file");
078:                    final File chosen = mChooser.getSelectedFile();
079:                    LOG.info("loading the contents of "
080:                            + chosen.getAbsolutePath());
081:                    try {
082:                        final int num = loadFile(chosen.getAbsolutePath());
083:                        JOptionPane.showMessageDialog(mParent, "Loaded " + num
084:                                + " events.", "CHAINSAW",
085:                                JOptionPane.INFORMATION_MESSAGE);
086:                    } catch (Exception e) {
087:                        LOG.warn("caught an exception loading the file", e);
088:                        JOptionPane.showMessageDialog(mParent,
089:                                "Error parsing file - " + e.getMessage(),
090:                                "CHAINSAW", JOptionPane.ERROR_MESSAGE);
091:                    }
092:                }
093:            }
094:
095:            /**
096:             * Loads the contents of file into the model
097:             *
098:             * @param aFile the file to extract events from
099:             * @return the number of events loaded
100:             * @throws SAXException if an error occurs
101:             * @throws IOException if an error occurs
102:             */
103:            private int loadFile(String aFile) throws SAXException, IOException {
104:                synchronized (mParser) {
105:                    // Create a dummy document to parse the file
106:                    final StringBuffer buf = new StringBuffer();
107:                    buf.append("<?xml version=\"1.0\" standalone=\"yes\"?>\n");
108:                    buf.append("<!DOCTYPE log4j:eventSet ");
109:                    buf.append("[<!ENTITY data SYSTEM \"file:///");
110:                    buf.append(aFile);
111:                    buf.append("\">]>\n");
112:                    buf.append("<log4j:eventSet xmlns:log4j=\"Claira\">\n");
113:                    buf.append("&data;\n");
114:                    buf.append("</log4j:eventSet>\n");
115:
116:                    final InputSource is = new InputSource(new StringReader(buf
117:                            .toString()));
118:                    mParser.parse(is);
119:                    return mHandler.getNumEvents();
120:                }
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.