@Test public void documentSplitting() throws Exception { StringBuffer buffer = new StringBuffer(); buffer.append("=Heading1=").append('\n'); buffer.append("Content").append('\n'); buffer.append("==Heading11==").append('\n'); buffer.append("Content").append('\n'); buffer.append("==Heading12==").append('\n'); buffer.append("Content").append('\n'); buffer.append("=Heading2=").append('\n'); buffer.append("Content").append('\n'); XDOM xdom = xwikiSyntaxParser.parse(new StringReader(buffer.toString())); XDOMOfficeDocument officeDocument = new XDOMOfficeDocument(xdom, new HashMap<>(), this.componentManager); final DocumentReference baseDocument = new DocumentReference("xwiki", "Test", "Test"); when(this.mockCompactWikiStringEntityReferenceSerializer.serialize(baseDocument)).thenReturn("Test.Test"); when(this.mockCompactWikiStringEntityReferenceSerializer.serialize( new DocumentReference("xwiki", "Test", "Heading1"))).thenReturn("Test.Heading1"); when(this.mockCompactWikiStringEntityReferenceSerializer.serialize( new DocumentReference("xwiki", "Test", "Heading11"))).thenReturn("Test.Heading11"); when(this.mockCompactWikiStringEntityReferenceSerializer.serialize( new DocumentReference("xwiki", "Test", "Heading12"))).thenReturn("Test.Heading12"); when(this.mockCompactWikiStringEntityReferenceSerializer.serialize( new DocumentReference("xwiki", "Test", "Heading2"))).thenReturn("Test.Heading2"); when(this.mockDocumentReferenceResolver.resolve("Test.Test")).thenReturn( new DocumentReference("xwiki", "Test", "Test")); when(this.mockDocumentReferenceResolver.resolve("Test.Heading1")).thenReturn( new DocumentReference("xwiki", "Test", "Heading1")); when(this.mockDocumentReferenceResolver.resolve("Test.Heading11")).thenReturn( new DocumentReference("xwiki", "Test", "Heading11")); when(this.mockDocumentReferenceResolver.resolve("Test.Heading12")).thenReturn( new DocumentReference("xwiki", "Test", "Heading12")); when(this.mockDocumentReferenceResolver.resolve("Test.Heading2")).thenReturn( new DocumentReference("xwiki", "Test", "Heading2")); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = this.officeDocumentSplitter.split(officeDocument, new int[] {1, 2, 3, 4, 5, 6}, "headingNames", baseDocument); assertEquals(5, result.size()); }
@Override public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException { String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>(); SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit); NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion( namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer); WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null); List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion); for (WikiDocument doc : documents) { DocumentReference targetReference = this.currentMixedDocumentReferenceResolver.resolve(doc.getFullName()); TargetDocumentDescriptor targetDocumentDescriptor = new TargetDocumentDescriptor(targetReference, this.componentManager); if (doc.getParent() != null) { DocumentReference targetParent = this.currentMixedDocumentReferenceResolver.resolve(doc.getParent().getFullName()); targetDocumentDescriptor.setParentReference(targetParent); } Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument); XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager); result.put(targetDocumentDescriptor, splitDocument); } return result; }
DefaultXDOMOfficeDocumentSplitter implements XDOMOfficeDocumentSplitter { @Override public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException { String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>(); SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit); NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion( namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer); WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null); List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion); for (WikiDocument doc : documents) { DocumentReference targetReference = this.currentMixedDocumentReferenceResolver.resolve(doc.getFullName()); TargetDocumentDescriptor targetDocumentDescriptor = new TargetDocumentDescriptor(targetReference, this.componentManager); if (doc.getParent() != null) { DocumentReference targetParent = this.currentMixedDocumentReferenceResolver.resolve(doc.getParent().getFullName()); targetDocumentDescriptor.setParentReference(targetParent); } Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument); XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager); result.put(targetDocumentDescriptor, splitDocument); } return result; } }
DefaultXDOMOfficeDocumentSplitter implements XDOMOfficeDocumentSplitter { @Override public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException { String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>(); SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit); NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion( namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer); WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null); List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion); for (WikiDocument doc : documents) { DocumentReference targetReference = this.currentMixedDocumentReferenceResolver.resolve(doc.getFullName()); TargetDocumentDescriptor targetDocumentDescriptor = new TargetDocumentDescriptor(targetReference, this.componentManager); if (doc.getParent() != null) { DocumentReference targetParent = this.currentMixedDocumentReferenceResolver.resolve(doc.getParent().getFullName()); targetDocumentDescriptor.setParentReference(targetParent); } Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument); XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager); result.put(targetDocumentDescriptor, splitDocument); } return result; }  }
DefaultXDOMOfficeDocumentSplitter implements XDOMOfficeDocumentSplitter { @Override public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException { String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>(); SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit); NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion( namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer); WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null); List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion); for (WikiDocument doc : documents) { DocumentReference targetReference = this.currentMixedDocumentReferenceResolver.resolve(doc.getFullName()); TargetDocumentDescriptor targetDocumentDescriptor = new TargetDocumentDescriptor(targetReference, this.componentManager); if (doc.getParent() != null) { DocumentReference targetParent = this.currentMixedDocumentReferenceResolver.resolve(doc.getParent().getFullName()); targetDocumentDescriptor.setParentReference(targetParent); } Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument); XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager); result.put(targetDocumentDescriptor, splitDocument); } return result; }  @Override Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument,
        int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference); }
DefaultXDOMOfficeDocumentSplitter implements XDOMOfficeDocumentSplitter { @Override public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException { String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference); Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>(); SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit); NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion( namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer); WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null); List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion); for (WikiDocument doc : documents) { DocumentReference targetReference = this.currentMixedDocumentReferenceResolver.resolve(doc.getFullName()); TargetDocumentDescriptor targetDocumentDescriptor = new TargetDocumentDescriptor(targetReference, this.componentManager); if (doc.getParent() != null) { DocumentReference targetParent = this.currentMixedDocumentReferenceResolver.resolve(doc.getParent().getFullName()); targetDocumentDescriptor.setParentReference(targetParent); } Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument); XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager); result.put(targetDocumentDescriptor, splitDocument); } return result; }  @Override Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument,
        int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference);  }