use of org.xwiki.refactoring.splitter.criterion.HeadingLevelSplittingCriterion in project xwiki-platform by xwiki.
the class DefaultXDOMOfficeDocumentSplitter method split.
@Override
public Map<TargetDocumentDescriptor, XDOMOfficeDocument> split(XDOMOfficeDocument officeDocument, int[] headingLevelsToSplit, String namingCriterionHint, DocumentReference baseDocumentReference) throws OfficeImporterException {
// TODO: This code needs to be refactored along with the xwiki-refactoring module code.
String strBaseDoc = this.entityReferenceSerializer.serialize(baseDocumentReference);
Map<TargetDocumentDescriptor, XDOMOfficeDocument> result = new HashMap<TargetDocumentDescriptor, XDOMOfficeDocument>();
// Create splitting and naming criterion for refactoring.
SplittingCriterion splittingCriterion = new HeadingLevelSplittingCriterion(headingLevelsToSplit);
NamingCriterion namingCriterion = DocumentSplitterUtils.getNamingCriterion(namingCriterionHint, strBaseDoc, this.docBridge, this.plainTextRenderer);
// Create the root document required by refactoring module.
WikiDocument rootDoc = new WikiDocument(strBaseDoc, officeDocument.getContentDocument(), null);
List<WikiDocument> documents = this.documentSplitter.split(rootDoc, splittingCriterion, namingCriterion);
for (WikiDocument doc : documents) {
// Initialize a target page descriptor.
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);
}
// Rewire artifacts.
Map<String, byte[]> artifacts = DocumentSplitterUtils.relocateArtifacts(doc, officeDocument);
// Create the resulting XDOMOfficeDocument.
XDOMOfficeDocument splitDocument = new XDOMOfficeDocument(doc.getXdom(), artifacts, this.componentManager);
result.put(targetDocumentDescriptor, splitDocument);
}
return result;
}
Aggregations