Search in sources :

Example 1 with HeadingLevelSplittingCriterion

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;
}
Also used : TargetDocumentDescriptor(org.xwiki.officeimporter.splitter.TargetDocumentDescriptor) HashMap(java.util.HashMap) NamingCriterion(org.xwiki.refactoring.splitter.criterion.naming.NamingCriterion) WikiDocument(org.xwiki.refactoring.WikiDocument) HeadingLevelSplittingCriterion(org.xwiki.refactoring.splitter.criterion.HeadingLevelSplittingCriterion) XDOMOfficeDocument(org.xwiki.officeimporter.document.XDOMOfficeDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) HeadingLevelSplittingCriterion(org.xwiki.refactoring.splitter.criterion.HeadingLevelSplittingCriterion) SplittingCriterion(org.xwiki.refactoring.splitter.criterion.SplittingCriterion)

Aggregations

HashMap (java.util.HashMap)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 XDOMOfficeDocument (org.xwiki.officeimporter.document.XDOMOfficeDocument)1 TargetDocumentDescriptor (org.xwiki.officeimporter.splitter.TargetDocumentDescriptor)1 WikiDocument (org.xwiki.refactoring.WikiDocument)1 HeadingLevelSplittingCriterion (org.xwiki.refactoring.splitter.criterion.HeadingLevelSplittingCriterion)1 SplittingCriterion (org.xwiki.refactoring.splitter.criterion.SplittingCriterion)1 NamingCriterion (org.xwiki.refactoring.splitter.criterion.naming.NamingCriterion)1