| 1 | package pro.verron.officestamper.utils.openpackaging; | |
| 2 | ||
| 3 | import org.docx4j.openpackaging.exceptions.Docx4JException; | |
| 4 | import org.docx4j.openpackaging.packages.PresentationMLPackage; | |
| 5 | import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | |
| 6 | import pro.verron.officestamper.utils.UtilsException; | |
| 7 | ||
| 8 | import java.io.InputStream; | |
| 9 | import java.io.OutputStream; | |
| 10 | ||
| 11 | /// Utility class for working with Open Packaging documents. This class provides methods to load and export Word | |
| 12 | /// documents using DOCX4J | |
| 13 | public class OpenpackagingUtils { | |
| 14 | private OpenpackagingUtils() { | |
| 15 | throw new UtilsException("Utility class shouldn't be instantiated"); | |
| 16 | } | |
| 17 | ||
| 18 | /// Loads a Word document from the provided input stream. | |
| 19 | /// | |
| 20 | /// @param is the input stream containing the Word document data | |
| 21 | /// | |
| 22 | /// @return a WordprocessingMLPackage representing the loaded document | |
| 23 | /// | |
| 24 | /// @throws UtilsException if there is an error loading the document | |
| 25 | public static WordprocessingMLPackage loadWord(InputStream is) { | |
| 26 | try { | |
| 27 |
1
1. loadWord : replaced return value with null for pro/verron/officestamper/utils/openpackaging/OpenpackagingUtils::loadWord → NO_COVERAGE |
return WordprocessingMLPackage.load(is); |
| 28 | } catch (Docx4JException e) { | |
| 29 | throw new UtilsException(e); | |
| 30 | } | |
| 31 | } | |
| 32 | ||
| 33 | /// Exports a Word document to the provided output stream. | |
| 34 | /// | |
| 35 | /// @param wordprocessingMLPackage the Word document to export | |
| 36 | /// @param os the output stream to write the document to | |
| 37 | /// | |
| 38 | /// @throws UtilsException if there is an error exporting the document | |
| 39 | public static void exportWord(WordprocessingMLPackage wordprocessingMLPackage, OutputStream os) { | |
| 40 | try { | |
| 41 |
1
1. exportWord : removed call to org/docx4j/openpackaging/packages/WordprocessingMLPackage::save → NO_COVERAGE |
wordprocessingMLPackage.save(os); |
| 42 | } catch (Docx4JException e) { | |
| 43 | throw new UtilsException(e); | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | ||
| 48 | /// Loads a PowerPoint document from the provided input stream. | |
| 49 | /// | |
| 50 | /// @param is the input stream containing the PowerPoint document data | |
| 51 | /// | |
| 52 | /// @return a PresentationMLPackage representing the loaded document | |
| 53 | /// | |
| 54 | /// @throws UtilsException if there is an error loading the document | |
| 55 | public static PresentationMLPackage loadPowerPoint(InputStream is) { | |
| 56 | try { | |
| 57 |
1
1. loadPowerPoint : replaced return value with null for pro/verron/officestamper/utils/openpackaging/OpenpackagingUtils::loadPowerPoint → NO_COVERAGE |
return PresentationMLPackage.load(is); |
| 58 | } catch (Docx4JException e) { | |
| 59 | throw new UtilsException(e); | |
| 60 | } | |
| 61 | } | |
| 62 | ||
| 63 | ||
| 64 | /// Exports a PowerPoint document to the provided output stream. | |
| 65 | /// | |
| 66 | /// @param presentationMLPackage the PowerPoint document to export | |
| 67 | /// @param os the output stream to write the document to | |
| 68 | /// | |
| 69 | /// @throws UtilsException if there is an error exporting the document | |
| 70 | public static void exportPowerPoint(PresentationMLPackage presentationMLPackage, OutputStream os) { | |
| 71 | try { | |
| 72 |
1
1. exportPowerPoint : removed call to org/docx4j/openpackaging/packages/PresentationMLPackage::save → NO_COVERAGE |
presentationMLPackage.save(os); |
| 73 | } catch (Docx4JException e) { | |
| 74 | throw new UtilsException(e); | |
| 75 | } | |
| 76 | } | |
| 77 | } | |
Mutations | ||
| 27 |
1.1 |
|
| 41 |
1.1 |
|
| 57 |
1.1 |
|
| 72 |
1.1 |