Search in sources :

Example 1 with CfDiv

use of io.clownfish.clownfish.datamodels.CfDiv in project Clownfish by rawdog71.

the class Clownfish method manageLayout.

private String manageLayout(CfSite cfsite, String templatename, String templatecontent, String cfstylesheet, String cfjavascript, Map parametermap) {
    CfLayout cflayout = new CfLayout(templatename);
    Document doc = Jsoup.parse(templatecontent);
    Elements divs = doc.getElementsByAttribute("template");
    for (Element div : divs) {
        String template = div.attr("template");
        String contents = div.attr("contents");
        String datalists = div.attr("datalists");
        String assets = div.attr("assets");
        String assetlists = div.attr("assetlists");
        String keywordlists = div.attr("keywordlists");
        CfDiv cfdiv = new CfDiv();
        cfdiv.setId(div.attr("id"));
        cfdiv.setName(div.attr("template"));
        if (!contents.isEmpty()) {
            cfdiv.getContentArray().addAll(ClownfishUtil.toList(contents.split(",")));
        }
        if (!datalists.isEmpty()) {
            cfdiv.getContentlistArray().addAll(ClownfishUtil.toList(datalists.split(",")));
        }
        if (!assets.isEmpty()) {
            cfdiv.getAssetArray().addAll(ClownfishUtil.toList(assets.split(",")));
        }
        if (!assetlists.isEmpty()) {
            cfdiv.getAssetlistArray().addAll(ClownfishUtil.toList(assetlists.split(",")));
        }
        if (!keywordlists.isEmpty()) {
            cfdiv.getKeywordlistArray().addAll(ClownfishUtil.toList(keywordlists.split(",")));
        }
        if (!template.isEmpty()) {
            CfTemplate cfdivtemplate = cftemplateService.findByName(template);
            List<CfLayoutcontent> layoutcontent = cflayoutcontentService.findBySiterefAndTemplateref(cfsite.getId(), cfdivtemplate.getId());
            long currentTemplateVersion = 0;
            try {
                currentTemplateVersion = cftemplateversionService.findMaxVersion((cfdivtemplate).getId());
            } catch (NullPointerException ex) {
                currentTemplateVersion = 0;
            }
            String content = templateUtil.getVersion((cfdivtemplate).getId(), currentTemplateVersion);
            content = templateUtil.fetchIncludes(content, modus);
            content = replacePlaceholders(content, cfdiv, layoutcontent);
            content = interpretscript(content, cfdivtemplate, cfstylesheet, cfjavascript, parametermap);
            // System.out.println(out);
            div.removeAttr("template");
            div.removeAttr("contents");
            div.removeAttr("datalists");
            div.removeAttr("assets");
            div.removeAttr("assetlists");
            div.removeAttr("keywordlists");
            if (preview) {
                div.addClass("cf_div");
            }
            if (preview) {
                if ((null != sitetree) && (null != sitetree.getLayout())) {
                    for (CfDiv comp_div : sitetree.getLayout().getDivs()) {
                        if ((0 == cfdiv.getName().compareToIgnoreCase(comp_div.getName())) && (comp_div.isVisible())) {
                            div.html(content);
                        }
                    }
                }
            } else {
                div.html(content);
            }
        }
        cflayout.getDivArray().put(div.attr("id"), cfdiv);
    }
    if (preview) {
        doc.head().append("<link rel=\"stylesheet\" href=\"resources/css/cf_preview.css\">");
        doc.head().append("<script async=\"\" defer=\"\" src=\"resources/js/cf_preview.js\"></script>");
    }
    return doc.html();
}
Also used : CfDiv(io.clownfish.clownfish.datamodels.CfDiv) CfLayout(io.clownfish.clownfish.datamodels.CfLayout) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 2 with CfDiv

use of io.clownfish.clownfish.datamodels.CfDiv in project Clownfish by rawdog71.

the class SiteTreeBean method onSelect.

public void onSelect(NodeSelectEvent event) {
    selectedNode = event.getTreeNode();
    selectedSite = (CfSite) selectedNode.getData();
    classcontentlist = cfclasscontentService.findByMaintenance(true);
    if (null != selectedSite.getTemplateref()) {
        CfTemplate template = cftemplateService.findById(selectedSite.getTemplateref().longValue());
        int idx = templatelist.getTemplateListe().indexOf(template);
        selectedTemplate = templatelist.getTemplateListe().get(idx);
        iframeurl = selectedSite.getName() + "?preview=true";
        selectedDiv = null;
        showContent = false;
        showDatalist = false;
        showAsset = false;
        showAssetLibrary = false;
        showKeywordLibrary = false;
        if (template.isLayout()) {
            contenteditable = true;
            FacesMessage message = new FacesMessage("LAYOUT TEMPLATE");
            FacesContext.getCurrentInstance().addMessage(null, message);
            // List<CfLayoutcontent> layoutcontent = cflayoutcontentService.findBySiteref(selectedSite.getId());
            layout = new CfLayout(template.getName());
            Document doc = Jsoup.parse(template.getContent());
            Elements divs = doc.getElementsByAttribute("template");
            for (Element div : divs) {
                String contents = div.attr("contents");
                String datalists = div.attr("datalists");
                String assets = div.attr("assets");
                String assetlists = div.attr("assetlists");
                String keywordlists = div.attr("keywordlists");
                CfDiv cfdiv = new CfDiv();
                cfdiv.setId(div.attr("id"));
                cfdiv.setName(div.attr("template"));
                if (!contents.isEmpty()) {
                    cfdiv.getContentArray().addAll(ClownfishUtil.toList(contents.split(",")));
                }
                if (!datalists.isEmpty()) {
                    cfdiv.getContentlistArray().addAll(ClownfishUtil.toList(datalists.split(",")));
                }
                if (!assets.isEmpty()) {
                    cfdiv.getAssetArray().addAll(ClownfishUtil.toList(assets.split(",")));
                }
                if (!assetlists.isEmpty()) {
                    cfdiv.getAssetlistArray().addAll(ClownfishUtil.toList(assetlists.split(",")));
                }
                if (!keywordlists.isEmpty()) {
                    cfdiv.getKeywordlistArray().addAll(ClownfishUtil.toList(keywordlists.split(",")));
                }
                layout.getDivArray().put(div.attr("id"), cfdiv);
            }
        } else {
            contenteditable = false;
            selected_contentclass = null;
            selected_datalisttclass = null;
            selected_asset = null;
            selected_assetlist = null;
            selected_keywordlist = null;
        }
    } else {
        selectedTemplate = null;
    }
    if (null != selectedSite.getStylesheetref()) {
        CfStylesheet styleshet = cfstylesheetService.findById(selectedSite.getStylesheetref().longValue());
        int idx = stylesheetlist.getStylesheetListe().indexOf(styleshet);
        selectedStylesheet = stylesheetlist.getStylesheetListe().get(idx);
    } else {
        selectedStylesheet = null;
    }
    if (null != selectedSite.getJavascriptref()) {
        CfJavascript javascript = cfjavascriptService.findById(selectedSite.getJavascriptref().longValue());
        int idx = javascriptlist.getJavascriptListe().indexOf(javascript);
        selectedJavascript = javascriptlist.getJavascriptListe().get(idx);
    } else {
        selectedJavascript = null;
    }
    selectedDatasources.clear();
    List<CfSitedatasource> selectedSiteDatasources = cfsitedatasourceService.findBySiteref(selectedSite.getId());
    for (CfSitedatasource sitedatasource : selectedSiteDatasources) {
        CfDatasource ds = cfdatasourceService.findById(sitedatasource.getCfSitedatasourcePK().getDatasourceref());
        selectedDatasources.add(ds);
    }
    selectedContentlist.clear();
    List<CfSitelist> selectedSitecontentlist = cfsitelistService.findBySiteref(selectedSite.getId());
    for (CfSitelist sitelist : selectedSitecontentlist) {
        CfList cl = cflistService.findById(sitelist.getCfSitelistPK().getListref());
        selectedContentlist.add(cl);
    }
    selectedClasscontentlist.clear();
    List<CfSitecontent> selectedClasscontentliste = cfsitecontentService.findBySiteref(selectedSite.getId());
    for (CfSitecontent sitecontent : selectedClasscontentliste) {
        CfClasscontent cc = cfclasscontentService.findById(sitecontent.getCfSitecontentPK().getClasscontentref());
        selectedClasscontentlist.add(cc);
    }
    selectedAssetlist.clear();
    List<CfSiteassetlist> selectedAssetliste = cfsiteassetlistService.findBySiteref(selectedSite.getId());
    for (CfSiteassetlist siteassetlist : selectedAssetliste) {
        CfAssetlist csa = cfassetlistService.findById(siteassetlist.getCfSiteassetlistPK().getAssetlistref());
        selectedAssetlist.add(csa);
    }
    selectedKeywordlist.clear();
    List<CfSitekeywordlist> selectedKeywordliste = cfsitekeywordlistService.findBySiteref(selectedSite.getId());
    for (CfSitekeywordlist sitekeywordlist : selectedKeywordliste) {
        CfKeywordlist kwl = cfkeywordlistService.findById(sitekeywordlist.getCfSitekeywordlistPK().getKeywordlistref());
        selectedKeywordlist.add(kwl);
    }
    siteName = selectedSite.getName();
    siteTitle = selectedSite.getTitle();
    siteDescription = selectedSite.getDescription();
    sitejob = selectedSite.isJob();
    sitesearchrelevant = selectedSite.isSearchrelevant();
    sitemap = selectedSite.isSitemap();
    sitestatic = selectedSite.isStaticsite();
    aliaspath = selectedSite.getAliaspath();
    sitehtmlcompression = selectedSite.getHtmlcompression();
    characterEncoding = selectedSite.getCharacterencoding();
    contentType = selectedSite.getContenttype();
    locale = selectedSite.getLocale();
    saprfclist = cfsitesaprfcService.findBySiteref(selectedSite.getId());
    newButtonDisabled = true;
    FacesMessage message = new FacesMessage("Selected " + selectedSite.getName());
    FacesContext.getCurrentInstance().addMessage(null, message);
}
Also used : CfSitedatasource(io.clownfish.clownfish.dbentities.CfSitedatasource) Element(org.jsoup.nodes.Element) CfDatasource(io.clownfish.clownfish.dbentities.CfDatasource) CfSiteassetlist(io.clownfish.clownfish.dbentities.CfSiteassetlist) CfAssetlist(io.clownfish.clownfish.dbentities.CfAssetlist) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) CfClasscontent(io.clownfish.clownfish.dbentities.CfClasscontent) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate) CfDiv(io.clownfish.clownfish.datamodels.CfDiv) CfSitekeywordlist(io.clownfish.clownfish.dbentities.CfSitekeywordlist) CfList(io.clownfish.clownfish.dbentities.CfList) CfJavascript(io.clownfish.clownfish.dbentities.CfJavascript) CfKeywordlist(io.clownfish.clownfish.dbentities.CfKeywordlist) CfLayout(io.clownfish.clownfish.datamodels.CfLayout) CfSitecontent(io.clownfish.clownfish.dbentities.CfSitecontent) CfSitelist(io.clownfish.clownfish.dbentities.CfSitelist) CfStylesheet(io.clownfish.clownfish.dbentities.CfStylesheet) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

CfDiv (io.clownfish.clownfish.datamodels.CfDiv)2 CfLayout (io.clownfish.clownfish.datamodels.CfLayout)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 CfAssetlist (io.clownfish.clownfish.dbentities.CfAssetlist)1 CfClasscontent (io.clownfish.clownfish.dbentities.CfClasscontent)1 CfDatasource (io.clownfish.clownfish.dbentities.CfDatasource)1 CfJavascript (io.clownfish.clownfish.dbentities.CfJavascript)1 CfKeywordlist (io.clownfish.clownfish.dbentities.CfKeywordlist)1 CfList (io.clownfish.clownfish.dbentities.CfList)1 CfSiteassetlist (io.clownfish.clownfish.dbentities.CfSiteassetlist)1 CfSitecontent (io.clownfish.clownfish.dbentities.CfSitecontent)1 CfSitedatasource (io.clownfish.clownfish.dbentities.CfSitedatasource)1 CfSitekeywordlist (io.clownfish.clownfish.dbentities.CfSitekeywordlist)1 CfSitelist (io.clownfish.clownfish.dbentities.CfSitelist)1 CfStylesheet (io.clownfish.clownfish.dbentities.CfStylesheet)1 CfTemplate (io.clownfish.clownfish.dbentities.CfTemplate)1 FacesMessage (javax.faces.application.FacesMessage)1