CCM NG: Classes for rendering assets and content items with the new page model

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5063 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2017-10-19 17:25:02 +00:00
parent ba6e28df85
commit 2c5677e8c4
21 changed files with 948 additions and 26 deletions

View File

@ -19,7 +19,7 @@
package org.librecms.assets; package org.librecms.assets;
import com.arsdigita.cms.ui.assets.forms.AudioForm; import com.arsdigita.cms.ui.assets.forms.AudioForm;
import com.arsdigita.cms.ui.assets.forms.ExternalVideoAssetForm;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import java.io.Serializable; import java.io.Serializable;

View File

@ -35,12 +35,10 @@ import javax.persistence.Lob;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.envers.Audited; import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.NotEmpty;
import org.libreccm.jpa.utils.MimeTypeConverter; import org.libreccm.jpa.utils.MimeTypeConverter;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import javax.persistence.Convert; import javax.persistence.Convert;
import javax.validation.constraints.NotNull;
import static org.librecms.CmsConstants.*; import static org.librecms.CmsConstants.*;

View File

@ -0,0 +1,52 @@
/*
* 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.pagemodel.assets;
import org.librecms.contentsection.Asset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public abstract class AbstractAssetRenderer {
public Map<String, Object> render(final Asset asset,
final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("objectId", asset.getObjectId());
result.put("uuid", asset.getUuid());
result.put("displayName", asset.getDisplayName());
result.put("title", asset.getTitle().getValue(language));
renderAsset(asset, language, result);
return result;
}
protected abstract void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result);
}

View File

@ -0,0 +1,44 @@
/*
* 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.pagemodel.assets;
import org.librecms.contentsection.Asset;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.TYPE})
public @interface AssetRenderer {
Class<? extends Asset> renders();
}

View File

@ -0,0 +1,98 @@
/*
* 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.pagemodel.assets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class AssetRenderers {
private static final Logger LOGGER = LogManager
.getLogger(AssetRenderers.class);
@Inject
private Instance<AbstractAssetRenderer> renderers;
public AbstractAssetRenderer findRenderer(
final Class<? extends Asset> assetType) {
LOGGER.debug("Trying to find renderer for asset type \"{}\"...",
assetType.getName());
final AssetRendererLiteral literal = new AssetRendererLiteral(assetType);
final Instance<AbstractAssetRenderer> instance = renderers
.select(literal);
if (instance.isUnsatisfied()) {
LOGGER.warn("No renderer for asset type \"{}\". "
+ "Returning default renderer.",
assetType.getName());
return new AbstractAssetRenderer() {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
//Nothing here.
}
};
} else {
return instance.iterator().next();
}
}
private class AssetRendererLiteral
extends AnnotationLiteral<AssetRenderer>
implements AssetRenderer {
private static final long serialVersionUID = 2635180159989399554L;
private final Class<? extends Asset> renders;
public AssetRendererLiteral(final Class<? extends Asset> renders) {
this.renders = renders;
}
@Override
public Class<? extends Asset> renders() {
return renders;
}
}
}

View File

@ -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 org.librecms.pagemodel.assets;
import org.librecms.assets.AudioAsset;
import org.librecms.assets.LegalMetadata;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = AudioAsset.class)
public class AudioAssetRenderer extends BinaryAssetRenderer {
@Inject
@AssetRenderer(renders = LegalMetadata.class)
private AbstractAssetRenderer legalMetadataRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
super.renderAsset(asset, language, result);
final AudioAsset audioAsset;
if (asset instanceof AudioAsset) {
audioAsset = (AudioAsset) asset;
} else {
return;
}
result.put("legalMetadata",
legalMetadataRenderer.render(audioAsset.getLegalMetadata(), language));
}
}

View File

@ -0,0 +1,53 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.BinaryAsset;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class BinaryAssetRenderer extends AbstractAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final BinaryAsset binaryAsset;
if (asset instanceof BinaryAsset) {
binaryAsset = (BinaryAsset) asset;
} else {
return;
}
result.put("description",
binaryAsset.getDescription().getValue(language));
result.put("fileName", binaryAsset.getFileName());
result.put("mimeType", Objects.toString(binaryAsset.getMimeType()));
result.put("size", binaryAsset.getSize());
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.pagemodel.assets;
import org.librecms.contentsection.Asset;
import org.librecms.pagemodel.assets.AbstractAssetRenderer;
import org.librecms.pagemodel.assets.AssetRenderer;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import org.librecms.assets.Bookmark;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = Bookmark.class)
public class BookmarkRenderer extends AbstractAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final Bookmark bookmark;
if (asset instanceof Bookmark) {
bookmark = (Bookmark) asset;
} else {
return;
}
result.put("description", bookmark.getDescription().getValue(language));
result.put("url", bookmark.getUrl());
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.ExternalAudioAsset;
import org.librecms.assets.LegalMetadata;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = ExternalAudioAsset.class)
public class ExternalAudioAssetRenderer extends BookmarkRenderer {
@Inject
@AssetRenderer(renders = LegalMetadata.class)
private AbstractAssetRenderer legalMetadataRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
super.renderAsset(asset, language, result);
final ExternalAudioAsset externalAudioAsset;
if (asset instanceof ExternalAudioAsset) {
externalAudioAsset = (ExternalAudioAsset) asset;
} else {
return;
}
result.put("legalMetadata",
legalMetadataRenderer
.render(externalAudioAsset.getLegalMetadata(),
language));
}
}

View File

@ -0,0 +1,62 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.ExternalVideoAsset;
import org.librecms.assets.LegalMetadata;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = ExternalVideoAsset.class)
public class ExternalVideoAssetRenderer extends BookmarkRenderer {
@Inject
@AssetRenderer(renders = LegalMetadata.class)
private AbstractAssetRenderer legalMetadataRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale locale,
final Map<String, Object> result) {
super.renderAsset(asset, locale, result);
final ExternalVideoAsset externalVideoAsset;
if (asset instanceof ExternalVideoAsset) {
externalVideoAsset = (ExternalVideoAsset) asset;
} else {
return;
}
result.put("legalMetadata",
legalMetadataRenderer
.render(externalVideoAsset.getLegalMetadata(), locale));
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.FileAsset;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = FileAsset.class)
public class FileAssetRenderer extends BinaryAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale locale,
final Map<String, Object> result) {
super.renderAsset(asset, locale, result);
//Nothing more yet
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.Image;
import org.librecms.assets.LegalMetadata;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@AssetRenderer(renders = Image.class)
@RequestScoped
public class ImageRenderer extends BinaryAssetRenderer {
@Inject
@AssetRenderer(renders = LegalMetadata.class)
private AbstractAssetRenderer legalMetadataRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
super.renderAsset(asset, language, result);
final Image image;
if (asset instanceof Image) {
image = (Image) asset;
} else {
return;
}
result.put("width", image.getWidth());
result.put("height", image.getHeight());
result.put("legalMetadata",
legalMetadataRenderer.render(image.getLegalMetadata(),
language));
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.LegalMetadata;
import org.librecms.contentsection.Asset;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = LegalMetadata.class)
public class LegalMetadataRenderer extends AbstractAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final LegalMetadata legalMetadata;
if (asset instanceof LegalMetadata) {
legalMetadata = (LegalMetadata) asset;
} else {
return;
}
result.put("rightsHolder", legalMetadata.getRightsHolder());
result.put("rights", legalMetadata.getRights().getValue(language));
result.put("publisher", legalMetadata.getPublisher());
result.put("creator", legalMetadata.getCreator());
result.put("contributors",
new ArrayList<>(legalMetadata.getContributors()));
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.Bookmark;
import org.librecms.assets.RelatedLink;
import org.librecms.contentsection.Asset;
import org.librecms.contentsection.ContentItem;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = RelatedLink.class)
public class RelatedLinkRenderer extends AbstractAssetRenderer {
@Inject
@AssetRenderer(renders = Bookmark.class)
private AbstractAssetRenderer bookmarkRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final RelatedLink relatedLink;
if (asset instanceof RelatedLink) {
relatedLink = (RelatedLink) asset;
} else {
return;
}
if (relatedLink.getTargetItem() != null) {
result.put("targetItem",
renderTargetItem(relatedLink.getTargetItem(),
language));
}
if (relatedLink.getBookmark() != null) {
result.put("bookmark",
bookmarkRenderer.render(relatedLink.getBookmark(),
language));
}
}
protected Map<String, Object> renderTargetItem(final ContentItem targetItem,
final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("objectId", targetItem.getObjectId());
result.put("itemUuid", targetItem.getItemUuid());
result.put("displayName", targetItem.getDisplayName());
result.put("name", targetItem.getName().getValue(language));
result.put("title", targetItem.getTitle().getValue(language));
result.put("description",
targetItem.getDescription().getValue(language));
return result;
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.SideNote;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = SideNote.class)
public class SideNoteRenderer extends AbstractAssetRenderer {
@Override
protected void renderAsset(final Asset asset,
final Locale language,
final Map<String, Object> result) {
final SideNote siteNote;
if (asset instanceof SideNote) {
siteNote = (SideNote) asset;
} else {
return;
}
result.put("text", siteNote.getText().getValue(language));
}
}

View File

@ -0,0 +1,64 @@
/*
* 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.pagemodel.assets;
import org.librecms.assets.LegalMetadata;
import org.librecms.assets.VideoAsset;
import org.librecms.contentsection.Asset;
import java.util.Locale;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
@AssetRenderer(renders = VideoAsset.class)
public class VideoAssetRenderer extends BinaryAssetRenderer {
@Inject
@AssetRenderer(renders = LegalMetadata.class)
private AbstractAssetRenderer legalMetadataRenderer;
@Override
protected void renderAsset(final Asset asset,
final Locale locale,
final Map<String, Object> result) {
super.renderAsset(asset, locale, result);
final VideoAsset videoAsset;
if (asset instanceof VideoAsset) {
videoAsset = (VideoAsset) asset;
} else {
return;
}
result.put("width", videoAsset.getWidth());
result.put("height", videoAsset.getHeight());
result.put("legalMetadata",
legalMetadataRenderer.render(videoAsset.getLegalMetadata(),
locale));
}
}

View File

@ -18,12 +18,19 @@
*/ */
package org.librecms.pagemodel.contentitems; package org.librecms.pagemodel.contentitems;
import org.librecms.pagemodel.assets.AbstractAssetRenderer;
import org.librecms.contentsection.AttachmentList;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentType;
import org.librecms.contentsection.ItemAttachment;
import org.librecms.pagemodel.assets.AssetRenderers;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
/** /**
* *
@ -31,6 +38,9 @@ import java.util.Map;
*/ */
public abstract class AbstractContentItemRenderer { public abstract class AbstractContentItemRenderer {
@Inject
private AssetRenderers assetRenderers;
public Map<String, Object> render(final ContentItem item, public Map<String, Object> render(final ContentItem item,
final Locale language) { final Locale language) {
@ -49,6 +59,12 @@ public abstract class AbstractContentItemRenderer {
result.put("lastModified", item.getLastModified()); result.put("lastModified", item.getLastModified());
result.put("creationUserName", item.getCreationUserName()); result.put("creationUserName", item.getCreationUserName());
result.put("lastModifyingUserName", item.getLastModifyingUserName()); result.put("lastModifyingUserName", item.getLastModifyingUserName());
result.put("attachments",
item
.getAttachments()
.stream()
.map(list -> renderAttachmentList(list, language))
.collect(Collectors.toList()));
renderItem(item, language, result); renderItem(item, language, result);
@ -56,8 +72,8 @@ public abstract class AbstractContentItemRenderer {
} }
protected abstract void renderItem(final ContentItem item, protected abstract void renderItem(final ContentItem item,
final Locale language, final Locale language,
final Map<String, Object> result); final Map<String, Object> result);
protected Map<String, Object> renderContentType( protected Map<String, Object> renderContentType(
final ContentType contentType, final Locale language) { final ContentType contentType, final Locale language) {
@ -72,4 +88,45 @@ public abstract class AbstractContentItemRenderer {
return result; return result;
} }
protected Map<String, Object> renderAttachmentList(
final AttachmentList attachmentList,
final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("listId", attachmentList.getListId());
result.put("uuid", attachmentList.getUuid());
result.put("name", attachmentList.getName());
result.put("order", attachmentList.getOrder());
result.put("title", attachmentList.getTitle().getValue(language));
result.put("description",
attachmentList.getDescription().getValue(language));
result.put("attachments",
attachmentList
.getAttachments()
.stream()
.map(attachment -> renderAttachment(attachment, language))
.collect(Collectors.toList()));
return result;
}
protected Map<String, Object> renderAttachment(
final ItemAttachment<?> attachment,
final Locale language) {
final Map<String, Object> result = new HashMap<>();
result.put("attachmentId", attachment.getAttachmentId());
result.put("uuid", attachment.getUuid());
result.put("sortKey", attachment.getSortKey());
final AbstractAssetRenderer renderer = assetRenderers
.findRenderer(attachment.getAsset().getClass());
result.put("asset", renderer.render(attachment.getAsset(), language));
return result;
}
} }

View File

@ -35,7 +35,10 @@ import javax.inject.Qualifier;
*/ */
@Qualifier @Qualifier
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target({ElementType.METHOD,
ElementType.FIELD,
ElementType.PARAMETER,
ElementType.TYPE})
public @interface ContentItemRenderer { public @interface ContentItemRenderer {
/** /**

View File

@ -91,14 +91,7 @@ public class ContentItemRenderers {
return findRenderer(itemType); return findRenderer(itemType);
} }
} else { } else {
final AbstractContentItemRenderer renderer = instance return instance.iterator().next();
.iterator()
.next();
@SuppressWarnings("unchecked")
final AbstractContentItemRenderer result
= renderer;
return result;
} }
} }

View File

@ -38,14 +38,14 @@ import java.util.ResourceBundle;
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
public class ContentItemEditor extends Window { public class ContentItemEditor<T extends ContentItem> extends Window {
private static final long serialVersionUID = 3341827053652019616L; private static final long serialVersionUID = 3341827053652019616L;
private List<Component> authoringsSteps; private List<Component> authoringsSteps;
public ContentItemEditor(final ContentSectionViewController controller, public ContentItemEditor(final ContentSectionViewController controller,
final ContentItem item) { final T item) {
super(); super();
@ -101,7 +101,7 @@ public class ContentItemEditor extends Window {
private Component createAuthoringStep( private Component createAuthoringStep(
final ContentSectionViewController controller, final ContentSectionViewController controller,
final ContentItem item, final T item,
final String componentClassName) { final String componentClassName) {
try { try {
@ -111,7 +111,7 @@ public class ContentItemEditor extends Window {
return stepClass return stepClass
.getDeclaredConstructor(ContentSectionViewController.class, .getDeclaredConstructor(ContentSectionViewController.class,
ContentItem.class) item.getClass())
.newInstance(controller, item); .newInstance(controller, item);
} catch (ClassNotFoundException } catch (ClassNotFoundException
| NoSuchMethodException | NoSuchMethodException

View File

@ -21,6 +21,7 @@ package org.librecms.ui;
import com.vaadin.cdi.ViewScoped; import com.vaadin.cdi.ViewScoped;
import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.libreccm.ui.LocalizedStringWidgetController;
import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.FolderRepository; import org.librecms.contentsection.FolderRepository;
import org.librecms.contenttypes.ContentTypesManager; import org.librecms.contenttypes.ContentTypesManager;
@ -49,6 +50,9 @@ public class ContentSectionViewController {
@Inject @Inject
private GlobalizationHelper globalizationHelper; private GlobalizationHelper globalizationHelper;
@Inject
private LocalizedStringWidgetController localizedStringWidgetController;
@Inject @Inject
private PermissionChecker permissionChecker; private PermissionChecker permissionChecker;
@ -62,27 +66,31 @@ public class ContentSectionViewController {
return browseDocumentsDataProvider; return browseDocumentsDataProvider;
} }
protected FolderBrowserFolderTreeDataProvider getFolderTreeDataProvider() { public FolderBrowserFolderTreeDataProvider getFolderTreeDataProvider() {
return folderTreeDataProvider; return folderTreeDataProvider;
} }
protected ContentTypesManager getContentTypesManager() { public ContentTypesManager getContentTypesManager() {
return contentTypesManager; return contentTypesManager;
} }
protected FolderRepository getFolderRepository() { public FolderRepository getFolderRepository() {
return folderRepository; return folderRepository;
} }
protected GlobalizationHelper getGlobalizationHelper() { public GlobalizationHelper getGlobalizationHelper() {
return globalizationHelper; return globalizationHelper;
} }
protected PermissionChecker getPermissionChecker() { public LocalizedStringWidgetController getLocalizedStringWidgetController() {
return localizedStringWidgetController;
}
public PermissionChecker getPermissionChecker() {
return permissionChecker; return permissionChecker;
} }
protected ContentSectionRepository getSectionRepository() { public ContentSectionRepository getSectionRepository() {
return sectionRepository; return sectionRepository;
} }