mirror of https://github.com/apache/poi.git
make some section properties public to prevent access from converters using reflection
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147390 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7aeab59f46
commit
f20bdfe9d5
|
@ -21,7 +21,6 @@ import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFDocumentCore;
|
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||||
|
@ -32,8 +31,6 @@ import org.apache.poi.hwpf.model.ListTables;
|
||||||
import org.apache.poi.hwpf.usermodel.BorderCode;
|
import org.apache.poi.hwpf.usermodel.BorderCode;
|
||||||
import org.apache.poi.hwpf.usermodel.Paragraph;
|
import org.apache.poi.hwpf.usermodel.Paragraph;
|
||||||
import org.apache.poi.hwpf.usermodel.Range;
|
import org.apache.poi.hwpf.usermodel.Range;
|
||||||
import org.apache.poi.hwpf.usermodel.Section;
|
|
||||||
import org.apache.poi.hwpf.usermodel.SectionProperties;
|
|
||||||
import org.apache.poi.hwpf.usermodel.TableIterator;
|
import org.apache.poi.hwpf.usermodel.TableIterator;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
@ -239,20 +236,6 @@ public class AbstractWordUtils
|
||||||
return String.valueOf( number );
|
return String.valueOf( number );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SectionProperties getSectionProperties( Section section )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Field field = Section.class.getDeclaredField( "_props" );
|
|
||||||
field.setAccessible( true );
|
|
||||||
return (SectionProperties) field.get( section );
|
|
||||||
}
|
|
||||||
catch ( Exception exc )
|
|
||||||
{
|
|
||||||
throw new Error( exc );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isEmpty( String str )
|
static boolean isEmpty( String str )
|
||||||
{
|
{
|
||||||
return str == null || str.length() == 0;
|
return str == null || str.length() == 0;
|
||||||
|
|
|
@ -27,17 +27,15 @@ import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
|
|
||||||
|
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
import org.apache.poi.hpsf.SummaryInformation;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFDocumentCore;
|
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||||
|
import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
|
||||||
import org.apache.poi.hwpf.usermodel.CharacterRun;
|
import org.apache.poi.hwpf.usermodel.CharacterRun;
|
||||||
import org.apache.poi.hwpf.usermodel.Paragraph;
|
import org.apache.poi.hwpf.usermodel.Paragraph;
|
||||||
import org.apache.poi.hwpf.usermodel.Picture;
|
import org.apache.poi.hwpf.usermodel.Picture;
|
||||||
import org.apache.poi.hwpf.usermodel.Range;
|
import org.apache.poi.hwpf.usermodel.Range;
|
||||||
import org.apache.poi.hwpf.usermodel.Section;
|
import org.apache.poi.hwpf.usermodel.Section;
|
||||||
import org.apache.poi.hwpf.usermodel.SectionProperties;
|
|
||||||
import org.apache.poi.hwpf.usermodel.Table;
|
import org.apache.poi.hwpf.usermodel.Table;
|
||||||
import org.apache.poi.hwpf.usermodel.TableCell;
|
import org.apache.poi.hwpf.usermodel.TableCell;
|
||||||
import org.apache.poi.hwpf.usermodel.TableRow;
|
import org.apache.poi.hwpf.usermodel.TableRow;
|
||||||
|
@ -146,18 +144,21 @@ public class WordToFoConverter extends AbstractWordConverter
|
||||||
this.foDocumentFacade = new FoDocumentFacade( document );
|
this.foDocumentFacade = new FoDocumentFacade( document );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createPageMaster( SectionProperties sep, String type,
|
protected String createPageMaster( Section section, String type,
|
||||||
int section )
|
int sectionIndex )
|
||||||
{
|
{
|
||||||
float height = sep.getYaPage() / WordToFoUtils.TWIPS_PER_INCH;
|
float height = section.getPageHeight() / WordToFoUtils.TWIPS_PER_INCH;
|
||||||
float width = sep.getXaPage() / WordToFoUtils.TWIPS_PER_INCH;
|
float width = section.getPageWidth() / WordToFoUtils.TWIPS_PER_INCH;
|
||||||
float leftMargin = sep.getDxaLeft() / WordToFoUtils.TWIPS_PER_INCH;
|
float leftMargin = section.getMarginLeft()
|
||||||
float rightMargin = sep.getDxaRight() / WordToFoUtils.TWIPS_PER_INCH;
|
/ WordToFoUtils.TWIPS_PER_INCH;
|
||||||
float topMargin = sep.getDyaTop() / WordToFoUtils.TWIPS_PER_INCH;
|
float rightMargin = section.getMarginRight()
|
||||||
float bottomMargin = sep.getDyaBottom() / WordToFoUtils.TWIPS_PER_INCH;
|
/ WordToFoUtils.TWIPS_PER_INCH;
|
||||||
|
float topMargin = section.getMarginTop() / WordToFoUtils.TWIPS_PER_INCH;
|
||||||
|
float bottomMargin = section.getMarginBottom()
|
||||||
|
/ WordToFoUtils.TWIPS_PER_INCH;
|
||||||
|
|
||||||
// add these to the header
|
// add these to the header
|
||||||
String pageMasterName = type + "-page" + section;
|
String pageMasterName = type + "-page" + sectionIndex;
|
||||||
|
|
||||||
Element pageMaster = foDocumentFacade
|
Element pageMaster = foDocumentFacade
|
||||||
.addSimplePageMaster( pageMasterName );
|
.addSimplePageMaster( pageMasterName );
|
||||||
|
@ -178,15 +179,15 @@ public class WordToFoConverter extends AbstractWordConverter
|
||||||
// WordToFoUtils.setBorder(regionBody, sep.getBrcLeft(), "left");
|
// WordToFoUtils.setBorder(regionBody, sep.getBrcLeft(), "left");
|
||||||
// WordToFoUtils.setBorder(regionBody, sep.getBrcRight(), "right");
|
// WordToFoUtils.setBorder(regionBody, sep.getBrcRight(), "right");
|
||||||
|
|
||||||
if ( sep.getCcolM1() > 0 )
|
if ( section.getNumColumns() > 1 )
|
||||||
{
|
{
|
||||||
regionBody.setAttribute( "column-count", ""
|
regionBody.setAttribute( "column-count",
|
||||||
+ ( sep.getCcolM1() + 1 ) );
|
"" + ( section.getNumColumns() ) );
|
||||||
if ( sep.getFEvenlySpaced() )
|
if ( section.isColumnsEvenlySpaced() )
|
||||||
{
|
{
|
||||||
regionBody.setAttribute( "column-gap",
|
float distance = section.getDistanceBetweenColumns()
|
||||||
( sep.getDxaColumns() / WordToFoUtils.TWIPS_PER_INCH )
|
/ WordToFoUtils.TWIPS_PER_INCH;
|
||||||
+ "in" );
|
regionBody.setAttribute( "column-gap", distance + "in" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -376,9 +377,7 @@ public class WordToFoConverter extends AbstractWordConverter
|
||||||
protected void processSection( HWPFDocumentCore wordDocument,
|
protected void processSection( HWPFDocumentCore wordDocument,
|
||||||
Section section, int sectionCounter )
|
Section section, int sectionCounter )
|
||||||
{
|
{
|
||||||
String regularPage = createPageMaster(
|
String regularPage = createPageMaster( section, "page", sectionCounter );
|
||||||
WordToFoUtils.getSectionProperties( section ), "page",
|
|
||||||
sectionCounter );
|
|
||||||
|
|
||||||
Element pageSequence = foDocumentFacade.addPageSequence( regularPage );
|
Element pageSequence = foDocumentFacade.addPageSequence( regularPage );
|
||||||
Element flow = foDocumentFacade.addFlowToPageSequence( pageSequence,
|
Element flow = foDocumentFacade.addFlowToPageSequence( pageSequence,
|
||||||
|
|
|
@ -27,17 +27,15 @@ import javax.xml.transform.TransformerFactory;
|
||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
|
|
||||||
|
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
import org.apache.poi.hpsf.SummaryInformation;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFDocumentCore;
|
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||||
|
import org.apache.poi.hwpf.converter.FontReplacer.Triplet;
|
||||||
import org.apache.poi.hwpf.usermodel.CharacterRun;
|
import org.apache.poi.hwpf.usermodel.CharacterRun;
|
||||||
import org.apache.poi.hwpf.usermodel.Paragraph;
|
import org.apache.poi.hwpf.usermodel.Paragraph;
|
||||||
import org.apache.poi.hwpf.usermodel.Picture;
|
import org.apache.poi.hwpf.usermodel.Picture;
|
||||||
import org.apache.poi.hwpf.usermodel.Range;
|
import org.apache.poi.hwpf.usermodel.Range;
|
||||||
import org.apache.poi.hwpf.usermodel.Section;
|
import org.apache.poi.hwpf.usermodel.Section;
|
||||||
import org.apache.poi.hwpf.usermodel.SectionProperties;
|
|
||||||
import org.apache.poi.hwpf.usermodel.Table;
|
import org.apache.poi.hwpf.usermodel.Table;
|
||||||
import org.apache.poi.hwpf.usermodel.TableCell;
|
import org.apache.poi.hwpf.usermodel.TableCell;
|
||||||
import org.apache.poi.hwpf.usermodel.TableRow;
|
import org.apache.poi.hwpf.usermodel.TableRow;
|
||||||
|
@ -82,23 +80,22 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||||
|
|
||||||
private static String getSectionStyle( Section section )
|
private static String getSectionStyle( Section section )
|
||||||
{
|
{
|
||||||
SectionProperties sep = WordToHtmlUtils.getSectionProperties( section );
|
float leftMargin = section.getMarginLeft() / TWIPS_PER_INCH;
|
||||||
|
float rightMargin = section.getMarginRight() / TWIPS_PER_INCH;
|
||||||
float leftMargin = sep.getDxaLeft() / TWIPS_PER_INCH;
|
float topMargin = section.getMarginTop() / TWIPS_PER_INCH;
|
||||||
float rightMargin = sep.getDxaRight() / TWIPS_PER_INCH;
|
float bottomMargin = section.getMarginBottom() / TWIPS_PER_INCH;
|
||||||
float topMargin = sep.getDyaTop() / TWIPS_PER_INCH;
|
|
||||||
float bottomMargin = sep.getDyaBottom() / TWIPS_PER_INCH;
|
|
||||||
|
|
||||||
String style = "margin: " + topMargin + "in " + rightMargin + "in "
|
String style = "margin: " + topMargin + "in " + rightMargin + "in "
|
||||||
+ bottomMargin + "in " + leftMargin + "in; ";
|
+ bottomMargin + "in " + leftMargin + "in; ";
|
||||||
|
|
||||||
if ( sep.getCcolM1() > 0 )
|
if ( section.getNumColumns() > 1 )
|
||||||
{
|
{
|
||||||
style += "column-count: " + ( sep.getCcolM1() + 1 ) + "; ";
|
style += "column-count: " + ( section.getNumColumns() ) + "; ";
|
||||||
if ( sep.getFEvenlySpaced() )
|
if ( section.isColumnsEvenlySpaced() )
|
||||||
{
|
{
|
||||||
style += "column-gap: "
|
float distance = section.getDistanceBetweenColumns()
|
||||||
+ ( sep.getDxaColumns() / TWIPS_PER_INCH ) + "in; ";
|
/ TWIPS_PER_INCH;
|
||||||
|
style += "column-gap: " + distance + "in; ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,11 +43,63 @@ public final class Section extends Range
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return distance to be maintained between columns, in twips. Used when
|
||||||
|
* {@link #isColumnsEvenlySpaced()} == true
|
||||||
|
*/
|
||||||
|
public int getDistanceBetweenColumns()
|
||||||
|
{
|
||||||
|
return _props.getDxaColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMarginBottom()
|
||||||
|
{
|
||||||
|
return _props.getDyaBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMarginLeft()
|
||||||
|
{
|
||||||
|
return _props.getDxaLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMarginRight()
|
||||||
|
{
|
||||||
|
return _props.getDxaRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMarginTop()
|
||||||
|
{
|
||||||
|
return _props.getDyaTop();
|
||||||
|
}
|
||||||
|
|
||||||
public int getNumColumns()
|
public int getNumColumns()
|
||||||
{
|
{
|
||||||
return _props.getCcolM1() + 1;
|
return _props.getCcolM1() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return page height (in twips) in current section. Default value is 15840
|
||||||
|
* twips
|
||||||
|
*/
|
||||||
|
public int getPageHeight()
|
||||||
|
{
|
||||||
|
return _props.getYaPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return page width (in twips) in current section. Default value is 12240
|
||||||
|
* twips
|
||||||
|
*/
|
||||||
|
public int getPageWidth()
|
||||||
|
{
|
||||||
|
return _props.getXaPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isColumnsEvenlySpaced()
|
||||||
|
{
|
||||||
|
return _props.getFEvenlySpaced();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue