Source Code Cross Referenced for ReportEditor.java in  » Content-Management-System » harmonise » org » openharmonise » him » editors » report » 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 » Content Management System » harmonise » org.openharmonise.him.editors.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.him.editors.report;
020:
021:        import java.awt.*;
022:        import java.awt.event.*;
023:        import java.net.*;
024:        import java.rmi.*;
025:        import java.util.*;
026:        import java.util.List;
027:
028:        import javax.swing.*;
029:        import javax.xml.parsers.*;
030:        import javax.xml.rpc.*;
031:
032:        import org.jaxen.*;
033:        import org.jaxen.dom.*;
034:        import org.openharmonise.him.*;
035:        import org.openharmonise.him.editors.report.rqom.*;
036:        import org.openharmonise.him.editors.report.utils.*;
037:        import org.openharmonise.him.harmonise.*;
038:        import org.openharmonise.him.reports.*;
039:        import org.openharmonise.vfs.*;
040:        import org.openharmonise.vfs.authentication.*;
041:        import org.openharmonise.vfs.context.*;
042:        import org.openharmonise.vfs.metadata.*;
043:        import org.openharmonise.vfs.metadata.range.*;
044:        import org.openharmonise.vfs.servers.*;
045:        import org.w3c.dom.*;
046:
047:        /**
048:         * Dialog to editor system reports.
049:         * 
050:         * @author Matthew Large
051:         * @version $Revision: 1.2 $
052:         *
053:         */
054:        public class ReportEditor extends JDialog implements  LayoutManager,
055:                ActionListener, ContextListener, ReportQueryListener {
056:
057:            /**
058:             * XML element name for property instance values.
059:             */
060:            private static final String TAG_PROPERTYINSTANCE_VALUES = "PropertyInstanceValues";
061:
062:            /**
063:             * XML element name for properties.
064:             */
065:            private static final String TAG_PROPERTY = "Property";
066:
067:            /**
068:             * XML element name for property instances.
069:             */
070:            private static final String TAG_PROPERTYINSTANCE = "PropertyInstance";
071:
072:            /**
073:             * XML attribute name for operators.
074:             */
075:            private static final String ATTRIB_OPERATOR = "operator";
076:
077:            /**
078:             * XML element name for paths.
079:             */
080:            private static final String TAG_PATH = "Path";
081:
082:            /**
083:             * XML element name for workflow stages.
084:             */
085:            private static final String TAG_WORKFLOW_STAGE = "WorkflowStage";
086:
087:            private static final String TAG_OBJECT_ATTRIBUTES = "ObjectAttributes";
088:
089:            private static final String TAG_METADATA = "Metadata";
090:
091:            /**
092:             * XML element name for workflow property instance values.
093:             */
094:            private static final String TAG_WORKFLOW_PROPERTYINSTANCE_VALUES = TAG_PROPERTYINSTANCE_VALUES; //"WorkflowPropertyInstanceValues";
095:
096:            /**
097:             * XML element name for workflow properties.
098:             */
099:            private static final String TAG_WORKFLOW_PROPERTY = TAG_PROPERTY; //"WorkflowProperty";
100:
101:            /**
102:             * XML element name for workflow property instances.
103:             */
104:            private static final String TAG_WORKFLOW_PROPERTYINSTANCE = TAG_PROPERTYINSTANCE; //"WorkflowPropertyInstance";
105:
106:            /**
107:             * OK button.
108:             */
109:            private JButton m_buttonOK = null;
110:
111:            /**
112:             * Cancel button.
113:             */
114:            private JButton m_buttonCancel = null;
115:
116:            /**
117:             * Run button.
118:             */
119:            private JButton m_buttonRun = null;
120:
121:            /**
122:             * Main layout panel.
123:             */
124:            private JPanel m_panel = null;
125:
126:            /**
127:             * Report query.
128:             */
129:            private ReportQuery m_reportQuery = null;
130:
131:            /**
132:             * Full path to virtual file for report query.
133:             */
134:            private String m_sReportPath = null;
135:
136:            /**
137:             * true to show the main report panel.
138:             */
139:            private boolean m_bShowQueryPanel = true;
140:
141:            /**
142:             * Label for dialog.
143:             */
144:            private JLabel m_label = null;
145:
146:            private ReportPanel m_reportPanel = null;
147:
148:            static private HashMap m_sysPropMappings;
149:            static {
150:                m_sysPropMappings = new HashMap();
151:                m_sysPropMappings.put("display_name",
152:                        HarmonisePaths.PATH_SYSTEM_PROPS + "/title");
153:                m_sysPropMappings.put("summary",
154:                        HarmonisePaths.PATH_SYSTEM_PROPS + "/description");
155:            }
156:
157:            /**
158:             * Constructs a new report editor.
159:             * 
160:             * @param sReportPath Full path to report query
161:             * @throws HeadlessException
162:             */
163:            public ReportEditor(String sReportPath) throws HeadlessException {
164:                super ();
165:                this .m_sReportPath = sReportPath;
166:                this .setTitle("Report Builder");
167:                this .setModal(true);
168:                this .m_reportQuery = new ReportQuery();
169:                this .setup();
170:            }
171:
172:            /**
173:             * Constructs a new report editor.
174:             * 
175:             * @param sReportPath Full path to report query
176:             * @param xml Report query XML
177:             * @throws HeadlessException
178:             */
179:            public ReportEditor(String sReportPath, Document xml)
180:                    throws HeadlessException {
181:                super ();
182:                this .m_sReportPath = sReportPath;
183:                this .setTitle("Report Builder");
184:                this .setModal(true);
185:                this .setQuery(xml);
186:                this .setup();
187:            }
188:
189:            /**
190:             * Configures this dialog.
191:             *
192:             */
193:            private void setup() {
194:
195:                if (this .m_sReportPath
196:                        .equalsIgnoreCase("/webdav/Reports/queries/LinkChecker")) {
197:                    this .m_bShowQueryPanel = false;
198:                    this .setTitle("Link checker");
199:                }
200:
201:                ContextHandler.getInstance().addListener(
202:                        ContextType.CONTEXT_APP_FOCUS, this );
203:
204:                this .setResizable(false);
205:
206:                this .getContentPane().setLayout(this );
207:
208:                if (this .m_bShowQueryPanel) {
209:                    this .setSize(640, 520);
210:                } else {
211:                    this .setSize(550, 100);
212:                }
213:                int x = this .getGraphicsConfiguration().getBounds().width / 2
214:                        - this .getSize().width / 2;
215:                int y = this .getGraphicsConfiguration().getBounds().height / 2
216:                        - this .getSize().height / 2;
217:
218:                this .setLocation(x, y);
219:
220:                String fontName = "Dialog";
221:                int fontSize = 11;
222:                Font font = new Font(fontName, Font.PLAIN, fontSize);
223:                this .getContentPane().setBackground(new Color(224, 224, 224));
224:
225:                if (this .m_bShowQueryPanel) {
226:                    this .m_label = new JLabel(
227:                            "Select from the options below to define the resource properties used in the report");
228:                } else {
229:                    this .m_label = new JLabel(
230:                            "Select 'Run' to run the link checking report");
231:                }
232:                this .getContentPane().add(this .m_label);
233:
234:                if (this .m_bShowQueryPanel) {
235:                    this .m_buttonOK = new JButton("OK");
236:                    this .m_buttonOK.setActionCommand("OK");
237:                    this .m_buttonOK.addActionListener(this );
238:                    this .m_buttonOK.setFont(font);
239:                    this .getContentPane().add(this .m_buttonOK);
240:                }
241:
242:                this .m_buttonCancel = new JButton("Cancel");
243:                this .m_buttonCancel.setActionCommand("CANCEL");
244:                this .m_buttonCancel.addActionListener(this );
245:                this .m_buttonCancel.setFont(font);
246:                this .getContentPane().add(this .m_buttonCancel);
247:
248:                this .m_buttonRun = new JButton("Run");
249:                this .m_buttonRun.setActionCommand("RUN");
250:                this .m_buttonRun.addActionListener(this );
251:                this .m_buttonRun.setFont(font);
252:                this .getContentPane().add(this .m_buttonRun);
253:
254:                VirtualFile vfReportFile = ServerList.getInstance()
255:                        .getHarmoniseServer().getVFS().getVirtualFile(
256:                                this .m_sReportPath).getResource();
257:
258:                if (vfReportFile != null
259:                        && (vfReportFile.getState() != VirtualFile.STATE_LIVE || (vfReportFile
260:                                .isVersionable() && ((VersionedVirtualFile) vfReportFile)
261:                                .getPendingVersionPath() != null))) {
262:                    this .m_buttonRun.setEnabled(false);
263:                }
264:
265:                if (this .m_bShowQueryPanel) {
266:                    m_panel = new JPanel();
267:                    m_panel.setLayout(new BorderLayout());
268:                    m_reportPanel = new ReportPanel(this .m_reportQuery);
269:                    JScrollPane scroller = new JScrollPane(m_reportPanel,
270:                            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
271:                            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
272:                    scroller.getVerticalScrollBar().setUnitIncrement(20);
273:                    this .m_panel.add(scroller);
274:                    this .getContentPane().add(this .m_panel);
275:                    this .m_reportQuery.addListener(this );
276:                } else {
277:                    this .m_reportQuery = null;
278:                }
279:
280:            }
281:
282:            /* (non-Javadoc)
283:             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
284:             */
285:            public void actionPerformed(ActionEvent ae) {
286:                if (ae.getActionCommand().equals("OK")) {
287:                    ContextHandler.getInstance().removeListener(
288:                            ContextType.CONTEXT_APP_FOCUS, this );
289:                    this .hide();
290:                } else if (ae.getActionCommand().equals("CANCEL")) {
291:                    ContextHandler.getInstance().removeListener(
292:                            ContextType.CONTEXT_APP_FOCUS, this );
293:                    this .m_reportQuery = null;
294:                    this .hide();
295:                } else if (ae.getActionCommand().equals("RUN")) {
296:
297:                    Server server = null;
298:                    server = ServerList.getInstance().getHarmoniseServer();
299:                    URI uri = server.getURI();
300:
301:                    String sURI = uri.getScheme() + "://" + uri.getHost() + ":"
302:                            + uri.getPort() + "/webdav/services/ReportService";
303:                    URL url = null;
304:                    try {
305:                        url = new URL(sURI);
306:                    } catch (MalformedURLException e2) {
307:                        e2.printStackTrace();
308:                        System.exit(1);
309:                    }
310:
311:                    AuthInfo auth = server.getVFS().getAuthentication();
312:
313:                    try {
314:                        String sOutputPath = ReportServiceClient.executeQuery(
315:                                url, this .m_sReportPath, auth.getUsername(),
316:                                auth.getPassword());
317:                        VirtualFile vfReportOutput = server.getVFS()
318:                                .getVirtualFile(sOutputPath).getResource();
319:                        if (vfReportOutput != null) {
320:                            server.getVFS().getVirtualFile(
321:                                    vfReportOutput.getFilePath()).getResource()
322:                                    .refreshChildren();
323:                        }
324:                    } catch (RemoteException e) {
325:                        e.printStackTrace();
326:                    } catch (ServiceException e) {
327:                        e.printStackTrace();
328:                    }
329:                    ContextHandler.getInstance().removeListener(
330:                            ContextType.CONTEXT_APP_FOCUS, this );
331:                    this .m_reportQuery = null;
332:                    this .hide();
333:                }
334:            }
335:
336:            /* (non-Javadoc)
337:             * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
338:             */
339:            public void layoutContainer(Container arg0) {
340:                this .m_label.setSize(this .m_label.getPreferredSize());
341:                this .m_label.setLocation(5, 3);
342:
343:                if (this .m_bShowQueryPanel) {
344:                    this .m_panel.setSize(this .getSize().width - 10, this 
345:                            .getHeight() - 80);
346:                    this .m_panel.setLocation(0, 20);
347:
348:                    this .m_buttonOK.setSize(70, 20);
349:                    this .m_buttonOK.setLocation(this .getWidth() - 280, this 
350:                            .getHeight() - 50);
351:                }
352:
353:                this .m_buttonCancel.setSize(70, 20);
354:                this .m_buttonCancel.setLocation(this .getWidth() - 190, this 
355:                        .getHeight() - 50);
356:
357:                this .m_buttonRun.setSize(70, 20);
358:                this .m_buttonRun.setLocation(this .getWidth() - 100, this 
359:                        .getHeight() - 50);
360:            }
361:
362:            /**
363:             * @param arg0
364:             * @throws java.awt.HeadlessException
365:             */
366:            private ReportEditor(Dialog arg0) throws HeadlessException {
367:                super (arg0);
368:            }
369:
370:            /**
371:             * @param arg0
372:             * @param arg1
373:             * @throws java.awt.HeadlessException
374:             */
375:            private ReportEditor(Dialog arg0, boolean arg1)
376:                    throws HeadlessException {
377:                super (arg0, arg1);
378:            }
379:
380:            /**
381:             * @param arg0
382:             * @throws java.awt.HeadlessException
383:             */
384:            private ReportEditor(Frame arg0) throws HeadlessException {
385:                super (arg0);
386:            }
387:
388:            /**
389:             * @param arg0
390:             * @param arg1
391:             * @throws java.awt.HeadlessException
392:             */
393:            private ReportEditor(Frame arg0, boolean arg1)
394:                    throws HeadlessException {
395:                super (arg0, arg1);
396:            }
397:
398:            /**
399:             * @param arg0
400:             * @param arg1
401:             * @throws java.awt.HeadlessException
402:             */
403:            private ReportEditor(Dialog arg0, String arg1)
404:                    throws HeadlessException {
405:                super (arg0, arg1);
406:            }
407:
408:            /**
409:             * @param arg0
410:             * @param arg1
411:             * @param arg2
412:             * @throws java.awt.HeadlessException
413:             */
414:            private ReportEditor(Dialog arg0, String arg1, boolean arg2)
415:                    throws HeadlessException {
416:                super (arg0, arg1, arg2);
417:            }
418:
419:            /**
420:             * @param arg0
421:             * @param arg1
422:             * @throws java.awt.HeadlessException
423:             */
424:            private ReportEditor(Frame arg0, String arg1)
425:                    throws HeadlessException {
426:                super (arg0, arg1);
427:            }
428:
429:            /**
430:             * @param arg0
431:             * @param arg1
432:             * @param arg2
433:             * @throws java.awt.HeadlessException
434:             */
435:            private ReportEditor(Frame arg0, String arg1, boolean arg2)
436:                    throws HeadlessException {
437:                super (arg0, arg1, arg2);
438:            }
439:
440:            /**
441:             * @param arg0
442:             * @param arg1
443:             * @param arg2
444:             * @param arg3
445:             * @throws java.awt.HeadlessException
446:             */
447:            private ReportEditor(Dialog arg0, String arg1, boolean arg2,
448:                    GraphicsConfiguration arg3) throws HeadlessException {
449:                super (arg0, arg1, arg2, arg3);
450:            }
451:
452:            /**
453:             * @param arg0
454:             * @param arg1
455:             * @param arg2
456:             * @param arg3
457:             */
458:            private ReportEditor(Frame arg0, String arg1, boolean arg2,
459:                    GraphicsConfiguration arg3) {
460:                super (arg0, arg1, arg2, arg3);
461:            }
462:
463:            /* (non-Javadoc)
464:             * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
465:             */
466:            public void removeLayoutComponent(Component arg0) {
467:            }
468:
469:            /* (non-Javadoc)
470:             * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
471:             */
472:            public void addLayoutComponent(String arg0, Component arg1) {
473:            }
474:
475:            /* (non-Javadoc)
476:             * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
477:             */
478:            public Dimension minimumLayoutSize(Container arg0) {
479:                return this .getSize();
480:            }
481:
482:            /* (non-Javadoc)
483:             * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
484:             */
485:            public Dimension preferredLayoutSize(Container arg0) {
486:                return this .getSize();
487:            }
488:
489:            /* (non-Javadoc)
490:             * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
491:             */
492:            public void contextMessage(ContextEvent ce) {
493:                if (ce.CONTEXT_TYPE == ContextType.CONTEXT_APP_FOCUS) {
494:                    this .toFront();
495:                }
496:            }
497:
498:            /**
499:             * Sets the report query data.
500:             * 
501:             * @param xml Report query XML
502:             */
503:            public void setQuery(Document xml) {
504:                this .m_reportQuery = new ReportQuery();
505:
506:                Element elRoot = xml.getDocumentElement();
507:
508:                try {
509:                    DOMXPath xpGroups = new DOMXPath(
510:                            "descendant::Group[parent::Conditions]");
511:                    List groupEls = xpGroups.selectNodes(elRoot);
512:
513:                    DOMXPath xpPath = new DOMXPath("descendant::Path/.");
514:                    Iterator itor = groupEls.iterator();
515:                    while (itor.hasNext()) {
516:                        Element element = (Element) itor.next();
517:                        this .m_reportQuery.setPath(xpPath
518:                                .stringValueOf(element));
519:                    }
520:
521:                    StringBuffer strbuf = new StringBuffer();
522:
523:                    strbuf.append("descendant::").append(TAG_PROPERTYINSTANCE);
524:
525:                    DOMXPath xpProps = new DOMXPath(strbuf.toString());
526:
527:                    strbuf.setLength(0);
528:
529:                    String sChildAxis = "child::";
530:                    strbuf.append(sChildAxis).append(TAG_PROPERTY).append(
531:                            "/child::Path/.");
532:
533:                    DOMXPath xpPropPath = new DOMXPath(strbuf.toString());
534:
535:                    strbuf.setLength(0);
536:
537:                    strbuf.append(sChildAxis).append(
538:                            TAG_PROPERTYINSTANCE_VALUES).append(
539:                            "/descendant::Data/.");
540:
541:                    DOMXPath xpValueData = new DOMXPath(strbuf.toString());
542:
543:                    strbuf.setLength(0);
544:
545:                    strbuf.append(sChildAxis).append(
546:                            TAG_PROPERTYINSTANCE_VALUES).append(
547:                            "/descendant::Path/.");
548:
549:                    DOMXPath xpValuePath = new DOMXPath(strbuf.toString());
550:                    List propEls = xpProps.selectNodes(elRoot);
551:                    itor = propEls.iterator();
552:                    while (itor.hasNext()) {
553:                        Element element = (Element) itor.next();
554:                        String sPropPath = xpPropPath.stringValueOf(element);
555:
556:                        String sPropVal = xpValueData.stringValueOf(element);
557:                        if (sPropVal.equals("")) {
558:                            sPropVal = xpValuePath.stringValueOf(element);
559:                        }
560:                        String sOperator = element
561:                                .getAttribute(ATTRIB_OPERATOR);
562:
563:                        if (sPropPath
564:                                .startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS)) {
565:                            WorkflowStage stage = new WorkflowStage(sPropPath,
566:                                    this .m_reportQuery);
567:                            stage.setStagePath(sPropVal);
568:                            if (sOperator != null && sOperator.length() > 0) {
569:                                if (sOperator.equals("=")) {
570:                                    stage.setCompleted(true);
571:                                } else {
572:                                    stage.setCompleted(false);
573:                                }
574:                            }
575:                            this .m_reportQuery.addWorkflowStage(stage);
576:                        } else {
577:                            Metadata metadata = new Metadata(sPropPath,
578:                                    this .m_reportQuery);
579:                            metadata.setValue(sPropVal);
580:                            if (sOperator.equals("<>")) {
581:                                metadata.setOperator("NOT");
582:                            } else {
583:                                metadata.setOperator(sOperator);
584:                            }
585:
586:                            this .m_reportQuery.addMetadata(metadata);
587:                        }
588:                    }
589:                    String sReportAtt = "descendant::ReportAttributes/";
590:                    DOMXPath xpObjectAttributes = new DOMXPath(sReportAtt
591:                            + "ObjectAttributes/child::*");
592:                    List objectAttEls = xpObjectAttributes.selectNodes(elRoot);
593:                    Iterator iter = objectAttEls.iterator();
594:                    while (iter.hasNext()) {
595:                        Element element = (Element) iter.next();
596:                        String sObject = element.getTagName();
597:                        String sSysProp = (String) m_sysPropMappings
598:                                .get(sObject);
599:                        Metadata metadata = new Metadata(sSysProp,
600:                                this .m_reportQuery);
601:                        m_reportQuery.addDisplayAttributes(metadata);
602:                    }
603:                    DOMXPath xpMetadata = new DOMXPath(sReportAtt
604:                            + "Metadata/Property");
605:                    propEls = xpMetadata.selectNodes(elRoot);
606:                    iter = propEls.iterator();
607:                    while (iter.hasNext()) {
608:                        Element element = (Element) iter.next();
609:                        String sPath = xpPath.stringValueOf(element);
610:                        Metadata metadata = new Metadata(sPath,
611:                                this .m_reportQuery);
612:                        m_reportQuery.addDisplayAttributes(metadata);
613:                    }
614:                    DOMXPath xpOrderBy = new DOMXPath(
615:                            "descendant::ReportAttributes/OrderBy/child::*");
616:                    List orderByEls = xpOrderBy.selectNodes(elRoot);
617:                    iter = orderByEls.iterator();
618:                    while (iter.hasNext()) {
619:                        Element element = (Element) iter.next();
620:                        if (element.getTagName().equals(TAG_PROPERTY)) {
621:                            String sPath = xpPath.stringValueOf(element);
622:                            Metadata metadata = new Metadata(sPath,
623:                                    this .m_reportQuery);
624:                            m_reportQuery.addOrderByAttributes(metadata);
625:                        } else {
626:                            String sObject = element.getTagName();
627:                            String sSysProp = (String) m_sysPropMappings
628:                                    .get(sObject);
629:                            Metadata metadata = new Metadata(sSysProp,
630:                                    this .m_reportQuery);
631:                            m_reportQuery.addOrderByAttributes(metadata);
632:                        }
633:                    }
634:
635:                    DOMXPath xpUsers = new DOMXPath(
636:                            "descendant::ChangedBy/child::User");
637:                    DOMXPath xpUserPath = new DOMXPath("child::Path/.");
638:                    List users = xpUsers.selectNodes(elRoot);
639:                    itor = users.iterator();
640:                    while (itor.hasNext()) {
641:                        Element element = (Element) itor.next();
642:                        String sUserPath = xpUserPath.stringValueOf(element);
643:                        if (sUserPath != null) {
644:                            User user = new User(sUserPath, this .m_reportQuery);
645:                            this .m_reportQuery.addUser(user);
646:                        }
647:                    }
648:
649:                    DOMXPath xpActivities = new DOMXPath(
650:                            "descendant::Activities/child::*");
651:                    List activities = xpActivities.selectNodes(elRoot);
652:                    itor = activities.iterator();
653:                    while (itor.hasNext()) {
654:                        Element element = (Element) itor.next();
655:                        if (element.getTagName().equals("Archived")) {
656:                            this .m_reportQuery
657:                                    .addActivity(ReportQuery.ACTIVITY_ARCHIVE);
658:                        } else if (element.getTagName().equals("Move")) {
659:                            this .m_reportQuery
660:                                    .addActivity(ReportQuery.ACTIVITY_MOVE);
661:                        } else if (element.getTagName().equals("Published")) {
662:                            this .m_reportQuery
663:                                    .addActivity(ReportQuery.ACTIVITY_PUBLISH);
664:                        } else if (element.getTagName().equals("Retrieved")) {
665:                            this .m_reportQuery
666:                                    .addActivity(ReportQuery.ACTIVITY_RETRIEVE);
667:                        } else if (element.getTagName().equals("Workflow")) {
668:                            this .m_reportQuery
669:                                    .addActivity(ReportQuery.ACTIVITY_WORKFLOW);
670:                        }
671:                    }
672:                } catch (JaxenException e) {
673:                    e.printStackTrace();
674:                }
675:
676:            }
677:
678:            /**
679:             * Returns the report query data.
680:             * 
681:             * @return Report query XML
682:             */
683:            public Document getQuery() {
684:                Document xml = null;
685:
686:                if (this .m_reportQuery != null) {
687:                    try {
688:                        xml = DocumentBuilderFactory.newInstance()
689:                                .newDocumentBuilder().newDocument();
690:
691:                        Element elRoot = xml.createElement("ReportQuery");
692:                        xml.appendChild(elRoot);
693:
694:                        Element elQuery = xml.createElement("Query");
695:                        elRoot.appendChild(elQuery);
696:
697:                        Element elList = xml.createElement("List");
698:                        elList.setAttribute("name", "ReportList");
699:                        elQuery.appendChild(elList);
700:
701:                        Element elConditions = xml.createElement("Conditions");
702:                        elConditions.setAttribute("name", "ReportConditions");
703:                        elList.appendChild(elConditions);
704:
705:                        Element elGroup = xml.createElement("Group");
706:                        elGroup.setAttribute("sub", "true");
707:                        elConditions.appendChild(elGroup);
708:
709:                        Element elGroupObject = xml
710:                                .createElement(PathTagMapping
711:                                        .getGroupTagName(this .m_reportQuery
712:                                                .getPath()));
713:                        elGroup.appendChild(elGroupObject);
714:
715:                        Element elGroupPath = xml.createElement(TAG_PATH);
716:                        Text txt = xml.createTextNode(this .m_reportQuery
717:                                .getPath());
718:                        elGroupPath.appendChild(txt);
719:                        elGroupObject.appendChild(elGroupPath);
720:
721:                        Iterator itor = this .m_reportQuery.getMetadata()
722:                                .iterator();
723:                        while (itor.hasNext()) {
724:                            Metadata metadata = (Metadata) itor.next();
725:                            Property prop = PropertyCache.getInstance()
726:                                    .getPropertyByPath(metadata.getPath());
727:                            String sValue = metadata.getValue();
728:                            if (prop == null || sValue == null
729:                                    || sValue.length() == 0) {
730:                                continue;
731:                            }
732:
733:                            Element elPropInst = xml
734:                                    .createElement(TAG_PROPERTYINSTANCE);
735:                            if (metadata.getOperator().equalsIgnoreCase("NOT")) {
736:                                elPropInst.setAttribute(ATTRIB_OPERATOR, "<>");
737:                            } else {
738:                                elPropInst.setAttribute(ATTRIB_OPERATOR,
739:                                        metadata.getOperator());
740:                            }
741:                            elConditions.appendChild(elPropInst);
742:
743:                            Element elProp = xml.createElement(TAG_PROPERTY);
744:                            elPropInst.appendChild(elProp);
745:                            Element elPropPath = xml.createElement(TAG_PATH);
746:                            txt = xml.createTextNode(metadata.getPath());
747:                            elPropPath.appendChild(txt);
748:                            elProp.appendChild(elPropPath);
749:
750:                            Element elPropInstVals = xml
751:                                    .createElement(TAG_PROPERTYINSTANCE_VALUES);
752:                            elPropInst.appendChild(elPropInstVals);
753:
754:                            if (prop.getRange() instanceof  ResourceRange
755:                                    || prop.getRange() instanceof  ValueRange) {
756:                                Element elObjectElement = xml
757:                                        .createElement(PathTagMapping
758:                                                .getObjectTagName(sValue));
759:                                elPropInstVals.appendChild(elObjectElement);
760:                                Element elObjectPath = xml
761:                                        .createElement(TAG_PATH);
762:                                txt = xml.createTextNode(sValue);
763:                                elObjectPath.appendChild(txt);
764:                                elObjectElement.appendChild(elObjectPath);
765:                            } else if (prop.getRange() instanceof  CollectionRange) {
766:                                Element elObjectElement = xml
767:                                        .createElement(PathTagMapping
768:                                                .getGroupTagName(sValue));
769:                                elPropInstVals.appendChild(elObjectElement);
770:                                Element elObjectPath = xml
771:                                        .createElement(TAG_PATH);
772:                                txt = xml.createTextNode(sValue);
773:                                elObjectPath.appendChild(txt);
774:                                elObjectElement.appendChild(elObjectPath);
775:                            } else {
776:                                Element elValueObject = xml
777:                                        .createElement("Data");
778:                                txt = xml.createTextNode(sValue);
779:                                elValueObject.appendChild(txt);
780:                                elPropInstVals.appendChild(elValueObject);
781:                            }
782:                        }
783:
784:                        itor = this .m_reportQuery.getWorkflowStages()
785:                                .iterator();
786:                        while (itor.hasNext()) {
787:                            WorkflowStage workflowStage = (WorkflowStage) itor
788:                                    .next();
789:                            String sPath = workflowStage.getPath();
790:                            String sStagePath = workflowStage.getStagePath();
791:                            if (sPath == null || sPath.length() == 0
792:                                    || sStagePath == null
793:                                    || sStagePath.length() == 0) {
794:                                continue;
795:                            }
796:
797:                            Element elPropInst = xml
798:                                    .createElement(TAG_WORKFLOW_PROPERTYINSTANCE);
799:                            if (workflowStage.isCompleted()) {
800:                                elPropInst.setAttribute(ATTRIB_OPERATOR, "=");
801:                            } else {
802:                                elPropInst.setAttribute(ATTRIB_OPERATOR, "<>");
803:                            }
804:                            elConditions.appendChild(elPropInst);
805:
806:                            Element elProp = xml
807:                                    .createElement(TAG_WORKFLOW_PROPERTY);
808:                            elPropInst.appendChild(elProp);
809:                            Element elPropPath = xml.createElement(TAG_PATH);
810:                            txt = xml.createTextNode(workflowStage.getPath());
811:                            elPropPath.appendChild(txt);
812:                            elProp.appendChild(elPropPath);
813:
814:                            Element elPropInstVals = xml
815:                                    .createElement(TAG_WORKFLOW_PROPERTYINSTANCE_VALUES);
816:                            elPropInst.appendChild(elPropInstVals);
817:
818:                            Element elValueObject = xml
819:                                    .createElement(TAG_WORKFLOW_STAGE);
820:                            Element elPath = xml.createElement(TAG_PATH);
821:                            elValueObject.appendChild(elPath);
822:                            txt = xml.createTextNode(workflowStage
823:                                    .getStagePath());
824:                            elPath.appendChild(txt);
825:                            elPropInstVals.appendChild(elValueObject);
826:                        }
827:
828:                        Element elSearchObject = xml
829:                                .createElement("SearchObject");
830:                        elList.appendChild(elSearchObject);
831:                        Element elSearchObjectElement = xml
832:                                .createElement(PathTagMapping
833:                                        .getObjectTagName(this .m_reportQuery
834:                                                .getPath()));
835:                        elSearchObject.appendChild(elSearchObjectElement);
836:
837:                        Element elReportAttributes = xml
838:                                .createElement("ReportAttributes");
839:                        elQuery.appendChild(elReportAttributes);
840:
841:                        Element elMetadata = xml.createElement(TAG_METADATA);
842:                        elReportAttributes.appendChild(elMetadata);
843:
844:                        itor = this .m_reportQuery.getDisplayAttributes()
845:                                .iterator();
846:                        while (itor.hasNext()) {
847:                            Metadata attribute = (Metadata) itor.next();
848:                            if (attribute.isSystemProperty()) {
849:                                Element elObjectAttributes = xml
850:                                        .createElement("ObjectAttributes");
851:                                elReportAttributes
852:                                        .appendChild(elObjectAttributes);
853:                                String sPath = getSysPropFromMetadata(attribute);
854:                                Element elSysProp = xml.createElement(sPath);
855:                                elObjectAttributes.appendChild(elSysProp);
856:                            } else {
857:                                Element elProp = xml
858:                                        .createElement(TAG_PROPERTY);
859:                                elMetadata.appendChild(elProp);
860:
861:                                Element elPath = xml.createElement(TAG_PATH);
862:                                elProp.appendChild(elPath);
863:                                txt = xml.createTextNode(attribute.getPath());
864:                                elPath.appendChild(txt);
865:                            }
866:                        }
867:
868:                        Element elOrderBy = xml.createElement("OrderBy");
869:                        elReportAttributes.appendChild(elOrderBy);
870:
871:                        itor = this .m_reportQuery.getOrderByAttributes()
872:                                .iterator();
873:                        while (itor.hasNext()) {
874:                            Metadata attribute = (Metadata) itor.next();
875:
876:                            if (attribute.isSystemProperty()) {
877:                                String sPath = getSysPropFromMetadata(attribute);
878:                                Element elSysProp = xml.createElement(sPath);
879:                                elOrderBy.appendChild(elSysProp);
880:                            } else {
881:                                Element elProp = xml
882:                                        .createElement(TAG_PROPERTY);
883:                                elOrderBy.appendChild(elProp);
884:
885:                                Element elPath = xml.createElement(TAG_PATH);
886:                                elProp.appendChild(elPath);
887:                                txt = xml.createTextNode(attribute.getPath());
888:                                elPath.appendChild(txt);
889:                            }
890:                        }
891:
892:                        Element elEventConditions = xml
893:                                .createElement("EventConditions");
894:                        elQuery.appendChild(elEventConditions);
895:
896:                        Element elActivityPeriod = xml
897:                                .createElement("ActivityPeriod");
898:                        elEventConditions.appendChild(elActivityPeriod);
899:
900:                        Element elChangedBy = xml.createElement("ChangedBy");
901:                        elEventConditions.appendChild(elChangedBy);
902:
903:                        itor = this .m_reportQuery.getUsers().iterator();
904:                        while (itor.hasNext()) {
905:                            User user = (User) itor.next();
906:                            Element elUser = xml.createElement("User");
907:                            elChangedBy.appendChild(elUser);
908:
909:                            Element elUserPath = xml.createElement(TAG_PATH);
910:                            txt = xml.createTextNode(user.getPath());
911:                            elUserPath.appendChild(txt);
912:                            elUser.appendChild(elUserPath);
913:                        }
914:
915:                        Element elActivities = xml.createElement("Activities");
916:                        elEventConditions.appendChild(elActivities);
917:
918:                        itor = this .m_reportQuery.getActivities().iterator();
919:                        while (itor.hasNext()) {
920:                            String sActivity = (String) itor.next();
921:                            if (sActivity.equals(ReportQuery.ACTIVITY_ARCHIVE)) {
922:                                Element elArchived = xml
923:                                        .createElement("Archived");
924:                                elActivities.appendChild(elArchived);
925:                            } else if (sActivity
926:                                    .equals(ReportQuery.ACTIVITY_MOVE)) {
927:                                Element elMove = xml.createElement("Move");
928:                                elActivities.appendChild(elMove);
929:                            } else if (sActivity
930:                                    .equals(ReportQuery.ACTIVITY_PUBLISH)) {
931:                                Element elPublished = xml
932:                                        .createElement("Published");
933:                                elActivities.appendChild(elPublished);
934:                            } else if (sActivity
935:                                    .equals(ReportQuery.ACTIVITY_RETRIEVE)) {
936:                                Element elRetrieved = xml
937:                                        .createElement("Retrieved");
938:                                elActivities.appendChild(elRetrieved);
939:                            } else if (sActivity
940:                                    .equals(ReportQuery.ACTIVITY_WORKFLOW)) {
941:                                Element elWorkflow = xml
942:                                        .createElement("Workflow");
943:                                elActivities.appendChild(elWorkflow);
944:                            }
945:                        }
946:                    } catch (ParserConfigurationException e) {
947:                        e.printStackTrace();
948:                    } catch (FactoryConfigurationError e) {
949:                        e.printStackTrace();
950:                    }
951:                }
952:                return xml;
953:            }
954:
955:            private String getSysPropFromMetadata(Metadata metadata) {
956:                Iterator iter = m_sysPropMappings.keySet().iterator();
957:                String key = null;
958:                while (iter.hasNext()) {
959:                    String temp = (String) iter.next();
960:                    if (metadata.getPath().equals(m_sysPropMappings.get(temp))) {
961:                        key = temp;
962:                        break;
963:                    }
964:                }
965:                return key;
966:            }
967:
968:            /* (non-Javadoc)
969:             * @see com.simulacramedia.contentmanager.editors.report.rqom.ReportQueryListener#dataChanged()
970:             */
971:            public void dataChanged() {
972:                this .m_buttonRun.setEnabled(false);
973:                this.m_reportPanel.setScopeEnabled(m_reportQuery
974:                        .isReportPanelEditable());
975:            }
976:
977:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.