Source Code Cross Referenced for OOCalcReportDataSource.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » reportmanager » 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 » Report » jmagallanes 1.0 » com.calipso.reportgenerator.reportmanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.reportmanager;
002:
003:        import com.calipso.reportgenerator.reportcalculator.IDataSource;
004:        import com.calipso.reportgenerator.reportcalculator.Matrix;
005:        import com.calipso.reportgenerator.common.InfoException;
006:        import com.sun.star.sheet.*;
007:        import com.sun.star.uno.Exception;
008:        import com.sun.star.uno.UnoRuntime;
009:        import com.sun.star.frame.XComponentLoader;
010:        import com.sun.star.beans.PropertyValue;
011:        import com.sun.star.lang.XComponent;
012:        import com.sun.star.lang.IndexOutOfBoundsException;
013:        import com.sun.star.lang.WrappedTargetException;
014:        import com.sun.star.container.XIndexAccess;
015:        import com.sun.star.table.*;
016:        import com.sun.star.text.XText;
017:        import com.calipso.reportgenerator.common.*;
018:        import java.util.List;
019:        import java.util.ArrayList;
020:
021:        /**
022:         * Resuelve un data source desde la clanilla de cálculo de Open Office
023:         */
024:
025:        public class OOCalcReportDataSource extends ReportDataSource {
026:
027:            private OOConnectionManager connectionManager;
028:            private IDataSource dataSource;
029:            private int rowStart, columnStart, rowEnd, columnEnd;
030:
031:            public OOCalcReportDataSource(ReportSpec reportSpec,
032:                    ReportDataSourceSpec dataSourceSpec,
033:                    ReportGeneratorConfiguration managerConfiguration) {
034:                super (reportSpec, dataSourceSpec);
035:                super .setGeneratorConfiguration(managerConfiguration);
036:                connectionManager = new OOConnectionManager(
037:                        "uno:socket,host=223.255.255.147,port=8100;urp;StarOffice.ServiceManager");
038:            }
039:
040:            private void loadFromOOCalc(Matrix matrix) throws InfoException {
041:                try {
042:                    XSpreadsheetDocument xSpreadsheetDocument = loadFile();
043:                    XSpreadsheet xSheet = getWorkingSheet(xSpreadsheetDocument);
044:                    setEndPoint(xSheet);
045:                    fillDataSource(xSheet, matrix);
046:                } catch (Exception e) {
047:                    throw new InfoException(LanguageTraslator.traslate("275"),
048:                            e);
049:                }
050:            }
051:
052:            private void fillDataSource(XSpreadsheet xSheet, Matrix matrix)
053:                    throws IndexOutOfBoundsException, InfoException {
054:                XCell xCell;
055:                try {
056:                    for (int i = rowStart; i < rowEnd; i++) {
057:                        Object[] row = getRow(xSheet, i);
058:                        /*for( int j = columnStart ; j < columnEnd ; j++) {
059:                          xCell = xSheet.getCellByPosition(j, i);
060:                          XText xCellText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
061:                          row.add(xCellText.getString());
062:                        }*/
063:                        matrix.add(row);
064:                    }
065:                } catch (OutOfMemoryError e) {
066:                    throw new InfoException(LanguageTraslator.traslate("326"),
067:                            e);
068:                }
069:            }
070:
071:            private Object[] getRow(XSpreadsheet xSheet, int row)
072:                    throws IndexOutOfBoundsException, InfoException {
073:                int dimCount = getReportSpec().getDimensionsByIndex().size();
074:                int colNum = dimCount
075:                        + getReportSpec().getMetricsByIndex().size();
076:                Object[] collection = new Object[colNum];
077:                //for(int i = row.getFirstCellNum() ; i < row.getLastCellNum() ; i++) {
078:                int j = columnStart;
079:                for (int i = 0; i < (colNum); i++) {
080:                    if (i < dimCount) {
081:                        //Es dimension
082:                        ReportDimensionSpec dimension = getReportSpec()
083:                                .getDimensionFromIndex(i);
084:                        if (dimension.getCalculated()) {
085:                            collection[i] = dimension.getValue(collection,
086:                                    getReportDataSourceSpec());
087:                        } else {
088:                            XCell cell = xSheet.getCellByPosition(row, j);
089:                            XText xCellText = (XText) UnoRuntime
090:                                    .queryInterface(XText.class, cell);
091:                            Object value = xCellText.getString();
092:                            collection[i] = getValueForDimension(value,
093:                                    dimension, collection, i);
094:                            j++;
095:                        }
096:                    } else {
097:                        //Es metrica
098:                        ReportMetricSpec metric = getReportSpec()
099:                                .getMetricFromIndex(i - dimCount);
100:                        if (metric.getCalculated()) {
101:                            collection[i] = metric.getValue(collection);
102:                        } else {
103:                            XCell cell = xSheet.getCellByPosition(row, j);
104:                            XText xCellText = (XText) UnoRuntime
105:                                    .queryInterface(XText.class, cell);
106:                            Object value = xCellText.getString();
107:                            collection[i] = getValueForMetric(value, metric,
108:                                    collection, i);
109:                            j++;
110:                        }
111:                    }
112:                }
113:                return collection;
114:
115:            }
116:
117:            private XSpreadsheet getWorkingSheet(
118:                    XSpreadsheetDocument xSpreadsheetDocument)
119:                    throws IndexOutOfBoundsException, WrappedTargetException {
120:                XSpreadsheets xSheets = xSpreadsheetDocument.getSheets();
121:                XIndexAccess xSIndexAccess = (XIndexAccess) UnoRuntime
122:                        .queryInterface(XIndexAccess.class, xSheets);
123:                return (XSpreadsheet) xSIndexAccess.getByIndex(0);
124:            }
125:
126:            private void setEndPoint(XSpreadsheet xSheet)
127:                    throws IndexOutOfBoundsException {
128:                rowEnd = getEndCoordinate(xSheet, rowStart, columnStart, true);
129:                columnEnd = getEndCoordinate(xSheet, columnStart, rowStart,
130:                        false);
131:            }
132:
133:            private int getEndCoordinate(XSpreadsheet xSheet, int num1,
134:                    int num2, boolean row) throws IndexOutOfBoundsException {
135:                int point = 0;
136:                for (int i = num1;; i++) {
137:                    for (int j = num2;; j++) {
138:                        XCell xCell;
139:                        XText xCellText;
140:                        if (row) {
141:                            xCell = xSheet.getCellByPosition(i, j);
142:                            xCellText = (XText) UnoRuntime.queryInterface(
143:                                    XText.class, xCell);
144:                        } else {
145:                            xCell = xSheet.getCellByPosition(j, i);
146:                            xCellText = (XText) UnoRuntime.queryInterface(
147:                                    XText.class, xCell);
148:                        }
149:                        if (xCellText.getString().equals("")) {
150:                            point = j;
151:                            break;
152:                        }
153:                    }
154:                    break;
155:                }
156:                return point;
157:            }
158:
159:            private XSpreadsheetDocument loadFile() throws InfoException {
160:                try {
161:                    Object desktop = connectionManager.getConnection()
162:                            .getServiceManager().createInstanceWithContext(
163:                                    "com.sun.star.frame.Desktop",
164:                                    connectionManager.getConnection());
165:                    XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime
166:                            .queryInterface(XComponentLoader.class, desktop);
167:                    PropertyValue[] loadProps = new PropertyValue[1];
168:                    loadProps[0] = new PropertyValue();
169:                    loadProps[0].Name = "Hidden";
170:                    loadProps[0].Value = new Boolean(true);
171:                    XComponent xComponent = xComponentLoader
172:                            .loadComponentFromURL(
173:                                    "file:///sourcefiles/datasources/VENTAS_CLIENTES.sxc",
174:                                    "_blank", 0, loadProps);
175:                    XSpreadsheetDocument spreadsheetDocument = (XSpreadsheetDocument) UnoRuntime
176:                            .queryInterface(XSpreadsheetDocument.class,
177:                                    xComponent);
178:                    return spreadsheetDocument;
179:                } catch (Exception e) {
180:                    throw new InfoException(LanguageTraslator.traslate("274"),
181:                            e);
182:                }
183:            }
184:
185:            public IDataSource getDataSource(Matrix matrix)
186:                    throws InfoException {
187:                //if (dataSource == null) {
188:                //dataSource = newDataSource();
189:                loadFromOOCalc(matrix);
190:                //}
191:                return dataSource;
192:            }
193:
194:            public int getFilterVarMode() {
195:                return ReportFilterBuilder.VARMODE_DATAINDEX;
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.