Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
     Licensed to Plutext Pty Ltd under one or more contributor license agreements.  
     
   *  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.convert.out.common;
 
 import java.util.Set;
 
This class manages the preprocessing functionality for the conversion.
It contains two methods that get called from the conversions:
  • process: does the preprocessing and returns an OpcPackage or a WordprocessingMLPackage
  • createSections: generates the sections depending on the selected features
 
 public class Preprocess implements ConversionFeatures {
 	
 	private static Logger log = LoggerFactory.getLogger(Preprocess.class);		


This method applies those features in the preprocessing, that may be used with an OpcPackage.
Features processed:
  • PP_COMMON_DEEP_COPY

Parameters:
opcPackage, the package that should be preprocessed
features, the selected features
Returns:
a preprocessed OpcPackage
Throws:
org.docx4j.openpackaging.exceptions.Docx4JException
 
 	public static OpcPackage process(OpcPackage opcPackageSet<Stringfeaturesthrows Docx4JException {
 	OpcPackage  ret = opcPackage;
 	Set<StringrelationshipTypes = null;
 		checkParams(opcPackagefeatures);
 		relationshipTypes = createRelationshipTypes(features);
 		if (features.contains()) {
 			ret = PartialDeepCopy.process(opcPackagerelationshipTypes);
 			if (opcPackage instanceof WordprocessingMLPackage) {
 				.debug("Results of PP_COMMON_DEEP_COPY: " + ((WordprocessingMLPackage)opcPackage).getMainDocumentPart().getXML());
 			}
 		}
 		return ret;
 	}

Check what parts might be changed by the preprocessing, those parts need to be deep copied.

Parameters:
features, the selected features
Returns:
the affected parts
 
 	protected static Set<StringcreateRelationshipTypes(Set<Stringfeatures) {
 	Set<StringrelationshipTypes = new TreeSet<String>();
 		if (features.contains() || 
 			relationshipTypes.add(.);
 			relationshipTypes.add(.);
 			relationshipTypes.add(.);
 			//those are probably not affected but get visited by the 
 			//default TraversalUtil.
 			relationshipTypes.add(.);
 			relationshipTypes.add(.);
 			relationshipTypes.add(.);
 		}
			relationshipTypes.add(.);
		}
		return relationshipTypes;
	}

This method applies those features in the preprocessing, that may be used with an WordprocessingMLPackage. As the WordprocessingMLPackage is a OpcPackage it will call process(OpcPackage).
Features processed:
  • PP_COMMON_MOVE_BOOKMARKS
  • PP_COMMON_MOVE_PAGEBREAK
  • PP_COMMON_CONTAINERIZATION
  • PP_COMMON_COMBINE_FIELDS
  • PP_APACHEFOP_DISABLE_PAGEBREAK_FIRST_PARAGRAPH

Parameters:
wmlPackage, the package that should be preprocessed
features, the selected features
Returns:
a preprocessed WordprocessingMLPackage
Throws:
org.docx4j.openpackaging.exceptions.Docx4JException
	public static WordprocessingMLPackage process(WordprocessingMLPackage wmlPackageSet<Stringfeaturesthrows Docx4JException {
			.debug("PP_COMMON_COMBINE_FIELDS");
			FieldsCombiner.process(ret);
		}
			.debug("PP_COMMON_MOVE_BOOKMARKS");
			BookmarkMover.process(ret);
		}
			.debug("PP_COMMON_MOVE_PAGEBREAK");
			PageBreak.process(ret);
		}
			.debug("PP_COMMON_CONTAINERIZATION");
			Containerization.process(ret);
		}
			.debug("PP_APACHEFOP_DISABLE_PAGEBREAK_FIRST_PARAGRAPH");
			DisablePageBreakOnFirstParagraph.process(ret);
		}
		.debug("Results of preprocessing: " + wmlPackage.getMainDocumentPart().getXML());
		return ret;
	}

This method creates the Sections for the conversion. The type of the created sections depend on the selected features.
Features processed:
  • PP_COMMON_PAGE_NUMBERING
  • PP_COMMON_DUMMY_PAGE_NUMBERING
  • PP_COMMON_CREATE_SECTIONS
  • PP_COMMON_DUMMY_CREATE_SECTIONS

Parameters:
wmlPackage, the package that should be preprocessed
features, the selected features
Returns:
the created sections
Throws:
org.docx4j.openpackaging.exceptions.Docx4JException
	public static ConversionSectionWrappers createWrappers(WordprocessingMLPackage wmlPackageSet<Stringfeatures)  throws Docx4JException {
	boolean dummySections = false;
	boolean dummyPageNumbering = false;
		checkParams(wmlPackagefeatures);
		dummySections = !features.contains();
		dummyPageNumbering = !features.contains();
		ret = ConversionSectionWrapperFactory.process(wmlPackagedummySectionsdummyPageNumbering);
		return ret;
	}

Check the package and requested features and append defaults if necessary

Parameters:
opcPackage
features
	protected static void checkParams(OpcPackage opcPackageSet<Stringfeatures) {
		if (opcPackage == null) {
			throw new IllegalArgumentException("The passed opcPackage is null.");
		}
		if (features == null) {
			throw new IllegalArgumentException("The set of the features is null.");
		}
		//PP_COMMON_DEEP_COPY, isn' required, no check
		//PP_COMMON_MOVE_BOOKMARKS, isn' required, no check
		//PP_COMMON_CONTAINERIZATION, isn' required, no check
		//PP_COMMON_COMBINE_FIELDS is required if PP_COMMON_PAGE_NUMBERING is selected
		}
		//either PP_COMMON_PAGE_NUMBERING or PP_COMMON_DUMMY_PAGE_NUMBERING (Default) is required
		}
		//either PP_COMMON_CREATE_SECTIONS or PP_COMMON_DUMMY_CREATE_SECTIONS (Default) is required
		}
	}
New to GrepCode? Check out our FAQ X