Skip to content
Permalink
Browse files

Create a PageSelectorFilter for Draw document (odg)

  • Loading branch information...
sbraconnier committed Apr 17, 2019
1 parent a9b2314 commit b013a6e56dd0f271f65b53bbcdc1d9783ac216d5
Showing with 744 additions and 23 deletions.
  1. +38 −3 jodconverter-local/src/integTest/java/org/jodconverter/filter/PageCounterFilterITest.java
  2. +61 −0 jodconverter-local/src/integTest/java/org/jodconverter/filter/draw/PageSelectorFilterITest.java
  3. +1 −2 ...erter-local/src/integTest/java/org/jodconverter/filter/{ → text}/DocumentInserterFilterITest.java
  4. +1 −2 ...verter-local/src/integTest/java/org/jodconverter/filter/{ → text}/GraphicInserterFilterITest.java
  5. +1 −2 ...r-local/src/integTest/java/org/jodconverter/filter/{ → text}/LinkedImagesEmbedderFilterITest.java
  6. +1 −2 jodconverter-local/src/integTest/java/org/jodconverter/filter/{ → text}/PageMarginsFilterITest.java
  7. +1 −2 jodconverter-local/src/integTest/java/org/jodconverter/filter/{ → text}/PageSelectorFilterITest.java
  8. +1 −2 ...-local/src/integTest/java/org/jodconverter/filter/{ → text}/TableOfContentUpdaterFilterITest.java
  9. +1 −3 jodconverter-local/src/integTest/java/org/jodconverter/filter/{ → text}/TextInserterFilterITest.java
  10. +1 −2 jodconverter-local/src/integTest/java/org/jodconverter/filter/{ → text}/TextReplacerFilterITest.java
  11. +105 −0 jodconverter-local/src/integTest/java/org/jodconverter/office/utils/CalcITest.java
  12. +159 −0 jodconverter-local/src/integTest/java/org/jodconverter/office/utils/DrawITest.java
  13. +2 −2 jodconverter-local/src/integTest/java/org/jodconverter/office/utils/WriteITest.java
  14. BIN jodconverter-local/src/integTest/resources/documents/test_multi_page.odg
  15. +85 −0 jodconverter-local/src/main/java/org/jodconverter/filter/PageCounterFilter.java
  16. +97 −0 jodconverter-local/src/main/java/org/jodconverter/filter/draw/PageSelectorFilter.java
  17. +6 −1 jodconverter-local/src/main/java/org/jodconverter/filter/text/PageCounterFilter.java
  18. +63 −0 jodconverter-local/src/main/java/org/jodconverter/office/utils/Calc.java
  19. +56 −0 jodconverter-local/src/main/java/org/jodconverter/office/utils/Draw.java
  20. +32 −0 jodconverter-local/src/test/java/org/jodconverter/office/utils/CalcTest.java
  21. +32 −0 jodconverter-local/src/test/java/org/jodconverter/office/utils/DrawTest.java
@@ -31,7 +31,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.PageCounterFilter;
import org.jodconverter.filter.text.PageSelectorFilter;

public class PageCounterFilterITest extends AbstractOfficeITest {
@@ -41,6 +40,40 @@

@ClassRule public static TemporaryFolder testFolder = new TemporaryFolder();

/**
* Test the conversion of a document, choosing a specific page.
*
* @throws Exception if an error occurs.
*/
@Test
public void doFilterWithDeprecated_SelectPage2BetweenCounter_ShouldCount3Then1()
throws Exception {

final File targetFile = new File(testFolder.getRoot(), SOURCE_FILENAME + ".page2.txt");

final org.jodconverter.filter.text.PageCounterFilter countFilter1 =
new org.jodconverter.filter.text.PageCounterFilter();
final PageSelectorFilter selectorFilter = new PageSelectorFilter(2);
final org.jodconverter.filter.text.PageCounterFilter countFilter2 =
new org.jodconverter.filter.text.PageCounterFilter();

// Test the filter
LocalConverter.builder()
.filterChain(countFilter1, selectorFilter, countFilter2)
.build()
.convert(SOURCE_FILE)
.to(targetFile)
.execute();

final String content = FileUtils.readFileToString(targetFile, Charset.forName("UTF-8"));
assertThat(content)
.contains("Test document Page 2")
.doesNotContain("Test document Page 1")
.doesNotContain("Test document Page 3");
assertThat(countFilter1.getPageCount()).isEqualTo(3);
assertThat(countFilter2.getPageCount()).isEqualTo(1);
}

/**
* Test the conversion of a document, choosing a specific page.
*
@@ -51,9 +84,11 @@ public void doFilter_SelectPage2BetweenCounter_ShouldCount3Then1() throws Except

final File targetFile = new File(testFolder.getRoot(), SOURCE_FILENAME + ".page2.txt");

final PageCounterFilter countFilter1 = new PageCounterFilter();
final org.jodconverter.filter.PageCounterFilter countFilter1 =
new org.jodconverter.filter.PageCounterFilter();
final PageSelectorFilter selectorFilter = new PageSelectorFilter(2);
final PageCounterFilter countFilter2 = new PageCounterFilter();
final org.jodconverter.filter.PageCounterFilter countFilter2 =
new org.jodconverter.filter.PageCounterFilter();

// Test the filter
LocalConverter.builder()
@@ -0,0 +1,61 @@
/*
* Copyright 2004 - 2012 Mirko Nasato and contributors
* 2016 - 2018 Simon Braconnier and contributors
*
* This file is part of JODConverter - Java OpenDocument Converter.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jodconverter.filter.draw;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;

import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.PageCounterFilter;

public class PageSelectorFilterITest extends AbstractOfficeITest {

private static final String SOURCE_FILENAME = "test_multi_page.odg";
private static final File SOURCE_FILE = new File(DOCUMENTS_DIR, SOURCE_FILENAME);

@ClassRule public static TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void doFilter_SelectPage2_ShouldConvertOnlyPage2() throws Exception {

final File targetFile = new File(testFolder.getRoot(), SOURCE_FILENAME + ".page2.odg");

// Create the PageSelectorFilter to test.
final PageSelectorFilter selectorFilter = new PageSelectorFilter(2);
final PageCounterFilter countFilter = new PageCounterFilter();

// Test the filter

LocalConverter.builder()
.filterChain(selectorFilter, countFilter)
.build()
.convert(SOURCE_FILE)
.to(targetFile)
.execute();

assertThat(countFilter.getPageCount()).isEqualTo(1);
}
}
@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.assertj.core.api.Assertions.assertThat;

@@ -31,7 +31,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.DocumentInserterFilter;

public class DocumentInserterFilterITest extends AbstractOfficeITest {

@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import java.io.File;
import java.util.Map;
@@ -28,7 +28,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.GraphicInserterFilter;
import org.jodconverter.office.OfficeException;

public class GraphicInserterFilterITest extends AbstractOfficeITest {
@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.assertj.core.api.Assertions.assertThatCode;

@@ -29,7 +29,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.LinkedImagesEmbedderFilter;
import org.jodconverter.office.OfficeException;

public class LinkedImagesEmbedderFilterITest extends AbstractOfficeITest {
@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.junit.Assert.fail;

@@ -29,7 +29,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.PageMarginsFilter;
import org.jodconverter.office.OfficeException;

public class PageMarginsFilterITest extends AbstractOfficeITest {
@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.assertj.core.api.Assertions.assertThat;

@@ -31,7 +31,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.PageSelectorFilter;

public class PageSelectorFilterITest extends AbstractOfficeITest {

@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.assertj.core.api.Assertions.assertThat;

@@ -31,7 +31,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.TableOfContentUpdaterFilter;

public class TableOfContentUpdaterFilterITest extends AbstractOfficeITest {

@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import java.io.File;
import java.util.Map;
@@ -28,8 +28,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.GraphicInserterFilter;
import org.jodconverter.filter.text.TextInserterFilter;

public class TextInserterFilterITest extends AbstractOfficeITest {

@@ -17,7 +17,7 @@
* limitations under the License.
*/

package org.jodconverter.filter;
package org.jodconverter.filter.text;

import static org.assertj.core.api.Assertions.assertThat;

@@ -32,7 +32,6 @@

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.text.TextReplacerFilter;

public class TextReplacerFilterITest extends AbstractOfficeITest {

@@ -0,0 +1,105 @@
/*
* Copyright 2004 - 2012 Mirko Nasato and contributors
* 2016 - 2018 Simon Braconnier and contributors
*
* This file is part of JODConverter - Java OpenDocument Converter.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jodconverter.office.utils;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.sun.star.lang.XComponent;

import org.jodconverter.AbstractOfficeITest;
import org.jodconverter.LocalConverter;
import org.jodconverter.filter.Filter;
import org.jodconverter.filter.FilterChain;
import org.jodconverter.office.OfficeContext;

public class CalcITest extends AbstractOfficeITest {

@ClassRule public static TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void isCalcAndGetCalcDoc_WithCalcDocument_NoExceptionThrown() {

final Filter filter =
new Filter() {
@Override
public void doFilter(
final OfficeContext context, final XComponent document, final FilterChain chain)
throws Exception {

assertThat(Calc.isCalc(document)).isTrue();
assertThat(Calc.getCalcDoc(null)).isNull();
assertThat(Calc.getCalcDoc(document)).isNotNull();
}
};

final File outputFile = new File(testFolder.getRoot(), "out.pdf");
FileUtils.deleteQuietly(outputFile);

assertThatCode(
() -> {
LocalConverter.builder()
.filterChain(filter)
.build()
.convert(new File(DOCUMENTS_DIR + "test.ods"))
.to(outputFile)
.execute();
})
.doesNotThrowAnyException();
}

@Test
public void isNotCalcAndGetCalcDoc_WithTextDocument_NoExceptionThrown() {

final Filter filter =
new Filter() {
@Override
public void doFilter(
final OfficeContext context, final XComponent document, final FilterChain chain)
throws Exception {

assertThat(Calc.isCalc(document)).isFalse();
assertThat(Calc.getCalcDoc(null)).isNull();
assertThat(Calc.getCalcDoc(document)).isNull();
}
};

final File outputFile = new File(testFolder.getRoot(), "out.pdf");
FileUtils.deleteQuietly(outputFile);

assertThatCode(
() -> {
LocalConverter.builder()
.filterChain(filter)
.build()
.convert(new File(DOCUMENTS_DIR + "test.odt"))
.to(outputFile)
.execute();
})
.doesNotThrowAnyException();
}
}

0 comments on commit b013a6e

Please sign in to comment.
You can’t perform that action at this time.