Search in sources :

Example 6 with Resource

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

the class DeusNexStructureParser method parseQueryDocument.

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

Example 7 with Resource

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

the class DeusNexStructureParser method parseFCKQuery.

private Query parseFCKQuery(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);
        }
    }
    Query query = new Query();
    parseBasicResourceProperties(resourceElement, query);
    query.setDocument(documentElement);
    query.setResources(embeddedElements);
    query.setQueryIdType(DeusNexXmlUtils.getChildValue(resourceElement, "queryIdType"));
    query.setQueryStorageType(DeusNexXmlUtils.getChildValue(resourceElement, "queryStorageType"));
    query.setQueryState(DeusNexXmlUtils.getChildValue(resourceElement, "queryState"));
    query.setQueryType(DeusNexXmlUtils.getChildValue(resourceElement, "queryType"));
    return query;
}
Also used : Query(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query) Element(org.w3c.dom.Element) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList)

Example 8 with Resource

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

the class DeusNexDocumentImpl method mapParents.

private void mapParents(Resource resource) {
    if (resource instanceof ResourceContainer) {
        List<Resource> children = ((ResourceContainer) resource).getResources();
        if (children != null) {
            for (Resource child : children) {
                parents.put(child.getNo(), resource.getNo());
                mapParents(child);
            }
        }
    }
}
Also used : Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ResourceContainer(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.ResourceContainer)

Example 9 with Resource

use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource 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)

Example 10 with Resource

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

the class DeusNexStructureParser method parseFolder.

private Folder parseFolder(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
    List<Element> childResources = DeusNexXmlUtils.getElementsByXPath(resourceElement, "res");
    List<Resource> resources = new ArrayList<>();
    for (Element childResource : childResources) {
        Resource resource = parseResource(childResource);
        if (resource != null) {
            resources.add(resource);
        }
    }
    Folder folder = new Folder();
    parseBasicResourceProperties(resourceElement, folder);
    folder.setResources(resources);
    return folder;
}
Also used : Element(org.w3c.dom.Element) Resource(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource) ArrayList(java.util.ArrayList) Folder(fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Folder)

Aggregations

Resource (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Resource)10 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)5 DeusNexInternalException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexInternalException)4 WorkspaceNode (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode)4 IOException (java.io.IOException)4 DeusNexException (fi.otavanopisto.muikku.plugins.dnm.parser.DeusNexException)3 DeusNexDocument (fi.otavanopisto.muikku.plugins.dnm.parser.structure.DeusNexDocument)3 Query (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Query)3 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 SAXException (org.xml.sax.SAXException)3 Document (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Document)2 Folder (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Folder)2 ResourceContainer (fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.ResourceContainer)2 BinaryMaterial (fi.otavanopisto.muikku.plugins.material.model.BinaryMaterial)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 Material (fi.otavanopisto.muikku.plugins.material.model.Material)1