orcs works
This commit is contained in:
parent
d04fb61ae3
commit
89ac1761d2
2 changed files with 43 additions and 40 deletions
|
@ -2,7 +2,7 @@ package writer2latex.xhtml;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import javax.swing.text.Element;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -16,17 +16,17 @@ import writer2latex.util.Misc;
|
||||||
public class GreenstoneTags {
|
public class GreenstoneTags {
|
||||||
|
|
||||||
private static LinkedList<Integer> headerStack = new LinkedList<Integer>();
|
private static LinkedList<Integer> headerStack = new LinkedList<Integer>();
|
||||||
private static boolean pageSection = false;
|
private static boolean pageSectionOpened = false;
|
||||||
//headings none
|
//headings none
|
||||||
private static String headingTags = "headings";
|
private static String headingTags = "headings";
|
||||||
//sections div none
|
//sections div none
|
||||||
private static String pageTags = "sections";
|
private static String pageTags = "sections";
|
||||||
|
|
||||||
protected static void processHeading(Node currentNode, Node hnode, int pageNum) {
|
protected static Node processHeading(Node currentNode, Node hnode, int pageNum) {
|
||||||
|
|
||||||
//if (tags.equals("none") || tags.equals("pages")){
|
|
||||||
if (headingTags.equals("none") || pageTags.equals("section")){
|
if (headingTags.equals("none")){
|
||||||
return;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
String sLevel = Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL);
|
String sLevel = Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL);
|
||||||
|
@ -34,9 +34,9 @@ public class GreenstoneTags {
|
||||||
if (sLevel != null && !sLevel.isEmpty()) {
|
if (sLevel != null && !sLevel.isEmpty()) {
|
||||||
int nLevel = Integer.parseInt(sLevel);
|
int nLevel = Integer.parseInt(sLevel);
|
||||||
// Close page section if opened
|
// Close page section if opened
|
||||||
if (pageSection) {
|
if (pageSectionOpened) {
|
||||||
closeSection(hnode);
|
closeSection(hnode);
|
||||||
pageSection = false;
|
pageSectionOpened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeHeadingSections(hnode, nLevel);
|
closeHeadingSections(hnode, nLevel);
|
||||||
|
@ -58,17 +58,17 @@ public class GreenstoneTags {
|
||||||
&& headingTags.equals("headings-pages")
|
&& headingTags.equals("headings-pages")
|
||||||
) {
|
) {
|
||||||
//Open page section
|
//Open page section
|
||||||
openSection(hnode, pageNum);
|
openPageSection(hnode, pageNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
return hnode;
|
||||||
}
|
}
|
||||||
protected static void processPageBreak(Node currentNode, Node hnode, Integer pageNum){
|
protected static Node processPageBreak(Node currentNode, Node hnode, Integer pageNum){
|
||||||
|
|
||||||
if (headingTags.equals("none") || headingTags.equals("headings")){
|
if (headingTags.equals("none") || headingTags.equals("headings")){
|
||||||
return;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !( currentNode.getNodeType() == Node.ELEMENT_NODE
|
if ( !( currentNode.getNodeType() == Node.ELEMENT_NODE
|
||||||
|
@ -79,45 +79,47 @@ public class GreenstoneTags {
|
||||||
&& !headerStack.isEmpty()
|
&& !headerStack.isEmpty()
|
||||||
|| pageTags.equals("sections")
|
|| pageTags.equals("sections")
|
||||||
) {
|
) {
|
||||||
if (pageSection) {
|
if (pageSectionOpened) {
|
||||||
closeSection(hnode);
|
closeSection(hnode);
|
||||||
pageSection = false;
|
pageSectionOpened = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (pageNum != null) {
|
if (pageNum != null) {
|
||||||
openSection(hnode, pageNum);
|
openPageSection(hnode, pageNum);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return hnode;
|
||||||
}
|
}
|
||||||
//Method to open main document tag
|
//Method to open main document tag
|
||||||
protected static void StartDocument(Node hnode, String title, String heading, String pages, int pageNum){
|
protected static Node StartDocument(Node hnode, String title, String heading, String pages, int pageNum){
|
||||||
headingTags = heading;
|
headingTags = heading;
|
||||||
pageTags = pages;
|
pageTags = pages;
|
||||||
if (headingTags.equals("none")){
|
if (headingTags.equals("none")){
|
||||||
return;
|
return hnode;
|
||||||
}
|
}
|
||||||
//Create main document section
|
//Create main document section
|
||||||
openSection(hnode, title);
|
openSection(hnode, title);
|
||||||
if (pageTags.equals("sections")){
|
if (pageTags.equals("sections")){
|
||||||
//Open page section
|
//Open page section
|
||||||
openSection(hnode, pageNum);
|
openPageSection(hnode, pageNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hnode;
|
||||||
}
|
}
|
||||||
//Method to close open tags at the end of the document
|
//Method to close open tags at the end of the document
|
||||||
protected static void endDocument(Node hnode){
|
protected static Node endDocument(Node hnode){
|
||||||
if (headingTags.equals("none")){
|
if (headingTags.equals("none")){
|
||||||
return;
|
return hnode;
|
||||||
}
|
}
|
||||||
if (pageSection){
|
if (pageSectionOpened){
|
||||||
closeSection(hnode);
|
closeSection(hnode);
|
||||||
pageSection = false;
|
pageSectionOpened = false;
|
||||||
}
|
}
|
||||||
closeSection(hnode);
|
closeSection(hnode);
|
||||||
//Clean stack, close all sections
|
//Clean stack, close all sections
|
||||||
closeHeadingSections(hnode, 0);
|
closeHeadingSections(hnode, 0);
|
||||||
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTitle(Node currentNode) {
|
private static String getTitle(Node currentNode) {
|
||||||
|
@ -146,14 +148,14 @@ public class GreenstoneTags {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void openSection(Node hnode, Integer pageNum){
|
private static void openPageSection(Node hnode, Integer pageNum){
|
||||||
Document doc = hnode.getOwnerDocument();
|
Document doc = hnode.getOwnerDocument();
|
||||||
String commentText = "<Section>\n<Description>\n<Metadata name=\"Title\">" + pageNum
|
String commentText = "<Section>\n<Description>\n<Metadata name=\"Title\">" + pageNum
|
||||||
+ "</Metadata>\n<Metadata name=\"Page\">" + pageNum + "</Metadata>\n</Description>";
|
+ "</Metadata>\n<Metadata name=\"Page\">" + pageNum + "</Metadata>\n</Description>";
|
||||||
Node openSection = doc.createComment(commentText);
|
Node openSection = doc.createComment(commentText);
|
||||||
// insert open section comment before header node
|
// insert open section comment before header node
|
||||||
hnode.appendChild(openSection);
|
hnode.appendChild(openSection);
|
||||||
pageSection = true;
|
pageSectionOpened = true;
|
||||||
}
|
}
|
||||||
private static void openSection(Node hnode, String title){
|
private static void openSection(Node hnode, String title){
|
||||||
Document doc = hnode.getOwnerDocument();
|
Document doc = hnode.getOwnerDocument();
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
footCv.insertFootnotes(hnode,true);
|
footCv.insertFootnotes(hnode,true);
|
||||||
addFooter(hnode);
|
addFooter(hnode);
|
||||||
endCv.insertEndnotes(hnode);
|
endCv.insertEndnotes(hnode);
|
||||||
GreenstoneTags.endDocument(hnode);
|
hnode = (Element) GreenstoneTags.endDocument(hnode);
|
||||||
// Generate all indexes
|
// Generate all indexes
|
||||||
bInToc = true;
|
bInToc = true;
|
||||||
tocCv.generate();
|
tocCv.generate();
|
||||||
|
@ -214,7 +214,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(XMLString.TEXT_P)) {
|
else if (nodeName.equals(XMLString.TEXT_P)) {
|
||||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
||||||
breakBeforeNextNode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
hnode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
||||||
hnode = maybeSplit(hnode, style);
|
hnode = maybeSplit(hnode, style);
|
||||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||||
// is there a block element, we should use?
|
// is there a block element, we should use?
|
||||||
|
@ -263,8 +263,8 @@ public class TextConverter extends ConverterHelper {
|
||||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME));
|
||||||
int nOutlineLevel = getOutlineLevel((Element)child);
|
int nOutlineLevel = getOutlineLevel((Element)child);
|
||||||
Node rememberNode = hnode;
|
Node rememberNode = hnode;
|
||||||
breakBeforeNextNode = processPageBreaks(child, hnode, style, breakBeforeNextNode);
|
hnode = processPageBreaks(child, hnode, style, breakBeforeNextNode);
|
||||||
GreenstoneTags.processHeading(child, hnode, pageNum);
|
hnode = GreenstoneTags.processHeading(child, hnode, pageNum);
|
||||||
hnode = maybeSplit(hnode,style,nOutlineLevel);
|
hnode = maybeSplit(hnode,style,nOutlineLevel);
|
||||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||||
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
|
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
|
||||||
|
@ -273,7 +273,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
nodeName.equals(XMLString.TEXT_UNORDERED_LIST) || // old
|
nodeName.equals(XMLString.TEXT_UNORDERED_LIST) || // old
|
||||||
nodeName.equals(XMLString.TEXT_ORDERED_LIST)) // old
|
nodeName.equals(XMLString.TEXT_ORDERED_LIST)) // old
|
||||||
{
|
{
|
||||||
breakBeforeNextNode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
hnode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||||
hnode = maybeSplit(hnode,null);
|
hnode = maybeSplit(hnode,null);
|
||||||
if (listIsOnlyHeadings(child)) {
|
if (listIsOnlyHeadings(child)) {
|
||||||
nDontSplitLevel--;
|
nDontSplitLevel--;
|
||||||
|
@ -286,7 +286,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(XMLString.TABLE_TABLE)) {
|
else if (nodeName.equals(XMLString.TABLE_TABLE)) {
|
||||||
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TABLE_STYLE_NAME));
|
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, XMLString.TABLE_STYLE_NAME));
|
||||||
breakBeforeNextNode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
hnode = processPageBreaks(child, hnode,style, breakBeforeNextNode);
|
||||||
hnode = maybeSplit(hnode,style);
|
hnode = maybeSplit(hnode,style);
|
||||||
getTableCv().handleTable(child,hnode);
|
getTableCv().handleTable(child,hnode);
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
getTableCv().handleTable(child,hnode);
|
getTableCv().handleTable(child,hnode);
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(XMLString.TEXT_SECTION)) {
|
else if (nodeName.equals(XMLString.TEXT_SECTION)) {
|
||||||
breakBeforeNextNode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
hnode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||||
hnode = maybeSplit(hnode,null);
|
hnode = maybeSplit(hnode,null);
|
||||||
nDontSplitLevel--;
|
nDontSplitLevel--;
|
||||||
hnode = handleSection(child,hnode);
|
hnode = handleSection(child,hnode);
|
||||||
|
@ -1549,7 +1549,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1):
|
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1):
|
||||||
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_LEVEL),1);
|
Misc.getPosInteger(node.getAttribute(XMLString.TEXT_LEVEL),1);
|
||||||
}
|
}
|
||||||
private boolean processPageBreaks(Node currentNode, Node hnode,StyleWithProperties style, boolean breakBeforeNextNode){
|
private Node processPageBreaks(Node currentNode, Node hnode,StyleWithProperties style, boolean breakBeforeNextNode){
|
||||||
Integer newPageNumber = null;
|
Integer newPageNumber = null;
|
||||||
if (style != null) {
|
if (style != null) {
|
||||||
// If style:paragraph-properties extists and contain
|
// If style:paragraph-properties extists and contain
|
||||||
|
@ -1583,7 +1583,7 @@ public class TextConverter extends ConverterHelper {
|
||||||
|
|
||||||
//Start tagging
|
//Start tagging
|
||||||
String sTitle = converter.getTitle();
|
String sTitle = converter.getTitle();
|
||||||
GreenstoneTags.StartDocument(hnode, sTitle,headingTags,pageTags, pageNum);
|
hnode = GreenstoneTags.StartDocument(hnode, sTitle,headingTags,pageTags, pageNum);
|
||||||
|
|
||||||
//Print header
|
//Print header
|
||||||
addHeader(hnode);
|
addHeader(hnode);
|
||||||
|
@ -1609,20 +1609,21 @@ public class TextConverter extends ConverterHelper {
|
||||||
fitPageNumberToMasterPageStyle();
|
fitPageNumberToMasterPageStyle();
|
||||||
}
|
}
|
||||||
//if
|
//if
|
||||||
GreenstoneTags.processPageBreak(currentNode, hnode, pageNum);
|
hnode = GreenstoneTags.processPageBreak(currentNode, hnode, pageNum);
|
||||||
//Print new header
|
//Print new header
|
||||||
addHeader(hnode);
|
addHeader(hnode);
|
||||||
//breakBeforeNextNode = false;
|
breakBeforeNextNode = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (checkHardBreakAfter(style)) {
|
if (checkHardBreakAfter(style)) {
|
||||||
|
|
||||||
//breakBeforeNextNode = true;
|
breakBeforeNextNode = true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
breakBeforeNextNode = false;
|
||||||
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fitPageNumberToMasterPageStyle() {
|
private void fitPageNumberToMasterPageStyle() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue