CCM NG/ccm-cms: AssetPane
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4661 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
078a8ff300
commit
bad95d0fac
|
|
@ -18,21 +18,153 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.assets;
|
package com.arsdigita.cms.ui.assets;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Container;
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
|
import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.Asset;
|
||||||
|
import org.librecms.contentsection.AssetRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class AssetForm extends Form {
|
public abstract class AssetForm extends Form implements FormInitListener,
|
||||||
|
FormProcessListener,
|
||||||
|
FormSubmissionListener {
|
||||||
|
|
||||||
public AssetForm(final String name) {
|
private static final String ASSET_TITLE = "asset-title";
|
||||||
super(name);
|
|
||||||
|
private final AssetPane assetPane;
|
||||||
|
private final SingleSelectionModel<Long> selectionModel;
|
||||||
|
|
||||||
|
private TextField title;
|
||||||
|
private SaveCancelSection saveCancelSection;
|
||||||
|
|
||||||
|
public AssetForm(final AssetPane assetPane) {
|
||||||
|
super("asset-form", new ColumnPanel(2));
|
||||||
|
|
||||||
|
this.assetPane = assetPane;
|
||||||
|
selectionModel = assetPane.getSelectedAssetModel();
|
||||||
|
|
||||||
|
initComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AssetForm(final String name, final Container container) {
|
private void initComponents() {
|
||||||
super(name, container);
|
add(new Label(new GlobalizedMessage("cms.ui.asset.title",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
title = new TextField(ASSET_TITLE);
|
||||||
|
add(title);
|
||||||
|
|
||||||
|
addWidgets();
|
||||||
|
|
||||||
|
saveCancelSection = new SaveCancelSection();
|
||||||
|
add(saveCancelSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addWidgets() {
|
||||||
|
//Nothing here
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getTitle(final PageState state) {
|
||||||
|
return (String) title.getValue(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Optional<Asset> getSelectedAsset(final PageState state) {
|
||||||
|
|
||||||
|
if (selectionModel.getSelectedKey(state) == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
} else {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final AssetRepository assetRepo = cdiUtil.findBean(
|
||||||
|
AssetRepository.class);
|
||||||
|
final Asset asset = assetRepo
|
||||||
|
.findById(selectionModel.getSelectedKey(state))
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||||
|
"No asset with ID %d in the database.",
|
||||||
|
selectionModel.getSelectedKey(state))));
|
||||||
|
return Optional.of(asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
final Optional<Asset> selectedAsset = getSelectedAsset(state);
|
||||||
|
|
||||||
|
if (selectedAsset.isPresent()) {
|
||||||
|
title.setValue(state,
|
||||||
|
selectedAsset
|
||||||
|
.get()
|
||||||
|
.getTitle()
|
||||||
|
.getValue(KernelConfig
|
||||||
|
.getConfig()
|
||||||
|
.getDefaultLocale()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
final Optional<Asset> selectedAsset = getSelectedAsset(state);
|
||||||
|
final Asset asset;
|
||||||
|
if (selectedAsset.isPresent()) {
|
||||||
|
asset = selectedAsset.get();
|
||||||
|
updateAsset(asset, state);
|
||||||
|
} else {
|
||||||
|
asset = createAsset(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
asset.getTitle().addValue(
|
||||||
|
KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) title.getValue(state));
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final AssetRepository assetRepo = cdiUtil
|
||||||
|
.findBean(AssetRepository.class);
|
||||||
|
assetRepo.save(asset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Asset createAsset(final PageState state)
|
||||||
|
throws FormProcessException;
|
||||||
|
|
||||||
|
protected abstract void updateAsset(final Asset asset,
|
||||||
|
final PageState state)
|
||||||
|
throws FormProcessException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void submitted(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getCancelButton().isSelected(state)) {
|
||||||
|
selectionModel.clearSelection(state);
|
||||||
|
assetPane.browseMode(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.assets;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class AssetFormController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Paginator;
|
import com.arsdigita.bebop.Paginator;
|
||||||
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
import com.arsdigita.bebop.RequestLocal;
|
||||||
import com.arsdigita.bebop.Resettable;
|
import com.arsdigita.bebop.Resettable;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
|
|
@ -52,6 +53,7 @@ import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
import com.arsdigita.bebop.form.SingleSelect;
|
||||||
import com.arsdigita.bebop.form.Submit;
|
import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.bebop.parameters.ArrayParameter;
|
import com.arsdigita.bebop.parameters.ArrayParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.LongParameter;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
|
|
@ -83,6 +85,8 @@ import org.libreccm.categorization.CategoryManager;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
import org.libreccm.core.UnexpectedErrorException;
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.assets.AssetTypeInfo;
|
||||||
|
import org.librecms.assets.AssetTypesManager;
|
||||||
import org.librecms.contentsection.Asset;
|
import org.librecms.contentsection.Asset;
|
||||||
import org.librecms.contentsection.AssetManager;
|
import org.librecms.contentsection.AssetManager;
|
||||||
import org.librecms.contentsection.AssetRepository;
|
import org.librecms.contentsection.AssetRepository;
|
||||||
|
|
@ -92,6 +96,8 @@ import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.TooManyListenersException;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
||||||
|
|
@ -113,6 +119,7 @@ public class AssetPane extends LayoutPanel implements Resettable {
|
||||||
private final SingleSelectionModel selectionModel;
|
private final SingleSelectionModel selectionModel;
|
||||||
private final FolderSelectionModel folderSelectionModel;
|
private final FolderSelectionModel folderSelectionModel;
|
||||||
private final FolderRequestLocal folderRequestLocal;
|
private final FolderRequestLocal folderRequestLocal;
|
||||||
|
private final SingleSelectionModel<Long> selectedAssetModel;
|
||||||
private final ArrayParameter sourcesParameter = new ArrayParameter(
|
private final ArrayParameter sourcesParameter = new ArrayParameter(
|
||||||
new StringParameter(SOURCES_PARAM));
|
new StringParameter(SOURCES_PARAM));
|
||||||
private final StringParameter actionParameter = new StringParameter(
|
private final StringParameter actionParameter = new StringParameter(
|
||||||
|
|
@ -129,6 +136,7 @@ public class AssetPane extends LayoutPanel implements Resettable {
|
||||||
private SegmentedPanel.Segment actionsSegment;
|
private SegmentedPanel.Segment actionsSegment;
|
||||||
private SegmentedPanel.Segment newFolderSegment;
|
private SegmentedPanel.Segment newFolderSegment;
|
||||||
private SegmentedPanel.Segment editFolderSegment;
|
private SegmentedPanel.Segment editFolderSegment;
|
||||||
|
private SegmentedPanel.Segment editAssetSegement;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public AssetPane() {
|
public AssetPane() {
|
||||||
|
|
@ -157,6 +165,9 @@ public class AssetPane extends LayoutPanel implements Resettable {
|
||||||
};
|
};
|
||||||
folderRequestLocal = new FolderRequestLocal(folderSelectionModel);
|
folderRequestLocal = new FolderRequestLocal(folderSelectionModel);
|
||||||
|
|
||||||
|
selectedAssetModel = new ParameterSingleSelectionModel<>(
|
||||||
|
new LongParameter("selected-asset"));
|
||||||
|
|
||||||
final SegmentedPanel left = new SegmentedPanel();
|
final SegmentedPanel left = new SegmentedPanel();
|
||||||
setLeft(left);
|
setLeft(left);
|
||||||
|
|
||||||
|
|
@ -437,6 +448,54 @@ public class AssetPane extends LayoutPanel implements Resettable {
|
||||||
});
|
});
|
||||||
actions.addAction(editFolderAction);
|
actions.addAction(editFolderAction);
|
||||||
|
|
||||||
|
final Form newAssetForm = new Form("new-asset-form",
|
||||||
|
new BoxPanel(BoxPanel.HORIZONTAL));
|
||||||
|
newAssetForm.add(new Label(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.new", CmsConstants.CMS_BUNDLE)));
|
||||||
|
final SingleSelect newAssetTypeSelect = new SingleSelect(
|
||||||
|
"new-asset-type-select");
|
||||||
|
try {
|
||||||
|
newAssetTypeSelect.addPrintListener(new PrintListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepare(final PrintEvent event) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final AssetTypesManager typesManager = cdiUtil
|
||||||
|
.findBean(AssetTypesManager.class);
|
||||||
|
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||||
|
for (final AssetTypeInfo type : typesManager
|
||||||
|
.getAvailableAssetTypes()) {
|
||||||
|
final String labelKey = type.getLabelKey();
|
||||||
|
final String labelBundle = type.getLabelBundle();
|
||||||
|
final ResourceBundle bundle = ResourceBundle
|
||||||
|
.getBundle(labelBundle);
|
||||||
|
final String label = bundle.getString(labelKey);
|
||||||
|
target.addOption(new Option(
|
||||||
|
type.getAssetClass().getName(),
|
||||||
|
new Text(label)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (TooManyListenersException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
newAssetForm.add(newAssetTypeSelect);
|
||||||
|
newAssetForm.add(new Submit(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.new.create", CmsConstants.CMS_BUNDLE)));
|
||||||
|
newAssetForm.addProcessListener(new FormProcessListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
//Nothing yet
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
actionsSegment.add(newAssetForm);
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -518,6 +577,10 @@ public class AssetPane extends LayoutPanel implements Resettable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected SingleSelectionModel<Long> getSelectedAssetModel() {
|
||||||
|
return selectedAssetModel;
|
||||||
|
}
|
||||||
|
|
||||||
private String[] getSources(final PageState state) {
|
private String[] getSources(final PageState state) {
|
||||||
|
|
||||||
final String[] result = (String[]) state.getValue(sourcesParameter);
|
final String[] result = (String[]) state.getValue(sourcesParameter);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
/*
|
||||||
|
* 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.assets.forms;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormValidationListener;
|
||||||
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.cms.ui.assets.AssetForm;
|
||||||
|
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.assets.Bookmark;
|
||||||
|
import org.librecms.contentsection.Asset;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class BookmarkForm extends AssetForm {
|
||||||
|
|
||||||
|
private TextArea description;
|
||||||
|
private TextField url;
|
||||||
|
|
||||||
|
public BookmarkForm(final AssetPane assetPane) {
|
||||||
|
super(assetPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
add(new Label(
|
||||||
|
new GlobalizedMessage("cms.ui.assets.bookmark.description",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
description = new TextArea("bookmark-description");
|
||||||
|
add(description);
|
||||||
|
|
||||||
|
add(new Label(new GlobalizedMessage("cms.ui.assets.bookmark.url",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
url = new TextField("bookmark-url");
|
||||||
|
add(url);
|
||||||
|
|
||||||
|
addValidationListener(new FormValidationListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
|
||||||
|
try {
|
||||||
|
new URL((String) url.getValue(state));
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
data.addError(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.bookmark.url.malformed",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Asset createAsset(final PageState state)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
Objects.requireNonNull(state);
|
||||||
|
|
||||||
|
final Bookmark bookmark = new Bookmark();
|
||||||
|
|
||||||
|
bookmark
|
||||||
|
.getDescription()
|
||||||
|
.addValue(KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) description.getValue(state));
|
||||||
|
|
||||||
|
try {
|
||||||
|
bookmark.setUrl(new URL((String) url.getValue(state)));
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
throw new FormProcessException(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.bookmark.url.malformed",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
return bookmark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateAsset(final Asset asset, final PageState state)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
Objects.requireNonNull(asset);
|
||||||
|
Objects.requireNonNull(state);
|
||||||
|
|
||||||
|
if (!(asset instanceof Bookmark)) {
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Provided asset is not an instance of class (or sub class of) "
|
||||||
|
+ "'%s' but is an instance of class '%s'",
|
||||||
|
Bookmark.class.getName(),
|
||||||
|
asset.getClass().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Bookmark bookmark = (Bookmark) asset;
|
||||||
|
|
||||||
|
bookmark
|
||||||
|
.getDescription()
|
||||||
|
.addValue(KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) description.getValue(state));
|
||||||
|
|
||||||
|
try {
|
||||||
|
bookmark.setUrl(new URL((String) url.getValue(state)));
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
throw new FormProcessException(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.bookmark.url.malformed",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* 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.assets.forms;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.cms.ui.assets.AssetForm;
|
||||||
|
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.assets.LegalMetadata;
|
||||||
|
import org.librecms.contentsection.Asset;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class LegalMetadataForm extends AssetForm {
|
||||||
|
|
||||||
|
private TextArea rightsHolder;
|
||||||
|
private TextArea rights;
|
||||||
|
private TextArea publisher;
|
||||||
|
private TextArea creator;
|
||||||
|
|
||||||
|
public LegalMetadataForm(final AssetPane assetPane) {
|
||||||
|
super(assetPane);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
add(new Label(new GlobalizedMessage(
|
||||||
|
"cms.ui.assets.legalmetadata.rightsholder",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
|
||||||
|
rightsHolder = new TextArea("legalmetadata-rightsholder");
|
||||||
|
add(rightsHolder);
|
||||||
|
|
||||||
|
rights = new TextArea("legalmetadata-rights");
|
||||||
|
add(rights);
|
||||||
|
|
||||||
|
publisher = new TextArea("legalmetadata-rights");
|
||||||
|
add(publisher);
|
||||||
|
|
||||||
|
creator = new TextArea("legalmetadata-creator");
|
||||||
|
add(creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Asset createAsset(final PageState state)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
Objects.requireNonNull(state);
|
||||||
|
|
||||||
|
final LegalMetadata legalMetadata = new LegalMetadata();
|
||||||
|
|
||||||
|
legalMetadata.setRightsHolder((String) rightsHolder.getValue(state));
|
||||||
|
legalMetadata.getRights().addValue(
|
||||||
|
KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) rights.getValue(state));
|
||||||
|
|
||||||
|
legalMetadata.setPublisher((String) publisher.getValue(state));
|
||||||
|
legalMetadata.setCreator((String) creator.getValue(state));
|
||||||
|
|
||||||
|
return legalMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateAsset(final Asset asset, final PageState state)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
Objects.requireNonNull(asset);
|
||||||
|
Objects.requireNonNull(state);
|
||||||
|
|
||||||
|
if (!(asset instanceof LegalMetadata)) {
|
||||||
|
throw new IllegalArgumentException(String.format(
|
||||||
|
"Provided asset is not an instance of '%s' (or a sub class) "
|
||||||
|
+ "but is an instance of class '%s'.",
|
||||||
|
LegalMetadata.class.getName(),
|
||||||
|
asset.getClass().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final LegalMetadata legalMetadata = (LegalMetadata) asset;
|
||||||
|
|
||||||
|
legalMetadata.setRightsHolder((String) rightsHolder.getValue(state));
|
||||||
|
legalMetadata.getRights().addValue(
|
||||||
|
KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) rights.getValue(state));
|
||||||
|
|
||||||
|
legalMetadata.setPublisher((String) publisher.getValue(state));
|
||||||
|
legalMetadata.setCreator((String) creator.getValue(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,9 @@ import org.libreccm.modules.ShutdownEvent;
|
||||||
import org.libreccm.modules.UnInstallEvent;
|
import org.libreccm.modules.UnInstallEvent;
|
||||||
import org.libreccm.web.ApplicationType;
|
import org.libreccm.web.ApplicationType;
|
||||||
import org.libreccm.web.CcmApplication;
|
import org.libreccm.web.CcmApplication;
|
||||||
|
import org.librecms.assets.AssetTypes;
|
||||||
|
import org.librecms.assets.Bookmark;
|
||||||
|
import org.librecms.assets.LegalMetadata;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.ContentSectionCreator;
|
import org.librecms.contentsection.ContentSectionCreator;
|
||||||
import org.librecms.contentsection.ContentSectionSetup;
|
import org.librecms.contentsection.ContentSectionSetup;
|
||||||
|
|
@ -57,6 +60,7 @@ import java.util.Properties;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ContentTypes({Article.class, Event.class, MultiPartArticle.class, News.class})
|
@ContentTypes({Article.class, Event.class, MultiPartArticle.class, News.class})
|
||||||
|
@AssetTypes({Bookmark.class, LegalMetadata.class})
|
||||||
public class Cms implements CcmModule {
|
public class Cms implements CcmModule {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(Cms.class);
|
private static final Logger LOGGER = LogManager.getLogger(Cms.class);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants for assets.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public final class AssetConstants {
|
||||||
|
|
||||||
|
private AssetConstants() {
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String ASSETS_BUNDLE = "org.librecms.assets.Assets";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.assets;
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.assets.forms.BookmarkForm;
|
||||||
|
|
||||||
import org.librecms.contentsection.Asset;
|
import org.librecms.contentsection.Asset;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -37,13 +39,19 @@ import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
import static org.librecms.assets.AssetConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An assets for managing bookmarks which can be used to create links. Useful
|
* An assets for managing bookmarks which can be used to create links. Useful if
|
||||||
* if the same link appears in multiple places.
|
* the same link appears in multiple places.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
|
@AssetType(assetForm = BookmarkForm.class,
|
||||||
|
labelBundle = ASSETS_BUNDLE,
|
||||||
|
labelKey = "bookmark.label",
|
||||||
|
descriptionBundle = ASSETS_BUNDLE,
|
||||||
|
descriptionKey = "bookmark.description")
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "BOOKMARKS", schema = DB_SCHEMA)
|
@Table(name = "BOOKMARKS", schema = DB_SCHEMA)
|
||||||
@Audited
|
@Audited
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.assets;
|
package org.librecms.assets;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.assets.forms.LegalMetadataForm;
|
||||||
|
|
||||||
import org.librecms.contentsection.Asset;
|
import org.librecms.contentsection.Asset;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
|
|
@ -39,6 +41,7 @@ import javax.persistence.JoinTable;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
import static org.librecms.assets.AssetConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for storing legal metadata about a resource (a content item or an
|
* Container for storing legal metadata about a resource (a content item or an
|
||||||
|
|
@ -46,6 +49,11 @@ import static org.librecms.CmsConstants.*;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
|
@AssetType(assetForm = LegalMetadataForm.class,
|
||||||
|
labelKey = "legal_metadata.label",
|
||||||
|
labelBundle = ASSETS_BUNDLE,
|
||||||
|
descriptionKey = "legal_metadata.description",
|
||||||
|
descriptionBundle = ASSETS_BUNDLE)
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "LEGAL_METADATA", schema = DB_SCHEMA)
|
@Table(name = "LEGAL_METADATA", schema = DB_SCHEMA)
|
||||||
@Audited
|
@Audited
|
||||||
|
|
@ -86,7 +94,7 @@ public class LegalMetadata extends Asset implements Serializable {
|
||||||
joinColumns = {
|
joinColumns = {
|
||||||
@JoinColumn(name = "LEGAL_METADATA_ID")
|
@JoinColumn(name = "LEGAL_METADATA_ID")
|
||||||
})
|
})
|
||||||
@Column(name ="CONTRIBUTORS")
|
@Column(name = "CONTRIBUTORS")
|
||||||
private List<String> contributors;
|
private List<String> contributors;
|
||||||
|
|
||||||
public LegalMetadata() {
|
public LegalMetadata() {
|
||||||
|
|
|
||||||
|
|
@ -246,3 +246,5 @@ cms.ui.type.select=Select Content Type
|
||||||
cms.ui.type.select.none=There are no available content types to select
|
cms.ui.type.select.none=There are no available content types to select
|
||||||
cms.ui.assets=Assets
|
cms.ui.assets=Assets
|
||||||
cms.ui.folder.no_assets=No assets
|
cms.ui.folder.no_assets=No assets
|
||||||
|
cms.ui.assets.new=Create new asset
|
||||||
|
cms.ui.assets.new.create=Create asset
|
||||||
|
|
|
||||||
|
|
@ -245,3 +245,5 @@ cms.ui.type.select=Dolkumententype ausw\u00e4hlen
|
||||||
cms.ui.type.select.none=Keine verf\u00fcgbaren Dokumententypen
|
cms.ui.type.select.none=Keine verf\u00fcgbaren Dokumententypen
|
||||||
cms.ui.assets=Medien & Daten
|
cms.ui.assets=Medien & Daten
|
||||||
cms.ui.folder.no_assets=Keine Medien oder Datens\u00e4tze vorhanden
|
cms.ui.folder.no_assets=Keine Medien oder Datens\u00e4tze vorhanden
|
||||||
|
cms.ui.assets.new=Neues Asset anlegen
|
||||||
|
cms.ui.assets.new.create=Asset anlegen
|
||||||
|
|
|
||||||
|
|
@ -204,3 +204,5 @@ cms.ui.type.select=Select Content Type
|
||||||
cms.ui.type.select.none=There are no available content types to select
|
cms.ui.type.select.none=There are no available content types to select
|
||||||
cms.ui.assets=Assets
|
cms.ui.assets=Assets
|
||||||
cms.ui.folder.no_assets=No assets
|
cms.ui.folder.no_assets=No assets
|
||||||
|
cms.ui.assets.new=Create new asset
|
||||||
|
cms.ui.assets.new.create=Create asset
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
bookmark.label=Bookmark
|
||||||
|
bookmark.description=Asset type to store URLs to external resources.
|
||||||
|
legal_metadata.label=Legal metadata
|
||||||
|
legal_metadata.description=Stores legal metadata like the informations about the creator of an image etc.
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
bookmark.label=Lesezeichen (URL)
|
||||||
|
bookmark.description=Dieser Asset-Typ dient zur Ablage von URLs zu externen Resourcen.
|
||||||
|
legal_metadata.label=Rechtliche Informationen
|
||||||
|
legal_metadata.description=Rechtliche Informationen, z.B. die Urheberschaft von Bildern etc.
|
||||||
Loading…
Reference in New Issue