public static final List<LabsSite> getTemplateSites() throws ClientException { SiteManager sm; List<LabsSite> adaptersList = new ArrayList<LabsSite>(); try { sm = Framework.getService(SiteManager.class); } catch (Exception e) { return adaptersList; } StringBuilder query = new StringBuilder(); CoreSession session = getCoreSession(); query .append("SELECT * FROM ") .append(Docs.SITE.type()) .append(" WHERE ") .append(NXQL.ECM_LIFECYCLESTATE) .append(" = '") .append(State.PUBLISH.getState()) .append("'") .append(" AND ") .append(NXQL.ECM_PATH) .append(" STARTSWITH '") .append(sm.getSiteRoot(session).getPathAsString().replace("'", "\\'")) .append("'") .append(" AND ") .append(NXQL.ECM_MIXINTYPE) .append("='") .append(LabsSiteConstants.FacetNames.LABS_ELEMENT_TEMPLATE) .append("'"); DocumentModelList list = session.query(query.toString()); for (DocumentModel site : list) { adaptersList.add(Tools.getAdapter(LabsSite.class, site, session)); } return adaptersList; }
/** * update updateEmptySidebar * * @param session */ public static void updateEmptySidebar(CoreSession session) { try { DocumentModelList children = session.query("SELECT * FROM " + Docs.SITE.type()); for (DocumentModel docLabsSite : children) { LabsSite labsSite = Tools.getAdapter(LabsSite.class, docLabsSite, session); HtmlPage sidebar = labsSite.getSidebar(); if (sidebar.getSections().size() < 2) { session.removeDocument(sidebar.getDocument().getRef()); session.save(); LabsSiteUtils.createDefaultSidebarPage(labsSite.getDocument(), session); session.save(); } } } catch (ClientException e) { LOG.error("updateEmptySidebar : ", e); } }
/** * publish a page or site * * @param document to publish * @throws NoPublishException if no published with a problem */ public static void publish(DocumentModel document, CoreSession session) throws NoPublishException { try { if (LabsSiteConstants.State.DRAFT.getState().equals(document.getCurrentLifeCycleState())) { LabsPublisher publisherAdapter = Tools.getAdapter(LabsPublisher.class, document, session); publisherAdapter.publish(); if (Docs.SITE.type().equals(document.getType())) { LabsSite site = Tools.getAdapter(LabsSite.class, document, session); LabsPublisher publisher = Tools.getAdapter(LabsPublisher.class, site.getIndexDocument(), session); if (publisher.isDraft()) { publisher.publish(); } } } } catch (ClientException e) { throw new NoPublishException(LabsPublishService.NOT_PUBLISHED); } }
/** @param session */ public static void updateSiteTemplateAndSidebar(CoreSession session) { try { DocumentModelList children = session.query("SELECT * FROM " + Docs.SITE.type()); for (DocumentModel docLabsSite : children) { LabsSite labsSite = Tools.getAdapter(LabsSite.class, docLabsSite, session); String templateName = labsSite.getTemplate().getTemplateName(); if (templateName.equals("homeSimple")) { labsSite.setTopPageNavigation(false); labsSite.getTemplate().setTemplateName("left"); LabsSiteUtils.createSimpleSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("homeLeftComplex")) { labsSite.setTopPageNavigation(true); labsSite.getTemplate().setTemplateName("left"); LabsSiteUtils.createComplexSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("centerFullScreen")) { labsSite.setTopPageNavigation(true); LabsSiteUtils.createDefaultSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("homeRightComplex")) { labsSite.getTemplate().setTemplateName("right"); labsSite.setTopPageNavigation(true); LabsSiteUtils.createComplexSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("homeRightSimple")) { labsSite.getTemplate().setTemplateName("right"); labsSite.setTopPageNavigation(false); LabsSiteUtils.createSimpleSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("domi")) { labsSite.setTopPageNavigation(true); LabsSiteUtils.createDefaultSidebarPage(labsSite.getDocument(), session); } else if (templateName.equals("supplyChain")) { labsSite.setTopPageNavigation(true); LabsSiteUtils.createDefaultSidebarPage(labsSite.getDocument(), session); } session.saveDocument(docLabsSite); } session.save(); } catch (ClientException e) { LOG.error("updateSiteTemplateAndSidebar : ", e); } }