TextDocument extends Document implements ListContainer,
		ParagraphContainer, VariableContainer, ChartContainer, FormContainer,
		ControlContainer { public void insertContentFromDocumentBefore(TextDocument sourceDocument, Paragraph referenceParagraph, boolean isCopyStyle){ try { OfficeTextElement sroot = sourceDocument.getContentRoot(); NodeList clist = sroot.getChildNodes(); for (int i = 0; i < clist.getLength(); i++) { OdfElement node = (OdfElement) clist.item(i); if(isCopyStyle){ insertOdfElement(referenceParagraph.getOdfElement(), sourceDocument, node, true); } else { insertOdfElementwithoutstyle(referenceParagraph.getOdfElement(), sourceDocument, node, true); } } } catch (Exception e) { Logger.getLogger(TextDocument.class.getName()).log(Level.SEVERE, null, e); } } protected  TextDocument(OdfPackage pkg, String internalPath, TextDocument.OdfMediaType odfMediaType); static TextDocument newTextDocument(); static TextDocument newTextDocument(TextDocument.OdfMediaType mimeType); static TextDocument newTextTemplateDocument(); static TextDocument newTextMasterDocument(); static TextDocument newTextWebDocument(); static TextDocument loadDocument(InputStream inputStream); static TextDocument loadDocument(String documentPath); static TextDocument loadDocument(File file); @Override OfficeTextElement getContentRoot(); OdfTextParagraph newParagraph(String text); OdfTextParagraph newParagraph(); OdfTextParagraph addText(String text); void changeMode(OdfMediaType mediaType); Section appendSection(Section section, boolean isResourceCopied); Section appendSection(String name); Header getHeader(); Header getHeader(boolean isFirstPage); Footer getFooter(); Footer getFooter(boolean isFirstPage); OdfElement getTableContainerElement(); OdfElement getListContainerElement(); List addList(); List addList(ListDecorator decorator); void clearList(); Iterator<List> getListIterator(); boolean removeList(List list); void addPageBreak(); void addPageBreak(Paragraph refParagraph); void setPageColumns(int columnsNumber, double spacing); void addColumnBreak(); void addColumnBreak(Paragraph refParagraph); void addPageBreak(Paragraph refParagraph, MasterPage master); Paragraph addParagraph(String text); boolean removeParagraph(Paragraph para); OdfElement getParagraphContainerElement(); Paragraph getParagraphByIndex(int index, boolean isEmptyParagraphSkipped); Paragraph getParagraphByReverseIndex(int reverseIndex, boolean isEmptyParagraphSkipped); Iterator<Paragraph> getParagraphIterator(); VariableField declareVariable(String name, VariableType type); VariableField getVariableFieldByName(String name); OdfElement getVariableContainerElement(); Chart createChart(String title, DataSet dataset, Rectangle rect); Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel,
			boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect); Chart createChart(String title, String[] labels, String[] legends, double[][] data, Rectangle rect); void deleteChartById(String chartId); void deleteChartByTitle(String title); Chart getChartById(String chartId); java.util.List<Chart> getChartByTitle(String title); int getChartCount(); TextTableOfContentElement createDefaultTOC(Paragraph refParagraph, boolean before); TextTableOfContentElement createTOCwithStyle(Paragraph refParagraph,
			TOCStyle additionalStyle, boolean before); Paragraph insertParagraph(Paragraph referenceParagraph, Paragraph sourceParagraph,boolean before); Table insertTable(Paragraph referenceParagraph, Table sourceTable,boolean before); OdfElement insertOdfElement(OdfElement referenceOdfElement,Document sourceDocument ,OdfElement sourceOdfElement,boolean before); void insertContentFromDocumentAfter(TextDocument sourceDocument, Paragraph referenceParagraph, boolean isCopyStyle); void insertContentFromDocumentBefore(TextDocument sourceDocument, Paragraph referenceParagraph, boolean isCopyStyle); Form createForm(String name); Iterator<Form> getFormIterator(); boolean removeForm(Form form); Form getFormByName(String name); OfficeFormsElement getFormContainerElement(); boolean getApplyDesignMode(); boolean getAutomaticFocus(); void setApplyDesignMode(boolean isDesignMode); void setAutomaticFocus(boolean isAutoFocus); Control createDrawControl(); OdfElement getDrawControlContainerElement();  }
@Test public void testinsertContentFromDocumentBefore() throws Exception { TextDocument src1 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt")); TextDocument src2 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt")); TextDocument target1 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt")); TextDocument target2 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt")); Paragraph p1 = target1.getParagraphByIndex(2, true); target1.insertContentFromDocumentBefore(src1, p1, true); Iterable<OdfStyle> pstyles1 = target1.getStylesDom().getOfficeStyles().getStylesForFamily(OdfStyleFamily.Paragraph); Iterator<OdfStyle> ite = pstyles1.iterator(); int i=0; System.out.println("Custom Styles in TestInsertDocumentWithStyleBefore.odt"); while(ite.hasNext()){ OdfStyle odfStyle = ite.next(); String sname = odfStyle.getAttribute("style:name"); if(sname.startsWith("style")) { i++; System.out.println(sname); } } Assert.assertEquals(6, i); target1.save(ResourceUtilities.newTestOutputFile("TestInsertDocumentWithStyleBefore.odt")); target2 = TextDocument.loadDocument(ResourceUtilities.getAbsolutePath("TestInsertDocument.odt")); Paragraph p2 = target2.getParagraphByIndex(2, true); target2.insertContentFromDocumentBefore(src2, p2, false); Iterable<OdfStyle> pstyles2 = target2.getStylesDom().getOfficeStyles().getStylesForFamily(OdfStyleFamily.Paragraph); Iterator<OdfStyle> ite2 = pstyles2.iterator(); i=0; System.out.println("Custom Styles in TestInsertDocumentWithoutStyleBefore.odt"); while(ite2.hasNext()){ OdfStyle odfStyle = ite2.next(); String sname = odfStyle.getAttribute("style:name"); if(sname.startsWith("style")) { i++; System.out.println(sname); } } Assert.assertEquals(3, i); target2.save(ResourceUtilities.newTestOutputFile("TestInsertDocumentWithoutStyleBefore.odt")); }