}
public void traverse(Node e, Element dstElement) throws Exception {
classesForDebug.add(e.getClass().toString());
boolean skipChildren = false;
Element newElement = null;
/**
* Original ODT's element evalutation
*/
if (e instanceof TextNoteBodyElement) {// Corpo di una nota
TextNoteBodyElement noteBody = (TextNoteBodyElement) e;
} else if (e instanceof TextNoteCitationElement) {// Rimando ad una nota
} else if (e instanceof OfficeTextElement) {// OFFICE
OfficeTextElement ote = (OfficeTextElement) e;
} else if (e instanceof OfficeScriptsElement) {// OFFICE
} else if (e instanceof OfficeDocumentContentElement) {// OFFICE
} else if (e instanceof OdfOfficeAutomaticStyles) {// OFFICE
} else if (e instanceof OfficeBodyElement) {// OFFICE
} else if (e instanceof TextSElement) {// ?
TextSElement te = (TextSElement) e;
} else if (e instanceof TextAElement) {// is an hyperlink
TextAElement ta = (TextAElement) e;
String ref = ta.getAttribute("xlink:href");
HyperlinkElement a = getCurrentResource().getDocument().createHyperlinkElement("a");
if (ref.startsWith("#")) {// internal Link
a.setTitle(ta.getAttribute("xlink:href"));
getInternalLink().add(a);
} else {
a.setExternalHRef(ref);
}
dstElement.add(a);
// a.add("ciao");
traverse(ta.getFirstChild(), a);
skipChildren = true;
} else if (e instanceof TextBookmarkElement) {// is bookmark in epub can
// be used to implement
// internal link anchors
TextBookmarkElement ta = (TextBookmarkElement) e;
HyperlinkElement a = getCurrentResource().getDocument().createHyperlinkElement("a");
a.setId(ta.getAttribute("text:name"));
dstElement.add(a);
getBookmarks().put("#" + ta.getAttribute("text:name"), a);
} else if (e instanceof TextNoteElement) {// Is a footnote container
addFootnote((TextNoteElement) e, dstElement);
skipChildren = true;
} else if (e instanceof OdfDrawFrame) {
OdfDrawFrame dframe = (OdfDrawFrame) e;
// if(!(dframe.getParentNode().getParentNode() instanceof DrawTextBoxElement)){
// here can be captured resize options
newElement = addImageBox(dframe, dstElement);
//}
} else if (e instanceof DrawTextBoxElement) {
DrawTextBoxElement didascalia = (DrawTextBoxElement) e;
} else if (e instanceof OdfDrawImage) {
addImage((OdfDrawImage) e, dstElement);
} else if (e instanceof OdfTextList) {
OdfTextList otl = (OdfTextList) e;
dstElement = getCurrentResource().getDocument().getBody();
/**
* ul.a {list-style-type:circle;} ul.b {list-style-type:square;}
* ol.c {list-style-type:upper-roman;} ol.d
* {list-style-type:lower-alpha;}
*/
Object n = getXpath().evaluate(
"//text:list-style[@style:name='" + otl.getTextStyleNameAttribute()
+ "']/text:list-level-style-bullet", getOdt().getContentDom(), XPathConstants.NODE);
if (n != null) {// is a bullet list
newElement = getCurrentResource().getDocument().createElement("ul");
} else {
n = getXpath().evaluate(
"//text:list-style[@style:name='" + otl.getTextStyleNameAttribute()
+ "']/text:list-level-style-number", getOdt().getContentDom(), XPathConstants.NODE);
if (n != null) {
newElement = getCurrentResource().getDocument().createElement("ol");
}
}
if (newElement != null) {
dstElement.add(newElement);
newElement.setClassName(otl.getTextStyleNameAttribute());
}
// title[@lang='eng']
} else if (e instanceof TextListItemElement) {
TextListItemElement li = (TextListItemElement) e;
newElement = getCurrentResource().getDocument().createElement("li");
dstElement.add(newElement);
} else if (e instanceof TableTableElement) {
TableTableElement otl = (TableTableElement) e;
dstElement = getCurrentResource().getDocument().getBody();
newElement = getCurrentResource().getDocument().createElement("table");
dstElement.add(newElement);
newElement.setClassName(otl.getStyleName());
Selector selector = getStylesheet().getSimpleSelector(null, otl.getStyleName());
SelectorRule rule = getStylesheet().getRuleForSelector(selector, true);
rule.set("width", new CSSName("100%"));
selector = getStylesheet().getSimpleSelector("table", null);
rule = getStylesheet().getRuleForSelector(selector, true);
rule.set("border-collapse", new CSSName("collapse"));
rule.set("border", new CSSName("1px solid black"));
selector = getStylesheet().getSimpleSelector("td",null);
rule = getStylesheet().getRuleForSelector(selector, true);
rule.set("border", new CSSName("1px solid black"));
selector = getStylesheet().getSimpleSelector("tr", null);
rule = getStylesheet().getRuleForSelector(selector, true);
rule.set("border", new CSSName("1px solid black"));
} else if (e instanceof TableTableRowElement) {
TableTableRowElement otl = (TableTableRowElement) e;
newElement = getCurrentResource().getDocument().createElement("tr");
dstElement.add(newElement);
newElement.setClassName(otl.getStyleName());
} else if (e instanceof TableTableCellElement) {
TableTableCellElement otl = (TableTableCellElement) e;
newElement = getCurrentResource().getDocument().createElement("td");
dstElement.add(newElement);
newElement.setClassName(otl.getStyleName());
} else if (e instanceof OdfTextHeading) {// text:p
// System.out.println(e.getTextContent());
OdfTextHeading oth = (OdfTextHeading) e;
if (hasPageBreak(oth)) {
createNewResource();
}
newElement = getCurrentResource().getDocument().createElement("h" + oth.getAttribute("text:outline-level"));
if (dstElement != null) {
dstElement.add(newElement);
} else {
getCurrentResource().getDocument().getBody().add(newElement);
}
newElement.setClassName(oth.getStyleName());
if (oth.getTextContent() != null && oth.getTextContent().trim().length() > 0) {
addTocEntry(oth.getTextContent(), Integer.parseInt(oth.getAttribute("text:outline-level")), newElement);
}
if (oth.getAutomaticStyle() != null) {// probabile che sia stato
// oth.getAutomaticStyles() // modificato lo stile
List<OdfStyleBase> classeCSS = new ArrayList<OdfStyleBase>();
OdfStyleBase p = oth.getAutomaticStyle().getParentStyle();
while (p != null) {
classeCSS.add(p);
p = p.getParentStyle();
}
Collections.reverse(classeCSS);
for (OdfStyleBase odfStyleBase : classeCSS) {
stylesPropsToCSS(odfStyleBase.getStyleProperties(), newElement.getClassName());
}
stylesPropsToCSS(oth.getAutomaticStyle().getStyleProperties(), oth.getStyleName());
if (newElement != null) {
newElement.setClassName(oth.getStyleName());
}
if (isDebugMode()) {
Utils.printStyleProps(oth.getAutomaticStyle().getStyleProperties());
}
}
getOdt().getDocumentStyles().getElementsByTagName(oth.getTextStyleNameAttribute());
} else if (e instanceof OdfTextParagraph) {// text:p
// System.out.println(e.getTextContent());
OdfTextParagraph otp = (OdfTextParagraph) e;
if (hasPageBreak(otp)) {
createNewResource();
}
newElement = getCurrentResource().getDocument().createElement("p");
if (dstElement != null) {
dstElement.add(newElement);
} else {
getCurrentResource().getDocument().getBody().add(newElement);
}
newElement.setClassName(otp.getStyleName().trim());
if (otp.getAutomaticStyle() != null) {// probabile che sia stato
// modificato lo stile
List<OdfStyleBase> classeCSS = new ArrayList<OdfStyleBase>();
OdfStyleBase p = otp.getAutomaticStyle().getParentStyle();
while (p != null) {
classeCSS.add(p);
p = p.getParentStyle();
}
Collections.reverse(classeCSS);
for (OdfStyleBase odfStyleBase : classeCSS) {
stylesPropsToCSS(odfStyleBase.getStyleProperties(), newElement.getClassName());
}
// while(p!=null){
// if(p.getAttribute("style:name")!=null&&p.getAttribute("style:name").trim().length()>0){
// newElement.setClassName(p.getAttribute("style:name").trim()+" "+newElement.getClassName());
// stylesPropsToCSS(p.getStyleProperties(),
// p.getAttribute("style:name"));
// }
// p=p.getParentStyle();
//
// }
// Object
// n=getXpath().evaluate("//style:style[@style:name='Body_20_Text_20_3']",
// getOdt().getDocumentStyles(), XPathConstants.NODE);
// n=getXpath().evaluate("//style:style[@style:name='Standard']",
// getOdt().getDocumentStyles(), XPathConstants.NODE);
// getXpath().evaluate("//style:style[@style:name='P38']",
// getOdt().getDocumentStyles(), XPathConstants.NODE)
stylesPropsToCSS(otp.getAutomaticStyle().getStyleProperties(), otp.getStyleName());
if (isDebugMode()) {
Utils.printStyleProps(otp.getAutomaticStyle().getStyleProperties());
}
}
} else if (e instanceof OdfTextSpan) {// text:span
// System.out.println(e.getTextContent());
// sembra che se automatic.style � vuoto allora esiste uno stile
// definito che pu� definire bold e italic
OdfTextSpan ots = (OdfTextSpan) e;
if (ots.getAutomaticStyle() != null) {// probabile che sia stato
// modificato lo stile
newElement = getCurrentResource().getDocument().createElement("span");
dstElement.add(newElement);
newElement.setClassName(ots.getStyleName());
stylesPropsToCSS(ots.getAutomaticStyle().getStyleProperties(), newElement.getClassName());
if (isDebugMode()) {
Utils.printStyleProps(ots.getAutomaticStyle().getStyleProperties());
}
}