org.docx4j.toc.switches.TSwitch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j Show documentation
Show all versions of docx4j Show documentation
docx4j is a library which helps you to work with the Office Open
XML file format as used in docx
documents, pptx presentations, and xlsx spreadsheets.
/*
* Copyright 2013, Plutext Pty Ltd.
*
* This file is part of the Commercial Edition of docx4j,
* which is licensed under the Plutext Commercial License (the "License");
* you may not use this file except in compliance with the License.
*
* In particular, this source code is CONFIDENTIAL, and you must ensure it
* stays that way.
*
* You may obtain a copy of the License at
*
* http://www.plutext.com/license/Plutext_Commercial_License.pdf
*
* 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.toc.switches;
import java.util.Map;
import org.docx4j.Docx4jProperties;
import org.docx4j.toc.TocEntry;
import org.docx4j.wml.Style;
/**
* Uses paragraphs formatted with (or based on) styles other than the built-in heading styles.
* text in this switch's field-argument specifies those styles as a set of comma-separated doublets,
* with each doublet being a comma-separated set of style name and table of content level.
* \t can be combined with \o.
*
*/
public class TSwitch extends AbstractSwitch{
public static final String ID = "\\t";
private static final int PRIORITY = 9;
private static final String DOCX4J_FIELDS_TOC_SWITCH_T_SEPARATOR = "docx4j.Fields.TOC.SwitchT.Separator";
private static final String COMMA = ",";
@Override
public void process(Style s, SwitchProcessor sp) {
if(sp.isStyleFound()){
return;
}
TocEntry te = sp.getEntry();
Map styleLevelMap = getStyleLevelMap();
for(String styleMapValue: styleLevelMap.keySet()){
if( sp.styleBasedOnHelper.isBasedOn(s, styleMapValue)){
te.setEntryLevel(styleLevelMap.get(styleMapValue));
sp.setStyleFound(true);
break;
}
}
}
@Override
public boolean isStyleSwitch() {
return true;
}
@Override
public String parseFieldArgument(String fieldArgument) {
this.fieldArgument = fieldArgument;
tSwitchSeparator = Docx4jProperties.getProperty(DOCX4J_FIELDS_TOC_SWITCH_T_SEPARATOR, COMMA);
return EMPTY;
}
@Override
public boolean hasFieldArgument() {
return true;
}
@Override
public int getPriority() {
return PRIORITY;
}
}