Removed depcrecated package com/arsdigita/cms/ui/pages and depcrecated PagesServlet (replaced by JAX-RS application)
parent
7a4aa27eef
commit
77d73fd336
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pages;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.libreccm.pagemodel.PageModel;
|
||||
import org.libreccm.pagemodel.PageModelRepository;
|
||||
import org.librecms.pages.Pages;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class PageModelAdminPageController {
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private PageModelRepository pageModelRepository;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<PageModelData> findDraftPageModelsByApplication(
|
||||
final Pages pages
|
||||
) {
|
||||
final List<PageModel> pageModels = pageModelRepository
|
||||
.findDraftByApplication(pages);
|
||||
return pageModels.stream().map(this::buildPageModelData).collect(
|
||||
Collectors.toList()
|
||||
);
|
||||
}
|
||||
|
||||
private PageModelData buildPageModelData(final PageModel fromPageModel) {
|
||||
final PageModelData result = new PageModelData();
|
||||
result.setPageModelId(fromPageModel.getPageModelId());
|
||||
result.setTitle(globalizationHelper.getValueFromLocalizedString(
|
||||
fromPageModel.getTitle()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pages;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class PageModelData {
|
||||
|
||||
private long pageModelId;
|
||||
|
||||
private String title;
|
||||
|
||||
public long getPageModelId() {
|
||||
return pageModelId;
|
||||
}
|
||||
|
||||
public void setPageModelId(long pageModelId) {
|
||||
this.pageModelId = pageModelId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,447 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pages;
|
||||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.TabbedPane;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.Tree;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.SingleSelect;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.bebop.tree.TreeModel;
|
||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
||||
import com.arsdigita.cms.ui.CMSApplicationPage;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.ui.ReactApp;
|
||||
import com.arsdigita.ui.admin.categories.CategoriesTreeModel;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.pagemodel.PageModel;
|
||||
import org.libreccm.pagemodel.PageModelRepository;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pages.PageManager;
|
||||
import org.librecms.pages.PageRepository;
|
||||
import org.librecms.pages.Pages;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class PagesAdminPage extends CMSApplicationPage {
|
||||
|
||||
private static final String INDEX_PAGE_MODEL_SELECT = "indexPageModelSelect";
|
||||
|
||||
private static final String ITEM_PAGE_MODEL_SELECT = "itemPageModelSelect";
|
||||
|
||||
private static final String INHERIT_PAGEMODEL = "--inherit--";
|
||||
|
||||
private final ParameterSingleSelectionModel<String> selectedCategory;
|
||||
|
||||
private final Tree categoryTree;
|
||||
|
||||
private final Label nothingSelectedLabel;
|
||||
|
||||
private final Form pageModelForm;
|
||||
|
||||
private final SingleSelect indexPageModelSelect;
|
||||
|
||||
private final SingleSelect itemPageModelSelect;
|
||||
|
||||
private final SaveCancelSection saveCancelSection;
|
||||
|
||||
private Pages pagesInstance;
|
||||
|
||||
private PagesContextBar pagesContextBar;
|
||||
|
||||
public PagesAdminPage() {
|
||||
|
||||
super("", new SimpleContainer());
|
||||
|
||||
super.setAttribute("application", "admin");
|
||||
super.setClassAttr("cms-admin");
|
||||
// super.setTitle(new Label(new GlobalizedMessage("cms.ui.pages.title",
|
||||
// CmsConstants.CMS_BUNDLE)));
|
||||
|
||||
selectedCategory = new ParameterSingleSelectionModel<>(
|
||||
new StringParameter("selectedCategory"));
|
||||
super.addGlobalStateParam(selectedCategory.getStateParameter());
|
||||
|
||||
categoryTree = new Tree(new CategoryTreeModelBuilder());
|
||||
categoryTree.addChangeListener(this::categoryTreeStateChanged);
|
||||
|
||||
final LayoutPanel panel = new LayoutPanel();
|
||||
panel.setLeft(categoryTree);
|
||||
|
||||
nothingSelectedLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.pages.no_category_selected",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
// nothingSelectedLabel.addPrintListener(this::printNothingSelectedLabel);
|
||||
super.setVisibleDefault(nothingSelectedLabel, true);
|
||||
|
||||
pageModelForm = new Form("pageModelForm");
|
||||
super.setVisibleDefault(pageModelForm, false);
|
||||
|
||||
final Label heading = new Label();
|
||||
heading.addPrintListener(this::printPageModelFormHeading);
|
||||
heading.setClassAttr("heading");
|
||||
pageModelForm.add(heading);
|
||||
|
||||
indexPageModelSelect = new SingleSelect(INDEX_PAGE_MODEL_SELECT);
|
||||
indexPageModelSelect
|
||||
.setLabel(new GlobalizedMessage("cms.ui.pages.index_page_model",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
try {
|
||||
indexPageModelSelect.addPrintListener(this::populatePageModelSelect);
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
pageModelForm.add(indexPageModelSelect);
|
||||
// super.setVisibleDefault(indexPageModelSelect, false);
|
||||
|
||||
itemPageModelSelect = new SingleSelect(ITEM_PAGE_MODEL_SELECT);
|
||||
itemPageModelSelect
|
||||
.setLabel(new GlobalizedMessage("cms.ui.pages.item_page_model",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
try {
|
||||
itemPageModelSelect.addPrintListener(this::populatePageModelSelect);
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
pageModelForm.add(itemPageModelSelect);
|
||||
// super.setVisibleDefault(itemPageModelSelect, false);
|
||||
|
||||
saveCancelSection = new SaveCancelSection();
|
||||
pageModelForm.add(saveCancelSection);
|
||||
// super.setVisibleDefault(saveCancelSection, false);
|
||||
|
||||
pageModelForm.addInitListener(this::initPageModelForm);
|
||||
pageModelForm.addValidationListener(this::validatePageModelForm);
|
||||
pageModelForm.addProcessListener(this::processPageModelForm);
|
||||
|
||||
final BoxPanel rightPanel = new BoxPanel(BoxPanel.VERTICAL);
|
||||
rightPanel.setClassAttr("right-panel");
|
||||
rightPanel.add(nothingSelectedLabel);
|
||||
rightPanel.add(pageModelForm);
|
||||
panel.setRight(rightPanel);
|
||||
|
||||
// final SimpleContainer pageModelsManager = new SimpleContainer(
|
||||
// "admin:pageModelsManager", AdminUiConstants.ADMIN_XML_NS);
|
||||
// pageModelsManager.add(new Text("Placeholder page models editor"));
|
||||
final ReactApp pageModelsManager = new ReactApp(
|
||||
"page-models-editor", "scripts/dist/ccm-cms-pagemodelseditor.js");
|
||||
|
||||
pagesContextBar = new PagesContextBar();
|
||||
super.add(pagesContextBar);
|
||||
|
||||
final TabbedPane tabbedPane = new TabbedPane();
|
||||
tabbedPane.addTab(new Label(new GlobalizedMessage(
|
||||
"cms.ui.pages.tab.pages", CmsConstants.CMS_BUNDLE)),
|
||||
panel);
|
||||
tabbedPane
|
||||
.addTab(new Label(new GlobalizedMessage(
|
||||
"cms.ui.pages.tab.page_models", CmsConstants.CMS_BUNDLE)),
|
||||
pageModelsManager);
|
||||
super.add(tabbedPane);
|
||||
|
||||
super.addActionListener(this::initPage);
|
||||
|
||||
super.lock();
|
||||
}
|
||||
|
||||
public Pages getPagesInstance() {
|
||||
return pagesInstance;
|
||||
}
|
||||
|
||||
public void setPagesInstance(final Pages pagesInstance) {
|
||||
this.pagesInstance = pagesInstance;
|
||||
pagesContextBar.setPagesInstance(pagesInstance);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void register(final Page page) {
|
||||
//
|
||||
// super.register(page);
|
||||
//
|
||||
// page.setVisibleDefault(nothingSelectedLabel, true);
|
||||
// page.setVisibleDefault(pageModelForm, false);
|
||||
//
|
||||
// page.addGlobalStateParam(selectedCategory.getStateParameter());
|
||||
//
|
||||
// }
|
||||
private void initPage(final ActionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (selectedCategory.isSelected(state)) {
|
||||
nothingSelectedLabel.setVisible(state, false);
|
||||
pageModelForm.setVisible(state, true);
|
||||
} else {
|
||||
nothingSelectedLabel.setVisible(state, true);
|
||||
pageModelForm.setVisible(state, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private void printNothingSelectedLabel(final PrintEvent event) {
|
||||
//
|
||||
// final PageState state = event.getPageState();
|
||||
// final Label target = (Label) event.getTarget();
|
||||
//
|
||||
// target.setVisible(state, !selectedCategory.isSelected(state));
|
||||
// }
|
||||
private void printPageModelFormHeading(final PrintEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final Label target = (Label) event.getTarget();
|
||||
|
||||
// target.setVisible(state, !selectedCategory.isSelected(state));
|
||||
if (selectedCategory.isSelected(state)) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(Long.parseLong(selectedCategory.getSelectedKey(state)))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
selectedCategory.getSelectedKey(state))));
|
||||
|
||||
target.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pages.page_config_for_category",
|
||||
CmsConstants.CMS_BUNDLE,
|
||||
new Object[]{category.getName()}));
|
||||
}
|
||||
}
|
||||
|
||||
private void populatePageModelSelect(final PrintEvent event) {
|
||||
|
||||
// final PageState state = event.getPageState();
|
||||
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||
|
||||
// if (!selectedCategory.isSelected(state)) {
|
||||
// target.setVisible(state, false);
|
||||
// return;
|
||||
// }
|
||||
target.clearOptions();
|
||||
|
||||
target.addOption(new Option(INHERIT_PAGEMODEL,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.pages.assigned_page_model.inherit",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
|
||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final PageModelRepository pageModelRepo = cdiUtil.findBean(
|
||||
// PageModelRepository.class
|
||||
// );
|
||||
// final List<PageModel> pageModels = pageModelRepo
|
||||
// .findDraftByApplication(pagesInstance);
|
||||
// final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
// .findBean(GlobalizationHelper.class);
|
||||
// for (final PageModel pageModel : pageModels) {
|
||||
// target.addOption(
|
||||
// new Option(
|
||||
// Long.toString(pageModel.getPageModelId()),
|
||||
// new Text(
|
||||
// globalizationHelper.getValueFromLocalizedString(
|
||||
// pageModel.getTitle()
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
final PageModelAdminPageController controller = CdiUtil.createCdiUtil()
|
||||
.findBean(PageModelAdminPageController.class);
|
||||
final List<PageModelData> pageModels = controller
|
||||
.findDraftPageModelsByApplication(pagesInstance);
|
||||
for (final PageModelData pageModel : pageModels) {
|
||||
target.addOption(
|
||||
new Option(
|
||||
Long.toString(pageModel.getPageModelId()),
|
||||
new Text(pageModel.getTitle())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void categoryTreeStateChanged(final ChangeEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final String selectedKey = (String) categoryTree.getSelectedKey(state);
|
||||
selectedCategory.setSelectedKey(state, selectedKey);
|
||||
}
|
||||
|
||||
private void initPageModelForm(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
// pageModelForm.setVisible(state, selectedCategory.isSelected(state));
|
||||
saveCancelSection.setVisible(state, selectedCategory.isSelected(state));
|
||||
|
||||
if (!selectedCategory.isSelected(state)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
final PageRepository pageRepo = cdiUtil
|
||||
.findBean(PageRepository.class);
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(Long.parseLong(selectedCategory.getSelectedKey(state)))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
selectedCategory.getSelectedKey(state))));
|
||||
|
||||
final Optional<org.librecms.pages.Page> page = pageRepo
|
||||
.findPageForCategory(category);
|
||||
|
||||
if (page.isPresent()) {
|
||||
|
||||
// if (page.get().getIndexPageModel() == null) {
|
||||
// indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
// } else {
|
||||
// indexPageModelSelect.setValue(state,
|
||||
// Long.toString(page
|
||||
// .get()
|
||||
// .getIndexPageModel()
|
||||
// .getPageModelId()));
|
||||
// }
|
||||
//
|
||||
// if (page.get().getItemPageModel() == null) {
|
||||
// itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
// } else {
|
||||
// itemPageModelSelect.setValue(state,
|
||||
// Long.toString(page
|
||||
// .get()
|
||||
// .getItemPageModel()
|
||||
// .getPageModelId()));
|
||||
// }
|
||||
} else {
|
||||
indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL);
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePageModelForm(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
//Nothing for now
|
||||
}
|
||||
|
||||
private void processPageModelForm(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
final PageManager pageManager = cdiUtil
|
||||
.findBean(PageManager.class);
|
||||
final PageRepository pageRepo = cdiUtil
|
||||
.findBean(PageRepository.class);
|
||||
final PageModelRepository pageModelRepo = cdiUtil
|
||||
.findBean(PageModelRepository.class);
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(Long.parseLong(selectedCategory.getSelectedKey(state)))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
selectedCategory.getSelectedKey(state))));
|
||||
|
||||
final org.librecms.pages.Page page = pageRepo
|
||||
.findPageForCategory(category)
|
||||
.orElse(pageManager.createPageForCategory(category));
|
||||
|
||||
final String selectedIndexPageModelId = data
|
||||
.getString(INDEX_PAGE_MODEL_SELECT);
|
||||
final String selectedItemPageModelId = data
|
||||
.getString(ITEM_PAGE_MODEL_SELECT);
|
||||
|
||||
// if (!INHERIT_PAGEMODEL.equals(selectedIndexPageModelId)) {
|
||||
// final PageModel model = pageModelRepo
|
||||
// .findById(Long.parseLong(selectedIndexPageModelId))
|
||||
// .orElseThrow(() -> new UnexpectedErrorException(String
|
||||
// .format("No PageModel with ID %s in the database.",
|
||||
// selectedIndexPageModelId)));
|
||||
// page.setIndexPageModel(model);
|
||||
// }
|
||||
//
|
||||
// if (!INHERIT_PAGEMODEL.equals(selectedItemPageModelId)) {
|
||||
// final PageModel model = pageModelRepo
|
||||
// .findById(Long.parseLong(selectedItemPageModelId))
|
||||
// .orElseThrow(() -> new UnexpectedErrorException(String
|
||||
// .format("No PageModel with ID %s in the database.",
|
||||
// selectedItemPageModelId)));
|
||||
// page.setItemPageModel(model);
|
||||
// }
|
||||
|
||||
pageRepo.save(page);
|
||||
}
|
||||
|
||||
categoryTree.clearSelection(state);
|
||||
selectedCategory.clearSelection(state);
|
||||
}
|
||||
|
||||
private class CategoryTreeModelBuilder
|
||||
extends LockableImpl
|
||||
implements TreeModelBuilder {
|
||||
|
||||
@Override
|
||||
public TreeModel makeModel(final Tree tree,
|
||||
final PageState state) {
|
||||
|
||||
return new CategoriesTreeModel(tree,
|
||||
pagesInstance.getCategoryDomain());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pages;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.ContextBar;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.web.ApplicationRepository;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pages.Pages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class PagesContextBar extends ContextBar {
|
||||
|
||||
private Pages pagesInstance;
|
||||
|
||||
@Override
|
||||
public List<Entry> entries(final PageState state) {
|
||||
|
||||
final List<Entry> entries = super.entries(state);
|
||||
|
||||
final String centerTitle = (String) new GlobalizedMessage(
|
||||
"cms.ui.content_center", CmsConstants.CMS_BUNDLE).localize();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ApplicationRepository appRepo = cdiUtil.findBean(
|
||||
ApplicationRepository.class);
|
||||
final List<CcmApplication> apps = appRepo.findByType(
|
||||
CmsConstants.CONTENT_CENTER_APP_TYPE);
|
||||
|
||||
final String centerPath = apps.get(0).getPrimaryUrl();
|
||||
final URL url = URL.there(state.getRequest(), centerPath);
|
||||
entries.add(new Entry(centerTitle, url));
|
||||
|
||||
final URL pagesUrl = URL.there(
|
||||
state.getRequest(),
|
||||
pagesInstance.getPrimaryUrl());
|
||||
entries.add(new Entry(String.format("Pages:: %s",
|
||||
pagesInstance.getPrimaryUrl()),
|
||||
pagesUrl));
|
||||
|
||||
return entries;
|
||||
|
||||
}
|
||||
|
||||
protected Pages getPagesInstance() {
|
||||
return pagesInstance;
|
||||
}
|
||||
|
||||
protected void setPagesInstance(final Pages pagesInstance) {
|
||||
this.pagesInstance = pagesInstance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.pages;
|
||||
|
||||
import com.arsdigita.cms.ui.pages.PagesAdminPage;
|
||||
import com.arsdigita.templating.PresentationManager;
|
||||
import com.arsdigita.templating.Templating;
|
||||
import com.arsdigita.web.BaseApplicationServlet;
|
||||
import com.arsdigita.web.LoginSignal;
|
||||
import com.arsdigita.xml.Document;
|
||||
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.Shiro;
|
||||
import org.libreccm.web.ApplicationRepository;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* Servlet for the Admin UI for pages a {@link /ccm/{primaryUrl}}. The admin UI
|
||||
* itself is implemented by {@link PagesAdminPage}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@WebServlet(urlPatterns = {"/templates/servlet/pages/*"})
|
||||
public class PagesServlet extends BaseApplicationServlet {
|
||||
|
||||
private static final long serialVersionUID = -303317198251922697L;
|
||||
|
||||
@Inject
|
||||
private ApplicationRepository applicationRepo;
|
||||
|
||||
@Inject
|
||||
private PagesRepository pagesRepo;
|
||||
|
||||
@Inject
|
||||
private PermissionChecker permissionChecker;
|
||||
|
||||
@Inject
|
||||
private Shiro shiro;
|
||||
|
||||
@Override
|
||||
protected void doService(final HttpServletRequest request,
|
||||
final HttpServletResponse response,
|
||||
final CcmApplication application)
|
||||
throws ServletException, IOException {
|
||||
|
||||
if (!shiro.getSubject().isAuthenticated()) {
|
||||
throw new LoginSignal(request);
|
||||
}
|
||||
|
||||
if (!permissionChecker.isPermitted(PagesPrivileges.ADMINISTER_PAGES)) {
|
||||
throw new AuthorizationException("The current user is not "
|
||||
+ "permitted to administer pages.");
|
||||
}
|
||||
|
||||
final PagesAdminPage page = new PagesAdminPage();
|
||||
|
||||
if (!(application instanceof Pages)) {
|
||||
throw new ServletException(
|
||||
"Provided application is not an instance of Pages");
|
||||
}
|
||||
|
||||
page.setPagesInstance((Pages) application);
|
||||
|
||||
final Document document = page.buildDocument(request, response);
|
||||
|
||||
final PresentationManager presentationManager = Templating
|
||||
.getPresentationManager();
|
||||
presentationManager.servePage(document, request, response);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue