Search in sources :

Example 1 with Spacing

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

the class ForumOpenXMLFormatter method visit.

@Override
public void visit(INode node) {
    MessageNode m = (MessageNode) node;
    StringBuilder creatorAndDate = new StringBuilder();
    Identity creator = m.getCreator();
    if (StringHelper.containsNonWhitespace(m.getPseudonym())) {
        creatorAndDate.append(m.getPseudonym()).append(" ");
        if (m.isGuest()) {
            creatorAndDate.append(translator.translate("guest.suffix"));
        } else {
            creatorAndDate.append(translator.translate("pseudonym.suffix"));
        }
    } else if (m.isGuest()) {
        creatorAndDate.append(translator.translate("guest"));
    } else if (creator != null) {
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.FIRSTNAME, null));
        creatorAndDate.append(" ");
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.LASTNAME, null));
    } else {
        creatorAndDate.append("???");
    }
    creatorAndDate.append(" ");
    creatorAndDate.append(formatter.formatDateAndTime(m.getCreationDate()));
    if (isTopThread) {
        document.appendHeading1(m.getTitle(), creatorAndDate.toString());
        isTopThread = false;
    } else {
        document.appendHeading2(m.getTitle(), creatorAndDate.toString());
    }
    Identity modifier = m.getModifier();
    if (modifier != null) {
        StringBuilder modSb = new StringBuilder();
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            modSb.append(m.getPseudonym()).append(" ");
            if (m.isGuest()) {
                modSb.append(translator.translate("guest.suffix"));
            } else {
                modSb.append(translator.translate("pseudonym.suffix"));
            }
        } else {
            modSb.append(translator.translate("msg.modified")).append(": ").append(modifier.getUser().getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(modifier.getUser().getProperty(UserConstants.LASTNAME, null)).append(" ").append(formatter.formatDateAndTime(m.getModifiedDate()));
        }
        document.appendSubtitle(modSb.toString());
    }
    String body = m.getBody();
    if (body != null) {
        body = body.replace("<p>&nbsp;", "<p>");
    }
    document.appendHtmlText(body, new Spacing(180, 0));
    // message attachments
    VFSItem attachmentsItem = forumContainer.resolve(m.getKey().toString());
    if (attachmentsItem instanceof VFSContainer) {
        processAttachments((VFSContainer) attachmentsItem);
    }
}
Also used : MessageNode(org.olat.modules.fo.archiver.MessageNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing) Identity(org.olat.core.id.Identity)

Example 2 with Spacing

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

the class ForumOpenXMLFormatter method visit.

@Override
public void visit(INode node) {
    MessageNode m = (MessageNode) node;
    StringBuilder creatorAndDate = new StringBuilder();
    Identity creator = m.getCreator();
    if (StringHelper.containsNonWhitespace(m.getPseudonym())) {
        creatorAndDate.append(m.getPseudonym()).append(" ");
        if (m.isGuest()) {
            creatorAndDate.append(translator.translate("guest.suffix"));
        } else {
            creatorAndDate.append(translator.translate("pseudonym.suffix"));
        }
    } else if (m.isGuest()) {
        creatorAndDate.append(translator.translate("guest"));
    } else if (creator != null) {
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.FIRSTNAME, null));
        creatorAndDate.append(" ");
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.LASTNAME, null));
    } else {
        creatorAndDate.append("???");
    }
    creatorAndDate.append(" ");
    creatorAndDate.append(formatter.formatDateAndTime(m.getCreationDate()));
    if (isTopThread) {
        document.appendHeading1(m.getTitle(), creatorAndDate.toString());
        isTopThread = false;
    } else {
        document.appendHeading2(m.getTitle(), creatorAndDate.toString());
    }
    Identity modifier = m.getModifier();
    if (modifier != null) {
        StringBuilder modSb = new StringBuilder();
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            modSb.append(m.getPseudonym()).append(" ");
            if (m.isGuest()) {
                modSb.append(translator.translate("guest.suffix"));
            } else {
                modSb.append(translator.translate("pseudonym.suffix"));
            }
        } else {
            modSb.append(translator.translate("msg.modified")).append(": ").append(modifier.getUser().getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(modifier.getUser().getProperty(UserConstants.LASTNAME, null)).append(" ").append(formatter.formatDateAndTime(m.getModifiedDate()));
        }
        document.appendSubtitle(modSb.toString());
    }
    String body = m.getBody();
    if (body != null) {
        body = body.replace("<p>&nbsp;", "<p>");
    }
    document.appendHtmlText(body, new Spacing(180, 0));
    // message attachments
    VFSItem attachmentsItem = forumContainer.resolve(m.getKey().toString());
    if (attachmentsItem instanceof VFSContainer) {
        processAttachments((VFSContainer) attachmentsItem);
    }
}
Also used : MessageNode(org.olat.modules.fo.archiver.MessageNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing) Identity(org.olat.core.id.Identity)

Example 3 with Spacing

use of org.olat.core.util.openxml.OpenXMLDocument.Spacing 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 4 with Spacing

use of org.olat.core.util.openxml.OpenXMLDocument.Spacing 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

Spacing (org.olat.core.util.openxml.OpenXMLDocument.Spacing)4 Identity (org.olat.core.id.Identity)2 PredefinedStyle (org.olat.core.util.openxml.OpenXMLDocument.PredefinedStyle)2 Style (org.olat.core.util.openxml.OpenXMLDocument.Style)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 MessageNode (org.olat.modules.fo.archiver.MessageNode)2