Search in sources :

Example 1 with Document

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document in project muikku by otavanopisto.

the class DeusNexStructureParser method parseFCKDocument.

private Document parseFCKDocument(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
    Element documentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "document");
    if (documentElement == null) {
        logger.severe("Missing data/document node");
        return null;
    }
    List<Resource> embeddedElements = new ArrayList<>();
    List<Element> embeddedResourceElements = DeusNexXmlUtils.getElementsByXPath(resourceElement, "embedded/res");
    for (Element embeddedResourceElement : embeddedResourceElements) {
        Resource resource = parseResource(embeddedResourceElement);
        if (resource != null) {
            embeddedElements.add(resource);
        }
    }
    Document document = new Document();
    parseBasicResourceProperties(resourceElement, document);
    document.setDocument(documentElement);
    document.setResources(embeddedElements);
    return document;
}
Also used : Element(org.w3c.dom.Element) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) Document(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)

Example 2 with Document

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document in project muikku by otavanopisto.

the class DeusNexStructureParser method parseLink.

private Resource parseLink(Element resourceElement) throws DeusNexInternalException {
    // TODO: Add support for proper link materials
    Document document = new Document();
    Element linkElement = resourceElement.getOwnerDocument().createElement("a");
    try {
        linkElement.setAttribute("href", DeusNexXmlUtils.getChildValue(resourceElement, "path"));
        linkElement.setTextContent(DeusNexXmlUtils.getChildValue(resourceElement, "title"));
        parseBasicResourceProperties(resourceElement, document);
        Element documentElement = resourceElement.getOwnerDocument().createElement("document");
        Element fckDocumentElement = resourceElement.getOwnerDocument().createElement("fckdocument");
        fckDocumentElement.setAttribute("lang", "fi");
        fckDocumentElement.appendChild(linkElement);
        documentElement.appendChild(fckDocumentElement);
        document.setDocument(documentElement);
    } catch (DOMException | XPathExpressionException | DeusNexSyntaxException e) {
        throw new DeusNexInternalException("Link parsing failed", e);
    }
    return document;
}
Also used : DOMException(org.w3c.dom.DOMException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Element(org.w3c.dom.Element) DeusNexInternalException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException) DeusNexSyntaxException(fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexSyntaxException) Document(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)

Example 3 with Document

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document in project muikku by otavanopisto.

the class DeusNexStructureParser method parseStyleDocument.

private Document parseStyleDocument(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
    Element documentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "document/styledocument");
    if (documentElement == null) {
        logger.severe("Missing data/document node");
        return null;
    }
    List<Resource> embeddedElements = new ArrayList<>();
    List<Element> embeddedResourceElements = DeusNexXmlUtils.getElementsByXPath(resourceElement, "embedded/res");
    for (Element embeddedResourceElement : embeddedResourceElements) {
        Resource resource = parseResource(embeddedResourceElement);
        if (resource != null) {
            embeddedElements.add(resource);
        }
    }
    Document document = new Document();
    parseBasicResourceProperties(resourceElement, document);
    document.setDocument(documentElement);
    document.setResources(embeddedElements);
    return document;
}
Also used : Element(org.w3c.dom.Element) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) Document(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)

Aggregations

Document (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)3 Element (org.w3c.dom.Element)3 Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)2 ArrayList (java.util.ArrayList)2 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)1 DeusNexSyntaxException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexSyntaxException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 DOMException (org.w3c.dom.DOMException)1