/************************************************************************
*
* TocReader.java
*
* Copyright: 2002-2014 by Henrik Just
*
* This file is part of Writer2LaTeX.
*
* Writer2LaTeX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Writer2LaTeX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Writer2LaTeX. If not, see
The class reads a text:table-of-content
element.
Initialize the TocReader with a table of content node.
* @param onode a text:table-of-content
*/
public TocReader(Element onode) {
sName = Misc.getAttribute(onode,XMLString.TEXT_NAME);
sStyleName = Misc.getAttribute(onode,XMLString.TEXT_STYLE_NAME);
Element tocSource = Misc.getChildByTagName(onode,XMLString.TEXT_TABLE_OF_CONTENT_SOURCE);
//Element indexBody = Misc.getChildByTagName(onode,XMLString.TEXT_INDEX_BODY);
if (tocSource!=null) {
nOutlineLevel = Misc.getPosInteger(tocSource.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1);
bUseOutlineLevel = !"false".equals(tocSource.getAttribute(XMLString.TEXT_USE_OUTLINE_LEVEL));
bUseIndexSourceStyles = "true".equals(tocSource.getAttribute(XMLString.TEXT_USE_INDEX_SOURCE_STYLES));
bUseIndexMarks = !"false".equals(tocSource.getAttribute(XMLString.TEXT_USE_INDEX_MARKS));
bIsByChapter = "chapter".equals(tocSource.getAttribute(XMLString.TEXT_INDEX_SCOPE));
// traverse the source to collect templates
Node child = tocSource.getFirstChild();
while (child!=null) {
if (child.getNodeType()==Node.ELEMENT_NODE) {
Element elm = (Element) child;
if (XMLString.TEXT_INDEX_TITLE_TEMPLATE.equals(elm.getTagName())) {
indexTitleTemplate = elm;
}
if (XMLString.TEXT_TABLE_OF_CONTENT_ENTRY_TEMPLATE.equals(elm.getTagName())) {
int nLevel = Misc.getPosInteger(elm.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1);
if (1<=nLevel && nLevel<=10) { tocEntryTemplate[nLevel] = elm; }
}
if (XMLString.TEXT_INDEX_SOURCE_STYLES.equals(elm.getTagName())) {
int nLevel = Misc.getPosInteger(elm.getAttribute(XMLString.TEXT_OUTLINE_LEVEL),1);
if (1<=nLevel && nLevel<=10) {
// traverse to collect index source styles for this level
Node child1 = elm.getFirstChild();
while (child1!=null) {
if (child1.getNodeType()==Node.ELEMENT_NODE) {
Element elm1 = (Element) child1;
if (XMLString.TEXT_INDEX_SOURCE_STYLE.equals(elm1.getTagName())) {
String sIndexSourceStyle = Misc.getAttribute(elm1,XMLString.TEXT_STYLE_NAME);
if (sIndexSourceStyle!=null) {
indexSourceStyles.put(sIndexSourceStyle,new Integer(nLevel));
}
}
}
child1 = child1.getNextSibling();
}
}
}
}
child = child.getNextSibling();
}
}
}
/**
Get the (section) name for this toc
* @return the name of the toc */ public String getName() { return sName; } /**Get the (section) style name for this toc
* @return name of the section style to use for this toc */ public String getStyleName() { return sStyleName; } /**Get max outline level for this toc
* @return max outline level */ public int getOutlineLevel() { return nOutlineLevel; } /**Do we use outline (headings) in this toc?
* @return true if headings should be used */ public boolean useOutlineLevel() { return bUseOutlineLevel; } /**Do we use additional styles in this toc?
* @return true if additional styles should be used */ public boolean useIndexSourceStyles() { return bUseIndexSourceStyles; } /**Do we use toc marks in this toc?
* @return true if toc marks should be used */ public boolean useIndexMarks() { return bUseIndexMarks; } /**Is this toc by chapter?
* @return true if the scope is a chapter only */ public boolean isByChapter() { return bIsByChapter; } /**Get the index title template for this toc
* @return thetext:index-title-template
element, or null
*/
public Element getIndexTitleTemplate() { return indexTitleTemplate; }
/** Get the entry template for this toc at a specific level
* @param nLevel the outline level * @return thetext:table-of-content-entry-template
element, or null
*/
public Element getTocEntryTemplate(int nLevel) {
if (1<=nLevel && nLevel<=10) { return tocEntryTemplate[nLevel]; }
else { return null; }
}
/** Get a set view of all index source styles
* @return a set of all index source style names */ public SetGet the level associated with a specific index source style
* @param sStyleName the style name of the index source style * @return the level or -1 if the style is not used in this toc */ public int getIndexSourceStyleLevel(String sStyleName) { if (indexSourceStyles.containsKey(sStyleName)) { return indexSourceStyles.get(sStyleName).intValue(); } else { return -1; } } /**Return the generated content of this toc, if available
* @return thetext:index-body
element
*/
/* public Element getIndexBody() { return indexBody; } */
}