org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart Maven / Gradle / Ivy
/*
* Copyright 2007-2008, Plutext Pty Ltd.
*
* This file is part of docx4j.
docx4j is licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.docx4j.openpackaging.parts.WordprocessingML;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.JAXBException;
import org.docx4j.TraversalUtil;
import org.docx4j.TraversalUtil.CallbackImpl;
import org.docx4j.XmlUtils;
import org.docx4j.fonts.CJKToEnglish;
import org.docx4j.fonts.RunFontSelector;
import org.docx4j.fonts.RunFontSelector.RunFontActionType;
import org.docx4j.fonts.RunFontSelector.RunFontCharacterVisitor;
import org.docx4j.jaxb.Context;
import org.docx4j.jaxb.McIgnorableNamespaceDeclarator;
import org.docx4j.model.PropertyResolver;
import org.docx4j.model.styles.StyleTree;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.Part;
import org.docx4j.openpackaging.parts.PartName;
import org.docx4j.openpackaging.parts.relationships.Namespaces;
import org.docx4j.openpackaging.parts.relationships.RelationshipsPart;
import org.docx4j.relationships.Relationship;
import org.docx4j.wml.Body;
import org.docx4j.wml.Br;
import org.docx4j.wml.CTEndnotes;
import org.docx4j.wml.CTFootnotes;
import org.docx4j.wml.Comments;
import org.docx4j.wml.ContentAccessor;
import org.docx4j.wml.Ftr;
import org.docx4j.wml.Hdr;
import org.docx4j.wml.Lvl;
import org.docx4j.wml.Numbering;
import org.docx4j.wml.P;
import org.docx4j.wml.P.Hyperlink;
import org.docx4j.wml.PPr;
import org.docx4j.wml.R;
import org.docx4j.wml.RPr;
import org.docx4j.wml.RStyle;
import org.docx4j.wml.SdtElement;
import org.docx4j.wml.SdtPr;
import org.docx4j.wml.Style;
import org.docx4j.wml.Styles;
import org.docx4j.wml.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
/**
* @author jharrop
*
*/
public class MainDocumentPart extends DocumentPart implements ContentAccessor {
private static Logger log = LoggerFactory.getLogger(MainDocumentPart.class);
public MainDocumentPart(PartName partName) throws InvalidFormatException {
super(partName);
init();
}
public MainDocumentPart() throws InvalidFormatException {
super(new PartName("/word/document.xml"));
init();
}
public void init() {
// Used if this Part is added to [Content_Types].xml
setContentType(new org.docx4j.openpackaging.contenttype.ContentType(
org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT));
/*
* From [MS-OE376]
*
* 2.1.8 Part 1 Section 11.3.10, Main Document Part
*
* a. The standard states that the content type for the Main Document part is:
*
* application/vnd.openxmlformats-officedocument.wordprocessingml.main+xml.
*
* Office uses the following content type for the Main Document part:
*
* application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml.
*
* This note applies to the following products: 2007, 2007 SP1, 2007 SP2.
*/
// Used when this Part is added to a rels
setRelationshipType(Namespaces.DOCUMENT);
}
@Override
protected void setMceIgnorable(McIgnorableNamespaceDeclarator namespacePrefixMapper) {
// NB it is up to you to jaxbElement.setIgnorable; see further McIgnorableNamespaceDeclarator
// MainDocumentPartMceIgnorableHelper helper = new MainDocumentPartMceIgnorableHelper();
// this.jaxbElement.setIgnorable(
// helper.getMceIgnorable(this.getJaxbElement().getBody()));
namespacePrefixMapper.setMcIgnorable(
this.getJaxbElement().getIgnorable() );
}
@Override
public String getMceIgnorable() {
return this.getJaxbElement().getIgnorable();
}
/**
* Convenience method to getJaxbElement().getBody().getContent()
* @since 2.7
*/
public List