You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2015/04/18 21:25:17 UTC
svn commit: r1674568 - in /directory/studio/trunk/plugins/ldapbrowser.core:
pom-first.xml
src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java
Author: seelmann
Date: Sat Apr 18 19:25:17 2015
New Revision: 1674568
URL: http://svn.apache.org/r1674568
Log:
Fix ODF export, use simple-odf from Apache ODF Toolkit (incubating) project (DIRSTUDIO-1006)
Modified:
directory/studio/trunk/plugins/ldapbrowser.core/pom-first.xml
directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java
Modified: directory/studio/trunk/plugins/ldapbrowser.core/pom-first.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.core/pom-first.xml?rev=1674568&r1=1674567&r2=1674568&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.core/pom-first.xml (original)
+++ directory/studio/trunk/plugins/ldapbrowser.core/pom-first.xml Sat Apr 18 19:25:17 2015
@@ -45,6 +45,19 @@
<plugins>
<!-- Embedded artifacts -->
<plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>.</directory>
+ <includes>
+ <include>lib/**</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
@@ -62,6 +75,26 @@
<artifactId>poi</artifactId>
<version>3.9</version>
</artifactItem>
+ <artifactItem>
+ <groupId>org.apache.odftoolkit</groupId>
+ <artifactId>simple-odf</artifactId>
+ <version>0.7-incubating</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.odftoolkit</groupId>
+ <artifactId>odfdom-java</artifactId>
+ <version>0.8.8-incubating</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.11.0</version>
+ </artifactItem>
+ <artifactItem>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>1.4.01</version>
+ </artifactItem>
</artifactItems>
</configuration>
</execution>
@@ -119,7 +152,11 @@
<Embed-Directory>lib</Embed-Directory>
<Embedded-Artifacts>lib/poi-3.9.jar;g="org.apache.poi";a="poi";v="3.9"</Embedded-Artifacts>
<Bundle-ClassPath>.,
- lib/poi-3.9.jar</Bundle-ClassPath>
+ lib/poi-3.9.jar,
+ lib/xercesImpl-2.11.0.jar,
+ lib/xml-apis-1.4.01.jar,
+ lib/odfdom-java-0.8.8-incubating.jar,
+ lib/simple-odf-0.7-incubating.jar</Bundle-ClassPath>
</instructions>
</configuration>
<executions>
Modified: directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java?rev=1674568&r1=1674567&r2=1674568&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java (original)
+++ directory/studio/trunk/plugins/ldapbrowser.core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/ExportOdfRunnable.java Sat Apr 18 19:25:17 2015
@@ -42,16 +42,11 @@ import org.apache.directory.studio.ldapb
import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
import org.apache.directory.studio.ldifparser.model.container.LdifContentRecord;
import org.eclipse.core.runtime.Preferences;
-/*
-import org.openoffice.odf.doc.OdfFileDom;
-import org.openoffice.odf.doc.OdfSpreadsheetDocument;
-import org.openoffice.odf.doc.element.table.OdfTable;
-import org.openoffice.odf.doc.element.table.OdfTableCell;
-import org.openoffice.odf.doc.element.table.OdfTableRow;
-import org.openoffice.odf.dom.OdfNamespace;
-import org.openoffice.odf.dom.type.office.OdfValueType;
-*/
-import org.w3c.dom.Element;
+import org.odftoolkit.odfdom.type.ValueType;
+import org.odftoolkit.simple.SpreadsheetDocument;
+import org.odftoolkit.simple.table.Cell;
+import org.odftoolkit.simple.table.Row;
+import org.odftoolkit.simple.table.Table;
/**
@@ -138,7 +133,6 @@ public class ExportOdfRunnable implement
*/
public void run( StudioProgressMonitor monitor )
{
- /*
monitor.beginTask( BrowserCoreMessages.jobs__export_odf_task, 2 );
monitor.reportProgress( " " ); //$NON-NLS-1$
monitor.worked( 1 );
@@ -150,35 +144,24 @@ public class ExportOdfRunnable implement
// export
try
{
- OdfSpreadsheetDocument doc = OdfSpreadsheetDocument.createSpreadsheetDocument();
- OdfFileDom contentDoc = doc.getContentDom();
+ SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
// Remove the default table added in construction
- Element spreadsheetElement = ( Element ) contentDoc.getElementsByTagNameNS( OdfNamespace.OFFICE.getUri(),
- "spreadsheet" ).item( 0 ); //$NON-NLS-1$
- OdfTable table = ( OdfTable ) ( spreadsheetElement.getElementsByTagNameNS( OdfNamespace.TABLE.getUri(),
- "table" ).item( 0 ) ); //$NON-NLS-1$
- table.getParentNode().removeChild( table );
+ doc.removeSheet( 0 );
// create the table
- table = new OdfTable( contentDoc );
- table.setName( "Export" ); //$NON-NLS-1$
- Element officeSpreadsheet = ( Element ) contentDoc.getElementsByTagNameNS( OdfNamespace.OFFICE.getUri(),
- "spreadsheet" ).item( 0 ); //$NON-NLS-1$
- officeSpreadsheet.appendChild( table );
+ Table table = doc.appendSheet( "Export" ); //$NON-NLS-1$
// header
- OdfTableRow headerRow = new OdfTableRow( contentDoc );
- table.appendChild( headerRow );
+ Row headerRow = table.appendRow();
LinkedHashMap<String, Short> attributeNameMap = new LinkedHashMap<String, Short>();
if ( this.exportDn )
{
- // short cellNum = ( short ) 0;
- //attributeNameMap.put( "dn", new Short( cellNum ) ); //$NON-NLS-1$
- OdfTableCell cell = new OdfTableCell( contentDoc );
- cell.setValueType( OdfValueType.STRING );
+ short cellNum = ( short ) 0;
+ attributeNameMap.put( "dn", new Short( cellNum ) ); //$NON-NLS-1$
+ Cell cell = headerRow.getCellByIndex( cellNum );
+ cell.setValueType( ValueType.STRING.name() );
cell.setStringValue( "dn" ); //$NON-NLS-1$
- headerRow.appendCell( cell );
}
// max export
@@ -188,16 +171,18 @@ public class ExportOdfRunnable implement
}
int count = 0;
- exportToOdf( browserConnection, searchParameter, contentDoc, table, headerRow, count, monitor,
+ exportToOdf( browserConnection, searchParameter, table, headerRow, count, monitor,
attributeNameMap, valueDelimiter, binaryEncoding, this.exportDn );
+ // remove default rows
+ table.removeRowsByIndex( 0, 2 );
+
doc.save( exportOdfFilename );
}
catch ( Exception e )
{
monitor.reportError( e );
}
- */
}
@@ -206,7 +191,6 @@ public class ExportOdfRunnable implement
*
* @param browserConnection the browser connection
* @param searchParameter the search parameter
- * @param contentDoc the document
* @param table the table
* @param headerRow the header row
* @param count the count
@@ -218,9 +202,8 @@ public class ExportOdfRunnable implement
*
* @throws IOException Signals that an I/O exception has occurred.
*/
-/*
private static void exportToOdf( IBrowserConnection browserConnection, SearchParameter searchParameter,
- OdfFileDom contentDoc, OdfTable table, OdfTableRow headerRow, int count, StudioProgressMonitor monitor,
+ Table table, Row headerRow, int count, StudioProgressMonitor monitor,
LinkedHashMap<String, Short> attributeNameMap, String valueDelimiter, int binaryEncoding, boolean exportDn )
throws IOException
{
@@ -234,7 +217,7 @@ public class ExportOdfRunnable implement
if ( container instanceof LdifContentRecord )
{
LdifContentRecord record = ( LdifContentRecord ) container;
- recordToOdfRow( browserConnection, record, contentDoc, table, headerRow, attributeNameMap,
+ recordToOdfRow( browserConnection, record, table, headerRow, attributeNameMap,
valueDelimiter, binaryEncoding, exportDn );
count++;
@@ -262,7 +245,6 @@ public class ExportOdfRunnable implement
monitor.reportError( e );
}
}
-*/
/**
@@ -270,7 +252,6 @@ public class ExportOdfRunnable implement
*
* @param browserConnection the browser connection
* @param record the record
- * @param contentDoc the document
* @param table the table
* @param headerRow the header row
* @param headerRowAttributeNameMap the header row attribute name map
@@ -278,9 +259,8 @@ public class ExportOdfRunnable implement
* @param binaryEncoding the binary encoding
* @param exportDn the export dn
*/
-/*
private static void recordToOdfRow( IBrowserConnection browserConnection, LdifContentRecord record,
- OdfFileDom contentDoc, OdfTable table, OdfTableRow headerRow, Map<String, Short> headerRowAttributeNameMap,
+ Table table, Row headerRow, Map<String, Short> headerRowAttributeNameMap,
String valueDelimiter, int binaryEncoding, boolean exportDn )
{
// group multi-valued attributes
@@ -288,44 +268,37 @@ public class ExportOdfRunnable implement
binaryEncoding );
// output attributes
- OdfTableRow row = new OdfTableRow( contentDoc );
- table.appendChild( row );
+ Row row = table.appendRow();
if ( exportDn )
{
- OdfTableCell cell = new OdfTableCell( contentDoc );
- cell.setValueType( OdfValueType.STRING );
+ Cell cell = row.getCellByIndex( 0 );
+ cell.setValueType( ValueType.STRING.name() );
cell.setStringValue( record.getDnLine().getValueAsString() );
- row.appendCell( cell );
-
}
for ( String attributeName : attributeMap.keySet() )
{
+ String value = attributeMap.get( attributeName );
+ if ( value == null )
+ {
+ value = ""; //$NON-NLS-1$
+ }
if ( !headerRowAttributeNameMap.containsKey( attributeName ) )
{
short cellNum = ( short ) headerRowAttributeNameMap.size();
headerRowAttributeNameMap.put( attributeName, new Short( cellNum ) );
-
- OdfTableCell cell = new OdfTableCell( contentDoc );
- cell.setValueType( OdfValueType.STRING );
+ Cell cell = headerRow.getCellByIndex( cellNum );
+ cell.setValueType( ValueType.STRING.name() );
cell.setStringValue( attributeName );
- headerRow.appendCell( cell );
}
-
- }
- for ( String attributeName : headerRowAttributeNameMap.keySet() )
- {
- String value = attributeMap.get( attributeName );
- if ( value == null )
+ if ( headerRowAttributeNameMap.containsKey( attributeName ) )
{
- value = ""; //$NON-NLS-1$
+ short cellNum = headerRowAttributeNameMap.get( attributeName ).shortValue();
+ Cell cell = row.getCellByIndex( cellNum );
+ cell.setValueType( ValueType.STRING.name() );
+ cell.setStringValue( value );
}
- OdfTableCell cell = new OdfTableCell( contentDoc );
- cell.setValueType( OdfValueType.STRING );
- cell.setStringValue( value );
- row.appendCell( cell );
}
}
-*/
}