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 javax.swing.text.Element;
|
||||
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
@ -16,17 +16,17 @@ import writer2latex.util.Misc;
|
|||
public class GreenstoneTags {
|
||||
|
||||
private static LinkedList<Integer> headerStack = new LinkedList<Integer>();
|
||||
private static boolean pageSection = false;
|
||||
private static boolean pageSectionOpened = false;
|
||||
//headings none
|
||||
private static String headingTags = "headings";
|
||||
//sections div none
|
||||
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")){
|
||||
return;
|
||||
|
||||
if (headingTags.equals("none")){
|
||||
return hnode;
|
||||
}
|
||||
|
||||
String sLevel = Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL);
|
||||
|
@ -34,9 +34,9 @@ public class GreenstoneTags {
|
|||
if (sLevel != null && !sLevel.isEmpty()) {
|
||||
int nLevel = Integer.parseInt(sLevel);
|
||||
// Close page section if opened
|
||||
if (pageSection) {
|
||||
if (pageSectionOpened) {
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
pageSectionOpened = false;
|
||||
}
|
||||
|
||||
closeHeadingSections(hnode, nLevel);
|
||||
|
@ -58,17 +58,17 @@ public class GreenstoneTags {
|
|||
&& headingTags.equals("headings-pages")
|
||||
) {
|
||||
//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")){
|
||||
return;
|
||||
return hnode;
|
||||
}
|
||||
|
||||
if ( !( currentNode.getNodeType() == Node.ELEMENT_NODE
|
||||
|
@ -79,45 +79,47 @@ public class GreenstoneTags {
|
|||
&& !headerStack.isEmpty()
|
||||
|| pageTags.equals("sections")
|
||||
) {
|
||||
if (pageSection) {
|
||||
if (pageSectionOpened) {
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
pageSectionOpened = false;
|
||||
|
||||
}
|
||||
if (pageNum != null) {
|
||||
openSection(hnode, pageNum);
|
||||
openPageSection(hnode, pageNum);
|
||||
|
||||
}
|
||||
}
|
||||
return hnode;
|
||||
}
|
||||
//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;
|
||||
pageTags = pages;
|
||||
if (headingTags.equals("none")){
|
||||
return;
|
||||
return hnode;
|
||||
}
|
||||
//Create main document section
|
||||
openSection(hnode, title);
|
||||
if (pageTags.equals("sections")){
|
||||
//Open page section
|
||||
openSection(hnode, pageNum);
|
||||
openPageSection(hnode, pageNum);
|
||||
}
|
||||
|
||||
|
||||
return hnode;
|
||||
}
|
||||
//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")){
|
||||
return;
|
||||
return hnode;
|
||||
}
|
||||
if (pageSection){
|
||||
if (pageSectionOpened){
|
||||
closeSection(hnode);
|
||||
pageSection = false;
|
||||
pageSectionOpened = false;
|
||||
}
|
||||
closeSection(hnode);
|
||||
//Clean stack, close all sections
|
||||
closeHeadingSections(hnode, 0);
|
||||
return hnode;
|
||||
}
|
||||
|
||||
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();
|
||||
String commentText = "<Section>\n<Description>\n<Metadata name=\"Title\">" + pageNum
|
||||
+ "</Metadata>\n<Metadata name=\"Page\">" + pageNum + "</Metadata>\n</Description>";
|
||||
Node openSection = doc.createComment(commentText);
|
||||
// insert open section comment before header node
|
||||
hnode.appendChild(openSection);
|
||||
pageSection = true;
|
||||
pageSectionOpened = true;
|
||||
}
|
||||
private static void openSection(Node hnode, String title){
|
||||
Document doc = hnode.getOwnerDocument();
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TextConverter extends ConverterHelper {
|
|||
footCv.insertFootnotes(hnode,true);
|
||||
addFooter(hnode);
|
||||
endCv.insertEndnotes(hnode);
|
||||
GreenstoneTags.endDocument(hnode);
|
||||
hnode = (Element) GreenstoneTags.endDocument(hnode);
|
||||
// Generate all indexes
|
||||
bInToc = true;
|
||||
tocCv.generate();
|
||||
|
@ -214,7 +214,7 @@ public class TextConverter extends ConverterHelper {
|
|||
}
|
||||
else if (nodeName.equals(XMLString.TEXT_P)) {
|
||||
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);
|
||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||
// 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));
|
||||
int nOutlineLevel = getOutlineLevel((Element)child);
|
||||
Node rememberNode = hnode;
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode, style, breakBeforeNextNode);
|
||||
GreenstoneTags.processHeading(child, hnode, pageNum);
|
||||
hnode = processPageBreaks(child, hnode, style, breakBeforeNextNode);
|
||||
hnode = GreenstoneTags.processHeading(child, hnode, pageNum);
|
||||
hnode = maybeSplit(hnode,style,nOutlineLevel);
|
||||
nCharacterCount+=OfficeReader.getCharacterCount(child);
|
||||
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_ORDERED_LIST)) // old
|
||||
{
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||
hnode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||
hnode = maybeSplit(hnode,null);
|
||||
if (listIsOnlyHeadings(child)) {
|
||||
nDontSplitLevel--;
|
||||
|
@ -286,7 +286,7 @@ public class TextConverter extends ConverterHelper {
|
|||
}
|
||||
else if (nodeName.equals(XMLString.TABLE_TABLE)) {
|
||||
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);
|
||||
getTableCv().handleTable(child,hnode);
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ public class TextConverter extends ConverterHelper {
|
|||
getTableCv().handleTable(child,hnode);
|
||||
}
|
||||
else if (nodeName.equals(XMLString.TEXT_SECTION)) {
|
||||
breakBeforeNextNode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||
hnode = processPageBreaks(child, hnode,null, breakBeforeNextNode);
|
||||
hnode = maybeSplit(hnode,null);
|
||||
nDontSplitLevel--;
|
||||
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_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;
|
||||
if (style != null) {
|
||||
// If style:paragraph-properties extists and contain
|
||||
|
@ -1583,7 +1583,7 @@ public class TextConverter extends ConverterHelper {
|
|||
|
||||
//Start tagging
|
||||
String sTitle = converter.getTitle();
|
||||
GreenstoneTags.StartDocument(hnode, sTitle,headingTags,pageTags, pageNum);
|
||||
hnode = GreenstoneTags.StartDocument(hnode, sTitle,headingTags,pageTags, pageNum);
|
||||
|
||||
//Print header
|
||||
addHeader(hnode);
|
||||
|
@ -1609,20 +1609,21 @@ public class TextConverter extends ConverterHelper {
|
|||
fitPageNumberToMasterPageStyle();
|
||||
}
|
||||
//if
|
||||
GreenstoneTags.processPageBreak(currentNode, hnode, pageNum);
|
||||
hnode = GreenstoneTags.processPageBreak(currentNode, hnode, pageNum);
|
||||
//Print new header
|
||||
addHeader(hnode);
|
||||
//breakBeforeNextNode = false;
|
||||
return false;
|
||||
breakBeforeNextNode = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (checkHardBreakAfter(style)) {
|
||||
|
||||
//breakBeforeNextNode = true;
|
||||
return true;
|
||||
breakBeforeNextNode = true;
|
||||
|
||||
}
|
||||
return false;
|
||||
breakBeforeNextNode = false;
|
||||
return hnode;
|
||||
}
|
||||
|
||||
private void fitPageNumberToMasterPageStyle() {
|
||||
|
|
Loading…
Add table
Reference in a new issue