Source Code Cross Referenced for XPathPanel.java in  » Testing » jakarta-jmeter » org » apache » jmeter » assertions » 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 » Testing » jakarta jmeter » org.apache.jmeter.assertions.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.assertions.gui;
020:
021:        import java.awt.LayoutManager;
022:        import java.awt.event.ActionEvent;
023:        import java.awt.event.ActionListener;
024:
025:        import javax.swing.Box;
026:        import javax.swing.JButton;
027:        import javax.swing.JCheckBox;
028:        import javax.swing.JOptionPane;
029:        import javax.swing.JPanel;
030:        import javax.swing.JTextField;
031:        import javax.xml.parsers.ParserConfigurationException;
032:        import javax.xml.transform.TransformerException;
033:
034:        import org.apache.jmeter.util.JMeterUtils;
035:        import org.apache.jmeter.util.XPathUtil;
036:        import org.apache.jorphan.logging.LoggingManager;
037:        import org.apache.log.Logger;
038:        import org.apache.xpath.XPathAPI;
039:        import org.w3c.dom.Document;
040:        import org.w3c.dom.Element;
041:
042:        /**
043:         * author jspears
044:         * 
045:         */
046:        public class XPathPanel extends JPanel {
047:            private static Document testDoc = null;
048:
049:            private final static Logger log = LoggingManager
050:                    .getLoggerForClass();
051:
052:            private JCheckBox negated;
053:
054:            private JTextField xpath;
055:
056:            private JButton checkXPath;
057:
058:            /**
059:             * 
060:             */
061:            public XPathPanel() {
062:                super ();
063:                init();
064:            }
065:
066:            /**
067:             * @param isDoubleBuffered
068:             */
069:            public XPathPanel(boolean isDoubleBuffered) {
070:                super (isDoubleBuffered);
071:                init();
072:            }
073:
074:            /**
075:             * @param layout
076:             */
077:            public XPathPanel(LayoutManager layout) {
078:                super (layout);
079:                init();
080:            }
081:
082:            /**
083:             * @param layout
084:             * @param isDoubleBuffered
085:             */
086:            public XPathPanel(LayoutManager layout, boolean isDoubleBuffered) {
087:                super (layout, isDoubleBuffered);
088:                init();
089:            }
090:
091:            private void init() {
092:                Box hbox = Box.createHorizontalBox();
093:                hbox.add(Box.createHorizontalGlue());
094:                hbox.add(getXPathTextField());
095:                hbox.add(Box.createHorizontalGlue());
096:                hbox.add(getCheckXPathButton());
097:
098:                Box vbox = Box.createVerticalBox();
099:                vbox.add(hbox);
100:                vbox.add(Box.createVerticalGlue());
101:                vbox.add(getNegatedCheckBox());
102:
103:                add(vbox);
104:
105:                setDefaultValues();
106:            }
107:
108:            public void setDefaultValues() {
109:                setXPath("/"); //$NON-NLS-1$
110:                setNegated(false);
111:            }
112:
113:            /**
114:             * Get the XPath String
115:             * 
116:             * @return String
117:             */
118:            public String getXPath() {
119:                return this .xpath.getText();
120:            }
121:
122:            /**
123:             * Set the string that will be used in the xpath evaluation
124:             * 
125:             * @param xpath
126:             */
127:            public void setXPath(String xpath) {
128:                this .xpath.setText(xpath);
129:            }
130:
131:            /**
132:             * Does this negate the xpath results
133:             * 
134:             * @return boolean
135:             */
136:            public boolean isNegated() {
137:                return this .negated.isSelected();
138:            }
139:
140:            /**
141:             * Set this to true, if you want success when the xpath does not match.
142:             * 
143:             * @param negated
144:             */
145:            public void setNegated(boolean negated) {
146:                this .negated.setSelected(negated);
147:            }
148:
149:            /**
150:             * Negated chechbox
151:             * 
152:             * @return JCheckBox
153:             */
154:            public JCheckBox getNegatedCheckBox() {
155:                if (negated == null) {
156:                    negated = new JCheckBox(JMeterUtils
157:                            .getResString("xpath_assertion_negate"), false); //$NON-NLS-1$
158:                }
159:
160:                return negated;
161:            }
162:
163:            /**
164:             * Check XPath button
165:             * 
166:             * @return JButton
167:             */
168:            public JButton getCheckXPathButton() {
169:                if (checkXPath == null) {
170:                    checkXPath = new JButton(JMeterUtils
171:                            .getResString("xpath_assertion_button")); //$NON-NLS-1$
172:                    checkXPath.addActionListener(new ActionListener() {
173:                        public void actionPerformed(ActionEvent e) {
174:                            validXPath(xpath.getText(), true);
175:                        }
176:                    });
177:                }
178:                return checkXPath;
179:            }
180:
181:            public JTextField getXPathTextField() {
182:                if (xpath == null) {
183:                    xpath = new JTextField(50);
184:                }
185:                return xpath;
186:            }
187:
188:            /**
189:             * @return Returns the showNegate.
190:             */
191:            public boolean isShowNegated() {
192:                return this .getNegatedCheckBox().isVisible();
193:            }
194:
195:            /**
196:             * @param showNegate
197:             *            The showNegate to set.
198:             */
199:            public void setShowNegated(boolean showNegate) {
200:                getNegatedCheckBox().setVisible(showNegate);
201:            }
202:
203:            /**
204:             * Test weather an XPath is valid. It seems the Xalan has no easy way to
205:             * check, so this creates a test document, then tries to evaluate the xpath.
206:             * 
207:             * @param xpathString
208:             *            XPath String to validate
209:             * @param showDialog
210:             *            weather to show a dialog
211:             * @return returns true if valid, valse otherwise.
212:             */
213:            public static boolean validXPath(String xpathString,
214:                    boolean showDialog) {
215:                String ret = null;
216:                boolean success = true;
217:                try {
218:                    if (testDoc == null) {
219:                        testDoc = XPathUtil.makeDocumentBuilder(false, false,
220:                                false).newDocument();
221:                        Element el = testDoc.createElement("root"); //$NON-NLS-1$
222:                        testDoc.appendChild(el);
223:
224:                    }
225:                    if (XPathAPI.eval(testDoc, xpathString) == null) {
226:                        // We really should never get here
227:                        // because eval will throw an exception
228:                        // if xpath is invalid, but whatever, better
229:                        // safe
230:                        log.warn("xpath eval was null ");
231:                        ret = "xpath eval was null";
232:                        success = false;
233:                    }
234:
235:                } catch (ParserConfigurationException e) {
236:                    success = false;
237:                    ret = e.getLocalizedMessage();
238:                } catch (TransformerException e) {
239:                    success = false;
240:                    ret = e.getLocalizedMessage();
241:                }
242:
243:                if (showDialog) {
244:                    JOptionPane
245:                            .showMessageDialog(
246:                                    null,
247:                                    (success) ? JMeterUtils
248:                                            .getResString("xpath_assertion_valid") : ret, //$NON-NLS-1$
249:                                    (success) ? JMeterUtils
250:                                            .getResString("xpath_assertion_valid") : JMeterUtils //$NON-NLS-1$
251:                                                    .getResString("xpath_assertion_failed"), (success) ? JOptionPane.INFORMATION_MESSAGE //$NON-NLS-1$
252:                                            : JOptionPane.ERROR_MESSAGE);
253:                }
254:                return success;
255:
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.