CCM NG/ccm-cms: Creating content items works now
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4695 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 0153f10833
pull/2/head
parent
2b319e2434
commit
af612dc774
|
|
@ -22,6 +22,11 @@
|
||||||
<Logger name="org.hibernate.type.descriptor.sql"
|
<Logger name="org.hibernate.type.descriptor.sql"
|
||||||
level="trace">
|
level="trace">
|
||||||
</Logger>-->
|
</Logger>-->
|
||||||
|
|
||||||
|
<!--<Logger name="com.arsdigita.bebop.util.Traversal"
|
||||||
|
level="debug">
|
||||||
|
</Logger>-->
|
||||||
|
|
||||||
<Logger name="com.arsdigita.cms.ui.assets.AssetFolderBrowserController"
|
<Logger name="com.arsdigita.cms.ui.assets.AssetFolderBrowserController"
|
||||||
level="debug">
|
level="debug">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ package com.arsdigita.cms.contenttypes.ui.mparticle;
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
import com.arsdigita.bebop.FormData;
|
import com.arsdigita.bebop.FormData;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.FormSection;
|
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
|
@ -36,7 +35,9 @@ import com.arsdigita.cms.ui.authoring.CreationSelector;
|
||||||
import com.arsdigita.cms.ui.authoring.LanguageWidget;
|
import com.arsdigita.cms.ui.authoring.LanguageWidget;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.arsdigita.cms.CMSConfig;
|
import org.arsdigita.cms.CMSConfig;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,150 @@
|
||||||
|
/*
|
||||||
|
* 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.authoring;
|
||||||
|
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.libreccm.workflow.AssignableTask;
|
||||||
|
import org.libreccm.workflow.AssignableTaskManager;
|
||||||
|
import org.libreccm.workflow.Workflow;
|
||||||
|
import org.libreccm.workflow.WorkflowManager;
|
||||||
|
import org.libreccm.workflow.WorkflowTemplate;
|
||||||
|
import org.libreccm.workflow.WorkflowTemplateRepository;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
import org.librecms.contentsection.ContentType;
|
||||||
|
import org.librecms.contentsection.ContentTypeRepository;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.nio.charset.IllegalCharsetNameException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
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 ApplyWorkflowController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentTypeRepository typeRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private WorkflowTemplateRepository templateRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private WorkflowManager workflowManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private AssignableTaskManager assignableTaskManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionChecker permissionChecker;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected WorkflowTemplate getDefaultWorkflow(final ContentType contentType) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(contentType);
|
||||||
|
|
||||||
|
final ContentType type = typeRepo
|
||||||
|
.findById(contentType.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalCharsetNameException(String.format(
|
||||||
|
"No ContentType with ID %d in the database. Where did that ID come from?",
|
||||||
|
contentType.getObjectId())));
|
||||||
|
|
||||||
|
return type.getDefaultWorkflow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
Long getDefaultWorkflowId(final ContentType contentType) {
|
||||||
|
final WorkflowTemplate workflowTemplate
|
||||||
|
= getDefaultWorkflow(contentType);
|
||||||
|
if (workflowTemplate == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return workflowTemplate.getWorkflowId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected List<WorkflowTemplate> getWorkflowTemplates(
|
||||||
|
final ContentSection section) {
|
||||||
|
|
||||||
|
final ContentSection contentSection = sectionRepo
|
||||||
|
.findById(section.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No ContentSection with ID %d in the database. "
|
||||||
|
+ "Where did that ID come from?",
|
||||||
|
section.getObjectId())));
|
||||||
|
|
||||||
|
return new ArrayList<>(contentSection.getWorkflowTemplates());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected void applyWorkflow(final ContentItem item,
|
||||||
|
final Folder folder,
|
||||||
|
final Long workflowTemplateId) {
|
||||||
|
|
||||||
|
final WorkflowTemplate workflowTemplate;
|
||||||
|
if (workflowTemplateId == null
|
||||||
|
&& permissionChecker
|
||||||
|
.isPermitted(ItemPrivileges.APPLY_ALTERNATE_WORKFLOW, folder)) {
|
||||||
|
|
||||||
|
workflowTemplate = templateRepo
|
||||||
|
.findById(workflowTemplateId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No WorkflowTemplate with ID %d in database. "
|
||||||
|
+ "Where did that ID come from?",
|
||||||
|
workflowTemplateId)));
|
||||||
|
} else {
|
||||||
|
workflowTemplate = item.getContentType().getDefaultWorkflow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (workflowTemplate != null) {
|
||||||
|
|
||||||
|
final Workflow workflow = workflowManager
|
||||||
|
.createWorkflow(workflowTemplate, item);
|
||||||
|
workflowManager.start(workflow);
|
||||||
|
|
||||||
|
if (!workflow.getTasks().isEmpty()) {
|
||||||
|
|
||||||
|
if (workflow.getTasks().get(0) instanceof AssignableTask) {
|
||||||
|
|
||||||
|
final AssignableTask task = (AssignableTask) workflow
|
||||||
|
.getTasks()
|
||||||
|
.get(0);
|
||||||
|
assignableTaskManager.lockTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -52,6 +52,7 @@ import org.libreccm.workflow.WorkflowTemplateRepository;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TooManyListenersException;
|
import java.util.TooManyListenersException;
|
||||||
|
|
||||||
|
|
@ -146,11 +147,13 @@ public class ApplyWorkflowFormSection
|
||||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
final ContentSection section = creationSelector.getContentSection(
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
state);
|
final ApplyWorkflowController controller = cdiUtil
|
||||||
final WorkflowTemplate template = contentType.getDefaultWorkflow();
|
.findBean(ApplyWorkflowController.class);
|
||||||
if (template != null) {
|
final Long workflowTemplateId = controller
|
||||||
radioGroup.setValue(state, template.getWorkflowId());
|
.getDefaultWorkflowId(contentType);
|
||||||
|
if (workflowTemplateId != null) {
|
||||||
|
radioGroup.setValue(state, workflowTemplateId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,7 +195,6 @@ public class ApplyWorkflowFormSection
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final PermissionChecker permissionChecker = cdiUtil
|
final PermissionChecker permissionChecker = cdiUtil
|
||||||
.findBean(PermissionChecker.class);
|
.findBean(PermissionChecker.class);
|
||||||
;
|
|
||||||
|
|
||||||
if (super.isVisible(state)
|
if (super.isVisible(state)
|
||||||
&& permissionChecker
|
&& permissionChecker
|
||||||
|
|
@ -215,52 +217,57 @@ public class ApplyWorkflowFormSection
|
||||||
*/
|
*/
|
||||||
public void applyWorkflow(final PageState state, final ContentItem item) {
|
public void applyWorkflow(final PageState state, final ContentItem item) {
|
||||||
|
|
||||||
final Long flowId = (Long) radioGroup.getValue(state);
|
final Long workflowTemplateId = (Long) radioGroup.getValue(state);
|
||||||
final ContentSection section = creationSelector.getContentSection(
|
|
||||||
state);
|
|
||||||
final Folder folder = creationSelector.getFolder(state);
|
final Folder folder = creationSelector.getFolder(state);
|
||||||
final WorkflowTemplate template;
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final PermissionChecker permissionChecker = cdiUtil
|
final ApplyWorkflowController controller = cdiUtil
|
||||||
.findBean(PermissionChecker.class);
|
.findBean(ApplyWorkflowController.class);
|
||||||
final WorkflowTemplateRepository templateRepo = cdiUtil
|
|
||||||
.findBean(WorkflowTemplateRepository.class);
|
|
||||||
|
|
||||||
if (flowId != null
|
controller.applyWorkflow(item, folder, workflowTemplateId);
|
||||||
&& permissionChecker.isPermitted(
|
|
||||||
ItemPrivileges.APPLY_ALTERNATE_WORKFLOW, folder)) {
|
|
||||||
template = templateRepo
|
|
||||||
.findById(flowId)
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
|
||||||
"No WorkflowTemplate with ID %d in database. "
|
|
||||||
+ "Where did that ID come from?")));
|
|
||||||
} else {
|
|
||||||
template = item.getContentType().getDefaultWorkflow();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template != null) {
|
// final WorkflowTemplate template;
|
||||||
|
//
|
||||||
final WorkflowManager workflowManager = cdiUtil
|
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.findBean(WorkflowManager.class);
|
// final PermissionChecker permissionChecker = cdiUtil
|
||||||
|
// .findBean(PermissionChecker.class);
|
||||||
final Workflow workflow = workflowManager.createWorkflow(template,
|
// final WorkflowTemplateRepository templateRepo = cdiUtil
|
||||||
item);
|
// .findBean(WorkflowTemplateRepository.class);
|
||||||
workflowManager.start(workflow);
|
//
|
||||||
|
// if (flowId != null
|
||||||
if (!workflow.getTasks().isEmpty()) {
|
// && permissionChecker.isPermitted(
|
||||||
|
// ItemPrivileges.APPLY_ALTERNATE_WORKFLOW, folder)) {
|
||||||
if (workflow.getTasks().get(0) instanceof AssignableTask) {
|
// template = templateRepo
|
||||||
|
// .findById(flowId)
|
||||||
final AssignableTaskManager taskManager = cdiUtil
|
// .orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
.findBean(AssignableTaskManager.class);
|
// "No WorkflowTemplate with ID %d in database. "
|
||||||
final AssignableTask task = (AssignableTask) workflow
|
// + "Where did that ID come from?")));
|
||||||
.getTasks()
|
// } else {
|
||||||
.get(0);
|
// template = item.getContentType().getDefaultWorkflow();
|
||||||
taskManager.lockTask(task);
|
// }
|
||||||
}
|
//
|
||||||
}
|
// if (template != null) {
|
||||||
}
|
//
|
||||||
|
// final WorkflowManager workflowManager = cdiUtil
|
||||||
|
// .findBean(WorkflowManager.class);
|
||||||
|
//
|
||||||
|
// final Workflow workflow = workflowManager.createWorkflow(template,
|
||||||
|
// item);
|
||||||
|
// workflowManager.start(workflow);
|
||||||
|
//
|
||||||
|
// if (!workflow.getTasks().isEmpty()) {
|
||||||
|
//
|
||||||
|
// if (workflow.getTasks().get(0) instanceof AssignableTask) {
|
||||||
|
//
|
||||||
|
// final AssignableTaskManager taskManager = cdiUtil
|
||||||
|
// .findBean(AssignableTaskManager.class);
|
||||||
|
// final AssignableTask task = (AssignableTask) workflow
|
||||||
|
// .getTasks()
|
||||||
|
// .get(0);
|
||||||
|
// taskManager.lockTask(task);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,12 +276,20 @@ public class ApplyWorkflowFormSection
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ContentSection getContentSection(final PageState state) {
|
protected ContentSection getContentSection(final PageState state) {
|
||||||
|
|
||||||
return creationSelector.getContentSection(state);
|
return creationSelector.getContentSection(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<WorkflowTemplate> getCollection(final PageState state) {
|
protected List<WorkflowTemplate> getCollection(final PageState state) {
|
||||||
return super.getCollection(state);
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ApplyWorkflowController controller = cdiUtil
|
||||||
|
.findBean(ApplyWorkflowController.class);
|
||||||
|
|
||||||
|
final ContentSection section = creationSelector
|
||||||
|
.getContentSection(state);
|
||||||
|
|
||||||
|
return controller.getWorkflowTemplates(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
import com.arsdigita.cms.ui.ContentItemPage;
|
||||||
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
import com.arsdigita.cms.ui.folder.FolderSelectionModel;
|
||||||
import com.arsdigita.cms.ui.item.ItemCreateForm;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
import com.arsdigita.web.RedirectSignal;
|
import com.arsdigita.web.RedirectSignal;
|
||||||
import com.arsdigita.web.URL;
|
import com.arsdigita.web.URL;
|
||||||
|
|
@ -45,6 +44,7 @@ import org.librecms.contentsection.ContentType;
|
||||||
import org.librecms.contentsection.ContentTypeManager;
|
import org.librecms.contentsection.ContentTypeManager;
|
||||||
import org.librecms.contentsection.ContentTypeRepository;
|
import org.librecms.contentsection.ContentTypeRepository;
|
||||||
import org.librecms.contentsection.Folder;
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contentsection.FolderRepository;
|
||||||
import org.librecms.contenttypes.AuthoringKitInfo;
|
import org.librecms.contenttypes.AuthoringKitInfo;
|
||||||
import org.librecms.contenttypes.ContentTypeInfo;
|
import org.librecms.contenttypes.ContentTypeInfo;
|
||||||
import org.librecms.contenttypes.ContentTypesManager;
|
import org.librecms.contenttypes.ContentTypesManager;
|
||||||
|
|
@ -92,7 +92,7 @@ public class CreationSelector extends MetaForm {
|
||||||
private final FolderSelectionModel folderSelectionModel;
|
private final FolderSelectionModel folderSelectionModel;
|
||||||
private final SingleSelectionModel<Long> typeSelectionModel;
|
private final SingleSelectionModel<Long> typeSelectionModel;
|
||||||
|
|
||||||
private static Class[] arguments = new Class[]{
|
private static final Class[] ARGUMENTS = new Class[]{
|
||||||
ItemSelectionModel.class,
|
ItemSelectionModel.class,
|
||||||
CreationSelector.class
|
CreationSelector.class
|
||||||
};
|
};
|
||||||
|
|
@ -108,11 +108,13 @@ public class CreationSelector extends MetaForm {
|
||||||
* Constructs a new <code>CreationSelector</code>. Load all the possible
|
* Constructs a new <code>CreationSelector</code>. Load all the possible
|
||||||
* creation components from the database and stick them in the Map.
|
* creation components from the database and stick them in the Map.
|
||||||
*
|
*
|
||||||
* @param typeSelectionModel the {@link SingleSelectionModel} which will
|
* @param typeSelectionModel the {@link SingleSelectionModel} which will
|
||||||
* supply a BigDecimal ID of the content type to instantiate
|
* supply a BigDecimal ID of the content type to
|
||||||
|
* instantiate
|
||||||
*
|
*
|
||||||
* @param folderSelectionModel the {@link FolderSelectionModel} containing
|
* @param folderSelectionModel the {@link FolderSelectionModel} containing
|
||||||
* the folder in which new items are to be created
|
* the folder in which new items are to be
|
||||||
|
* created
|
||||||
*/
|
*/
|
||||||
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
|
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
|
||||||
final FolderSelectionModel folderSelectionModel) {
|
final FolderSelectionModel folderSelectionModel) {
|
||||||
|
|
@ -156,8 +158,8 @@ public class CreationSelector extends MetaForm {
|
||||||
throw new UncheckedWrapperException(String.format(
|
throw new UncheckedWrapperException(String.format(
|
||||||
"Type with id %d not found.", typeId));
|
"Type with id %d not found.", typeId));
|
||||||
}
|
}
|
||||||
final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(
|
final ContentTypeInfo typeInfo = typesManager
|
||||||
type.get());
|
.getContentTypeInfo(type.get());
|
||||||
final AuthoringKitInfo kit = typeInfo.getAuthoringKit();
|
final AuthoringKitInfo kit = typeInfo.getAuthoringKit();
|
||||||
component = instantiateKitComponent(kit, type.get());
|
component = instantiateKitComponent(kit, type.get());
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
|
|
@ -195,24 +197,25 @@ public class CreationSelector extends MetaForm {
|
||||||
final Object[] vals;
|
final Object[] vals;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ItemSelectionModel itemModel = new ItemSelectionModel(type,
|
final ItemSelectionModel itemSelectionModel
|
||||||
itemIdParameter);
|
= new ItemSelectionModel(
|
||||||
vals = new Object[]{itemModel, this};
|
type, itemIdParameter);
|
||||||
|
vals = new Object[]{itemSelectionModel, this};
|
||||||
|
|
||||||
final Constructor<? extends FormSection> constructor = createClass
|
final Constructor<? extends FormSection> constructor = createClass
|
||||||
.getConstructor(arguments);
|
.getConstructor(ARGUMENTS);
|
||||||
final Component component = (Component) constructor
|
final Component component = (Component) constructor
|
||||||
.newInstance(vals);
|
.newInstance(vals);
|
||||||
return component;
|
return component;
|
||||||
} catch (IllegalAccessException
|
} catch (IllegalAccessException
|
||||||
| IllegalArgumentException
|
| IllegalArgumentException
|
||||||
| InstantiationException
|
| InstantiationException
|
||||||
| NoSuchMethodException
|
| NoSuchMethodException
|
||||||
| SecurityException
|
| SecurityException
|
||||||
| InvocationTargetException ex) {
|
| InvocationTargetException ex) {
|
||||||
LOGGER.error("\"Failed to instantiate creation component \"{}\".",
|
LOGGER.error("Failed to instantiate creation component \"{}\".",
|
||||||
kit.getCreateComponent().getName());
|
kit.getCreateComponent().getName());
|
||||||
LOGGER.error(ex);
|
LOGGER.error("Exception: ", ex);
|
||||||
throw new UncheckedWrapperException(String.format(
|
throw new UncheckedWrapperException(String.format(
|
||||||
"Failed to instantiate creation component \"%s\".",
|
"Failed to instantiate creation component \"%s\".",
|
||||||
kit.getCreateComponent().getName()),
|
kit.getCreateComponent().getName()),
|
||||||
|
|
@ -227,10 +230,10 @@ public class CreationSelector extends MetaForm {
|
||||||
* @param state represents the current request
|
* @param state represents the current request
|
||||||
*
|
*
|
||||||
* @return the currently selected folder, in which new items should be
|
* @return the currently selected folder, in which new items should be
|
||||||
* placed.
|
* placed.
|
||||||
*/
|
*/
|
||||||
public final Folder getFolder(final PageState state) {
|
public final Folder getFolder(final PageState state) {
|
||||||
return (Folder) folderSelectionModel.getSelectedObject(state);
|
return folderSelectionModel.getSelectedObject(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -244,9 +247,12 @@ public class CreationSelector extends MetaForm {
|
||||||
* @return the currently selected content section.
|
* @return the currently selected content section.
|
||||||
*/
|
*/
|
||||||
public final ContentSection getContentSection(final PageState state) {
|
public final ContentSection getContentSection(final PageState state) {
|
||||||
final ContentSection section = getFolder(state).getSection();
|
|
||||||
|
|
||||||
return section;
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CreationSelectorController controller = cdiUtil
|
||||||
|
.findBean(CreationSelectorController.class);
|
||||||
|
|
||||||
|
return controller.getContentSectionForFolder(getFolder(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -255,7 +261,7 @@ public class CreationSelector extends MetaForm {
|
||||||
* complete.
|
* complete.
|
||||||
*
|
*
|
||||||
* @param state the page state
|
* @param state the page state
|
||||||
* @param item the newly created item
|
* @param item the newly created item
|
||||||
*/
|
*/
|
||||||
public void editItem(final PageState state, final ContentItem item) {
|
public void editItem(final PageState state, final ContentItem item) {
|
||||||
final ContentSection section = getContentSection(state);
|
final ContentSection section = getContentSection(state);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* 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.authoring;
|
||||||
|
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contentsection.FolderRepository;
|
||||||
|
|
||||||
|
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 CreationSelectorController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private FolderRepository folderRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected ContentSection getContentSectionForFolder(final Folder folder) {
|
||||||
|
|
||||||
|
final Folder theFolder = folderRepo
|
||||||
|
.findById(folder.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No Folder with ID %d in the database. Where did that ID come from?",
|
||||||
|
folder.getObjectId())));
|
||||||
|
|
||||||
|
final ContentSection section = theFolder.getSection();
|
||||||
|
|
||||||
|
return sectionRepo
|
||||||
|
.findById(section.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No ContentSection with ID %d in the database.",
|
||||||
|
section.getObjectId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -23,8 +23,11 @@ import com.arsdigita.bebop.FormData;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.Text;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
|
import com.arsdigita.bebop.event.PrintEvent;
|
||||||
|
import com.arsdigita.bebop.event.PrintListener;
|
||||||
|
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.ContentType;
|
import org.librecms.contentsection.ContentType;
|
||||||
|
|
@ -35,10 +38,15 @@ import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contenttypes.ContentTypeInfo;
|
||||||
|
import org.librecms.contenttypes.ContentTypesManager;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form which will create a new document (that is subclasses of class
|
* A form which will create a new document (that is subclasses of class
|
||||||
|
|
@ -59,7 +67,7 @@ public class PageCreateForm
|
||||||
implements FormSubmissionListener, CreationComponent {
|
implements FormSubmissionListener, CreationComponent {
|
||||||
|
|
||||||
private final CreationSelector creationSelector;
|
private final CreationSelector creationSelector;
|
||||||
private final ApplyWorkflowFormSection workflowSection;
|
private ApplyWorkflowFormSection workflowSection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state parameter which specifies the content section
|
* The state parameter which specifies the content section
|
||||||
|
|
@ -78,17 +86,12 @@ public class PageCreateForm
|
||||||
* eventually
|
* eventually
|
||||||
*/
|
*/
|
||||||
public PageCreateForm(final ItemSelectionModel itemModel,
|
public PageCreateForm(final ItemSelectionModel itemModel,
|
||||||
final CreationSelector creationSelector) {
|
final CreationSelector creationSelector) {
|
||||||
|
|
||||||
super("PageCreate", itemModel);
|
super("PageCreate", itemModel);
|
||||||
|
|
||||||
this.creationSelector = creationSelector;
|
this.creationSelector = creationSelector;
|
||||||
|
|
||||||
/* Retrieve Content Type */
|
|
||||||
final ContentType type = getItemSelectionModel().getContentType();
|
|
||||||
/* Add workflow selection based on configured Content Type */
|
|
||||||
workflowSection = new ApplyWorkflowFormSection(type);
|
|
||||||
|
|
||||||
workflowSection.setCreationSelector(creationSelector);
|
workflowSection.setCreationSelector(creationSelector);
|
||||||
addSubmissionListener(this);
|
addSubmissionListener(this);
|
||||||
|
|
||||||
|
|
@ -104,15 +107,21 @@ public class PageCreateForm
|
||||||
@Override
|
@Override
|
||||||
protected void addWidgets() {
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
/* Retrieve Content Type */
|
||||||
|
final ContentType type = getItemSelectionModel().getContentType();
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentTypesManager typesManager = cdiUtil
|
||||||
|
.findBean(ContentTypesManager.class);
|
||||||
|
final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(type);
|
||||||
|
|
||||||
|
/* Add workflow selection based on configured Content Type */
|
||||||
|
workflowSection = new ApplyWorkflowFormSection(type);
|
||||||
add(workflowSection, ColumnPanel.INSERT);
|
add(workflowSection, ColumnPanel.INSERT);
|
||||||
/* content type */
|
/* content type */
|
||||||
add(new Label(new GlobalizedMessage("cms.ui.authoring.content_type",
|
add(new Label(new GlobalizedMessage("cms.ui.authoring.content_type",
|
||||||
CmsConstants.CMS_BUNDLE)));
|
CmsConstants.CMS_BUNDLE)));
|
||||||
/* Retrieve Content Type */
|
final Label typeOutput = new Label(new ContentTypePrintListener(typeInfo));
|
||||||
final ContentType type = getItemSelectionModel().getContentType();
|
add(typeOutput);
|
||||||
add(new Label(type.getLabel().getValue(KernelConfig
|
|
||||||
.getConfig()
|
|
||||||
.getDefaultLocale())));
|
|
||||||
/* language selection */
|
/* language selection */
|
||||||
add(new Label(new GlobalizedMessage("cms.ui.language.field",
|
add(new Label(new GlobalizedMessage("cms.ui.language.field",
|
||||||
CmsConstants.CMS_BUNDLE)));
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
|
@ -138,6 +147,7 @@ public class PageCreateForm
|
||||||
* Create a new item id.
|
* Create a new item id.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
|
*
|
||||||
* @throws com.arsdigita.bebop.FormProcessException
|
* @throws com.arsdigita.bebop.FormProcessException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -150,6 +160,7 @@ public class PageCreateForm
|
||||||
* component.
|
* component.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
|
*
|
||||||
* @throws com.arsdigita.bebop.FormProcessException
|
* @throws com.arsdigita.bebop.FormProcessException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -217,4 +228,30 @@ public class PageCreateForm
|
||||||
creationSelector.editItem(state, item);
|
creationSelector.editItem(state, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ContentTypePrintListener implements PrintListener {
|
||||||
|
|
||||||
|
private final ContentTypeInfo typeInfo;
|
||||||
|
|
||||||
|
public ContentTypePrintListener(final ContentTypeInfo typeInfo) {
|
||||||
|
this.typeInfo = typeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare(final PrintEvent event) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final ResourceBundle bundle = ResourceBundle
|
||||||
|
.getBundle(typeInfo.getLabelBundle(),
|
||||||
|
globalizationHelper.getNegotiatedLocale());
|
||||||
|
|
||||||
|
final String typeLabel = bundle.getString(typeInfo.getLabelKey());
|
||||||
|
|
||||||
|
final Label target = (Label) event.getTarget();
|
||||||
|
target.setLabel(typeLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,11 @@ import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.bebop.form.OptionGroup;
|
import com.arsdigita.bebop.form.OptionGroup;
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.libreccm.workflow.Task;
|
|
||||||
import org.libreccm.workflow.WorkflowTemplate;
|
import org.libreccm.workflow.WorkflowTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,9 +42,12 @@ import org.libreccm.workflow.WorkflowTemplate;
|
||||||
public class WorkflowsOptionPrintListener implements PrintListener {
|
public class WorkflowsOptionPrintListener implements PrintListener {
|
||||||
|
|
||||||
protected List<WorkflowTemplate> getCollection(final PageState state) {
|
protected List<WorkflowTemplate> getCollection(final PageState state) {
|
||||||
final ContentSection section = getContentSection(state);
|
|
||||||
|
|
||||||
return section.getWorkflowTemplates();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final WorkflowsOptionPrintListenerController controller = cdiUtil
|
||||||
|
.findBean(WorkflowsOptionPrintListenerController.class);
|
||||||
|
|
||||||
|
return controller.getWorkflowTemplates(getContentSection(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ContentSection getContentSection(final PageState state) {
|
protected ContentSection getContentSection(final PageState state) {
|
||||||
|
|
@ -52,6 +56,7 @@ public class WorkflowsOptionPrintListener implements PrintListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(final PrintEvent event) {
|
public void prepare(final PrintEvent event) {
|
||||||
|
|
||||||
final PageState state = event.getPageState();
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
final OptionGroup target = (OptionGroup) event.getTarget();
|
final OptionGroup target = (OptionGroup) event.getTarget();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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.workflow;
|
||||||
|
|
||||||
|
|
||||||
|
import org.libreccm.workflow.WorkflowTemplate;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
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 WorkflowsOptionPrintListenerController {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected List<WorkflowTemplate> getWorkflowTemplates(
|
||||||
|
final ContentSection section) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(section);
|
||||||
|
|
||||||
|
final ContentSection contentSection = sectionRepo
|
||||||
|
.findById(section.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No ContentSection with ID %d in the database. "
|
||||||
|
+ "Where did that ID come from?",
|
||||||
|
section.getObjectId())));
|
||||||
|
|
||||||
|
return contentSection.getWorkflowTemplates();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -41,7 +41,6 @@ import java.util.ArrayList;
|
||||||
import javax.persistence.NamedQueries;
|
import javax.persistence.NamedQueries;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import org.libreccm.core.CoreConstants;
|
|
||||||
|
|
||||||
import org.libreccm.workflow.WorkflowTemplate;
|
import org.libreccm.workflow.WorkflowTemplate;
|
||||||
import org.librecms.contentsection.privileges.AssetPrivileges;
|
import org.librecms.contentsection.privileges.AssetPrivileges;
|
||||||
|
|
|
||||||
|
|
@ -140,19 +140,20 @@ public class ContentTypesManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final AuthoringKit authoringKit = contentTypeClass.getAnnotation(
|
final AuthoringKit authoringKit = contentTypeClass
|
||||||
AuthoringKit.class);
|
.getAnnotation(AuthoringKit.class);
|
||||||
if (authoringKit != null) {
|
if (authoringKit != null) {
|
||||||
final AuthoringKitInfo authoringKitInfo = new AuthoringKitInfo();
|
final AuthoringKitInfo authoringKitInfo = new AuthoringKitInfo();
|
||||||
authoringKitInfo.setCreateComponent(authoringKit.createComponent());
|
authoringKitInfo.setCreateComponent(authoringKit.createComponent());
|
||||||
|
|
||||||
final List<AuthoringStepInfo> steps = Arrays.stream(authoringKit
|
final List<AuthoringStepInfo> steps = Arrays
|
||||||
.steps())
|
.stream(authoringKit.steps())
|
||||||
.map(step -> createAuthoringStepInfo(contentTypeClass, step))
|
.map(step -> createAuthoringStepInfo(contentTypeClass, step))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
authoringKitInfo.setAuthoringSteps(steps);
|
authoringKitInfo.setAuthoringSteps(steps);
|
||||||
steps.sort((step1, step2) -> Integer.compare(step1.getOrder(),
|
steps.sort((step1, step2) -> Integer.compare(step1.getOrder(),
|
||||||
step2.getOrder()));
|
step2.getOrder()));
|
||||||
|
contentTypeInfo.setAuthoringKit(authoringKitInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentTypeInfo;
|
return contentTypeInfo;
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ public class MultiPartArticle extends ContentItem implements Serializable {
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "OBJECT_ID")}
|
@JoinColumn(name = "OBJECT_ID")}
|
||||||
))
|
))
|
||||||
private LocalizedString summary;
|
private LocalizedString summary = new LocalizedString();
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
@JoinColumn(name = "MULTIPART_ARTICLE_ID")
|
@JoinColumn(name = "MULTIPART_ARTICLE_ID")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
import com.arsdigita.globalization.Globalized;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules which depend on CMS should implement this interface instead of
|
||||||
|
* com.arsdigita.globalization.Globalized to gain access to CMS globalization
|
||||||
|
* resource file (specifically important for content type packages).
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:yon@arsdigita.com">yon@arsdigita.com</a>
|
||||||
|
* @version $Revision: #5 $ $Date: 2004/08/17 $
|
||||||
|
*/
|
||||||
|
public interface CMSGlobalized extends Globalized {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The central CMS resource file (per language) which may be used by
|
||||||
|
* all of CMS specific modules.
|
||||||
|
* It overwrites the file provided by globalization package as a generic
|
||||||
|
* default/fall back!
|
||||||
|
*/
|
||||||
|
public static final String BUNDLE_NAME = "com.arsdigita.cms.CMSResources";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.globalization.ChainedResourceBundle;
|
||||||
|
|
||||||
|
import java.util.PropertyResourceBundle;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
|
||||||
|
// Developers Note (2013-04):
|
||||||
|
// No longer used because we found no way to make localization work properly.
|
||||||
|
// Back to use plain property files as of 2013-04 (version 6.6.8)
|
||||||
|
// Retained for easy reference to further develop localization infrastructure.
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main ResourceBundle for CMS UI.
|
||||||
|
* Can be extended using:
|
||||||
|
* - addBundle - to add new keys
|
||||||
|
* - putBundle - to override keys already in CMSResources e.g. to customize
|
||||||
|
* notification email text
|
||||||
|
*/
|
||||||
|
public class CMSResourceBundle extends ChainedResourceBundle implements CMSGlobalized {
|
||||||
|
|
||||||
|
public CMSResourceBundle() {
|
||||||
|
super();
|
||||||
|
// addBundle((PropertyResourceBundle) getBundle(BUNDLE_NAME));
|
||||||
|
|
||||||
|
// try to make proper localisation work, no success, ne regression either
|
||||||
|
addBundle((PropertyResourceBundle) getBundle(BUNDLE_NAME,
|
||||||
|
ResourceBundle.Control.getNoFallbackControl(
|
||||||
|
ResourceBundle.Control.FORMAT_DEFAULT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,516 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
|
import com.arsdigita.cms.ContentItem;
|
||||||
|
import com.arsdigita.cms.ItemCollection;
|
||||||
|
import com.arsdigita.cms.Folder;
|
||||||
|
import com.arsdigita.cms.TextAsset;
|
||||||
|
import com.arsdigita.cms.contenttypes.GenericArticle;
|
||||||
|
import com.arsdigita.kernel.Kernel;
|
||||||
|
import com.arsdigita.kernel.KernelExcursion;
|
||||||
|
import com.arsdigita.persistence.DataCollection;
|
||||||
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
import com.arsdigita.persistence.Session;
|
||||||
|
import com.arsdigita.persistence.SessionManager;
|
||||||
|
import com.arsdigita.persistence.TransactionContext;
|
||||||
|
import com.arsdigita.util.cmd.Program;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Jens Pelzetter
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("PMD.SystemPrintln")
|
||||||
|
public class ContentItemNameFix extends Program {
|
||||||
|
|
||||||
|
private boolean pretend = false;
|
||||||
|
|
||||||
|
public ContentItemNameFix() {
|
||||||
|
super("ContentItemNameFix", "1.0.0", "");
|
||||||
|
|
||||||
|
getOptions().addOption(
|
||||||
|
OptionBuilder
|
||||||
|
.hasArg(false)
|
||||||
|
.withLongOpt("pretend")
|
||||||
|
.withDescription("Only show what would be done")
|
||||||
|
.create("p"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void main(final String[] args) {
|
||||||
|
new ContentItemNameFix().run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doRun(final CommandLine cmdLine) {
|
||||||
|
|
||||||
|
System.out.printf("Running ContentItemNameFix...\n");
|
||||||
|
|
||||||
|
pretend = cmdLine.hasOption("p");
|
||||||
|
|
||||||
|
if (pretend) {
|
||||||
|
System.out.printf("Pretend option is on, only showing what would be done...\n\n");
|
||||||
|
} else {
|
||||||
|
System.out.print("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
new KernelExcursion() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void excurse() {
|
||||||
|
setEffectiveParty(Kernel.getSystemParty());
|
||||||
|
|
||||||
|
final Set<LinkToCheck> linksToCheck = new HashSet<LinkToCheck>();
|
||||||
|
|
||||||
|
final Session session = SessionManager.getSession();
|
||||||
|
final TransactionContext transactionContext = session.getTransactionContext();
|
||||||
|
|
||||||
|
transactionContext.beginTxn();
|
||||||
|
|
||||||
|
final DataCollection draftFolders = session.retrieve(Folder.BASE_DATA_OBJECT_TYPE);
|
||||||
|
draftFolders.addEqualsFilter(ContentItem.VERSION, "draft");
|
||||||
|
|
||||||
|
while (draftFolders.next()) {
|
||||||
|
checkFolder(draftFolders.getDataObject(), linksToCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
final DataCollection draftBundles = session.retrieve(
|
||||||
|
ContentBundle.BASE_DATA_OBJECT_TYPE);
|
||||||
|
draftBundles.addEqualsFilter(ContentItem.VERSION, "draft");
|
||||||
|
|
||||||
|
while (draftBundles.next()) {
|
||||||
|
checkBundle(draftBundles.getDataObject(), linksToCheck);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
transactionContext.commitTxn();
|
||||||
|
|
||||||
|
System.out.println("-------------------------------------------------------------");
|
||||||
|
|
||||||
|
System.out.println("Checking for potentially brocken links...");
|
||||||
|
System.out.println("GenericArticle (ccm-cms-types-article, ccm-cms-types-news, ...");
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
final DataCollection articles = session.retrieve(
|
||||||
|
GenericArticle.BASE_DATA_OBJECT_TYPE);
|
||||||
|
articles.addEqualsFilter(ContentItem.VERSION, "draft");
|
||||||
|
while (articles.next()) {
|
||||||
|
checkArticle(articles.getDataObject(), linksToCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
System.out.println("MultiPartArticles...");
|
||||||
|
System.out.println("");
|
||||||
|
|
||||||
|
final DataCollection mpArticles = session.retrieve(
|
||||||
|
"com.arsdigita.cms.contenttypes.MultiPartArticle");
|
||||||
|
mpArticles.addEqualsFilter(ContentItem.VERSION, "draft");
|
||||||
|
while (mpArticles.next()) {
|
||||||
|
checkMpArticle(mpArticles.getDataObject(), linksToCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}.run();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkFolder(final DataObject folderObj, final Set<LinkToCheck> linksToCheck) {
|
||||||
|
|
||||||
|
final Folder draftFolder = new Folder(folderObj);
|
||||||
|
final Folder liveFolder = (Folder) draftFolder.getLiveVersion();
|
||||||
|
|
||||||
|
if (liveFolder != null && !draftFolder.getName().equals(liveFolder.getName())) {
|
||||||
|
System.out.printf("Problems with folder %s:/%s (id: %s):\n",
|
||||||
|
draftFolder.getContentSection().getName(),
|
||||||
|
draftFolder.getPath(),
|
||||||
|
draftFolder.getID().toString());
|
||||||
|
System.out.printf("\t Live Folder has wrong name: Is '%s' but should be '%s'.",
|
||||||
|
liveFolder.getName(),
|
||||||
|
draftFolder.getName());
|
||||||
|
|
||||||
|
linksToCheck.add(new LinkToCheck(liveFolder.getName(),
|
||||||
|
draftFolder.getName(),
|
||||||
|
String.format("%s:/%s",
|
||||||
|
liveFolder.getContentSection().getName(),
|
||||||
|
liveFolder.getPath()),
|
||||||
|
String.format("%s:/%s",
|
||||||
|
draftFolder.getContentSection().getName(),
|
||||||
|
draftFolder.getPath())));
|
||||||
|
|
||||||
|
if (pretend) {
|
||||||
|
System.out.print("\n\n");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
liveFolder.setName(draftFolder.getName());
|
||||||
|
System.out.print(" Corrected.\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBundle(final DataObject bundleObj, final Set<LinkToCheck> linksToCheck) {
|
||||||
|
|
||||||
|
final ContentBundle draftBundle = new ContentBundle(bundleObj);
|
||||||
|
final ContentItem primaryDraftItem = draftBundle.getPrimaryInstance();
|
||||||
|
|
||||||
|
final String itemId = primaryDraftItem.getID().toString();
|
||||||
|
final String itemPath = String.format("%s:/%s",
|
||||||
|
primaryDraftItem.getContentSection().getName(),
|
||||||
|
primaryDraftItem.getPath());
|
||||||
|
|
||||||
|
final HeaderStatus headerStatus = new HeaderStatus();
|
||||||
|
|
||||||
|
//This is our reference, all bundles, instances etc belonging to the item sould have this
|
||||||
|
//name
|
||||||
|
final String itemName = primaryDraftItem.getName();
|
||||||
|
|
||||||
|
if (!draftBundle.getName().equals(itemName)) {
|
||||||
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
|
|
||||||
|
System.out.printf(
|
||||||
|
"\t Draft ContentBundle has wrong name: Is '%s' but should be '%s'.",
|
||||||
|
itemName,
|
||||||
|
draftBundle.getName());
|
||||||
|
|
||||||
|
linksToCheck.add(new LinkToCheck(draftBundle.getName(),
|
||||||
|
itemName,
|
||||||
|
String.format("%s:/%s",
|
||||||
|
draftBundle.getContentSection().getName(),
|
||||||
|
draftBundle.getPath()),
|
||||||
|
itemPath));
|
||||||
|
|
||||||
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
|
draftBundle.setName(itemName);
|
||||||
|
System.out.printf(" Corrected.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkInstances(draftBundle, itemName, itemId, itemPath, headerStatus, linksToCheck);
|
||||||
|
|
||||||
|
final ContentBundle liveBundle = (ContentBundle) draftBundle.getLiveVersion();
|
||||||
|
if (liveBundle != null) {
|
||||||
|
if (!liveBundle.getName().equals(itemName)) {
|
||||||
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
|
|
||||||
|
System.out.printf(
|
||||||
|
"\tLive ContentBundle has wrong name. Should be '%s' but is '%s'",
|
||||||
|
itemName,
|
||||||
|
liveBundle.getName());
|
||||||
|
|
||||||
|
linksToCheck.add(new LinkToCheck(liveBundle.getName(),
|
||||||
|
itemName,
|
||||||
|
String.format("%s:/%s",
|
||||||
|
liveBundle.getContentSection()
|
||||||
|
.getName(),
|
||||||
|
liveBundle.getPath()),
|
||||||
|
itemPath));
|
||||||
|
|
||||||
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
|
liveBundle.setName(itemName);
|
||||||
|
System.out.printf(" Corrected.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkInstances(liveBundle, itemName, itemId, itemPath, headerStatus, linksToCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headerStatus.isHeaderPrinted()) {
|
||||||
|
System.out.print("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkInstances(final ContentBundle draftBundle,
|
||||||
|
final String itemName,
|
||||||
|
final String itemId,
|
||||||
|
final String itemPath,
|
||||||
|
final HeaderStatus headerStatus,
|
||||||
|
final Set<LinkToCheck> linksToCheck) {
|
||||||
|
final ItemCollection instances = draftBundle.getInstances();
|
||||||
|
ContentItem current;
|
||||||
|
while (instances.next()) {
|
||||||
|
current = instances.getContentItem();
|
||||||
|
|
||||||
|
if (!itemName.equals(current.getName())) {
|
||||||
|
printItemHeaderLine(itemId, itemPath, headerStatus);
|
||||||
|
System.out.printf(
|
||||||
|
"\t%s instance %s (language: %s has wrong name. Should be '%s', but is '%s'.",
|
||||||
|
current.getVersion(),
|
||||||
|
current.getID().toString(),
|
||||||
|
current.getLanguage(),
|
||||||
|
itemName,
|
||||||
|
current.getName());
|
||||||
|
|
||||||
|
linksToCheck.add(new LinkToCheck(current.getName(),
|
||||||
|
itemName,
|
||||||
|
String.format("%s:/%s",
|
||||||
|
current.getContentSection().getName(),
|
||||||
|
current.getPath()),
|
||||||
|
itemPath));
|
||||||
|
|
||||||
|
if (pretend) {
|
||||||
|
System.out.print("\n");
|
||||||
|
} else {
|
||||||
|
current.setName(itemName);
|
||||||
|
System.out.printf(" Corrected.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class HeaderStatus {
|
||||||
|
|
||||||
|
private boolean headerPrinted = false;
|
||||||
|
|
||||||
|
public HeaderStatus() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHeaderPrinted() {
|
||||||
|
return headerPrinted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderPrinted(final boolean headerPrinted) {
|
||||||
|
this.headerPrinted = headerPrinted;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printItemHeaderLine(final String itemId,
|
||||||
|
final String itemPath,
|
||||||
|
final HeaderStatus headerStatus) {
|
||||||
|
if (!headerStatus.isHeaderPrinted()) {
|
||||||
|
System.out.printf("Problems with item %s (id: %s):\n", itemPath, itemId);
|
||||||
|
headerStatus.setHeaderPrinted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LinkToCheck {
|
||||||
|
|
||||||
|
private String wrongName;
|
||||||
|
private String correctName;
|
||||||
|
private String wrongPath;
|
||||||
|
private String correctPath;
|
||||||
|
|
||||||
|
public LinkToCheck() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkToCheck(final String wrongName,
|
||||||
|
final String correctName,
|
||||||
|
final String wrongPath,
|
||||||
|
final String correctPath) {
|
||||||
|
this.wrongName = wrongName;
|
||||||
|
this.correctName = correctName;
|
||||||
|
this.wrongPath = wrongPath;
|
||||||
|
this.correctPath = correctPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWrongName() {
|
||||||
|
return wrongName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWrongName(final String wrongName) {
|
||||||
|
this.wrongName = wrongName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCorrectName() {
|
||||||
|
return correctName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorrectName(final String correctName) {
|
||||||
|
this.correctName = correctName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWrongPath() {
|
||||||
|
return wrongPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWrongPath(final String wrongPath) {
|
||||||
|
this.wrongPath = wrongPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCorrectPath() {
|
||||||
|
return correctPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorrectPath(final String correctPath) {
|
||||||
|
this.correctPath = correctPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
if (wrongName == null) {
|
||||||
|
hash = 47 * hash;
|
||||||
|
} else {
|
||||||
|
hash = 47 * hash + wrongName.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correctName == null) {
|
||||||
|
hash = 47 * hash;
|
||||||
|
} else {
|
||||||
|
hash = 47 * hash + correctName.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final LinkToCheck other = (LinkToCheck) obj;
|
||||||
|
if (wrongName == null && other.getWrongName() != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wrongName != null && other.getWrongName() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correctName == null && other.getCorrectName() != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (correctName != null && other.getCorrectName() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((correctName.equals(other.getCorrectName()))
|
||||||
|
&& (wrongName.equals(other.getWrongName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkArticle(final DataObject articleObj,
|
||||||
|
final Set<LinkToCheck> linksToCheck) {
|
||||||
|
final GenericArticle article = new GenericArticle(articleObj);
|
||||||
|
|
||||||
|
final TextAsset textAsset = article.getTextAsset();
|
||||||
|
|
||||||
|
if (textAsset == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String text = textAsset.getText();
|
||||||
|
|
||||||
|
if (text == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (LinkToCheck linkToCheck : linksToCheck) {
|
||||||
|
//if (text.contains(linkToCheck.getWrongName())) {
|
||||||
|
|
||||||
|
/*if (text.matches(String.format("^(.*)href=\"(.*)%s(.*)\"(.*)$"
|
||||||
|
linkToCheck.getWrongName()))) {*/
|
||||||
|
if (checkForPotentialBrockenLink(text, linkToCheck.getWrongName())) {
|
||||||
|
System.out.printf("Found a potenially brocken link in article item %s:/%s:\n",
|
||||||
|
article.getContentSection().getName(),
|
||||||
|
article.getPath());
|
||||||
|
System.out.printf("\tLook for a link containing to path '%s' and replace it with "
|
||||||
|
+ "the stable link to the target item %s.\n\n",
|
||||||
|
linkToCheck.getWrongPath(),
|
||||||
|
linkToCheck.getCorrectPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkMpArticle(final DataObject mpArticleObj,
|
||||||
|
final Set<LinkToCheck> linksToCheck) {
|
||||||
|
final ContentItem mpItem = new ContentItem(mpArticleObj);
|
||||||
|
final DataCollection sections = (DataCollection) mpArticleObj.get("sections");
|
||||||
|
|
||||||
|
while (sections.next()) {
|
||||||
|
checkMpSection(mpItem, sections.getDataObject(), linksToCheck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkMpSection(final ContentItem mpItem,
|
||||||
|
final DataObject sectionObj,
|
||||||
|
final Set<LinkToCheck> linksToCheck) {
|
||||||
|
final DataObject textAssetObj = (DataObject) sectionObj.get("text");
|
||||||
|
|
||||||
|
if (textAssetObj == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String text = (String) textAssetObj.get(TextAsset.CONTENT);
|
||||||
|
|
||||||
|
if (text == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (LinkToCheck linkToCheck : linksToCheck) {
|
||||||
|
//if (text.contains(linkToCheck.getWrongName())) {
|
||||||
|
/*if (text.matches(String.format("^(.*)href=\"(.*)%s(.*)\"(.*)$",
|
||||||
|
linkToCheck.getWrongName()))) {*/
|
||||||
|
if(checkForPotentialBrockenLink(text, linkToCheck.getWrongName())) {
|
||||||
|
System.out.printf("Found a potenially brocken link in section '%s' of "
|
||||||
|
+ "MultiPartArticle %s:/%s.\n",
|
||||||
|
(String) sectionObj.get("title"),
|
||||||
|
mpItem.getContentSection().getName(),
|
||||||
|
mpItem.getPath());
|
||||||
|
System.out.printf("\tLook for a link containing to path '%s' and replace it with "
|
||||||
|
+ "the stable link to the target item %s.\n\n",
|
||||||
|
linkToCheck.getWrongPath(),
|
||||||
|
linkToCheck.getCorrectPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if a match for {@code checkFor} is found in the links of {@code text}.
|
||||||
|
* @param text
|
||||||
|
* @param checkFor
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean checkForPotentialBrockenLink(final String text, final String checkFor) {
|
||||||
|
final Document document = Jsoup.parseBodyFragment(text);
|
||||||
|
|
||||||
|
final Elements links = document.select("a");
|
||||||
|
boolean result = false;
|
||||||
|
for(Element link : links) {
|
||||||
|
result = (link.attr("href").contains(checkFor));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.globalization.Globalized;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compilation of methods to simplify the handling of globalizing keys.
|
||||||
|
* Basically it adds the name of package's resource bundle files to the
|
||||||
|
* globalize methods and forwards to GlobalizedMessage, shortening the
|
||||||
|
* method invocation in the various application classes.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:yon@arsdigita.com">yon@arsdigita.com</a>
|
||||||
|
* @version $Revision: #7 $ $Date: 2004/08/17 $
|
||||||
|
*/
|
||||||
|
public class GlobalizationUtil implements Globalized {
|
||||||
|
|
||||||
|
/** Name of Java resource files to handle CMS's globalisation. */
|
||||||
|
private static final String BUNDLE_NAME = "com.arsdigita.cms.CMSResources";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a globalized message using the package specific bundle,
|
||||||
|
* provided by BUNDLE_NAME.
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static GlobalizedMessage globalize(String key) {
|
||||||
|
return new GlobalizedMessage(key, BUNDLE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a globalized message object, using the package specific bundle,
|
||||||
|
* as specified by BUNDLE_NAME. Also takes in an Object[] of arguments to
|
||||||
|
* interpolate into the retrieved message using the MessageFormat class.
|
||||||
|
* @param key
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static GlobalizedMessage globalize(String key, Object[] args) {
|
||||||
|
return new GlobalizedMessage(key, BUNDLE_NAME, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the package specific resource bundle.
|
||||||
|
*
|
||||||
|
* Used e.g. by com.arsdigita.cms.ui.item.ItemLanguageTable to get the
|
||||||
|
* bundle tp pass to DataTable.
|
||||||
|
*
|
||||||
|
* @return Name of resource bundle as String
|
||||||
|
*/
|
||||||
|
public static String getBundleName() {
|
||||||
|
return BUNDLE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
|
||||||
|
// Developers Note:
|
||||||
|
// Counterpart to CMSResourceBundle java class.
|
||||||
|
// No longer used because we couldn't find a way to make proper localization
|
||||||
|
// work.
|
||||||
|
// Retained for easy reference to further develop localization infrastructure.
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* .
|
||||||
|
* Contains methods to simplify globalizing keys
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:yon@arsdigita.com">yon@arsdigita.com</a>
|
||||||
|
* @version $Revision: #7 $ $Date: 2004/08/17 $
|
||||||
|
*/
|
||||||
|
public class GlobalizationUtilOld {
|
||||||
|
|
||||||
|
/** Name of the Java class to handle CMS's globalisation. */
|
||||||
|
//public static String s_bundleName = "com.arsdigita.cms.util.CMSResourceBundle";
|
||||||
|
public static String s_bundleName = "com.arsdigita.cms.CMSResources";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns a globalized message using the package specific bundle,
|
||||||
|
* provided by method getBundleName()
|
||||||
|
*/
|
||||||
|
public static GlobalizedMessage globalize(String key) {
|
||||||
|
return new GlobalizedMessage(key, getBundleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a globalized message object, using the package specific bundle,
|
||||||
|
* provided by method getBundleName(). Also takes in an Object[] of
|
||||||
|
* arguments to interpolate into the retrieved message using the
|
||||||
|
* MessageFormat class.
|
||||||
|
*/
|
||||||
|
public static GlobalizedMessage globalize(String key, Object[] args) {
|
||||||
|
return new GlobalizedMessage(key, getBundleName(), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the package specific resource bundle.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getBundleName() {
|
||||||
|
return s_bundleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Not a part of API. Otherwise it would need to be properly synchronized.
|
||||||
|
* Only meant be used to override resource keys in CMSResources
|
||||||
|
* by a custom application, in Initializer.
|
||||||
|
*/
|
||||||
|
public static void internalSetBundleName(String bundleName) {
|
||||||
|
s_bundleName = bundleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,238 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
|
import com.arsdigita.cms.ContentPage;
|
||||||
|
import com.arsdigita.globalization.GlobalizationHelper;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.Kernel;
|
||||||
|
import com.arsdigita.util.Assert;
|
||||||
|
import com.arsdigita.util.Pair;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.MissingResourceException;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility methods for dealing with the multilingual items.
|
||||||
|
*
|
||||||
|
* @author Shashin Shinde (sshinde@redhat.com)
|
||||||
|
* @author Sören Bernstein <quasi@quasiweb.de>
|
||||||
|
*/
|
||||||
|
public class LanguageUtil {
|
||||||
|
|
||||||
|
private static org.apache.log4j.Logger s_log = org.apache.log4j.Logger.getLogger(
|
||||||
|
LanguageUtil.class);
|
||||||
|
private static String s_languages = null;
|
||||||
|
private static String[] s_languagesArray = null;
|
||||||
|
/**
|
||||||
|
* Mapping from the ISO639-1 2-letter codes to the ISO639-2 3-letter codes
|
||||||
|
*/
|
||||||
|
private static final String ISO639_2LA_3LA = "com.arsdigita.cms.util.iso639rev";
|
||||||
|
private static ResourceBundle s_lang3LA = ResourceBundle.getBundle(ISO639_2LA_3LA);
|
||||||
|
/**
|
||||||
|
* Mapping from the ISO639-1 2-letter codes to the full descriptive name
|
||||||
|
*/
|
||||||
|
private static final String ISO639_2LA_FULL = "com.arsdigita.cms.util.iso639full";
|
||||||
|
private static ResourceBundle s_langFull = ResourceBundle.getBundle(ISO639_2LA_FULL);
|
||||||
|
|
||||||
|
public static GlobalizedMessage globalize(String key) {
|
||||||
|
return new LanguageGlobalizedMessage(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the supported languages, eliminates all spaces and trims
|
||||||
|
*
|
||||||
|
* @param comma separated list of langages initialized from initializer at the server startup
|
||||||
|
*/
|
||||||
|
public static void setSupportedLanguages(String languages) {
|
||||||
|
s_languages = languages.replace(" ", "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the comma separated list of all supported languages
|
||||||
|
*/
|
||||||
|
public static String getSupportedLanguages() {
|
||||||
|
Assert.exists(s_languages, "supported languages not set");
|
||||||
|
return s_languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the collection of all supported languages.
|
||||||
|
*
|
||||||
|
* @return all supported languages
|
||||||
|
*/
|
||||||
|
public static Collection getSupportedLanguages2LA() {
|
||||||
|
String allLanguages = getSupportedLanguages();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
|
||||||
|
Collection langList = new LinkedList();
|
||||||
|
while (tokenizer.hasMoreElements()) {
|
||||||
|
String language = tokenizer.nextToken();
|
||||||
|
langList.add(language);
|
||||||
|
}
|
||||||
|
return langList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
|
||||||
|
* key and three letter code as value.
|
||||||
|
*
|
||||||
|
* @return all supported languages
|
||||||
|
*/
|
||||||
|
public static Collection getSupportedLanguages3LA() {
|
||||||
|
String allLanguages = getSupportedLanguages();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
|
||||||
|
Collection langList = new LinkedList();
|
||||||
|
while (tokenizer.hasMoreElements()) {
|
||||||
|
String language = tokenizer.nextToken();
|
||||||
|
langList.add(new Pair(language, getLang3LA(language)));
|
||||||
|
}
|
||||||
|
return langList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the collection of all supported languages. Each entry is a pair of 2 letter code as
|
||||||
|
* key and full language name as a value.
|
||||||
|
*
|
||||||
|
* @return all supported languages
|
||||||
|
*/
|
||||||
|
public static Collection getSupportedLanguagesFull() {
|
||||||
|
String allLanguages = getSupportedLanguages();
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(allLanguages, ",");
|
||||||
|
Collection langList = new LinkedList();
|
||||||
|
while (tokenizer.hasMoreElements()) {
|
||||||
|
String language = tokenizer.nextToken();
|
||||||
|
langList.add(new Pair(language, getLangFull(language)));
|
||||||
|
}
|
||||||
|
return langList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the List of languages in which this item can be created. Usefull on UI where we need to
|
||||||
|
* display the list of languages in which this Item can be created.
|
||||||
|
*/
|
||||||
|
public static Collection getCreatableLanguages(ContentPage item) {
|
||||||
|
ContentBundle bundle = item.getContentBundle();
|
||||||
|
Collection allList = getSupportedLanguages2LA();
|
||||||
|
allList.removeAll(bundle.getLanguages());
|
||||||
|
return allList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns three letter acronym for language code mapped from two letter code.
|
||||||
|
*
|
||||||
|
* @return three letter code for the two letter code. If the resource is not found then the key
|
||||||
|
* itself is returned.
|
||||||
|
*/
|
||||||
|
public static String getLang3LA(String lang) {
|
||||||
|
String threeLA;
|
||||||
|
try {
|
||||||
|
// Lookup 3-letter language code via java.util.Locale
|
||||||
|
threeLA = (new Locale(lang)).getISO3Language();
|
||||||
|
} catch (MissingResourceException mre) {
|
||||||
|
// If there is none
|
||||||
|
try {
|
||||||
|
// Lookup 3-letter code via ressource bundle
|
||||||
|
threeLA = s_lang3LA.getString(lang);
|
||||||
|
} catch (MissingResourceException mexc) {
|
||||||
|
// if there is still no match, log a warning and return the 2-letter code
|
||||||
|
s_log.warn("Three letter language code for key '" + lang + "' not found: " + mexc);
|
||||||
|
threeLA = lang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return threeLA;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the full language name mapped from the two letter acronym.
|
||||||
|
*
|
||||||
|
* @param lang 2 letter language code
|
||||||
|
*
|
||||||
|
* @return full language name for the given two letter code If the resource is not found then
|
||||||
|
* the key itself is returned.
|
||||||
|
*/
|
||||||
|
public static String getLangFull(String lang) {
|
||||||
|
// Lookup language name via java.util.Locale
|
||||||
|
String fullName = (new Locale(lang)).getDisplayLanguage(GlobalizationHelper.
|
||||||
|
getNegotiatedLocale());
|
||||||
|
|
||||||
|
if (lang.equals(fullName)) {
|
||||||
|
// If that fails
|
||||||
|
try {
|
||||||
|
// Lookup language name vie ressource bundle
|
||||||
|
fullName = s_langFull.getString(lang);
|
||||||
|
} catch (MissingResourceException mexc) {
|
||||||
|
// If there is still nomatch, log a warning and return 2-letter code
|
||||||
|
s_log.warn("Full language name for key '" + lang + "' not found " + mexc);
|
||||||
|
fullName = lang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes in a list of 2 letter codes and converts into 3 letter codes. Each entry is pair of 2
|
||||||
|
* letter code as key and 3 letter code as value.
|
||||||
|
*/
|
||||||
|
public static Collection convertTo3LA(Collection list) {
|
||||||
|
Collection conList = new LinkedList();
|
||||||
|
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||||
|
String lang2Code = (String) iter.next();
|
||||||
|
conList.add(new Pair(lang2Code, getLang3LA(lang2Code)));
|
||||||
|
}
|
||||||
|
return conList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection convertToFull(Collection list) {
|
||||||
|
Collection conList = new LinkedList();
|
||||||
|
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||||
|
String lang2Code = (String) iter.next();
|
||||||
|
conList.add(new Pair(lang2Code, getLangFull(lang2Code)));
|
||||||
|
}
|
||||||
|
return conList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection convertToG11N(Collection list) {
|
||||||
|
Collection conList = new LinkedList();
|
||||||
|
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||||
|
String lang2Code = (String) iter.next();
|
||||||
|
conList.add(new Pair(lang2Code, globalize(lang2Code)));
|
||||||
|
}
|
||||||
|
return conList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special GlobalizedMessage for use with the LanguageUtil#globalize method
|
||||||
|
private static class LanguageGlobalizedMessage extends GlobalizedMessage {
|
||||||
|
|
||||||
|
public LanguageGlobalizedMessage(String key) {
|
||||||
|
super(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object localize(Locale locale) {
|
||||||
|
return LanguageUtil.getLangFull(this.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
|
||||||
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* SAX event handler class for parsing configuration file.
|
||||||
|
*
|
||||||
|
* Parse URL-to-Page/Dispatcher/Servlet mappings from a file.
|
||||||
|
*
|
||||||
|
* Format of the file is XML:
|
||||||
|
* <pre>
|
||||||
|
* <dispatcher-configuration>
|
||||||
|
* <url-mapping
|
||||||
|
* <url>my-page</url>
|
||||||
|
* OR <page-class>com.arsdigita.Page.class</page-class>
|
||||||
|
* <url-mapping
|
||||||
|
* </dispatcher-configuration>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public class PageClassConfigHandler extends DefaultHandler {
|
||||||
|
|
||||||
|
private Map m_map;
|
||||||
|
private Map m_rmap;
|
||||||
|
private StringBuffer m_buffer;
|
||||||
|
private String m_url;
|
||||||
|
private String m_className;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param map A map to configure (pages-> classes)
|
||||||
|
* @param rmap A map to configure (classes-> pages)
|
||||||
|
*
|
||||||
|
* @pre md.m_map != null
|
||||||
|
*/
|
||||||
|
public PageClassConfigHandler(Map map, Map rmap) {
|
||||||
|
m_map = map;
|
||||||
|
// reverse map
|
||||||
|
m_rmap = rmap;
|
||||||
|
m_buffer = new StringBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int len) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
m_buffer.append(ch[start + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qn) {
|
||||||
|
if ( qn.equals("url") ) {
|
||||||
|
m_url = m_buffer.toString().trim();
|
||||||
|
} else if ( qn.equals("page-class") ) {
|
||||||
|
m_className = m_buffer.toString().trim();
|
||||||
|
} else if ( qn.equals("url-mapping") ) {
|
||||||
|
m_map.put(m_url, m_className);
|
||||||
|
m_rmap.put(m_className, m_url);
|
||||||
|
}
|
||||||
|
m_buffer = new StringBuffer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Security class used for checking and granting privileges in
|
||||||
|
* CMS.</p>
|
||||||
|
*
|
||||||
|
* @author Michael Pih
|
||||||
|
* @version $Revision: #7 $ $DateTime: 2004/08/17 23:15:09 $
|
||||||
|
* @version $Id: SecurityConstants.java 2090 2010-04-17 08:04:14Z pboy $
|
||||||
|
*/
|
||||||
|
public interface SecurityConstants {
|
||||||
|
|
||||||
|
// CMS Actions
|
||||||
|
public final static String STAFF_ADMIN = "staff_admin";
|
||||||
|
public final static String WORKFLOW_ADMIN = "workflow_admin";
|
||||||
|
public final static String CATEGORY_ADMIN = "category_admin";
|
||||||
|
public final static String LIFECYCLE_ADMIN = "lifecycle_admin";
|
||||||
|
public final static String CONTENT_TYPE_ADMIN = "content_type_admin";
|
||||||
|
public final static String PUBLISH = "publish";
|
||||||
|
public final static String NEW_ITEM = "new_item";
|
||||||
|
public final static String PUBLIC_PAGES = "public_pages";
|
||||||
|
public final static String PREVIEW_PAGES = "preview_pages";
|
||||||
|
public final static String ADMIN_PAGES = "admin_pages";
|
||||||
|
public final static String EDIT_ITEM = "edit_item";
|
||||||
|
public final static String SCHEDULE_PUBLICATION = "schedule_publication";
|
||||||
|
public final static String DELETE_ITEM = "delete_item";
|
||||||
|
public final static String APPLY_WORKFLOW = "apply_workflow";
|
||||||
|
public final static String CATEGORIZE_ITEMS = "categorize_items";
|
||||||
|
public final static String DELETE_IMAGES = "delete_images";
|
||||||
|
public final static String APPLY_ALTERNATE_WORKFLOWS = "apply_alternate_workflows";
|
||||||
|
|
||||||
|
// CMS Privileges
|
||||||
|
public final static String CMS_APPLY_ALTERNATE_WORKFLOWS = "cms_apply_alternate_workflows";
|
||||||
|
public final static String CMS_CATEGORIZE_ITEMS = "cms_categorize_items";
|
||||||
|
public final static String CMS_CATEGORY_ADMIN = "cms_category_admin";
|
||||||
|
public final static String CMS_CONTENT_TYPE_ADMIN = "cms_content_type_admin";
|
||||||
|
public final static String CMS_DELETE_ITEM = "cms_delete_item";
|
||||||
|
public final static String CMS_EDIT_ITEM = "cms_edit_item";
|
||||||
|
public final static String CMS_ITEM_ADMIN = "cms_item_admin";
|
||||||
|
public final static String CMS_LIFECYCLE_ADMIN = "cms_lifecycle_admin";
|
||||||
|
public final static String CMS_NEW_ITEM = "cms_new_item";
|
||||||
|
public final static String CMS_PREVIEW_ITEM = "cms_preview_item";
|
||||||
|
public final static String CMS_PUBLISH = "cms_publish";
|
||||||
|
public final static String CMS_APPROVE_ITEM = "cms_approve_item";
|
||||||
|
public final static String CMS_READ_ITEM = "cms_read_item";
|
||||||
|
public final static String CMS_STAFF_ADMIN = "cms_staff_admin";
|
||||||
|
public final static String CMS_WORKFLOW_ADMIN = "cms_workflow_admin";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.util;
|
||||||
|
|
||||||
|
import com.arsdigita.runtime.ConfigError;
|
||||||
|
import org.apache.oro.text.perl.Perl5Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility functions for use by installer classes.
|
||||||
|
*
|
||||||
|
* @author Jon Orris (jorris@redhat.com)
|
||||||
|
* @version $Revision: #6 $ $DateTime: 2004/08/17 23:15:09 $
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static void validateURLParameter(String name, String value)
|
||||||
|
throws ConfigError {
|
||||||
|
|
||||||
|
final String pattern = "/[^A-Za-z_0-9\\-]+/";
|
||||||
|
Perl5Util util = new Perl5Util();
|
||||||
|
if ( util.match(pattern, value) ) {
|
||||||
|
throw new ConfigError
|
||||||
|
("The \"" + name + "\" parameter must contain only " +
|
||||||
|
" alpha-numeric characters, underscores, and/or hyphens.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,141 @@
|
||||||
|
aa=Afar
|
||||||
|
ab=Abkhazian
|
||||||
|
af=Afrikaans
|
||||||
|
am=Amharic
|
||||||
|
ar=Arabic
|
||||||
|
as=Assamese
|
||||||
|
ay=Aymara
|
||||||
|
az=Azerbaijani
|
||||||
|
ba=Bashkir
|
||||||
|
be=Byelorussian
|
||||||
|
bg=Bulgarian
|
||||||
|
bh=Bihari
|
||||||
|
bi=Bislama
|
||||||
|
bn=Bengali;=Bangla
|
||||||
|
bo=Tibetan
|
||||||
|
br=Breton
|
||||||
|
ca=Catalan
|
||||||
|
co=Corsican
|
||||||
|
cs=Czech
|
||||||
|
cy=Welsh
|
||||||
|
da=Danish
|
||||||
|
de=German
|
||||||
|
dz=Bhutani
|
||||||
|
el=Greek
|
||||||
|
en=English
|
||||||
|
eo=Esperanto
|
||||||
|
es=Spanish
|
||||||
|
et=Estonian
|
||||||
|
eu=Basque
|
||||||
|
fa=Persian
|
||||||
|
fi=Finnish
|
||||||
|
fj=Fiji
|
||||||
|
fo=Faroese
|
||||||
|
fr=French
|
||||||
|
fy=Frisian
|
||||||
|
ga=Irish
|
||||||
|
gd=Scots=Gaelic
|
||||||
|
gl=Galician
|
||||||
|
gn=Guarani
|
||||||
|
gu=Gujarati
|
||||||
|
ha=Hausa
|
||||||
|
he=Hebrew
|
||||||
|
hi=Hindi
|
||||||
|
hr=Croatian
|
||||||
|
hu=Hungarian
|
||||||
|
hy=Armenian
|
||||||
|
ia=Interlingua
|
||||||
|
id=Indonesian
|
||||||
|
ie=Interlingue
|
||||||
|
ik=Inupiak
|
||||||
|
is=Icelandic
|
||||||
|
it=Italian
|
||||||
|
iu=Inuktitut
|
||||||
|
iw=Hebrew
|
||||||
|
ja=Japanese
|
||||||
|
jw=Javanese
|
||||||
|
ka=Georgian
|
||||||
|
kk=Kazakh
|
||||||
|
kl=Greenlandic
|
||||||
|
km=Cambodian
|
||||||
|
kn=Kannada
|
||||||
|
ko=Korean
|
||||||
|
ks=Kashmiri
|
||||||
|
ku=Kurdish
|
||||||
|
ky=Kirghiz
|
||||||
|
la=Latin
|
||||||
|
ln=Lingala
|
||||||
|
lo=Laothian
|
||||||
|
lt=Lithuanian
|
||||||
|
lv=Latvian
|
||||||
|
mg=Malagasy
|
||||||
|
mi=Maori
|
||||||
|
mk=Macedonian
|
||||||
|
ml=Malayalam
|
||||||
|
mn=Mongolian
|
||||||
|
mo=Moldavian
|
||||||
|
mr=Marathi
|
||||||
|
ms=Malay
|
||||||
|
mt=Maltese
|
||||||
|
my=Burmese
|
||||||
|
na=Nauru
|
||||||
|
ne=Nepali
|
||||||
|
nl=Dutch
|
||||||
|
no=Norwegian
|
||||||
|
oc=Occitan
|
||||||
|
om==Oromo
|
||||||
|
or=Oriya
|
||||||
|
pa=Punjabi
|
||||||
|
pl=Polish
|
||||||
|
ps=Pashto,=Pushto
|
||||||
|
pt=Portuguese
|
||||||
|
qu=Quechua
|
||||||
|
rm=Rhaeto-Romance
|
||||||
|
rn=Kirundi
|
||||||
|
ro=Romanian
|
||||||
|
ru=Russian
|
||||||
|
rw=Kinyarwanda
|
||||||
|
sa=Sanskrit
|
||||||
|
sd=Sindhi
|
||||||
|
sg=Sangho
|
||||||
|
sh=Serbo-Croatian
|
||||||
|
si=Sinhalese
|
||||||
|
sk=Slovak
|
||||||
|
sl=Slovenian
|
||||||
|
sm=Samoan
|
||||||
|
sn=Shona
|
||||||
|
so=Somali
|
||||||
|
sq=Albanian
|
||||||
|
sr=Serbian
|
||||||
|
ss=Siswati
|
||||||
|
st=Sesotho
|
||||||
|
su=Sundanese
|
||||||
|
sv=Swedish
|
||||||
|
sw=Swahili
|
||||||
|
ta=Tamil
|
||||||
|
te=Telugu
|
||||||
|
tg=Tajik
|
||||||
|
th=Thai
|
||||||
|
ti=Tigrinya
|
||||||
|
tk=Turkmen
|
||||||
|
tl=Tagalog
|
||||||
|
tn=Setswana
|
||||||
|
to=Tonga
|
||||||
|
tr=Turkish
|
||||||
|
ts=Tsonga
|
||||||
|
tt=Tatar
|
||||||
|
tw=Twi
|
||||||
|
ug=Uighur
|
||||||
|
uk=Ukrainian
|
||||||
|
ur=Urdu
|
||||||
|
uz=Uzbek
|
||||||
|
vi=Vietnamese
|
||||||
|
vo=Volapuk
|
||||||
|
wo=Wolof
|
||||||
|
xh=Xhosa
|
||||||
|
yi=Yiddish
|
||||||
|
yo=Yoruba
|
||||||
|
za=Zhuang
|
||||||
|
zh=Chinese
|
||||||
|
zu=Zulu
|
||||||
|
--=Undefined
|
||||||
|
|
@ -0,0 +1,138 @@
|
||||||
|
aa=aar
|
||||||
|
ab=abk
|
||||||
|
af=afr
|
||||||
|
am=amh
|
||||||
|
ar=ara
|
||||||
|
as=asm
|
||||||
|
ay=aym
|
||||||
|
az=aze
|
||||||
|
ba=bak
|
||||||
|
be=bel
|
||||||
|
be=bre
|
||||||
|
bg=bul
|
||||||
|
bh=bih
|
||||||
|
bi=bis
|
||||||
|
bn=ben
|
||||||
|
bo=bod
|
||||||
|
ca=cat
|
||||||
|
co=cos
|
||||||
|
cs=ces
|
||||||
|
cy=cym
|
||||||
|
da=dan
|
||||||
|
de=deu
|
||||||
|
dz=dzo
|
||||||
|
el=ell
|
||||||
|
en=eng
|
||||||
|
eo=epo
|
||||||
|
es=spa
|
||||||
|
et=est
|
||||||
|
eu=baq
|
||||||
|
fa=fas
|
||||||
|
fi=fin
|
||||||
|
fj=fij
|
||||||
|
fo=fao
|
||||||
|
fr=fra
|
||||||
|
fy=fry
|
||||||
|
ga=gai
|
||||||
|
gl=glg
|
||||||
|
gn=grn
|
||||||
|
gu=guj
|
||||||
|
ha=hau
|
||||||
|
he=heb
|
||||||
|
hi=hin
|
||||||
|
hr=hrv
|
||||||
|
hu=hun
|
||||||
|
hy=arm
|
||||||
|
ia=ina
|
||||||
|
id=ind
|
||||||
|
ik=ipk
|
||||||
|
is=ice
|
||||||
|
it=ita
|
||||||
|
iu=iku
|
||||||
|
iw=heb
|
||||||
|
ja=jpn
|
||||||
|
jv=jav
|
||||||
|
jw=jaw
|
||||||
|
ka=kat
|
||||||
|
kk=kaz
|
||||||
|
kl=kal
|
||||||
|
km=khm
|
||||||
|
kn=kan
|
||||||
|
ko=kor
|
||||||
|
ks=kas
|
||||||
|
ku=kur
|
||||||
|
ky=kir
|
||||||
|
la=lat
|
||||||
|
ln=lin
|
||||||
|
lo=lao
|
||||||
|
lt=lit
|
||||||
|
lv=lav
|
||||||
|
mg=mlg
|
||||||
|
mi=mri
|
||||||
|
mk=mak
|
||||||
|
ml=mlt
|
||||||
|
mn=mon
|
||||||
|
mo=mol
|
||||||
|
mr=mar
|
||||||
|
ms=msa
|
||||||
|
my=mya
|
||||||
|
na=nau
|
||||||
|
ne=nep
|
||||||
|
nl=dut
|
||||||
|
no=nor
|
||||||
|
oc=oci
|
||||||
|
om=orm
|
||||||
|
or=ori
|
||||||
|
pa=pan
|
||||||
|
pl=pol
|
||||||
|
ps=pus
|
||||||
|
pt=por
|
||||||
|
qu=que
|
||||||
|
rm=roh
|
||||||
|
rn=run
|
||||||
|
ro=ron
|
||||||
|
ru=rus
|
||||||
|
rw=kin
|
||||||
|
sa=san
|
||||||
|
sd=snd
|
||||||
|
sg=sag
|
||||||
|
sh=scr
|
||||||
|
si=sin
|
||||||
|
sk=slk
|
||||||
|
sl=slv
|
||||||
|
sm=smo
|
||||||
|
sn=sna
|
||||||
|
so=som
|
||||||
|
sq=sqi
|
||||||
|
sr=ser
|
||||||
|
ss=ssw
|
||||||
|
st=sot
|
||||||
|
su=sun
|
||||||
|
sv=sve
|
||||||
|
sw=swa
|
||||||
|
ta=tam
|
||||||
|
te=tel
|
||||||
|
tg=tgk
|
||||||
|
th=tha
|
||||||
|
ti=tir
|
||||||
|
tk=tuk
|
||||||
|
tl=tgl
|
||||||
|
tn=tsn
|
||||||
|
to=tog
|
||||||
|
tr=tur
|
||||||
|
ts=tso
|
||||||
|
tt=tat
|
||||||
|
tw=twi
|
||||||
|
ug=uig
|
||||||
|
uk=ukr
|
||||||
|
ur=urd
|
||||||
|
uz=uzb
|
||||||
|
vi=vie
|
||||||
|
vo=vol
|
||||||
|
wo=wol
|
||||||
|
xh=xho
|
||||||
|
yi=yid
|
||||||
|
yo=yor
|
||||||
|
za=zha
|
||||||
|
zh=zho
|
||||||
|
zu=zul
|
||||||
|
|
@ -272,3 +272,10 @@ cms.ui.assets.binaryasset.filename=File name
|
||||||
cms.ui.assets.binaryasset.mimetype=Type
|
cms.ui.assets.binaryasset.mimetype=Type
|
||||||
cms.ui.assets.binaryasset.size=Size (bytes)
|
cms.ui.assets.binaryasset.size=Size (bytes)
|
||||||
cms.ui.categories=Categories
|
cms.ui.categories=Categories
|
||||||
|
cms.ui.new_item=Create new content item
|
||||||
|
cms.ui.authoring.content_type=Content Type:
|
||||||
|
#Language
|
||||||
|
cms.ui.language.field=Sprache
|
||||||
|
cms.ui.authoring.workflow=Select a workflow
|
||||||
|
cms.ui.create=Create
|
||||||
|
cms.contenttypes.ui.summary=Summary
|
||||||
|
|
|
||||||
|
|
@ -270,3 +270,10 @@ cms.ui.assets.binaryasset.filename=Dateiname
|
||||||
cms.ui.assets.binaryasset.mimetype=Typ
|
cms.ui.assets.binaryasset.mimetype=Typ
|
||||||
cms.ui.assets.binaryasset.size=Gr\u00f6\u00dfe (Bytes)
|
cms.ui.assets.binaryasset.size=Gr\u00f6\u00dfe (Bytes)
|
||||||
cms.ui.categories=Kategorien
|
cms.ui.categories=Kategorien
|
||||||
|
cms.ui.new_item=Neues Content Item angelegen
|
||||||
|
cms.ui.authoring.content_type=Content Typ:
|
||||||
|
#Language
|
||||||
|
cms.ui.language.field=Sprache
|
||||||
|
cms.ui.authoring.workflow=Arbeitsablauf ausw\u00e4hlen
|
||||||
|
cms.ui.create=Anlegen
|
||||||
|
cms.contenttypes.ui.summary=Zusammenfassung
|
||||||
|
|
|
||||||
|
|
@ -229,3 +229,10 @@ cms.ui.assets.binaryasset.filename=File name
|
||||||
cms.ui.assets.binaryasset.mimetype=Type
|
cms.ui.assets.binaryasset.mimetype=Type
|
||||||
cms.ui.assets.binaryasset.size=Size (bytes)
|
cms.ui.assets.binaryasset.size=Size (bytes)
|
||||||
cms.ui.categories=Categories
|
cms.ui.categories=Categories
|
||||||
|
cms.ui.new_item=New item
|
||||||
|
cms.ui.authoring.content_type=Content Type:
|
||||||
|
#Language
|
||||||
|
cms.ui.language.field=Sprache
|
||||||
|
cms.ui.authoring.workflow=Select a workflow
|
||||||
|
cms.ui.create=Create
|
||||||
|
cms.contenttypes.ui.summary=Summary
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ import com.vaadin.ui.Label;
|
||||||
import com.vaadin.ui.TabSheet;
|
import com.vaadin.ui.TabSheet;
|
||||||
import com.vaadin.ui.VerticalLayout;
|
import com.vaadin.ui.VerticalLayout;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import org.libreccm.admin.ui.usersgroupsroles.UsersGroupsRoles;
|
||||||
|
import org.libreccm.admin.ui.usersgroupsroles.UsersTableDataProvider;
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
|
|
@ -82,13 +84,17 @@ public class AdminView extends CustomComponent implements View {
|
||||||
@Inject
|
@Inject
|
||||||
private GlobalizationHelper globalizationHelper;
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private UsersTableDataProvider usersTableDataProvider;
|
||||||
|
|
||||||
private ResourceBundle bundle;
|
private ResourceBundle bundle;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private UserRepository userRepo;
|
private UserRepository userRepo;
|
||||||
|
|
||||||
private final TabSheet tabSheet;
|
private final TabSheet tabSheet;
|
||||||
private final Grid<User> usersTable;
|
// private final Grid<User> usersTable;
|
||||||
|
private final UsersGroupsRoles usersGroupsRoles;
|
||||||
|
|
||||||
private final JpqlConsole jpqlConsole;
|
private final JpqlConsole jpqlConsole;
|
||||||
|
|
||||||
|
|
@ -96,38 +102,40 @@ public class AdminView extends CustomComponent implements View {
|
||||||
|
|
||||||
tabSheet = new TabSheet();
|
tabSheet = new TabSheet();
|
||||||
|
|
||||||
final TabSheet userGroupsRoles = new TabSheet();
|
// final TabSheet userGroupsRoles = new TabSheet();
|
||||||
usersTable = new Grid<>();
|
// usersTable = new Grid<>();
|
||||||
usersTable.setWidth("100%");
|
// usersTable.setWidth("100%");
|
||||||
// usersTable.setItems(userRepo.findAll());
|
//// usersTable.setItems(userRepo.findAll());
|
||||||
usersTable.addColumn(User::getName)
|
// usersTable.addColumn(User::getName)
|
||||||
.setId(COL_USER_NAME)
|
// .setId(COL_USER_NAME)
|
||||||
.setCaption("User name");
|
// .setCaption("User name");
|
||||||
usersTable
|
// usersTable
|
||||||
.addColumn(User::getGivenName)
|
// .addColumn(User::getGivenName)
|
||||||
.setId(COL_GIVEN_NAME)
|
// .setId(COL_GIVEN_NAME)
|
||||||
.setCaption("Given name");
|
// .setCaption("Given name");
|
||||||
usersTable
|
// usersTable
|
||||||
.addColumn(User::getFamilyName)
|
// .addColumn(User::getFamilyName)
|
||||||
.setId(COL_FAMILY_NAME)
|
// .setId(COL_FAMILY_NAME)
|
||||||
.setCaption("Family name");
|
// .setCaption("Family name");
|
||||||
usersTable
|
// usersTable
|
||||||
.addColumn(user -> user.getPrimaryEmailAddress().getAddress())
|
// .addColumn(user -> user.getPrimaryEmailAddress().getAddress())
|
||||||
.setId(COL_EMAIL)
|
// .setId(COL_EMAIL)
|
||||||
.setCaption("E-Mail");
|
// .setCaption("E-Mail");
|
||||||
usersTable
|
// usersTable
|
||||||
.addColumn(user -> {
|
// .addColumn(user -> {
|
||||||
if (user.isBanned()) {
|
// if (user.isBanned()) {
|
||||||
return bundle.getString("ui.admin.user.banned_yes");
|
// return bundle.getString("ui.admin.user.banned_yes");
|
||||||
} else {
|
// } else {
|
||||||
return bundle.getString("ui.admin.user.banned_no");
|
// return bundle.getString("ui.admin.user.banned_no");
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
.setId(COL_BANNED)
|
// .setId(COL_BANNED)
|
||||||
.setCaption("Banned?");
|
// .setCaption("Banned?");
|
||||||
userGroupsRoles.addTab(usersTable, "Users");
|
// userGroupsRoles.addTab(usersTable, "Users");
|
||||||
|
//
|
||||||
tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
|
// tabSheet.addTab(userGroupsRoles, "Users/Groups/Roles");
|
||||||
|
usersGroupsRoles = new UsersGroupsRoles(this);
|
||||||
|
tabSheet.addTab(usersGroupsRoles, "Users/Groups/Roles");
|
||||||
|
|
||||||
final ServletContext servletContext = VaadinServlet
|
final ServletContext servletContext = VaadinServlet
|
||||||
.getCurrent()
|
.getCurrent()
|
||||||
|
|
@ -139,54 +147,12 @@ public class AdminView extends CustomComponent implements View {
|
||||||
jpqlConsole = null;
|
jpqlConsole = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// final CssLayout header = new CssLayout() {
|
|
||||||
//
|
|
||||||
// private static final long serialVersionUID = -4372147161604688854L;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected String getCss(final Component component) {
|
|
||||||
// /*if ((component instanceof Image)
|
|
||||||
// && "libreccm-logo".equals(component.getId())) {
|
|
||||||
//
|
|
||||||
// return "position: absolute; top: 10px; left: 10px;";
|
|
||||||
//
|
|
||||||
// } else if ((component instanceof Label)
|
|
||||||
// && "libreccm-headerinfoline".equals(component
|
|
||||||
// .getId())) {
|
|
||||||
// return "background-color: #8b8e8a; width: 100%; position: absolute; top:120px; left: 0";
|
|
||||||
// }*/
|
|
||||||
// return "";
|
|
||||||
//
|
|
||||||
//// return ".v-csslayout {\n"
|
|
||||||
//// + "background-color: #56a1bd;\n"
|
|
||||||
//// + "background-image: -ie-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
|
|
||||||
//// + "background-image: -moz-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
|
|
||||||
//// + "background-image: -webkit-linear-gradient(top , #56a1db 5%, #024c68 95%\n"
|
|
||||||
//// + "background-image: linear-gradient(top , #56a1db 5%, #024c68 95%\n"
|
|
||||||
//// + "}\n"
|
|
||||||
//// + "\n"
|
|
||||||
//// + ".libreccm-logo {\n"
|
|
||||||
//// + "border-left: 10px solid #0f0;\n"
|
|
||||||
//// + "}\n";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// };
|
|
||||||
// header.setWidth("100%");
|
|
||||||
// header.setHeight("5em");
|
|
||||||
final GridLayout header = new GridLayout(5, 1);
|
final GridLayout header = new GridLayout(5, 1);
|
||||||
header.setWidth("100%");
|
header.setWidth("100%");
|
||||||
header.addStyleName("libreccm-header");
|
header.addStyleName("libreccm-header");
|
||||||
// final Image logo = new Image(
|
|
||||||
// "",
|
|
||||||
// new ClassResource("/themes/libreccm-default/images/libreccm.png"));
|
|
||||||
// logo.setId("libreccm-logo");
|
|
||||||
// logo.addStyleName("libreccm-logo");
|
|
||||||
// header.addComponent(logo, 0, 0);
|
|
||||||
// header.setComponentAlignment(logo, Alignment.MIDDLE_LEFT);
|
|
||||||
|
|
||||||
final Label headerInfoLine = new Label("LibreCCM");
|
final Label headerInfoLine = new Label("LibreCCM");
|
||||||
headerInfoLine.setId("libreccm-headerinfoline");
|
headerInfoLine.setId("libreccm-headerinfoline");
|
||||||
// headerInfoLine.setWidth("100%");
|
|
||||||
header.addComponent(headerInfoLine, 3, 0, 4, 0);
|
header.addComponent(headerInfoLine, 3, 0, 4, 0);
|
||||||
header.setComponentAlignment(headerInfoLine, Alignment.TOP_RIGHT);
|
header.setComponentAlignment(headerInfoLine, Alignment.TOP_RIGHT);
|
||||||
|
|
||||||
|
|
@ -216,15 +182,14 @@ public class AdminView extends CustomComponent implements View {
|
||||||
bundle = ResourceBundle
|
bundle = ResourceBundle
|
||||||
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
|
.getBundle(AdminUiConstants.ADMIN_BUNDLE,
|
||||||
globalizationHelper.getNegotiatedLocale());
|
globalizationHelper.getNegotiatedLocale());
|
||||||
|
|
||||||
|
usersGroupsRoles.setDataProvider(usersTableDataProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
public void enter(final ViewChangeListener.ViewChangeEvent event) {
|
||||||
|
|
||||||
// if (!subject.isAuthenticated()) {
|
// usersGroupsRoles.setUsers(userRepo.findAll());
|
||||||
// getUI().getNavigator().navigateTo(LoginView.VIEWNAME);
|
|
||||||
// }
|
|
||||||
usersTable.setItems(userRepo.findAll());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* 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.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
|
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||||
|
|
||||||
|
import com.vaadin.ui.CustomComponent;
|
||||||
|
import com.vaadin.ui.Grid;
|
||||||
|
import com.vaadin.ui.TabSheet;
|
||||||
|
import com.vaadin.ui.UI;
|
||||||
|
import org.libreccm.admin.ui.AdminView;
|
||||||
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class UsersGroupsRoles extends CustomComponent {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 7280416743018127366L;
|
||||||
|
|
||||||
|
private static final String COL_USER_NAME = "username";
|
||||||
|
private static final String COL_GIVEN_NAME = "given_name";
|
||||||
|
private static final String COL_FAMILY_NAME = "family_name";
|
||||||
|
private static final String COL_EMAIL = "email";
|
||||||
|
private static final String COL_BANNED = "banned";
|
||||||
|
|
||||||
|
private final AdminView view;
|
||||||
|
|
||||||
|
private final TabSheet tabSheet;
|
||||||
|
|
||||||
|
private final Grid<User> usersTable;
|
||||||
|
|
||||||
|
public UsersGroupsRoles(final AdminView view) {
|
||||||
|
|
||||||
|
this.view = view;
|
||||||
|
|
||||||
|
final ResourceBundle bundle = ResourceBundle.getBundle(
|
||||||
|
AdminUiConstants.ADMIN_BUNDLE, UI.getCurrent().getLocale());
|
||||||
|
|
||||||
|
tabSheet = new TabSheet();
|
||||||
|
usersTable = new Grid<>();
|
||||||
|
usersTable.setWidth("100%");
|
||||||
|
// usersTable.setItems(userRepo.findAll());
|
||||||
|
usersTable.addColumn(User::getName)
|
||||||
|
.setId(COL_USER_NAME)
|
||||||
|
.setCaption("User name");
|
||||||
|
usersTable
|
||||||
|
.addColumn(User::getGivenName)
|
||||||
|
.setId(COL_GIVEN_NAME)
|
||||||
|
.setCaption("Given name");
|
||||||
|
usersTable
|
||||||
|
.addColumn(User::getFamilyName)
|
||||||
|
.setId(COL_FAMILY_NAME)
|
||||||
|
.setCaption("Family name");
|
||||||
|
usersTable
|
||||||
|
.addColumn(user -> user.getPrimaryEmailAddress().getAddress())
|
||||||
|
.setId(COL_EMAIL)
|
||||||
|
.setCaption("E-Mail");
|
||||||
|
usersTable
|
||||||
|
.addColumn(user -> {
|
||||||
|
if (user.isBanned()) {
|
||||||
|
return bundle.getString("ui.admin.user.banned_yes");
|
||||||
|
} else {
|
||||||
|
return bundle.getString("ui.admin.user.banned_no");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setId(COL_BANNED)
|
||||||
|
.setCaption("Banned?");
|
||||||
|
|
||||||
|
|
||||||
|
tabSheet.addTab(usersTable, "Users");
|
||||||
|
|
||||||
|
setCompositionRoot(tabSheet);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void setUsers(final List<User> users) {
|
||||||
|
// usersTable.setItems(users);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void setDataProvider(final UsersTableDataProvider dataProvider) {
|
||||||
|
usersTable.setDataProvider(dataProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* 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.libreccm.admin.ui.usersgroupsroles;
|
||||||
|
|
||||||
|
import com.vaadin.cdi.ViewScoped;
|
||||||
|
import com.vaadin.data.provider.AbstractDataProvider;
|
||||||
|
import com.vaadin.data.provider.Query;
|
||||||
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@ViewScoped
|
||||||
|
public class UsersTableDataProvider extends AbstractDataProvider<User, String> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 8849235775786370772L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInMemory() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@Override
|
||||||
|
public int size(final Query<User, String> query) {
|
||||||
|
final CriteriaBuilder builder = entityManager
|
||||||
|
.getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Long> criteriaQuery = builder
|
||||||
|
.createQuery(Long.class);
|
||||||
|
final Root<User> from = criteriaQuery.from(User.class);
|
||||||
|
|
||||||
|
criteriaQuery = criteriaQuery.select(builder.count(from));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.getSingleResult()
|
||||||
|
.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@Override
|
||||||
|
public Stream<User> fetch(final Query<User, String> query) {
|
||||||
|
final CriteriaBuilder builder = entityManager
|
||||||
|
.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<User> criteriaQuery = builder
|
||||||
|
.createQuery(User.class);
|
||||||
|
final Root<User> from = criteriaQuery.from(User.class);
|
||||||
|
|
||||||
|
|
||||||
|
return entityManager
|
||||||
|
.createQuery(criteriaQuery)
|
||||||
|
.setMaxResults(query.getLimit())
|
||||||
|
.setFirstResult(query.getOffset())
|
||||||
|
.getResultList()
|
||||||
|
.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -323,8 +323,8 @@ public class CcmObjectRepositoryTest {
|
||||||
* {@link IllegalArgumentException} if called with {@code null} as the
|
* {@link IllegalArgumentException} if called with {@code null} as the
|
||||||
* object to save.
|
* object to save.
|
||||||
*/
|
*/
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
@InSequence(500)
|
@InSequence(500)
|
||||||
public void saveNullValue() {
|
public void saveNullValue() {
|
||||||
ccmObjectRepository.save(null);
|
ccmObjectRepository.save(null);
|
||||||
|
|
|
||||||
|
|
@ -222,8 +222,8 @@ public class GroupRepositoryTest {
|
||||||
groupRepository.save(group);
|
groupRepository.save(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
@InSequence(600)
|
@InSequence(600)
|
||||||
public void saveNullValue() {
|
public void saveNullValue() {
|
||||||
groupRepository.save(null);
|
groupRepository.save(null);
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,8 @@ public class PartyRepositoryTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
@InSequence(500)
|
@InSequence(500)
|
||||||
public void saveNullValue() {
|
public void saveNullValue() {
|
||||||
shiro.getSystemUser().execute(() -> partyRepository.save(null));
|
shiro.getSystemUser().execute(() -> partyRepository.save(null));
|
||||||
|
|
|
||||||
|
|
@ -320,8 +320,8 @@ public class RoleRepositoryTest {
|
||||||
* throws a {@link IllegalArgumentException} is called with {@code null} for
|
* throws a {@link IllegalArgumentException} is called with {@code null} for
|
||||||
* the {@link Role} to save.
|
* the {@link Role} to save.
|
||||||
*/
|
*/
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
@InSequence(600)
|
@InSequence(600)
|
||||||
public void saveNullValue() {
|
public void saveNullValue() {
|
||||||
roleRepository.save(null);
|
roleRepository.save(null);
|
||||||
|
|
|
||||||
|
|
@ -289,8 +289,8 @@ public class UserRepositoryTest {
|
||||||
shiro.getSystemUser().execute(() -> userRepository.save(user));
|
shiro.getSystemUser().execute(() -> userRepository.save(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ShouldThrowException(IllegalArgumentException.class)
|
@ShouldThrowException(NullPointerException.class)
|
||||||
@InSequence(700)
|
@InSequence(700)
|
||||||
public void saveNullValue() {
|
public void saveNullValue() {
|
||||||
shiro.getSystemUser().execute(() -> userRepository.save(null));
|
shiro.getSystemUser().execute(() -> userRepository.save(null));
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ create schema CCM_CORE;
|
||||||
DEFAULT_VALUE varchar(255),
|
DEFAULT_VALUE varchar(255),
|
||||||
PARAMETER_MODEL varchar(255),
|
PARAMETER_MODEL varchar(255),
|
||||||
PARAMETER_NAME varchar(255),
|
PARAMETER_NAME varchar(255),
|
||||||
OBJECT_ID bigint not null,s
|
OBJECT_ID bigint not null,
|
||||||
primary key (OBJECT_ID)
|
primary key (OBJECT_ID)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue