1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.wizards.reportbuilder;
25 
26 import com.sun.star.util.XModeSelector;
27 
28 import com.sun.star.awt.XWindowPeer;
29 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.container.XHierarchicalNameContainer;
32 import com.sun.star.frame.XController;
33 import com.sun.star.frame.XDispatch;
34 import com.sun.star.frame.XDispatchProvider;
35 import com.sun.star.frame.XFrame;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.report.XReportDefinition;
39 import com.sun.star.sdb.XSubDocument;
40 import com.sun.star.sdb.application.DatabaseObject;
41 import com.sun.star.sdb.application.XDatabaseDocumentUI;
42 import com.sun.star.sdbc.XConnection;
43 import com.sun.star.ucb.XCommandProcessor;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.util.XModifiable;
46 import com.sun.star.util.XURLTransformer;
47 import com.sun.star.wizards.common.NoValidPathException;
48 import com.sun.star.wizards.common.Resource;
49 import com.sun.star.wizards.db.FieldColumn;
50 import java.lang.reflect.Constructor;
51 import java.util.ArrayList;
52 import java.util.Iterator;
53 import java.util.LinkedHashMap;
54 import java.util.Set;
55 import java.util.Vector;
56 import com.sun.star.wizards.common.FileAccess;
57 import com.sun.star.wizards.common.NamedValueCollection;
58 import com.sun.star.wizards.common.PropertyNames;
59 import com.sun.star.wizards.report.IReportBuilderLayouter;
60 import com.sun.star.wizards.report.IReportDefinitionReadAccess;
61 import com.sun.star.wizards.report.IReportDocument;
62 import com.sun.star.wizards.report.ReportImplementationHelper;
63 import com.sun.star.wizards.report.ReportLayouter;
64 import com.sun.star.wizards.report.ReportWizard;
65 import java.util.logging.Level;
66 import java.util.logging.Logger;
67 
68 /**
69  * This class use the IReportDocument Interface to communicate between the UI
70  * and the ReportBuilderLayouter which communicates to the new Report Builder.
71  *
72  * @author ll93751
73  */
74 public class ReportBuilderImplementation extends ReportImplementationHelper
75         implements IReportDocument, IReportDefinitionReadAccess
76 {
77 
78     private Resource m_resource;
79     private XDatabaseDocumentUI m_documentUI;
80     private static final int MAXIMUM_GROUPCOUNT = 4;
81     private String[] groupNames = null;
82 
ReportBuilderImplementation(XMultiServiceFactory _serviceFactory)83     private ReportBuilderImplementation(XMultiServiceFactory _serviceFactory)
84     {
85         // creates an access to the Report Builder Extension
86         super(_serviceFactory, ReportLayouter.SOOPTLANDSCAPE);
87     }
88 
create(XMultiServiceFactory i_serviceFactory)89     public static IReportDocument create(XMultiServiceFactory i_serviceFactory)
90     {
91         return new ReportBuilderImplementation(i_serviceFactory);
92     }
93 
initialize(final XDatabaseDocumentUI i_documentUI, final Resource i_resource)94     public void initialize(final XDatabaseDocumentUI i_documentUI, final Resource i_resource)
95     {
96         m_documentUI = i_documentUI;
97         m_resource = i_resource;
98     }
99 
clearDocument()100     public void clearDocument()
101     {
102     }
103 
getWizardParent()104     public XWindowPeer getWizardParent()
105     {
106         return UnoRuntime.queryInterface(XWindowPeer.class, getFrame().getComponentWindow());
107     }
108     private XFrame m_xFrame = null;
109     // private ReportBuilderLayouter m_aReportBuilderLayouter = null;
110     private String m_sReportBuilderLayoutName = PropertyNames.EMPTY_STRING;
111 
112     /**
113      * Get access to the current ReportLayouter, which depends on the name.
114      * To change the ReportBuilderLayouter use <code>setReportBuilderLayouterName(String Name)</code>.
115      * @return
116      */
getReportBuilderLayouter()117     private IReportBuilderLayouter getReportBuilderLayouter()
118     {
119         return (IReportBuilderLayouter) getLayoutMap().get(m_sReportBuilderLayoutName);
120     }
121     private Object m_aReportDocument;
122     private XPropertySet m_documentDefinition;
123     private XReportDefinition m_reportDocument;
124 
125     /**
126      * initialize the Report Builder and open it representation
127      * @param _aDoc
128      * @param _xConnection
129      */
initialize(Object _aDoc)130     private void initialize(Object _aDoc)
131     {
132         m_aReportDocument = _aDoc;
133 
134         try
135         {
136             NamedValueCollection creationArgs = new NamedValueCollection();
137             creationArgs.put("DocumentServiceName", "com.sun.star.report.ReportDefinition");
138             creationArgs.put("Mode", "remote");
139 
140             XComponent[] docDefinition = new XComponent[]
141             {
142                 null
143             };
144             XComponent reportDefinitionComp = m_documentUI.createComponentWithArguments(
145                     DatabaseObject.REPORT, creationArgs.getPropertyValues(), docDefinition);
146 
147             m_documentDefinition = UnoRuntime.queryInterface(XPropertySet.class, docDefinition[0]);
148             m_reportDocument = UnoRuntime.queryInterface(XReportDefinition.class, reportDefinitionComp);
149         }
150         catch (com.sun.star.uno.Exception e)
151         {
152             ReportWizard.getLogger().log(com.sun.star.logging.LogLevel.SEVERE, "Problems with initialize the ReportDefinition" + e.getMessage());
153 
154         }
155 
156         switchOffPropertyBrowser();
157         switchOffAddFieldWindow();
158 
159         setPageOrientation(m_nDefaultPageOrientation, false /* NO_LAYOUT*/);
160     }
161 
getModeSelector()162     private XModeSelector getModeSelector()
163     {
164         final XController xController = getReportDefinition().getCurrentController();
165         return UnoRuntime.queryInterface(XModeSelector.class, xController);
166     }
167 
switchOffAddFieldWindow()168     private void switchOffAddFieldWindow()
169     {
170         try
171         {
172             getModeSelector().setMode("remote");
173         }
174         catch (com.sun.star.uno.Exception e)
175         {
176             int dummy = 0;
177         }
178     }
179 
switchOnAddFieldWindow()180     private void switchOnAddFieldWindow()
181     {
182         try
183         {
184             getModeSelector().setMode("normal");
185         }
186         catch (com.sun.star.uno.Exception e)
187         {
188             int dummy = 0;
189         }
190     }
191 
sleep(int _nSeconds)192     private void sleep(int _nSeconds)
193     {
194         try
195         {
196             Thread.sleep(_nSeconds * 1000);
197         }
198         catch (java.lang.InterruptedException e)
199         {
200         }
201 
202     }
203 
switchOffPropertyBrowser()204     private void switchOffPropertyBrowser()
205     {
206         try
207         {
208             final XController xController = getReportDefinition().getCurrentController();
209             final XDispatchProvider xDP = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
210 
211             // Create special service for parsing of given URL.
212             final Object aURLTransformer = getMSF().createInstance("com.sun.star.util.URLTransformer");
213             final XURLTransformer xURLTransformer = UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class, aURLTransformer);
214 
215             com.sun.star.util.URL[] aURL = new com.sun.star.util.URL[1];
216             aURL[0] = new com.sun.star.util.URL();
217             aURL[0].Complete = ".uno:ControlProperties";
218             xURLTransformer.parseStrict(aURL);
219 
220             final XDispatch xDispatch = xDP.queryDispatch(aURL[0], "_self", 0);
221             PropertyValue[] xEmpty = new PropertyValue[0];
222             xDispatch.dispatch(aURL[0], xEmpty);
223         }
224         catch (com.sun.star.uno.Exception e)
225         {
226             int dummy = 0;
227         }
228     }
229 
switchOnPropertyBrowser()230     private void switchOnPropertyBrowser()
231     {
232         // This is implemented with a toggle algorithm.
233         switchOffPropertyBrowser();
234     }
235 
236     /**
237      * Returns the Frame of the underlying Document
238      * @return Returns the Frame of the parent (underlying) Document
239      */
getFrame()240     public XFrame getFrame()
241     {
242         if (m_xFrame == null)
243         {
244             initialize(getRecordParser().getReportDocuments());
245             m_xFrame = getReportDefinition().getCurrentController().getFrame();
246             setPageOrientation(m_nDefaultPageOrientation, true /* NO_LAYOUT*/);
247         }
248         return m_xFrame;
249     }
250 
reconnectToDatabase(XMultiServiceFactory xMSF, PropertyValue[] Properties)251     public boolean reconnectToDatabase(XMultiServiceFactory xMSF, PropertyValue[] Properties)
252     {
253         return false;
254     }
255 
insertDatabaseDatatoReportDocument(XMultiServiceFactory xMSF)256     public void insertDatabaseDatatoReportDocument(XMultiServiceFactory xMSF)
257     {
258     }
259 
StopProcess()260     public void StopProcess()
261     {
262     }
263 
store(String Name, int OpenMode)264     public void store(String Name, int OpenMode) throws com.sun.star.uno.Exception
265     {
266         // store into the ZIP Storage
267         if (OpenMode == 1 /* static Report */)
268         {
269             // we will store later
270             return;
271         }
272 
273         final XCommandProcessor xProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, m_documentDefinition);
274         final com.sun.star.ucb.Command aCommand = new com.sun.star.ucb.Command();
275         aCommand.Name = "store";
276 
277         xProcessor.execute(aCommand, xProcessor.createCommandIdentifier(), null);
278 
279         final XHierarchicalNameContainer aNameContainer = UnoRuntime.queryInterface(XHierarchicalNameContainer.class, m_aReportDocument);
280         aNameContainer.insertByHierarchicalName(Name, m_documentDefinition);
281     }
282 
liveupdate_addGroupNametoDocument(String[] GroupNames, String CurGroupTitle, Vector GroupFieldVector, ArrayList ReportPath, int iSelCount)283     public boolean liveupdate_addGroupNametoDocument(String[] GroupNames, String CurGroupTitle, Vector GroupFieldVector, ArrayList ReportPath, int iSelCount)
284     {
285         final int GroupCount = GroupFieldVector.size();
286         if (GroupCount < MAXIMUM_GROUPCOUNT)
287         {
288             final FieldColumn CurFieldColumn = getRecordParser().getFieldColumnByTitle(CurGroupTitle);
289             GroupFieldVector.addElement(CurFieldColumn.getFieldName());
290         }
291         return true;
292     }
293 
refreshGroupFields(String[] _sNewNames)294     public void refreshGroupFields(String[] _sNewNames)
295     {
296     }
297 
liveupdate_removeGroupName(String[] NewSelGroupNames, String CurGroupTitle, Vector GroupFieldVector)298     public void liveupdate_removeGroupName(String[] NewSelGroupNames, String CurGroupTitle, Vector GroupFieldVector)
299     {
300         final FieldColumn CurFieldColumn = getRecordParser().getFieldColumnByTitle(CurGroupTitle);
301         GroupFieldVector.removeElement(CurFieldColumn.getFieldName());
302     }
303 
setPageOrientation(int nOrientation, boolean bDoLayout)304     private void setPageOrientation(int nOrientation, boolean bDoLayout)
305     {
306         getReportBuilderLayouter().setPageOrientation(nOrientation);
307         if (bDoLayout)
308         {
309             getReportBuilderLayouter().layout();
310         }
311     }
312 
setPageOrientation(int nOrientation)313     public void setPageOrientation(int nOrientation)
314     {
315         setPageOrientation(nOrientation, true);
316     }
317 
liveupdate_changeLayoutTemplate(String LayoutTemplatePath )318     public void liveupdate_changeLayoutTemplate(String LayoutTemplatePath/*, String BitmapPath*/)
319     {
320         /* Right Listbox */
321         final IReportBuilderLayouter aLayouter = getReportBuilderLayouter();
322         aLayouter.loadAndSetBackgroundTemplate(LayoutTemplatePath);
323         aLayouter.layout();
324     }
325 
326     /**
327      * Change the current Layouter by a new one with the given Name _sName.
328      * If there exist no other layouter with the given name, nothing happens, the layouter will not change to
329      * an illegal one.
330      * @param _sName Name of the other layouter.
331      */
setReportBuilderLayouterName(String _sName)332     public void setReportBuilderLayouterName(String _sName)
333     {
334         final IReportBuilderLayouter aCurrentLayouter = getReportBuilderLayouter();
335         final IReportBuilderLayouter aNewLayouter = (IReportBuilderLayouter) m_aLayoutMap.get(_sName);
336         if (aNewLayouter != null)
337         {
338             m_sReportBuilderLayoutName = _sName;
339             aNewLayouter.initializeData(aCurrentLayouter);
340             aNewLayouter.layout();
341         }
342     }
343 
liveupdate_changeContentTemplate(String ContentTemplatePath)344     public void liveupdate_changeContentTemplate(String ContentTemplatePath)
345     {
346         /* Left Listbox */
347         setReportBuilderLayouterName(ContentTemplatePath);
348     }
349 
layout_setupRecordSection(String TemplateName)350     public void layout_setupRecordSection(String TemplateName)
351     {
352     }
353 
removeTextTableAndTextSection()354     public void removeTextTableAndTextSection()
355     {
356     }
357 
layout_selectFirstPage()358     public void layout_selectFirstPage()
359     {
360     }
361 
closeReportDefinition()362     private void closeReportDefinition()
363     {
364         try
365         {
366             if (m_documentDefinition != null)
367             {
368                 // set the document to "not modified", to ensure that it won't ask the user before closing
369                 XModifiable documentModify = UnoRuntime.queryInterface(XModifiable.class, m_reportDocument);
370                 documentModify.setModified(false);
371                 // actually close
372                 XSubDocument subComponent = UnoRuntime.queryInterface(XSubDocument.class, m_documentDefinition);
373                 subComponent.close();
374             }
375         }
376         catch (Exception ex)
377         {
378             Logger.getLogger(ReportBuilderImplementation.class.getName()).log(Level.SEVERE, null, ex);
379         }
380         m_documentDefinition = null;
381         m_reportDocument = null;
382     }
383 
dispose()384     public void dispose()
385     {
386         getReportBuilderLayouter().dispose();
387         closeReportDefinition();
388     }
389 
getComponent()390     public XComponent getComponent()
391     {
392         return null;
393     }
394 
liveupdate_changeUserFieldContent(String fieldName, String titlename)395     public void liveupdate_changeUserFieldContent(String fieldName, String titlename)
396     {
397     }
398 
liveupdate_updateReportTitle(String _sTitleName)399     public void liveupdate_updateReportTitle(String _sTitleName)
400     {
401     }
402 
addReportToDBView()403     public void addReportToDBView()
404     {
405     }
406 
loadReport(final String i_reportName)407     private XComponent loadReport(final String i_reportName)
408     {
409         try
410         {
411             return m_documentUI.loadComponent(DatabaseObject.REPORT, i_reportName, false);
412         }
413         catch (Exception ex)
414         {
415             Logger.getLogger(ReportBuilderImplementation.class.getName()).log(Level.SEVERE, null, ex);
416         }
417         return null;
418     }
419 
loadReportFromDocumentDefinition()420     private XComponent loadReportFromDocumentDefinition()
421     {
422         final XCommandProcessor commandProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, m_documentDefinition);
423 
424         com.sun.star.ucb.Command aCommand = new com.sun.star.ucb.Command();
425         aCommand.Name = "open";
426         try
427         {
428             final Object result = commandProcessor.execute(aCommand, commandProcessor.createCommandIdentifier(), null);
429             return UnoRuntime.queryInterface(XComponent.class, result);
430         }
431         catch (Exception ex)
432         {
433             Logger.getLogger(ReportBuilderImplementation.class.getName()).log(Level.SEVERE, null, ex);
434         }
435         return null;
436     }
437 
createAndOpenReportDocument(String i_name, boolean i_asTemplate, boolean i_openForEditing)438     public void createAndOpenReportDocument(String i_name, boolean i_asTemplate, boolean i_openForEditing)
439     {
440         if (i_openForEditing)
441         {
442             // we won't destroy the report builder window, also don't create a document
443             // Do we need to reopen the report builder with the known name?
444             switchOnAddFieldWindow();
445             switchOnPropertyBrowser();
446             return;
447         }
448 
449         if (i_asTemplate)
450         {
451             // don't need the report definition anymore - the document it represents has already been stored
452             closeReportDefinition();
453 
454             // open the report, again, this time not in design, but containing data
455             loadReport(i_name);
456         }
457         else
458         {
459             // execute the report from the (yet unsaved) report definition
460             XComponent document = loadReportFromDocumentDefinition();
461 
462             // don't need the report definition anymore
463             closeReportDefinition();
464 
465             // store the generated report
466             if (getRecordParser().storeDatabaseDocumentToTempPath(document, i_name))
467             {
468                 getRecordParser().addReportDocument(document, false);
469             }
470         }
471 
472         dispose();
473     }
474 
getConnection()475     private XConnection getConnection()
476     {
477         return getRecordParser().DBConnection;
478     }
479 
initializeFieldColumns(final int _nType, final String TableName, final String[] FieldNames)480     public void initializeFieldColumns(final int _nType, final String TableName, final String[] FieldNames)
481     {
482         getRecordParser().initializeFieldColumns(FieldNames, TableName);
483 
484         final com.sun.star.wizards.db.RecordParser a = getRecordParser();
485         int[] FieldTypes = new int[FieldNames.length];
486         int[] FieldWidths = new int[FieldNames.length];
487         for (int i = 0; i < FieldNames.length; i++)
488         {
489             FieldTypes[i] = a.FieldColumns[i].getFieldType();
490             FieldWidths[i] = a.FieldColumns[i].getFieldWidth();
491         }
492         getReportBuilderLayouter().setTableName(_nType, TableName);
493         getReportBuilderLayouter().insertFieldNames(FieldNames);
494         getReportBuilderLayouter().insertFieldTypes(FieldTypes);
495         getReportBuilderLayouter().insertFieldWidths(FieldWidths);
496 
497         getReportBuilderLayouter().layout();
498     }
499 
setFieldTitles(String[] _aFieldTitles)500     public void setFieldTitles(String[] _aFieldTitles)
501     {
502         getRecordParser().setFieldTitles(_aFieldTitles);
503 
504         getReportBuilderLayouter().insertFieldTitles(_aFieldTitles);
505         getReportBuilderLayouter().layout();
506     }
507 
setSorting(String[][] _aSortFieldNames)508     public void setSorting(String[][] _aSortFieldNames)
509     {
510         getRecordParser().setSortFieldNames(_aSortFieldNames);
511         if (groupNames != null)
512         {
513             getRecordParser().prependSortFieldNames(groupNames);
514         }
515         getReportBuilderLayouter().insertSortingNames(_aSortFieldNames);
516         getReportBuilderLayouter().layout();
517     }
518 
setGrouping(String[] _aGroupFieldNames)519     public void setGrouping(String[] _aGroupFieldNames)
520     {
521         groupNames = _aGroupFieldNames;
522         getRecordParser().prependSortFieldNames(_aGroupFieldNames);
523 
524         getReportBuilderLayouter().insertGroupNames(_aGroupFieldNames);
525         getReportBuilderLayouter().layout();
526     }
527 
getLayoutPath()528     public String getLayoutPath()
529     {
530         return "default";
531     }
532     private ArrayList m_aReportPath;
533 
getReportPath()534     public ArrayList getReportPath()
535     {
536         if (m_aReportPath == null)
537         {
538             try
539             {
540                 // Check general availability of office paths
541                 m_aReportPath = FileAccess.getOfficePaths(getMSF(), "Template", "share", "/wizard");
542                 FileAccess.combinePaths(getMSF(), m_aReportPath, "/wizard/report");
543             }
544             catch (NoValidPathException ex)
545             {
546                 Logger.getLogger(ReportBuilderImplementation.class.getName()).log(Level.SEVERE, null, ex);
547             }
548         }
549         return m_aReportPath;
550     }
551 
getContentPath()552     public String getContentPath()
553     {
554         return PropertyNames.EMPTY_STRING;
555     }
556 
getDefaultPageOrientation()557     public int getDefaultPageOrientation()
558     {
559         return m_nDefaultPageOrientation;
560     }
561 
562     /**
563      * Helper function to get a com.sun.star.wizards.report.layout.ReportBuilderLayouter by its name
564      *
565      * @param _sClassName
566      * @return the object or null
567      */
getLayoutInstanceFrom(String _sClassName)568     private IReportBuilderLayouter getLayoutInstanceFrom(String _sClassName)
569     {
570         try
571         {
572             // TODO: Use Package.getPackages(...)
573             final Class a = Class.forName(_sClassName);
574 
575             final Constructor cTor = a.getConstructor(new Class[]
576                     {
577                         IReportDefinitionReadAccess.class, Resource.class
578                     });
579             Object[] aParams = new Object[2];
580             aParams[0] = this;
581             aParams[1] = m_resource;
582             return (IReportBuilderLayouter) cTor.newInstance(aParams);
583         }
584         catch (Exception e)
585         {
586             e.printStackTrace();
587         }
588         return null;
589     }
590     private LinkedHashMap m_aLayoutMap = null;
591 
insertIntoLayoutMap(IReportBuilderLayouter _aLayout)592     private void insertIntoLayoutMap(IReportBuilderLayouter _aLayout)
593     {
594         insertIntoLayoutMap(_aLayout, false);
595     }
596 
insertIntoLayoutMap(IReportBuilderLayouter _aLayout, boolean _bDefault)597     private void insertIntoLayoutMap(IReportBuilderLayouter _aLayout, boolean _bDefault)
598     {
599         if (_aLayout != null)
600         {
601             final String sName = _aLayout.getName();
602             if (_bDefault)
603             {
604                 m_sReportBuilderLayoutName = sName;  // here we set the default layout name!
605             }
606             m_aLayoutMap.put(sName, _aLayout);
607         }
608     }
609 
610     /**
611      * Initialize all well known com.sun.star.wizards.report.layout.ReportBuilderLayouter Objects and create exact one instance.
612      */
getLayoutMap()613     private LinkedHashMap getLayoutMap()
614     {
615         if (m_aLayoutMap == null)
616         {
617             // The LayoutMap is empty, so we create a new LinkedHashMap
618             m_aLayoutMap = new LinkedHashMap();
619 
620             // TODO: We must know the name of a layouts, There should be a way to say where to find, not the names.
621             IReportBuilderLayouter aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.Tabular");
622             insertIntoLayoutMap(aLayout, true);
623             aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.ColumnarSingleColumn");
624             insertIntoLayoutMap(aLayout);
625             aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.ColumnarTwoColumns");
626             insertIntoLayoutMap(aLayout);
627             aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.ColumnarThreeColumns");
628             insertIntoLayoutMap(aLayout);
629             aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.InBlocksLabelsAbove");
630             insertIntoLayoutMap(aLayout);
631             aLayout = getLayoutInstanceFrom("com.sun.star.wizards.reportbuilder.layout.InBlocksLabelsLeft");
632             insertIntoLayoutMap(aLayout);
633 
634         }
635         return m_aLayoutMap;
636     }
637 
638     /**
639      * Return a string array array with all found layouts
640      * At the moment these layout are hard coded
641      * @return
642      */
getDataLayout()643     public String[][] getDataLayout()
644     {
645         String[][] ContentFiles;
646         ContentFiles = new String[2][];
647         String[] a = new String[getLayoutMap().size()];
648         String[] b = new String[getLayoutMap().size()];
649 
650         // run through the whole layoutmap and
651         final Set aKeys = getLayoutMap().keySet();
652         final Iterator aKeyIterator = aKeys.iterator();
653         int i = 0;
654         while (aKeyIterator.hasNext())
655         {
656             final String sKey = (String) aKeyIterator.next();
657             a[i] = sKey;
658             final IReportBuilderLayouter aLayouter = (IReportBuilderLayouter) m_aLayoutMap.get(sKey);
659             b[i++] = aLayouter.getLocalizedName();
660         }
661 
662         ContentFiles[1] = a;
663         ContentFiles[0] = b;
664         return ContentFiles;
665     }
666     private String m_sDefaultHeaderLayoutPath;
667 
getHeaderLayout()668     public String[][] getHeaderLayout()
669     {
670         String[][] LayoutFiles;
671         try
672         {
673             // TODO: check different languages in header layouts
674             ArrayList aReportPath = FileAccess.getOfficePaths(getMSF(), "Template", "share", "/wizard");
675             FileAccess.combinePaths(getMSF(), aReportPath, "/wizard/report");
676 
677             LayoutFiles = FileAccess.getFolderTitles(getMSF(), null, aReportPath, ".otr");
678         }
679         catch (com.sun.star.wizards.common.NoValidPathException e)
680         {
681             // if there are problems, don't show anything is a little bit hard.
682             LayoutFiles = new String[2][];
683             String[] a = new String[1];
684             String[] b = new String[1];
685             a[0] = "DefaultLayoutOfHeaders";
686             b[0] = "default";
687             LayoutFiles[1] = a;
688             LayoutFiles[0] = b;
689         }
690         for (int i = 0; i < LayoutFiles[0].length; i++)
691         {
692             if (LayoutFiles[0][i].equals("default"))
693             {
694                 m_sDefaultHeaderLayoutPath = LayoutFiles[1][i];
695                 break;
696             }
697         }
698         return LayoutFiles;
699     }
700 
getReportDefinition()701     public XReportDefinition getReportDefinition()
702     {
703         if (m_reportDocument == null)
704         {
705             throw new NullPointerException("Report Definition is not already initialized, check if you too early access the report definition.");
706         }
707         return m_reportDocument;
708     }
709 
getGlobalMSF()710     public XMultiServiceFactory getGlobalMSF()
711     {
712         return getMSF();
713     }
714 
importReportData(ReportWizard aWizard)715     public void importReportData(ReportWizard aWizard)
716     {
717     }
718 
getDefaultHeaderLayout()719     public String getDefaultHeaderLayout()
720     {
721         return m_sDefaultHeaderLayoutPath;
722     }
723 
setCommand(String _sCommand)724     public void setCommand(String _sCommand)
725     {
726         getRecordParser().Command = _sCommand;
727         getReportDefinition().setCommand(_sCommand);
728     }
729 
setCommandType(int _nCommand)730     public void setCommandType(int _nCommand)
731     {
732         getReportDefinition().setCommandType(_nCommand);
733     }
734 
checkInvariants()735     public void checkInvariants() throws java.lang.Exception
736     {
737         final String sDefaultHeaderLayoutPath = getDefaultHeaderLayout();
738         if (sDefaultHeaderLayoutPath == null)
739         {
740             throw new java.io.IOException("default.otr");
741         }
742 
743         FileAccess aAccess = new FileAccess(getGlobalMSF());
744         if (!aAccess.exists(sDefaultHeaderLayoutPath, true))
745         {
746             throw new java.io.IOException("default.otr");
747         }
748     }
749 }
750