Search in sources :

Example 1 with Style

use of org.olat.core.util.openxml.OpenXMLDocument.Style in project OpenOLAT by OpenOLAT.

the class HTMLToOpenXMLHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    String tag = localName.toLowerCase();
    if ("p".equals(tag)) {
        getCurrentParagraph(pNeedNewParagraph);
    } else if ("span".equalsIgnoreCase(tag)) {
        flushText();
        Style[] styles = null;
        String cl = attributes.getValue("class");
        if ("math".equals(cl)) {
            latex = true;
        } else {
            String cssStyles = attributes.getValue("style");
            styles = setTextPreferences(cssStyles);
        }
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("br".equals(tag)) {
        closeParagraph();
    } else if ("em".equals(tag)) {
        flushText();
        Style[] styles = setTextPreferences(Style.italic);
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("strong".equals(tag)) {
        flushText();
        Style[] styles = setTextPreferences(Style.bold);
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("img".equals(tag)) {
        String path = path(attributes.getValue("src"));
        setImage(path);
    } else if ("table".equals(tag)) {
        startTable();
    } else if ("tr".equals(tag)) {
        startCurrentTableRow();
    } else if ("td".equals(tag) || "th".equals(tag)) {
        int colspan = OpenXMLUtils.getSpanAttribute("colspan", attributes);
        int rowspan = OpenXMLUtils.getSpanAttribute("rowspan", attributes);
        currentTable.addCellEl(colspan, rowspan);
    } else if ("ul".equals(tag) || "ol".equals(tag)) {
        currentListParagraph = factory.createListParagraph();
    } else if ("li".equals(tag)) {
        getCurrentListParagraph(true);
    } else if ("blockquote".equals(tag)) {
        Style[] styles = setTextPreferences(Style.italic);
        styleStack.add(new StyleStatus(tag, true, styles));
        appendParagraph(new Spacing(90, 0));
        pNeedNewParagraph = false;
    } else if ("div".equals(tag)) {
        String cl = attributes.getValue("class");
        if (StringHelper.containsNonWhitespace(cl)) {
            if (cl.contains("o_quote_author")) {
                Style[] styles = setTextPreferences(Style.italic);
                styleStack.add(new StyleStatus(tag, true, styles));
                appendParagraph(new Spacing(120, 0));
                pNeedNewParagraph = false;
            } else {
                getCurrentParagraph(pNeedNewParagraph);
                styleStack.add(new StyleStatus(tag, new Style[0]));
            }
        } else {
            getCurrentParagraph(pNeedNewParagraph);
            styleStack.add(new StyleStatus(tag, new Style[0]));
        }
    }
}
Also used : Style(org.olat.core.util.openxml.OpenXMLDocument.Style) PredefinedStyle(org.olat.core.util.openxml.OpenXMLDocument.PredefinedStyle) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing)

Example 2 with Style

use of org.olat.core.util.openxml.OpenXMLDocument.Style in project openolat by klemens.

the class HTMLToOpenXMLHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    String tag = localName.toLowerCase();
    if ("p".equals(tag)) {
        getCurrentParagraph(pNeedNewParagraph);
    } else if ("span".equalsIgnoreCase(tag)) {
        flushText();
        Style[] styles = null;
        String cl = attributes.getValue("class");
        if ("math".equals(cl)) {
            latex = true;
        } else {
            String cssStyles = attributes.getValue("style");
            styles = setTextPreferences(cssStyles);
        }
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("br".equals(tag)) {
        closeParagraph();
    } else if ("em".equals(tag)) {
        flushText();
        Style[] styles = setTextPreferences(Style.italic);
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("strong".equals(tag)) {
        flushText();
        Style[] styles = setTextPreferences(Style.bold);
        styleStack.add(new StyleStatus(tag, styles));
    } else if ("img".equals(tag)) {
        String path = path(attributes.getValue("src"));
        setImage(path);
    } else if ("table".equals(tag)) {
        startTable();
    } else if ("tr".equals(tag)) {
        startCurrentTableRow();
    } else if ("td".equals(tag) || "th".equals(tag)) {
        int colspan = OpenXMLUtils.getSpanAttribute("colspan", attributes);
        int rowspan = OpenXMLUtils.getSpanAttribute("rowspan", attributes);
        currentTable.addCellEl(colspan, rowspan);
    } else if ("ul".equals(tag) || "ol".equals(tag)) {
        currentListParagraph = factory.createListParagraph();
    } else if ("li".equals(tag)) {
        getCurrentListParagraph(true);
    } else if ("blockquote".equals(tag)) {
        Style[] styles = setTextPreferences(Style.italic);
        styleStack.add(new StyleStatus(tag, true, styles));
        appendParagraph(new Spacing(90, 0));
        pNeedNewParagraph = false;
    } else if ("div".equals(tag)) {
        String cl = attributes.getValue("class");
        if (StringHelper.containsNonWhitespace(cl)) {
            if (cl.contains("o_quote_author")) {
                Style[] styles = setTextPreferences(Style.italic);
                styleStack.add(new StyleStatus(tag, true, styles));
                appendParagraph(new Spacing(120, 0));
                pNeedNewParagraph = false;
            } else {
                getCurrentParagraph(pNeedNewParagraph);
                styleStack.add(new StyleStatus(tag, new Style[0]));
            }
        } else {
            getCurrentParagraph(pNeedNewParagraph);
            styleStack.add(new StyleStatus(tag, new Style[0]));
        }
    }
}
Also used : Style(org.olat.core.util.openxml.OpenXMLDocument.Style) PredefinedStyle(org.olat.core.util.openxml.OpenXMLDocument.PredefinedStyle) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing)

Aggregations

PredefinedStyle (org.olat.core.util.openxml.OpenXMLDocument.PredefinedStyle)2 Spacing (org.olat.core.util.openxml.OpenXMLDocument.Spacing)2 Style (org.olat.core.util.openxml.OpenXMLDocument.Style)2