Removed several old classes
parent
198c7d7b83
commit
7ce68f3cd7
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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;
|
||||
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContentCenter extends CcmApplication {
|
||||
|
||||
private static final long serialVersionUID = 6672720141286517654L;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,307 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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;
|
||||
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||
import com.arsdigita.cms.ui.CMSApplicationPage;
|
||||
import com.arsdigita.cms.ui.contentcenter.MainPage;
|
||||
|
||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||
import com.arsdigita.dispatcher.RequestContext;
|
||||
import com.arsdigita.kernel.security.Util;
|
||||
import com.arsdigita.templating.PresentationManager;
|
||||
import com.arsdigita.templating.Templating;
|
||||
import com.arsdigita.ui.login.LoginHelper;
|
||||
import com.arsdigita.web.ApplicationFileResolver;
|
||||
import com.arsdigita.web.BaseApplicationServlet;
|
||||
import com.arsdigita.web.LoginSignal;
|
||||
import com.arsdigita.web.WebConfig;
|
||||
import com.arsdigita.xml.Document;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.shiro.authz.AuthorizationException;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.libreccm.security.Shiro;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionRepository;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* CMS ContentCenter (content-center) application servlet serves all request
|
||||
* made within the Content Center application.
|
||||
*
|
||||
* @author Peter Boy <pboy@barkhof.uni-bremen.de>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@WebServlet(urlPatterns = "/content-center/*")
|
||||
public class ContentCenterServlet extends BaseApplicationServlet {
|
||||
|
||||
private static final long serialVersionUID = 16543266935651171L;
|
||||
|
||||
/**
|
||||
* URL (pathinfo) -> Page object mapping. Based on it (and the http request
|
||||
* url) the doService method to selects a page to display
|
||||
*/
|
||||
private final Map<String, Page> pages = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Path to directory containg ccm-cms template files
|
||||
*/
|
||||
private String m_templatePath;
|
||||
/**
|
||||
* Resolvers to find templates (JSP) and other stuff stored in file system.
|
||||
*/
|
||||
private ApplicationFileResolver m_resolver;
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ContentCenterServlet.class);
|
||||
|
||||
/**
|
||||
* Use parent's class initialisation extension point to perform additional
|
||||
* initialisation tasks.
|
||||
*/
|
||||
@Override
|
||||
protected void doInit() {
|
||||
LOGGER.info("starting doInit method");
|
||||
|
||||
// NEW STUFF here used to process the pages in this servlet
|
||||
// Addresses previously noted in WEB-INF/resources/content-center-map.xml
|
||||
// Obviously not required.
|
||||
|
||||
|
||||
addPage("/", new MainPage()); // index page at address ~/cc
|
||||
addPage("/index", new MainPage());
|
||||
|
||||
|
||||
// addPage("/item-search", new CMSItemSearchPage());
|
||||
// Old style
|
||||
//addPage("/item-search", new ItemSearchPage());
|
||||
//addPage("/searchredirect", new CMSSearchResultRedirector());
|
||||
|
||||
// STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not
|
||||
// handled by the this servlet directly.
|
||||
/**
|
||||
* Set Template base path for JSP's
|
||||
*/
|
||||
// ToDo: Make it configurable by an appropriate config registry entry!
|
||||
// m_templatePath = CMS.getConfig().getTemplateRoot();
|
||||
m_templatePath = "/templates/ccm-cms/content-center";
|
||||
/**
|
||||
* Set TemplateResolver class
|
||||
*/
|
||||
m_resolver = WebConfig.getConfig().getResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doService(final HttpServletRequest sreq,
|
||||
final HttpServletResponse sresp,
|
||||
final CcmApplication app) throws ServletException,
|
||||
IOException {
|
||||
LOGGER.info("starting doService method");
|
||||
|
||||
// ContentCenter workspace = (ContentCenter) app;
|
||||
|
||||
/* Check user and privilegies */
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final Shiro shiro = cdiUtil.findBean(Shiro.class);
|
||||
if (!shiro.getSubject().isAuthenticated()) {
|
||||
throw new LoginSignal(sreq); // send to login page
|
||||
}
|
||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||
PermissionChecker.class);
|
||||
final ContentSectionRepository sectionRepo = cdiUtil.findBean(
|
||||
ContentSectionRepository.class);
|
||||
final List<ContentSection> sections = sectionRepo.findAll();
|
||||
boolean hasAccess = false;
|
||||
for (final ContentSection section : sections) {
|
||||
if (permissionChecker.isPermitted(ItemPrivileges.EDIT,
|
||||
section.getRootDocumentsFolder())) {
|
||||
hasAccess = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAccess) { // user has no access privilege
|
||||
throw new AuthorizationException(
|
||||
"User is not entitled to access any content section");
|
||||
// throw new LoginSignal(sreq); // send to login page
|
||||
}
|
||||
|
||||
// New way to fetch the page
|
||||
String pathInfo = sreq.getPathInfo();
|
||||
if (pathInfo.length() > 1 && pathInfo.endsWith("/")) {
|
||||
/* NOTE: ServletAPI specifies, pathInfo may be empty or will
|
||||
* start with a '/' character. It currently carries a
|
||||
* trailing '/' if a "virtual" page, i.e. not a real jsp, but
|
||||
* result of a servlet mapping. But Application requires url
|
||||
* NOT to end with a trailing '/' for legacy free applications. */
|
||||
pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
|
||||
}
|
||||
|
||||
// An empty remaining URL or a URL which doesn't end in trailing slash:
|
||||
// probably want to redirect.
|
||||
// Probably DEPRECATED with new access method or only relevant for jsp
|
||||
// extension
|
||||
// if (m_trailingSlashList.contains(url) && !originalUrl.endsWith("/")) {
|
||||
// DispatcherHelper.sendRedirect(sresp, originalUrl + "/");
|
||||
// return;
|
||||
// }
|
||||
final Page page = pages.get(pathInfo);
|
||||
if (page != null) {
|
||||
|
||||
// Check user access.
|
||||
checkUserAccess(sreq, sresp);
|
||||
|
||||
if (page instanceof CMSPage) {
|
||||
// backwards compatibility fix until migration completed
|
||||
final CMSPage cmsPage = (CMSPage) page;
|
||||
final RequestContext ctx = DispatcherHelper.getRequestContext();
|
||||
cmsPage.init();
|
||||
cmsPage.dispatch(sreq, sresp, ctx);
|
||||
} else {
|
||||
final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page;
|
||||
cmsAppPage.init(sreq, sresp, app);
|
||||
// Serve the page.
|
||||
final Document doc = cmsAppPage.buildDocument(sreq, sresp);
|
||||
|
||||
PresentationManager pm = Templating.getPresentationManager();
|
||||
pm.servePage(doc, sreq, sresp);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Fall back on the JSP application dispatcher.
|
||||
// NOTE: The JSP must ensure the proper authentication and
|
||||
// authorisation if required!
|
||||
LOGGER.info("NO page registered to serve the requst url.");
|
||||
|
||||
RequestDispatcher rd = m_resolver.resolve(m_templatePath,
|
||||
sreq, sresp, app);
|
||||
if (rd != null) {
|
||||
LOGGER.debug("Got dispatcher " + rd);
|
||||
|
||||
final HttpServletRequest origreq = DispatcherHelper
|
||||
.restoreOriginalRequest(sreq);
|
||||
rd.forward(origreq, sresp);
|
||||
} else {
|
||||
|
||||
sresp.sendError(404, sreq.getRequestURI()
|
||||
+ " not found on this server.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LOGGER.info("doService method completed");
|
||||
|
||||
} // END doService()
|
||||
|
||||
/**
|
||||
* Internal service mechod, adds one pair of Url - Page to the internal hash
|
||||
* map, used as a cache.
|
||||
*
|
||||
* @param pathInfo url stub for a page to display
|
||||
* @param page Page object to display
|
||||
*/
|
||||
private void addPage(final String pathInfo, final Page page) {
|
||||
|
||||
// Current Implementation requires pathInfo to start with a leading '/'
|
||||
// SUN Servlet API specifies: "PathInfo *may be empty* or will start
|
||||
// with a '/' character."
|
||||
pages.put(pathInfo, page);
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Service Method returns the URL stub for the class name, can return null
|
||||
// * if not mapped
|
||||
// */
|
||||
// // Currently still in use by c.ad.cms.ui.ItemSearchWidget
|
||||
// public static String getURLStubForClass(String classname) {
|
||||
// LOGGER.debug("Getting URL Stub for : " + classname);
|
||||
// Iterator itr = s_pageURLs.keySet().iterator();
|
||||
// while (itr.hasNext()) {
|
||||
// String classname2 = (String) itr.next();
|
||||
// s_log.debug("key: " + classname + " value: "
|
||||
// + (String) s_pageURLs.get(classname2));
|
||||
// }
|
||||
// String url = (String) s_pageURLs.get(classname);
|
||||
// return url;
|
||||
// }
|
||||
/**
|
||||
* Verify that the user is logged in and is able to view the page.
|
||||
* Subclasses can override this method if they need to, but should always be
|
||||
* sure to call super.checkUserAccess(...)
|
||||
*
|
||||
* @param request The HTTP request
|
||||
* @param response The HTTP response
|
||||
* @param actx The request context
|
||||
*
|
||||
*/
|
||||
protected void checkUserAccess(final HttpServletRequest request,
|
||||
final HttpServletResponse response //,
|
||||
/// final RequestContext actx
|
||||
)
|
||||
throws ServletException {
|
||||
|
||||
if (!CdiUtil.createCdiUtil().findBean(Shiro.class).getSubject()
|
||||
.isAuthenticated()) {
|
||||
throw new LoginSignal(request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects the client to the login page, setting the return url to the
|
||||
* current request URI.
|
||||
*
|
||||
* @exception ServletException If there is an exception thrown while trying
|
||||
* to redirect, wrap that exception in a
|
||||
* ServletException
|
||||
*
|
||||
*/
|
||||
protected void redirectToLoginPage(HttpServletRequest req,
|
||||
HttpServletResponse resp)
|
||||
throws ServletException {
|
||||
String url = Util.getSecurityHelper()
|
||||
.getLoginURL(req)
|
||||
+ "?" + LoginHelper.RETURN_URL_PARAM_NAME
|
||||
+ "=" + DispatcherHelper.encodeReturnURL(req);
|
||||
try {
|
||||
LoginHelper.sendRedirect(req, resp, url);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("IO Exception", e);
|
||||
throw new ServletException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,155 +0,0 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.arsdigita.cms;
|
||||
|
||||
import com.arsdigita.cms.contenttypes.GenericAddress;
|
||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.domain.DomainObjectTraversalAdapter;
|
||||
import com.arsdigita.domain.DomainObjectXMLRenderer;
|
||||
import com.arsdigita.globalization.GlobalizationHelper;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import com.arsdigita.xml.Element;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* This is a special ContentItemXMLRenderer for CMS to get a more transparent
|
||||
* way to handle ContentBundles during XML output.
|
||||
*
|
||||
* The problem was to change RelatedLinks and therefore Link to always link to
|
||||
* the corresponding ContentBundle instead of the content item. To get the
|
||||
* corresponding content item during XML generation, I have to test for
|
||||
* ContentBundle and negotiate the language version.
|
||||
* This is not possible in com.arsdigita.ccm
|
||||
*
|
||||
* @author quasi
|
||||
*/
|
||||
public class ContentItemXMLRenderer extends DomainObjectXMLRenderer {
|
||||
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(ContentItemXMLRenderer.class);
|
||||
private String m_propertyName = "";
|
||||
private String m_keyName = "";
|
||||
private String m_relationAttribute = "";
|
||||
|
||||
public ContentItemXMLRenderer(final Element root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
// This method will be called by DomainObjectTraversal.walk()
|
||||
// It's purpose is to test for ContentBundle objects and if found, replace
|
||||
// that object with the negotiated version of the content item.
|
||||
// Otherwise this methd will do nothing.
|
||||
@Override
|
||||
protected void walk(final DomainObjectTraversalAdapter adapter,
|
||||
final DomainObject obj,
|
||||
final String path,
|
||||
final String context,
|
||||
final DomainObject linkObject) {
|
||||
//final long start = System.nanoTime();
|
||||
|
||||
DomainObject nObj = obj;
|
||||
|
||||
if (nObj instanceof ContentBundle) {
|
||||
|
||||
nObj = ((ContentBundle) obj).getInstance(GlobalizationHelper.getNegotiatedLocale(), true);
|
||||
}
|
||||
|
||||
super.walk(adapter, nObj, path, context, linkObject);
|
||||
|
||||
//System.out.printf("Walked object in %d ms\n", (System.nanoTime() - start) / 1000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleAttribute(final DomainObject obj, final String path, final Property property) {
|
||||
final String propertyName = property.getName();
|
||||
|
||||
// Special handling for the isoCountryCode field in GenericAddress
|
||||
if (obj instanceof GenericAddress && "isoCountryCode".equals(propertyName)) {
|
||||
//if (propertyName.equals("isoCountryCode")) {
|
||||
super.handleAttribute(obj, path, property);
|
||||
|
||||
final Element element = newElement(m_element, "country");
|
||||
element.setText(GenericAddress.getCountryNameFromIsoCode(((GenericAddress) obj).getIsoCountryCode()));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Special handling for the relation attribute keys
|
||||
if (!m_relationAttribute.isEmpty()) {
|
||||
String key = "";
|
||||
|
||||
// The RelationAttribute is part of this domain object as field
|
||||
if (obj instanceof RelationAttributeInterface
|
||||
&& ((RelationAttributeInterface) obj).
|
||||
hasRelationAttributeProperty(propertyName)) {
|
||||
|
||||
final RelationAttributeInterface relationAttributeObject = (RelationAttributeInterface) obj;
|
||||
key = relationAttributeObject.getRelationAttributeKey(
|
||||
propertyName);
|
||||
|
||||
}
|
||||
|
||||
// This RelationAttribute is part of an n:m association as link attribute
|
||||
if (obj instanceof LinkDomainObject
|
||||
&& propertyName.equals(m_keyName)) {
|
||||
key = (String) ((LinkDomainObject) obj).get(m_keyName);
|
||||
}
|
||||
|
||||
// Replace value of the property defined in RELATION_ATTRIBUTES string
|
||||
// of the primary domain object with the localized String.
|
||||
if (!key.isEmpty()) {
|
||||
// logger.debug(String.format(
|
||||
// "Getting relation attribute value for key '%s' of relation attribute '%s'",
|
||||
// key, m_relationAttribute));
|
||||
final RelationAttributeCollection relationAttributeCollection = new RelationAttributeCollection(
|
||||
m_relationAttribute, key);
|
||||
relationAttributeCollection.addLanguageFilter(GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage());
|
||||
if (!relationAttributeCollection.isEmpty()) {
|
||||
relationAttributeCollection.next();
|
||||
final Element element = newElement(m_element, m_keyName);
|
||||
element.setText(relationAttributeCollection.getName());
|
||||
final Element elementId = newElement(m_element, m_keyName + "Id");
|
||||
elementId.setText(relationAttributeCollection.getKey());
|
||||
relationAttributeCollection.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.handleAttribute(obj, path, property);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beginAssociation(final DomainObject obj, final String path, final Property property) {
|
||||
super.beginAssociation(obj, path, property);
|
||||
|
||||
final String propertyName = property.getName();
|
||||
|
||||
if (obj instanceof RelationAttributeInterface
|
||||
&& ((RelationAttributeInterface) obj).hasRelationAttributeProperty(
|
||||
propertyName)) {
|
||||
|
||||
final RelationAttributeInterface relationAttributeObject = (RelationAttributeInterface) obj;
|
||||
|
||||
m_propertyName = propertyName;
|
||||
m_keyName = relationAttributeObject.getRelationAttributeKeyName(propertyName);
|
||||
m_relationAttribute = relationAttributeObject.getRelationAttributeName(propertyName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void endAssociation(final DomainObject obj, final String path, final Property property) {
|
||||
|
||||
m_propertyName = "";
|
||||
m_keyName = "";
|
||||
m_relationAttribute = "";
|
||||
|
||||
super.endAssociation(obj, path, property);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -57,10 +57,10 @@ public class ContentSectionDispatcher implements Dispatcher {
|
|||
|
||||
public ContentSectionDispatcher() {
|
||||
|
||||
dispatcherChain.addChainedDispatcher(new CMSDispatcher(true));
|
||||
dispatcherChain.addChainedDispatcher(new FileDispatcher());
|
||||
dispatcherChain.addChainedDispatcher(new ItemDispatcher());
|
||||
dispatcherChain.addChainedDispatcher(new CMSDispatcher());
|
||||
// dispatcherChain.addChainedDispatcher(new CMSDispatcher(true));
|
||||
// dispatcherChain.addChainedDispatcher(new FileDispatcher());
|
||||
// dispatcherChain.addChainedDispatcher(new ItemDispatcher());
|
||||
// dispatcherChain.addChainedDispatcher(new CMSDispatcher());
|
||||
}
|
||||
|
||||
public void dispatch(HttpServletRequest request,
|
||||
|
|
|
|||
|
|
@ -1,246 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-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.dispatcher;
|
||||
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.ContentType;
|
||||
import com.arsdigita.cms.Folder;
|
||||
import com.arsdigita.cms.Template;
|
||||
import com.arsdigita.cms.TemplateManager;
|
||||
import com.arsdigita.cms.TemplateManagerFactory;
|
||||
import com.arsdigita.mimetypes.MimeType;
|
||||
import com.arsdigita.util.Assert;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* ------- May be outdated. TemplateResolver has been reworked. ----------
|
||||
* Resolves the JSP template to use for dispatching an
|
||||
* item. This replaces TemplateResolver since the latter
|
||||
* has a useless API.
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* <p>In general, the process for resolving a template involves two
|
||||
* steps:</p>
|
||||
*
|
||||
* <ol>
|
||||
*
|
||||
* <li>The template resolver examines specific properties of the
|
||||
* item, the content section, and/or the request itself and selects
|
||||
* an appropriate <em>context</em>. A context is simply a token
|
||||
* such as "plain" or "fancy".
|
||||
*
|
||||
* <li>Based on the selected context, the template resolver
|
||||
* identifies an appropriate template for the item. This is a
|
||||
* three-step process: (1) the resolver queries for an association
|
||||
* between the item and a specific template for the selected
|
||||
* context; (2) if no such association exists, the resolver queries
|
||||
* the item's content type for a default template to use in the
|
||||
* selected context; (3) if a default template is not found, return
|
||||
* null (at which point the dispatcher should probably give up and
|
||||
* return a 404 error).
|
||||
*
|
||||
* </ol>
|
||||
*/
|
||||
|
||||
public class DefaultTemplateResolver extends AbstractTemplateResolver
|
||||
implements TemplateResolver {
|
||||
|
||||
private static Logger s_log = Logger.getLogger(DefaultTemplateResolver.class);
|
||||
|
||||
/**
|
||||
* Returns the JSP template filename relative to the webapp
|
||||
* root.
|
||||
*
|
||||
* @param section The ContentSection for the request
|
||||
* @param item The ContentItem for the request
|
||||
* @param request The current HttpServletRequest
|
||||
*
|
||||
* @return The path to the jsp template.
|
||||
*/
|
||||
public String getTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
|
||||
String template = getItemTemplate(section, item, request);
|
||||
MimeType mimeType = MimeType.loadMimeType(Template.JSP_MIME_TYPE);
|
||||
|
||||
if (template == null) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("No item template, looking for content type template");
|
||||
}
|
||||
template = getTypeTemplate(section, item, request, mimeType);
|
||||
}
|
||||
|
||||
if (template == null) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("No content type template, looking for default template");
|
||||
}
|
||||
|
||||
template = getDefaultTemplate(section, item, request);
|
||||
|
||||
Assert.exists(template, "default template");
|
||||
}
|
||||
|
||||
if (s_log.isInfoEnabled()) {
|
||||
s_log.info("Got template " + template + " for item " + item.getOID());
|
||||
}
|
||||
|
||||
return ContentSection.getConfig().getTemplateRoot() + template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSP template filename relative to the webapp
|
||||
* root for a given Template reference.
|
||||
*
|
||||
* @param template The Template to resolve the URL for.
|
||||
*
|
||||
* @return The path to the jsp template.
|
||||
*/
|
||||
public String getTemplatePath(Template template) {
|
||||
|
||||
return ContentSection.getConfig().getTemplateRoot() +
|
||||
getTemplateFilename(template, template.getContentSection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XSL template filename relative to the webapp
|
||||
* root for a given Template reference.
|
||||
*
|
||||
* @param template The Template to resolve the URL for.
|
||||
*
|
||||
* @return The path to the xsl template.
|
||||
*/
|
||||
public String getTemplateXSLPath(Template template) {
|
||||
|
||||
return ContentSection.getConfig().getTemplateRoot() +
|
||||
getTemplateXSLFilename(template, template.getContentSection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template associated with the item (if any)
|
||||
*/
|
||||
protected String getItemTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
TemplateManager manager = TemplateManagerFactory.getInstance();
|
||||
String context = getTemplateContext(request);
|
||||
Template template = manager.getTemplate(item, context);
|
||||
|
||||
return template == null ? null : getTemplateFilename(
|
||||
template, section
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template associated with the type (if any)
|
||||
* @deprecated Use the version that specifies a mime type
|
||||
*/
|
||||
protected String getTypeTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
MimeType mimeType = MimeType.loadMimeType(Template.JSP_MIME_TYPE);
|
||||
return getTypeTemplate(section, item, request, mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template associated with the type (if any)
|
||||
*/
|
||||
protected String getTypeTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request,
|
||||
MimeType mimeType) {
|
||||
TemplateManager manager = TemplateManagerFactory.getInstance();
|
||||
ContentType type = item.getContentType();
|
||||
|
||||
Template template = null;
|
||||
|
||||
if (type != null ) {
|
||||
String context = getTemplateContext(request);
|
||||
template = manager.getDefaultTemplate(section, type, context, mimeType);
|
||||
} else {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Item has no content type, not looking for a " +
|
||||
"content type specific template");
|
||||
}
|
||||
}
|
||||
|
||||
return template == null ? null : getTemplateFilename(
|
||||
template, section
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default template
|
||||
*/
|
||||
protected String getDefaultTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
String path = (item instanceof Folder) ?
|
||||
ContentSection.getConfig().getDefaultFolderTemplatePath() :
|
||||
ContentSection.getConfig().getDefaultItemTemplatePath();
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename for a Template object
|
||||
*/
|
||||
protected String getTemplateFilename(Template template,
|
||||
ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
return getTemplateFilename(template, section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename for a Template object
|
||||
*/
|
||||
protected String getTemplateXSLFilename(Template template,
|
||||
ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request) {
|
||||
return getTemplateXSLFilename(template, section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename for a Template object
|
||||
*/
|
||||
protected String getTemplateFilename(Template template,
|
||||
ContentSection section) {
|
||||
|
||||
String templateName = template.getPath();
|
||||
String sectionURL = section.getPath();
|
||||
return sectionURL + "/" + templateName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename for a Template object
|
||||
*/
|
||||
protected String getTemplateXSLFilename(Template template,
|
||||
ContentSection section) {
|
||||
|
||||
String templateName = template.getPathNoJsp() + ".xsl";
|
||||
String sectionURL = section.getPath();
|
||||
|
||||
return sectionURL + "/" + templateName;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-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.dispatcher;
|
||||
|
||||
import com.arsdigita.dispatcher.ChainedDispatcher;
|
||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||
import com.arsdigita.dispatcher.RequestContext;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Dispatches to a file stored under the CMS package root
|
||||
* (<code>/packages/cms/www</code>). This includes both unmanaged files copied
|
||||
* or created directly in the file system, as well as pages and assets published
|
||||
* to the file system from CMS.
|
||||
*
|
||||
* @author Karl Goldstein (karlg@arsdigita.com)
|
||||
* @version $Revision$ $DateTime: 2004/08/17 23:15:09 $
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
public class FileDispatcher implements ChainedDispatcher {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ChainedDispatcher.class);
|
||||
|
||||
@Override
|
||||
public int chainedDispatch(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
RequestContext context)
|
||||
throws IOException, ServletException {
|
||||
|
||||
File jspFile = getPackageFile(context);
|
||||
|
||||
if (jspFile.exists() && !jspFile.isDirectory()) {
|
||||
String packageURL = context.getPageBase() + context
|
||||
.getRemainingURLPart();
|
||||
LOGGER.debug("DISPATCHING to " + packageURL);
|
||||
|
||||
// don't match folders, since they don't actually match a file
|
||||
if (!packageURL.endsWith("/")) {
|
||||
LOGGER.debug("DISPATCHING to " + packageURL);
|
||||
// Don't set caching headers - let JSP file do it if required
|
||||
//DispatcherHelper.maybeCacheDisable(response);
|
||||
DispatcherHelper.setRequestContext(request, context);
|
||||
DispatcherHelper.forwardRequestByPath(packageURL, request,
|
||||
response);
|
||||
return ChainedDispatcher.DISPATCH_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
return ChainedDispatcher.DISPATCH_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches the request URL to a file in the package www directory.
|
||||
*
|
||||
*/
|
||||
private File getPackageFile(RequestContext appContext) {
|
||||
|
||||
ServletContext servletContext = appContext.getServletContext();
|
||||
|
||||
String filePath = appContext.getRemainingURLPart();
|
||||
|
||||
String packageDocRoot = servletContext.getRealPath(appContext
|
||||
.getPageBase());
|
||||
|
||||
File jspFile = new File(packageDocRoot, filePath);
|
||||
|
||||
return jspFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,445 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-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.dispatcher;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.CMSConfig;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentItemXMLRenderer;
|
||||
import com.arsdigita.cms.ExtraXMLGenerator;
|
||||
import com.arsdigita.cms.SecurityManager;
|
||||
import com.arsdigita.cms.UserDefinedContentItem;
|
||||
import com.arsdigita.cms.XMLDeliveryCache;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.domain.DomainObjectTraversal;
|
||||
import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
|
||||
import com.arsdigita.kernel.Kernel;
|
||||
import com.arsdigita.kernel.Party;
|
||||
import com.arsdigita.kernel.permissions.PermissionDescriptor;
|
||||
import com.arsdigita.kernel.permissions.PermissionService;
|
||||
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
|
||||
import com.arsdigita.metadata.DynamicObjectType;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.metadata.Property;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.xml.Element;
|
||||
import org.apache.log4j.Logger;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>The default <tt>XMLGenerator</tt> implementation.</p>
|
||||
*
|
||||
* @author Michael Pih
|
||||
* @version $Revision: #20 $ $DateTime: 2004/08/17 23:15:09 $
|
||||
* @version $Id: SimpleXMLGenerator.java 2167 2011-06-19 21:12:12Z pboy $
|
||||
*/
|
||||
public class SimpleXMLGenerator implements XMLGenerator {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(SimpleXMLGenerator.class);
|
||||
public static final String ADAPTER_CONTEXT = SimpleXMLGenerator.class.getName();
|
||||
/**
|
||||
* jensp 2011-10-23: Sometimes the extra XML is not needed, for example
|
||||
* when embedding the XML of a content item into the XML output of another
|
||||
* content item. The default value {@code true}. To change the value
|
||||
* call {@link #setUseExtraXml(booelan)} after creating an instance of
|
||||
* your generator.
|
||||
*/
|
||||
private boolean useExtraXml = true;
|
||||
/**
|
||||
* jensp 2012-04-18: This value is forwarded to this ExtraXMLGenerators
|
||||
* by calling {@link ExtraXMLGenerator#setListMode(boolean)}. The behavior
|
||||
* triggered by this value depends on the specific implementation of
|
||||
* the {@code ExtraXMLGenerator}
|
||||
*/
|
||||
private boolean listMode = false;
|
||||
/**
|
||||
* Extra attributes for the cms:item element.
|
||||
*/
|
||||
private final Map<String, String> itemAttributes = new LinkedHashMap<String, String>();
|
||||
/**
|
||||
* Allows to overwrite the name and the namespace of the XML element
|
||||
* used to wrap the rendered item.
|
||||
*/
|
||||
private String itemElemName = "cms:item";
|
||||
private String itemElemNs = CMS.CMS_XML_NS;
|
||||
|
||||
// Register general purpose adaptor for all content items
|
||||
static {
|
||||
s_log.debug("Static initializer starting...");
|
||||
final SimpleDomainObjectTraversalAdapter adapter = new SimpleDomainObjectTraversalAdapter();
|
||||
adapter.addAssociationProperty("/object/type");
|
||||
adapter.addAssociationProperty("/object/categories");
|
||||
|
||||
DomainObjectTraversal.registerAdapter(
|
||||
ContentItem.BASE_DATA_OBJECT_TYPE,
|
||||
adapter,
|
||||
ADAPTER_CONTEXT);
|
||||
s_log.debug("Static initializer finished");
|
||||
}
|
||||
|
||||
public SimpleXMLGenerator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setUseExtraXml(final boolean useExtraXml) {
|
||||
this.useExtraXml = useExtraXml;
|
||||
}
|
||||
|
||||
public void setListMode(final boolean listMode) {
|
||||
this.listMode = listMode;
|
||||
}
|
||||
|
||||
public void addItemAttribute(final String name, final String value) {
|
||||
itemAttributes.put(name, value);
|
||||
}
|
||||
|
||||
public void setItemElemName(final String itemElemName, final String itemElemNs) {
|
||||
this.itemElemName = itemElemName;
|
||||
this.itemElemNs = itemElemNs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the XML to render the content panel.
|
||||
*
|
||||
* @param state The page state
|
||||
* @param parent The parent DOM element
|
||||
* @param useContext The use context
|
||||
*/
|
||||
@Override
|
||||
public void generateXML(final PageState state, final Element parent, final String useContext) {
|
||||
//final long start = System.nanoTime();
|
||||
|
||||
//ContentSection section = CMS.getContext().getContentSection();
|
||||
ContentItem item = getContentItem(state);
|
||||
|
||||
s_log.info("Generate XML for item " + item.getOID());
|
||||
|
||||
Party currentParty = Kernel.getContext().getParty();
|
||||
if (currentParty == null) {
|
||||
currentParty = Kernel.getPublicUser();
|
||||
}
|
||||
// check if current user can edit the current item (nb privilege is granted on draft item, but live item
|
||||
// has draft as its permission context
|
||||
//
|
||||
// Note that the xml that is generated is only of use if you DO NOT CACHE content pages.
|
||||
// cg.
|
||||
final PermissionDescriptor edit = new PermissionDescriptor(
|
||||
PrivilegeDescriptor.get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
|
||||
if (PermissionService.checkPermission(edit)) {
|
||||
parent.addAttribute("canEdit", "true");
|
||||
final Element canEditElem = parent.newChildElement("canEdit");
|
||||
canEditElem.setText("true");
|
||||
|
||||
}
|
||||
final PermissionDescriptor publish = new PermissionDescriptor(
|
||||
PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty);
|
||||
if (PermissionService.checkPermission(publish)) {
|
||||
parent.addAttribute("canPublish", "true");
|
||||
}
|
||||
final String className = item.getDefaultDomainClass();
|
||||
|
||||
// Ensure correct subtype of ContentItem is instantiated
|
||||
if (!item.getClass().getName().equals(className)) {
|
||||
s_log.info("Specializing item");
|
||||
try {
|
||||
item = (ContentItem) DomainObjectFactory.newInstance(
|
||||
new OID(item.getObjectType().getQualifiedName(), item.getID()));
|
||||
} catch (DataObjectNotFoundException ex) {
|
||||
throw new UncheckedWrapperException(
|
||||
(String) GlobalizationUtil.globalize(
|
||||
"cms.dispatcher.cannot_find_domain_object").localize(),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Implementing XMLGenerator directly is now deprecated
|
||||
if (item instanceof XMLGenerator) {
|
||||
s_log.info("Item implements XMLGenerator interface");
|
||||
final XMLGenerator xitem = (XMLGenerator) item;
|
||||
xitem.generateXML(state, parent, useContext);
|
||||
|
||||
} else if ("com.arsdigita.cms.UserDefinedContentItem".equals(className)) {
|
||||
s_log.info("Item is a user defined content item");
|
||||
final UserDefinedContentItem UDItem = (UserDefinedContentItem) item;
|
||||
generateUDItemXML(UDItem, state, parent, useContext);
|
||||
|
||||
} else {
|
||||
s_log.info("Item is using DomainObjectXMLRenderer");
|
||||
|
||||
// This is the preferred method
|
||||
//final Element content = startElement(useContext, parent);
|
||||
final Element content = startElement(useContext);
|
||||
s_log.debug("Item is not in cache, generating item.");
|
||||
|
||||
final XMLDeliveryCache xmlCache = XMLDeliveryCache.getInstance();
|
||||
|
||||
if (CMSConfig.getInstanceOf().getEnableXmlCache() && xmlCache.isCached(item.getOID(), useContext, listMode)) {
|
||||
xmlCache.retrieveFromCache(content, item.getOID(), useContext, listMode);
|
||||
} else {
|
||||
final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(content);
|
||||
|
||||
renderer.setWrapAttributes(true);
|
||||
renderer.setWrapRoot(false);
|
||||
renderer.setWrapObjects(false);
|
||||
renderer.setRevisitFullObject(true);
|
||||
|
||||
//System.out.printf("Prepared renderer in %d ms\n", (System.nanoTime() - start)
|
||||
// / 1000000);
|
||||
|
||||
renderer.walk(item, ADAPTER_CONTEXT);
|
||||
|
||||
//System.out.printf("Rendered standard item xml in %d ms\n", (System.nanoTime() - start)
|
||||
// / 1000000);
|
||||
|
||||
//parent.addContent(content);
|
||||
|
||||
//Only item XML Cache End
|
||||
|
||||
// s_log.debug("Content elem content: ");
|
||||
// logElementTree(content);
|
||||
// s_log.debug("Content elem content end -- ");
|
||||
|
||||
|
||||
/*
|
||||
* 2011-08-27 jensp: Introduced to remove the annoying special templates
|
||||
* for MultiPartArticle, SiteProxy and others. The method called
|
||||
* here was already definied but not used.
|
||||
*
|
||||
* 2011-10-23 jensp: It is now possible to disable the use of
|
||||
* extra XML.
|
||||
*/
|
||||
//final long extraXMLStart = System.nanoTime();
|
||||
if (useExtraXml) {
|
||||
for (ExtraXMLGenerator generator : item.getExtraXMLGenerators()) {
|
||||
generator.setListMode(listMode);
|
||||
generator.generateXML(item, content, state);
|
||||
}
|
||||
}
|
||||
|
||||
//Only published items
|
||||
//Only the XML of the item itself, no extra XML
|
||||
if (CMSConfig.getInstanceOf().getEnableXmlCache() && item.isLiveVersion()) {
|
||||
xmlCache.cache(item.getOID(), item, content, useContext, listMode);
|
||||
}
|
||||
}
|
||||
|
||||
if (PermissionService.checkPermission(edit)) {
|
||||
final ItemResolver resolver = item.getContentSection().getItemResolver();
|
||||
final Element editLinkElem = content.newChildElement("editLink");
|
||||
final ContentItem draftItem = item.getDraftVersion();
|
||||
editLinkElem.setText(resolver.generateItemURL(state,
|
||||
draftItem,
|
||||
item.getContentSection(),
|
||||
draftItem.getVersion()));
|
||||
}
|
||||
|
||||
parent.addContent(content);
|
||||
|
||||
//System.out.printf("Rendered item in %d ms\n\n", (System.nanoTime() - start) / 1000000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the current content item. This method can be overridden to
|
||||
* fetch any {@link com.arsdigita.cms.ContentItem}, but by default,
|
||||
* it fetches the <code>ContentItem</code> that is set in the page state
|
||||
* by the dispatcher.
|
||||
*
|
||||
* @param state The page state
|
||||
* @return A content item
|
||||
*/
|
||||
protected ContentItem getContentItem(final PageState state) {
|
||||
if (CMS.getContext().hasContentItem()) {
|
||||
return CMS.getContext().getContentItem();
|
||||
} else {
|
||||
final CMSPage page = (CMSPage) state.getPage();
|
||||
return page.getContentItem(state);
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateUDItemXML(final UserDefinedContentItem UDItem,
|
||||
final PageState state,
|
||||
final Element parent,
|
||||
final String useContext) {
|
||||
|
||||
final Element element = startElement(useContext, parent);
|
||||
final Element additionalAttrs = UDItemElement(useContext);
|
||||
|
||||
element.addAttribute("type", UDItem.getContentType().getName());
|
||||
element.addAttribute("id", UDItem.getID().toString());
|
||||
element.addAttribute("name", UDItem.getName());
|
||||
element.addAttribute("title", UDItem.getTitle());
|
||||
element.addAttribute("javaClass", UDItem.getContentType().getClassName());
|
||||
|
||||
final DynamicObjectType dot = new DynamicObjectType(UDItem.getSpecificObjectType());
|
||||
final Iterator declaredProperties =
|
||||
dot.getObjectType().getDeclaredProperties();
|
||||
Property currentProperty;
|
||||
Object value;
|
||||
while (declaredProperties.hasNext()) {
|
||||
currentProperty = (Property) declaredProperties.next();
|
||||
value = (Object) UDItem.get(currentProperty.getName());
|
||||
if (value != null) {
|
||||
element.addContent(
|
||||
UDItemAttrElement(currentProperty.getName(),
|
||||
value.toString()));
|
||||
} else {
|
||||
element.addContent(
|
||||
UDItemAttrElement(currentProperty.getName(),
|
||||
"none specified"));
|
||||
}
|
||||
}
|
||||
|
||||
//element.addContent(additionalAttrs);
|
||||
//parent.addContent(element);
|
||||
|
||||
}
|
||||
|
||||
private Element startElement(final String useContext, final Element parent) {
|
||||
//Element element = new Element("cms:item", CMS.CMS_XML_NS);
|
||||
//final Element element = new Element(itemElemName, itemElemNs);
|
||||
final Element element = parent.newChildElement(itemElemName, itemElemNs);
|
||||
if (useContext != null) {
|
||||
element.addAttribute("useContext", useContext);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> attr : itemAttributes.entrySet()) {
|
||||
element.addAttribute(attr.getKey(), attr.getValue());
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private Element startElement(final String useContext) {
|
||||
final Element element = new Element(itemElemName, itemElemNs);
|
||||
|
||||
if (useContext != null) {
|
||||
element.addAttribute("useContext", useContext);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> attr : itemAttributes.entrySet()) {
|
||||
element.addAttribute(attr.getKey(), attr.getValue());
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private Element startCachedElement(final String useContext) {
|
||||
final Element element = new Element(itemElemName, itemElemNs) {
|
||||
@Override
|
||||
public Element newChildElement(Element copyFrom) {
|
||||
s_log.debug("Copy of element added to cached elem.");
|
||||
return super.newChildElement(copyFrom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element newChildElement(String name, Element copyFrom) {
|
||||
s_log.debug("Copy of element added to cached elem.");
|
||||
return super.newChildElement(name, copyFrom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element addContent(final Element newContent) {
|
||||
s_log.debug("Content added to cached element");
|
||||
return super.addContent(newContent);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
if (useContext != null) {
|
||||
element.addAttribute("useContext", useContext);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> attr : itemAttributes.entrySet()) {
|
||||
element.addAttribute(attr.getKey(), attr.getValue());
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private void copyElement(final Element parent, final Element element) {
|
||||
final Element copy = parent.newChildElement(element.getName());
|
||||
final Iterator attrs = element.getAttributes().entrySet().iterator();
|
||||
Map.Entry attr;
|
||||
while (attrs.hasNext()) {
|
||||
attr = (Map.Entry) attrs.next();
|
||||
copy.addAttribute((String) attr.getKey(), (String) attr.getValue());
|
||||
}
|
||||
|
||||
final Iterator childs = element.getChildren().iterator();
|
||||
while (childs.hasNext()) {
|
||||
copyElement(copy, (Element) childs.next());
|
||||
}
|
||||
|
||||
if (element.getText() != null) {
|
||||
copy.setText(element.getText());
|
||||
}
|
||||
|
||||
if (element.getCDATASection() != null) {
|
||||
copy.setCDATASection(element.getCDATASection());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Element UDItemElement(final String useContext) {
|
||||
final Element element = new Element("cms:UDItemAttributes", CMS.CMS_XML_NS);
|
||||
/*
|
||||
if ( useContext != null ) {
|
||||
element.addAttribute("useContext", useContext);
|
||||
}
|
||||
*/
|
||||
return element;
|
||||
}
|
||||
|
||||
private Element UDItemAttrElement(final String name, final String value) {
|
||||
final Element element = new Element("cms:UDItemAttribute", CMS.CMS_XML_NS);
|
||||
element.addAttribute("UDItemAttrName", name);
|
||||
element.addAttribute("UDItemAttrValue", value);
|
||||
return element;
|
||||
}
|
||||
|
||||
private void logElementTree(final Element element) {
|
||||
s_log.debug("Tree of element" + element.getName() + ":\n");
|
||||
s_log.debug("\n" + logElementTree(element, new StringBuilder(), 0));
|
||||
}
|
||||
|
||||
private String logElementTree(final Element element, final StringBuilder builder, final int depth) {
|
||||
for (int i = 0; i < depth; i++) {
|
||||
builder.append('\t');
|
||||
}
|
||||
builder.append('<').append(element.getName()).append(">\n");
|
||||
|
||||
for (Object childObj : element.getChildren()) {
|
||||
final Element child = (Element) childObj;
|
||||
logElementTree(child, builder, depth + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < depth; i++) {
|
||||
builder.append('\t');
|
||||
}
|
||||
builder.append("</").append(element.getName()).append(">\n");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2001-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.dispatcher;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Reimplementation, based on ItemTemplateResolver
|
||||
*
|
||||
* <p>
|
||||
* Many sites offer alternative views of the same content item depending on
|
||||
* device or browser, or on user preference. For example, a site may have
|
||||
* "plain" and "fancy" versions of its pages. The fancy versions would be the
|
||||
* defaults, while the plain versions would be appropriate for users with
|
||||
* low-bandwidth connections, older browsers, or a distaste for flashy
|
||||
* appurtenances. In this the case the selection might be made based on a
|
||||
* cookie.</p>
|
||||
*
|
||||
* <p>
|
||||
* Another common example is the "printable" version of a page. In this case a
|
||||
* query variable might be more appropriate.</p>
|
||||
*
|
||||
*
|
||||
* @author Karl Goldstein (karlg@arsdigita.com)
|
||||
* @version $Id: TemplateResolver.java 1967 2009-08-29 21:05:51Z pboy $
|
||||
*
|
||||
*/
|
||||
public interface TemplateResolver {
|
||||
|
||||
/**
|
||||
* Returns the JSP template filename relative to the webapp root.
|
||||
*
|
||||
* @param section The ContentSection for the request
|
||||
* @param item The ContentItem for the request
|
||||
* @param request The current HttpServletRequest
|
||||
*
|
||||
* @return The path to the jsp template.
|
||||
*/
|
||||
public String getTemplate(ContentSection section,
|
||||
ContentItem item,
|
||||
HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns the JSP template filename relative to the webapp root for a given
|
||||
* Template reference.
|
||||
*
|
||||
* @param template The Template to resolve the URL for.
|
||||
*
|
||||
* @return The path to the jsp template.
|
||||
*/
|
||||
public String getTemplatePath(Template template);
|
||||
|
||||
/**
|
||||
* Returns the XSL template filename relative to the webapp root for a given
|
||||
* Template reference.
|
||||
*
|
||||
* @param template The Template to resolve the URL for.
|
||||
*
|
||||
* @return The path to the xsl template.
|
||||
*/
|
||||
public String getTemplateXSLPath(Template template);
|
||||
|
||||
/**
|
||||
* Sets the TemplateContext parameter in the request
|
||||
*
|
||||
* @param sTemplateContext the template context to set
|
||||
* @param request the request in which to set the template context
|
||||
*/
|
||||
public void setTemplateContext(String sTemplateContext,
|
||||
HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Gets the template context from the request.
|
||||
*
|
||||
* @param request the request from which to get the template context
|
||||
*
|
||||
* @return the template context
|
||||
*/
|
||||
public String getTemplateContext(HttpServletRequest request);
|
||||
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Tree;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.event.TreeExpansionEvent;
|
||||
import com.arsdigita.bebop.event.TreeExpansionListener;
|
||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
||||
|
||||
/**
|
||||
* A convenience class for CMS trees.
|
||||
*
|
||||
* @author Justin Ross <jross@redhat.com>
|
||||
*/
|
||||
public class BaseTree extends Tree {
|
||||
|
||||
public BaseTree(final TreeModelBuilder builder) {
|
||||
super(builder);
|
||||
|
||||
addChangeListener(new Change());
|
||||
addTreeExpansionListener(new TreeExpansion());
|
||||
}
|
||||
|
||||
private class Change implements ChangeListener {
|
||||
public final void stateChanged(final ChangeEvent e) {
|
||||
final PageState state = e.getPageState();
|
||||
final Object key = BaseTree.this.getSelectedKey(state);
|
||||
|
||||
if (key != null) {
|
||||
expand(key.toString(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TreeExpansion implements TreeExpansionListener {
|
||||
public final void treeExpanded(final TreeExpansionEvent e) {
|
||||
//s_log.error("expanded");
|
||||
}
|
||||
|
||||
public final void treeCollapsed(final TreeExpansionEvent e) {
|
||||
//s_log.error("collapsed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.PageLocations;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.web.ParameterMap;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.contentsection.ContentItemL10NManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The context bar of the content section UI.</p>
|
||||
*
|
||||
* @author Justin Ross
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class ContentItemContextBar extends ContentSectionContextBar {
|
||||
|
||||
private final ItemSelectionModel itemSelectionModel;
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
ContentItemContextBar(final ItemSelectionModel itemSelectionModel,
|
||||
final StringParameter selectedLanguageParam) {
|
||||
super();
|
||||
|
||||
this.itemSelectionModel = itemSelectionModel;
|
||||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final List<Entry> entries(final PageState state) {
|
||||
final List<Entry> entries = super.entries(state);
|
||||
final ContentItem item = itemSelectionModel.getSelectedObject(state);
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
final URL url = URL.there(state.getRequest(),
|
||||
section.getPrimaryUrl() + "/"
|
||||
+ PageLocations.ITEM_PAGE,
|
||||
params(item));
|
||||
|
||||
final StringBuilder title = new StringBuilder();
|
||||
title.append(localize("cms.ui.content_item"));
|
||||
title.append(": ")
|
||||
.append(item.getDisplayName());
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentItemL10NManager l10nManager = cdiUtil
|
||||
.findBean(ContentItemL10NManager.class);
|
||||
final String selectedLanguage = (String) state
|
||||
.getValue(selectedLanguageParam);
|
||||
final Locale selectedLocale;
|
||||
if (selectedLanguage == null
|
||||
|| selectedLanguage.isEmpty()) {
|
||||
selectedLocale = KernelConfig.getConfig().getDefaultLocale();
|
||||
} else {
|
||||
selectedLocale = new Locale(selectedLanguage);
|
||||
}
|
||||
|
||||
final String language;
|
||||
if (l10nManager.hasLanguage(item, selectedLocale)) {
|
||||
language = selectedLanguage;
|
||||
} else {
|
||||
state.setValue(selectedLanguageParam,
|
||||
KernelConfig.getConfig().getDefaultLanguage());
|
||||
language = KernelConfig.getConfig().getDefaultLanguage();
|
||||
}
|
||||
if (language != null) {
|
||||
title.append(" (")
|
||||
.append(language)
|
||||
.append(")");
|
||||
}
|
||||
|
||||
entries.add(new Entry(title.toString(), url));
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static ParameterMap params(final ContentItem item) {
|
||||
final ParameterMap params = new ParameterMap();
|
||||
|
||||
params.setParameter(ContentItemPage.ITEM_ID, item.getObjectId());
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
private static String localize(final String key) {
|
||||
return (String) ContentSectionPage.globalize(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,10 +24,8 @@ import com.arsdigita.bebop.FormProcessException;
|
|||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.Resettable;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.TabbedPane;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
|
|
@ -156,7 +154,6 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
private final ItemTemplates templatesPane;
|
||||
private final Link previewLink;
|
||||
private final GlobalNavigation globalNavigation;
|
||||
private final ContentItemContextBar contextBar;
|
||||
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
|
|
@ -268,9 +265,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
globalNavigation = new GlobalNavigation();
|
||||
add(globalNavigation);
|
||||
|
||||
contextBar = new ContentItemContextBar(itemSelectionModel,
|
||||
selectedLanguageParam);
|
||||
add(contextBar);
|
||||
|
||||
|
||||
// Create panels.
|
||||
summaryPane = new Summary(itemSelectionModel);
|
||||
|
|
|
|||
|
|
@ -1,154 +0,0 @@
|
|||
/*
|
||||
* 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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.PageLocations;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
import com.arsdigita.web.ParameterMap;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* The context bar of the content section UI.
|
||||
*
|
||||
* @author Justin Ross
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContentSectionContextBar extends WorkspaceContextBar {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ContentSectionContextBar.class);
|
||||
|
||||
@Override
|
||||
protected List<Entry> entries(final PageState state) {
|
||||
|
||||
/* Include breadcrumb entries already set by content-center (i.e. the
|
||||
* URL of the content center itself */
|
||||
final List<Entry> entries = super.entries(state);
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
final Stack<Entry> folderEntryStack = new Stack<>();
|
||||
String currentFolderLabel = null;
|
||||
ParameterMap params = new ParameterMap();
|
||||
boolean isTemplate = false;
|
||||
BigDecimal templateID = null;
|
||||
|
||||
if (CMS.getContext().hasContentItem()) {
|
||||
final ContentItem item = CMS.getContext().getContentItem();
|
||||
if (item == null) {
|
||||
LOGGER.warn("item is null");
|
||||
} else if (item.getContentType() == null) {
|
||||
LOGGER.warn(
|
||||
"item.getContentType() returns null. item.class.getName(): "
|
||||
+ item.getClass().getName());
|
||||
}
|
||||
|
||||
//ToDo NG - Not sure what happens here...
|
||||
// final Optional<CcmObject> parent = item.getParent();
|
||||
//
|
||||
// while (!isTemplate
|
||||
// && parent.isPresent()
|
||||
// && parent.get() instanceof ContentItem) {
|
||||
// if (currentFolderLabel != null) {
|
||||
// final URL folderURL = URL.there
|
||||
// (state.getRequest(),
|
||||
// section.getPath() + "/" + PageLocations.SECTION_PAGE,
|
||||
// params);
|
||||
// folderEntryStack.push(new Entry(currentFolderLabel, folderURL));
|
||||
// currentFolderLabel = null;
|
||||
// params = new ParameterMap();
|
||||
// }
|
||||
// final ContentItem pitem = (ContentItem) parent;
|
||||
//
|
||||
// if (pitem instanceof Folder) {
|
||||
// final Folder folder = (Folder) pitem;
|
||||
// parent = folder.getParent();
|
||||
//
|
||||
// currentFolderLabel = folder.getLabel();
|
||||
// if (parent != null || folder.equals(section.getRootFolder())) {
|
||||
// params.setParameter
|
||||
// (ContentSectionPage.SET_FOLDER, folder.getID());
|
||||
// }
|
||||
// } else if (pitem instanceof ContentBundle) {
|
||||
// final ACSObject ppitem = pitem.getParent();
|
||||
//
|
||||
// if (ppitem != null && ppitem instanceof Folder) {
|
||||
// final Folder folder = (Folder) ppitem;
|
||||
//
|
||||
// parent = folder.getParent();
|
||||
// currentFolderLabel = folder.getLabel();
|
||||
// if (parent != null || folder.equals(section
|
||||
// .getRootFolder())) {
|
||||
// params.setParameter
|
||||
// (ContentSectionPage.SET_FOLDER, folder.getID());
|
||||
// }
|
||||
// } else {
|
||||
// parent = null;
|
||||
// }
|
||||
// } else {
|
||||
// parent = null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
if (isTemplate) {
|
||||
params.setParameter(ContentSectionPage.SET_TAB,
|
||||
new BigDecimal(
|
||||
ContentSectionPage.CONTENTTYPES_TAB));
|
||||
params.setParameter(ContentSectionPage.SET_TEMPLATE, templateID);
|
||||
}
|
||||
|
||||
// add section-level entry. if this is for an item page, the URL
|
||||
// will be for the root folder.
|
||||
final URL url = URL.there(
|
||||
state.getRequest(),
|
||||
String.format("%s/" + PageLocations.SECTION_PAGE,
|
||||
section.getPrimaryUrl()),
|
||||
params);
|
||||
|
||||
final String sectionTitle = lz("cms.ui.content_section");
|
||||
final String title = sectionTitle + ": " + section.getLabel();
|
||||
|
||||
entries.add(new Entry(title, url));
|
||||
|
||||
// add any folders to the path now
|
||||
while (!folderEntryStack.empty()) {
|
||||
entries.add(folderEntryStack.pop());
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static String lz(final String key) {
|
||||
return (String) ContentSectionPage.globalize(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -132,7 +132,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
private ContentTypeAdminPane m_typePane;
|
||||
//private LayoutPanel m_userAdminPane;
|
||||
private LayoutPanel m_csePane;
|
||||
private ReportPane m_reportPane;
|
||||
|
||||
/**
|
||||
* Creates the content section index page containing - a Navigaton bar for
|
||||
|
|
@ -145,7 +144,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
setClassAttr("cms-admin");
|
||||
|
||||
add(new GlobalNavigation());
|
||||
add(new ContentSectionContextBar());
|
||||
|
||||
// Initialize the individual panes
|
||||
m_folderPane = getFolderAdminPane();
|
||||
|
|
@ -349,13 +347,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
|
|||
return m_csePane;
|
||||
}
|
||||
|
||||
protected ReportPane getReportPane() {
|
||||
if (m_reportPane == null) {
|
||||
m_reportPane = new ReportPane();
|
||||
}
|
||||
return m_reportPane;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the specified component, with the specified tab name, to the tabbed
|
||||
* pane only if it is not null.
|
||||
|
|
|
|||
|
|
@ -1,265 +0,0 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.arsdigita.cms.ui;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.FormModel;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.List;
|
||||
import com.arsdigita.bebop.MapComponentSelectionModel;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.Resettable;
|
||||
import com.arsdigita.bebop.SegmentedPanel;
|
||||
import com.arsdigita.bebop.SegmentedPanel.Segment;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.list.ListModel;
|
||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* A {@link LayoutPanel} to insert into {@link ContentSectionPage}.
|
||||
*
|
||||
* @author Sören Bernstein <quasi@quasiweb.de>
|
||||
*/
|
||||
public class ImagesPane extends LayoutPanel implements Resettable {
|
||||
|
||||
public static final Logger S_LOG = Logger.getLogger(ImagesPane.class);
|
||||
private final StringParameter m_imageComponentKey;
|
||||
private final MapComponentSelectionModel m_imageComponent;
|
||||
private final ImageComponentAdminListener m_adminListener;
|
||||
final private SegmentedPanel m_body;
|
||||
private HashMap<String, Segment> m_bodySegments = new HashMap();
|
||||
private final ResettableParameterSingleSelectionModel m_model;
|
||||
private final List m_links;
|
||||
private final LinksSection m_modes;
|
||||
|
||||
public ImagesPane() {
|
||||
super();
|
||||
|
||||
m_model = new ResettableParameterSingleSelectionModel(new
|
||||
StringParameter(List.SELECTED));
|
||||
m_model.setDefaultSelection(ImageComponent.LIBRARY);
|
||||
m_model.addChangeListener(new ImageAdminSelectionListener());
|
||||
|
||||
m_links = new List(new ImageAdminListModelBuilder());
|
||||
m_links.setSelectionModel(m_model);
|
||||
|
||||
final SimpleContainer left = new SimpleContainer();
|
||||
setLeft(left);
|
||||
|
||||
m_modes = new LinksSection();
|
||||
left.add(m_modes);
|
||||
|
||||
m_body = new SegmentedPanel();
|
||||
setBody(m_body);
|
||||
|
||||
m_imageComponentKey = new StringParameter("imageComponent");
|
||||
|
||||
final ParameterSingleSelectionModel componentModel = new
|
||||
ParameterSingleSelectionModel(m_imageComponentKey);
|
||||
m_imageComponent = new MapComponentSelectionModel(componentModel,
|
||||
new HashMap());
|
||||
|
||||
final Map selectors = m_imageComponent.getComponentsMap();
|
||||
m_adminListener = new ImageComponentAdminListener(m_imageComponent, this);
|
||||
|
||||
// Image library component
|
||||
final ImageLibraryComponent library = new
|
||||
ImageLibraryComponent(ImageComponent.ADMIN_IMAGES);
|
||||
library.getForm().addInitListener(m_adminListener);
|
||||
library.getForm().addProcessListener(m_adminListener);
|
||||
selectors.put(ImageComponent.LIBRARY, library);
|
||||
m_bodySegments.put(ImageComponent.LIBRARY, m_body.addSegment(
|
||||
new Label(GlobalizationUtil.globalize(
|
||||
"cms.contentasset.image.ui.image_library")),
|
||||
library));
|
||||
|
||||
// Image upload component
|
||||
final ImageUploadComponent upload = new
|
||||
ImageUploadComponent(ImageComponent.ADMIN_IMAGES);
|
||||
upload.getForm().addInitListener(m_adminListener);
|
||||
upload.getForm().addSubmissionListener(m_adminListener);
|
||||
upload.getForm().addProcessListener(m_adminListener);
|
||||
selectors.put(ImageComponent.UPLOAD, upload);
|
||||
m_bodySegments.put(ImageComponent.UPLOAD, m_body.addSegment(
|
||||
new Label(GlobalizationUtil.globalize(
|
||||
"cms.contentasset.image.ui.image_upload")),
|
||||
upload));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void register(final Page page) {
|
||||
super.register(page);
|
||||
|
||||
Iterator<String> keys = m_bodySegments.keySet().iterator();
|
||||
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
page.setVisibleDefault(m_bodySegments.get(key),
|
||||
m_model.getDefaultSelection().equals(key));
|
||||
}
|
||||
|
||||
page.addComponentStateParam(this, m_imageComponentKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets this pane and all its resettable components.
|
||||
*
|
||||
* @param state Page state
|
||||
*/
|
||||
@Override
|
||||
public final void reset(final PageState state) {
|
||||
super.reset(state);
|
||||
|
||||
m_model.reset(state);
|
||||
this.setActiveImageComponent(state, m_model.getDefaultSelection());
|
||||
}
|
||||
|
||||
public final void setActiveImageComponent(PageState state, String activeComp) {
|
||||
|
||||
Iterator<String> keys = m_bodySegments.keySet().iterator();
|
||||
m_imageComponent.setSelectedKey(state, activeComp);
|
||||
|
||||
while (keys.hasNext()) {
|
||||
|
||||
String key = keys.next();
|
||||
final boolean visibility = key.equals(activeComp);
|
||||
state.setVisible(m_bodySegments.get(key), visibility);
|
||||
|
||||
for (int index = 0; index < m_bodySegments.get(key).size(); index++) {
|
||||
|
||||
Component component = m_bodySegments.get(key).get(index);
|
||||
|
||||
// Reset all components if they are of type Resettable
|
||||
if (component instanceof Resettable) {
|
||||
((Resettable) component).reset(state);
|
||||
}
|
||||
|
||||
// Set visibility
|
||||
component.setVisible(state, visibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class ResettableParameterSingleSelectionModel
|
||||
extends ParameterSingleSelectionModel
|
||||
implements Resettable {
|
||||
|
||||
private String defaultKey;
|
||||
|
||||
public ResettableParameterSingleSelectionModel(ParameterModel m) {
|
||||
super(m);
|
||||
}
|
||||
|
||||
public void setDefaultSelection(String selKey) {
|
||||
this.defaultKey = selKey;
|
||||
}
|
||||
|
||||
public String getDefaultSelection() {
|
||||
return defaultKey;
|
||||
}
|
||||
|
||||
public void reset(PageState state) {
|
||||
|
||||
if (Assert.isEnabled()) {
|
||||
final FormModel model = state.getPage().getStateModel();
|
||||
Assert.isTrue(model.containsFormParam(getStateParameter()));
|
||||
}
|
||||
|
||||
state.setValue(getStateParameter(), this.defaultKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class ImageAdminListModel implements ListModel {
|
||||
|
||||
private ArrayList<String> m_keys;
|
||||
private int m_index = -1;
|
||||
|
||||
public ImageAdminListModel(ArrayList keys) {
|
||||
m_keys = keys;
|
||||
}
|
||||
|
||||
public boolean next() {
|
||||
return (m_index++ < m_keys.size() - 1);
|
||||
}
|
||||
|
||||
public Object getElement() {
|
||||
return GlobalizationUtil.globalize(
|
||||
"cms.contentasset.image.ui.image_" + m_keys.get(m_index)).localize();
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return m_keys.get(m_index);
|
||||
}
|
||||
}
|
||||
|
||||
private class ImageAdminListModelBuilder extends LockableImpl
|
||||
implements ListModelBuilder {
|
||||
|
||||
public ListModel makeModel(final List list, final PageState state) {
|
||||
ArrayList<String> keys = new ArrayList(2);
|
||||
keys.add(ImageComponent.LIBRARY);
|
||||
keys.add(ImageComponent.UPLOAD);
|
||||
return new ImageAdminListModel(keys);
|
||||
}
|
||||
}
|
||||
|
||||
private class ImageAdminSelectionListener implements ChangeListener {
|
||||
|
||||
public final void stateChanged(final ChangeEvent e) {
|
||||
S_LOG.debug("Selection state changed; I may change "
|
||||
+"the body's visible pane");
|
||||
|
||||
final PageState state = e.getPageState();
|
||||
|
||||
// ImagesPane.this.reset(state);
|
||||
|
||||
if (m_model.isSelected(state)) {
|
||||
S_LOG.debug("The selection model is selected; displaying "
|
||||
+"the item pane");
|
||||
|
||||
ImagesPane.this.setActiveImageComponent(
|
||||
state,
|
||||
state.getControlEventValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class LinksSection extends Section {
|
||||
|
||||
LinksSection() {
|
||||
setHeading(GlobalizationUtil.globalize(
|
||||
"cms.contentasset.image.ui.images"));
|
||||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
|
||||
group.setSubject(m_links);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Permeance Technologies Pty Ltd. 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.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.List;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.ChangeEvent;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.list.ListModel;
|
||||
import com.arsdigita.bebop.list.ListModelBuilder;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.ui.report.ContentSectionSummaryTable;
|
||||
import com.arsdigita.cms.ui.report.Report;
|
||||
import com.arsdigita.cms.ui.report.ReportListModel;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
/**
|
||||
* A pane that shows selectable reports and their results. A selectable list of
|
||||
* reports is shown on the left-hand side, a selected report is shown as body.
|
||||
*
|
||||
* @author
|
||||
* <a href="https://sourceforge.net/users/thomas-buckel/">thomas-buckel</a>
|
||||
* @author
|
||||
* <a href="https://sourceforge.net/users/tim-permeance/">tim-permeance</a>
|
||||
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ReportPane extends BaseAdminPane<String> {
|
||||
|
||||
private final SingleSelectionModel<String> selectionModel;
|
||||
private final java.util.List<Report> availableReports;
|
||||
|
||||
public ReportPane() {
|
||||
availableReports = getReports();
|
||||
|
||||
selectionModel = new ParameterSingleSelectionModel<>(
|
||||
new StringParameter(List.SELECTED));
|
||||
selectionModel.addChangeListener(new SelectionListener());
|
||||
setSelectionModel(selectionModel);
|
||||
|
||||
List m_reports = new List(new ReportListModelBuilder(availableReports));
|
||||
m_reports.setSelectionModel(selectionModel);
|
||||
|
||||
final ReportsListSection reportsListSection = new ReportsListSection(
|
||||
m_reports);
|
||||
setLeft(reportsListSection);
|
||||
|
||||
// Register the actual components of the reports for later usage
|
||||
for (Report report : availableReports) {
|
||||
getBody().add(report.getComponent());
|
||||
}
|
||||
|
||||
setIntroPane(new Label(gz("cms.ui.reports.intro")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of available reports.
|
||||
*/
|
||||
private java.util.List<Report> getReports() {
|
||||
java.util.List<Report> reports = new ArrayList<>();
|
||||
reports.add(new Report("cms.ui.reports.css.reportName",
|
||||
new ContentSectionSummaryTable()));
|
||||
// Add other reports as required
|
||||
|
||||
Collections.sort(
|
||||
reports,
|
||||
(r1, r2) -> r1.getName().compareTo(r2.getName()));
|
||||
|
||||
return reports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the report model that matches the given key.
|
||||
*
|
||||
* @param key Key to match.
|
||||
*
|
||||
* @return Report model that matches that given key, null if no matching
|
||||
* report was found.
|
||||
*/
|
||||
private Report getReportByKey(final String key) {
|
||||
for (Report report : availableReports) {
|
||||
if (report.getKey().equals(key)) {
|
||||
return report;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* UI section for left-hand list of reports.
|
||||
*/
|
||||
private class ReportsListSection extends Section {
|
||||
|
||||
ReportsListSection(final List reports) {
|
||||
setHeading(gz("cms.ui.reports.header"));
|
||||
ActionGroup group = new ActionGroup();
|
||||
setBody(group);
|
||||
group.setSubject(reports);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SelectionListener for selected report. It shows the selected report in
|
||||
* the body of this component.
|
||||
*/
|
||||
private class SelectionListener implements ChangeListener {
|
||||
|
||||
@Override
|
||||
public final void stateChanged(final ChangeEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
getBody().reset(state);
|
||||
|
||||
if (selectionModel.isSelected(state)) {
|
||||
Report selectedReport = getReportByKey(selectionModel
|
||||
.getSelectedKey(state).toString());
|
||||
if (selectedReport != null) {
|
||||
getBody().push(state, selectedReport.getComponent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* ListModelBuilder creating a ReportListModel for a list of reports.
|
||||
*/
|
||||
private static class ReportListModelBuilder
|
||||
extends LockableImpl
|
||||
implements ListModelBuilder {
|
||||
|
||||
private final java.util.List<Report> reports;
|
||||
|
||||
private ReportListModelBuilder(final java.util.List<Report> reports) {
|
||||
this.reports = reports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ListModel makeModel(final List list,
|
||||
final PageState state) {
|
||||
return new ReportListModel(reports);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.cms.ui.FileUploadSection;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.BinaryAsset;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base form for assets which extend {@link BinaryAsset}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T> Type of binary asset
|
||||
*/
|
||||
public abstract class AbstractBinaryAssetForm<T extends BinaryAsset>
|
||||
extends AbstractAssetForm<T> {
|
||||
|
||||
private TextArea description;
|
||||
|
||||
private Text fileName;
|
||||
|
||||
private Text mimeType;
|
||||
|
||||
private Text size;
|
||||
|
||||
private FileUploadSection fileUpload;
|
||||
|
||||
public AbstractBinaryAssetForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL);
|
||||
|
||||
panel.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.binaryasset.description",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
description = new TextArea("binaryasset-description");
|
||||
panel.add(description);
|
||||
|
||||
panel.add(new Label(
|
||||
new GlobalizedMessage("cms.ui.assets.binaryasset.filename",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
fileName = new Text();
|
||||
panel.add(fileName);
|
||||
|
||||
panel.add(new Label(
|
||||
new GlobalizedMessage("cms.ui.assets.binaryasset.mimetype",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
mimeType = new Text();
|
||||
panel.add(mimeType);
|
||||
|
||||
panel.add(new Label(
|
||||
new GlobalizedMessage("cms.ui.assets.binaryasset.size",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
size = new Text();
|
||||
panel.add(size);
|
||||
|
||||
fileUpload = new FileUploadSection(
|
||||
new GlobalizedMessage("cms.ui.assets.binaryasset.mimetype",
|
||||
CmsConstants.CMS_BUNDLE),
|
||||
"",
|
||||
"");
|
||||
panel.add(fileUpload);
|
||||
|
||||
add(panel);
|
||||
|
||||
setEncType(CmsConstants.FORM_ENCTYPE_MULTIPART);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
|
||||
description.setValue(state,
|
||||
data.get("description"));
|
||||
|
||||
if (data.containsKey("data")) {
|
||||
|
||||
final byte[] binaryData = (byte[]) data.get("data");
|
||||
if (binaryData.length == 0) {
|
||||
fileName.setText("-");
|
||||
mimeType.setText("-");
|
||||
size.setText("-");
|
||||
} else {
|
||||
fileName.setText((String) data.get("fileName"));
|
||||
mimeType.setText((String) data.get("mimeType"));
|
||||
size.setText(Long.toString((long) data.get("size")));
|
||||
}
|
||||
|
||||
} else {
|
||||
fileName.setText("-");
|
||||
mimeType.setText("-");
|
||||
size.setText("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
final Map<String, Object> data = getController()
|
||||
.getAssetData(selectedAssetId,
|
||||
getAssetClass(),
|
||||
getSelectedLocale(state));
|
||||
|
||||
description
|
||||
.setValue(
|
||||
state,
|
||||
data
|
||||
.get(AbstractBinaryAssetFormController.DESCRIPTION));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
return getFileData(event);
|
||||
}
|
||||
|
||||
private Map<String, Object> getFileData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final File file = fileUpload.getFile(event);
|
||||
if (file == null) {
|
||||
return Collections.emptyMap();
|
||||
} else {
|
||||
final Path path = file.toPath();
|
||||
final byte[] data;
|
||||
try {
|
||||
data = Files.readAllBytes(path);
|
||||
} catch (IOException ex) {
|
||||
throw new FormProcessException(ex);
|
||||
}
|
||||
|
||||
final Map<String, Object> assetData = new HashMap<>();
|
||||
|
||||
assetData.put(AbstractBinaryAssetFormController.DATA,
|
||||
data);
|
||||
assetData.put(AbstractBinaryAssetFormController.FILE_NAME,
|
||||
fileUpload.getFileName(event));
|
||||
assetData.put(AbstractBinaryAssetFormController.SIZE,
|
||||
data.length);
|
||||
assetData.put(AbstractBinaryAssetFormController.MIME_TYPE,
|
||||
fileUpload.getMimeType(event));
|
||||
|
||||
return assetData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
|
||||
import org.librecms.assets.BinaryAsset;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.activation.MimeType;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractBinaryAssetFormController<T extends BinaryAsset>
|
||||
extends AbstractAssetFormController<T> {
|
||||
|
||||
protected static final String DESCRIPTION = "description";
|
||||
|
||||
protected static final String FILE_NAME = "fileName";
|
||||
|
||||
protected static final String MIME_TYPE = "mimeType";
|
||||
|
||||
protected static final String DATA = "data";
|
||||
|
||||
protected static final String SIZE = "size";
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Map<String, Object> getAssetData(final T asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
final String description = asset
|
||||
.getDescription()
|
||||
.getValue(selectedLocale);
|
||||
|
||||
data.put(DESCRIPTION, description);
|
||||
data.put(FILE_NAME, asset.getFileName());
|
||||
data.put(MIME_TYPE, asset.getMimeType());
|
||||
data.put(DATA, asset.getData());
|
||||
data.put(SIZE, asset.getSize());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void updateAssetProperties(final T asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(DESCRIPTION)) {
|
||||
asset.getDescription().putValue(selectedLocale,
|
||||
(String) data.get(DESCRIPTION));
|
||||
}
|
||||
|
||||
if (data.containsKey(FILE_NAME)) {
|
||||
asset.setFileName((String) data.get(FILE_NAME));
|
||||
}
|
||||
|
||||
if (data.containsKey(MIME_TYPE)) {
|
||||
asset.setMimeType((MimeType) data.get(MIME_TYPE));
|
||||
}
|
||||
|
||||
if (data.containsKey(DATA)) {
|
||||
//asset.setData((byte[]) data.get(DATA));
|
||||
}
|
||||
|
||||
if (data.containsKey(SIZE)) {
|
||||
asset.setSize((long) data.get(SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.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.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
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.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Abstract base form for all forms for {@link BookmarkAsset}s.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T> Type of the Bookmark Asset.
|
||||
*/
|
||||
public abstract class AbstractBookmarkForm<T extends Bookmark>
|
||||
extends AbstractAssetForm<T> {
|
||||
|
||||
private TextArea description;
|
||||
|
||||
private TextField url;
|
||||
|
||||
public AbstractBookmarkForm(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 void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
|
||||
description
|
||||
.setValue(
|
||||
state,
|
||||
data.get(AbstractBookmarkFormController.DESCRIPTION));
|
||||
url.setValue(state, data.get(AbstractBookmarkFormController.URL));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
final Map<String, Object> data = getController()
|
||||
.getAssetData(selectedAssetId,
|
||||
getAssetClass(),
|
||||
getSelectedLocale(state));
|
||||
|
||||
description.setValue(
|
||||
state,
|
||||
data.get(AbstractBinaryAssetFormController.DESCRIPTION));
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateData(final Bookmark bookmark,
|
||||
final PageState state) {
|
||||
bookmark
|
||||
.getDescription()
|
||||
.putValue(getSelectedLocale(state),
|
||||
(String) description.getValue(state));
|
||||
|
||||
bookmark.setUrl((String) url.getValue(state));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
|
||||
import org.librecms.assets.Bookmark;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractBookmarkFormController<T extends Bookmark>
|
||||
extends AbstractAssetFormController<T> {
|
||||
|
||||
protected static final String DESCRIPTION = "description";
|
||||
|
||||
protected static final String URL = "url";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final T asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final String description = asset
|
||||
.getDescription()
|
||||
.getValue(selectedLocale);
|
||||
|
||||
final String url = asset.getUrl();
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put("description", description);
|
||||
data.put("url", url);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final T asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(DESCRIPTION)) {
|
||||
|
||||
asset.getDescription().putValue(selectedLocale,
|
||||
(String) data.get(DESCRIPTION));
|
||||
|
||||
}
|
||||
|
||||
if (data.containsKey(URL)) {
|
||||
|
||||
asset.setUrl((String) data.get(URL));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,434 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.BoxPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.event.TableActionListener;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.SingleSelect;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.ContactEntryKey;
|
||||
import org.librecms.assets.ContactableEntity;
|
||||
import org.librecms.assets.PostalAddress;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractContactableEntityForm<T extends ContactableEntity>
|
||||
extends AbstractAssetForm<T> {
|
||||
|
||||
private static final int COL_CONTACT_ENTRIES_KEY = 0;
|
||||
|
||||
private static final int COL_CONTACT_ENTRIES_VALUE = 1;
|
||||
|
||||
private static final int COL_CONTACT_ENTRIES_REMOVE = 2;
|
||||
|
||||
private SimpleContainer contactEntriesContainer;
|
||||
|
||||
private Table contactEntriesTable;
|
||||
|
||||
private SingleSelect contactEntryKeySelect;
|
||||
|
||||
private TextField contactEntryValueField;
|
||||
|
||||
private Submit addContactEntryLink;
|
||||
|
||||
private AssetSearchWidget postalAddressSearchWidget;
|
||||
|
||||
public AbstractContactableEntityForm(final AssetPane assetPane) {
|
||||
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
addPropertyWidgets();
|
||||
|
||||
contactEntriesContainer = new BoxPanel(BoxPanel.VERTICAL) {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
return getSelectedAssetId(state) != null;
|
||||
}
|
||||
|
||||
};
|
||||
add(contactEntriesContainer);
|
||||
|
||||
contactEntriesTable = buildContactEntriesTable();
|
||||
contactEntriesContainer.add(contactEntriesTable);
|
||||
|
||||
contactEntryKeySelect = new SingleSelect(new StringParameter(
|
||||
"contactentry-key"));
|
||||
try {
|
||||
contactEntryKeySelect
|
||||
.addPrintListener(new ContactEntryKeySelectPrintListener());
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.key",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
contactEntriesContainer.add(contactEntryKeySelect);
|
||||
|
||||
contactEntryValueField = new TextField("contact-entry-value");
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.value",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
contactEntriesContainer.add(contactEntryValueField);
|
||||
|
||||
addContactEntryLink = new Submit(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.add",
|
||||
CMS_BUNDLE)
|
||||
);
|
||||
contactEntriesContainer.add(addContactEntryLink);
|
||||
|
||||
contactEntriesContainer.add(new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.postaladdress",
|
||||
CMS_BUNDLE))
|
||||
);
|
||||
postalAddressSearchWidget = new AssetSearchWidget(
|
||||
"contactable-postaladdress", PostalAddress.class
|
||||
);
|
||||
contactEntriesContainer.add(postalAddressSearchWidget);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
postalAddressSearchWidget.setValue(
|
||||
state,
|
||||
data.get(AbstractContactableEntityFormController.POSTAL_ADDRESS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(
|
||||
final FormSectionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
if (postalAddressSearchWidget.getValue(state) != null) {
|
||||
|
||||
data.put(AbstractContactableEntityFormController.POSTAL_ADDRESS,
|
||||
postalAddressSearchWidget.getValue(state));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (addContactEntryLink.isSelected(state)) {
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
if (selectedAssetId == null) {
|
||||
throw new FormProcessException(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.assets.none_selected", CMS_BUNDLE)
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final AbstractContactableEntityFormController<ContactableEntity> controller
|
||||
= (AbstractContactableEntityFormController<ContactableEntity>) getController();
|
||||
|
||||
final String key = (String) contactEntryKeySelect
|
||||
.getValue(state);
|
||||
final String value = (String) contactEntryValueField.getValue(state);
|
||||
|
||||
controller.addContactEntry(key, value, selectedAssetId);
|
||||
|
||||
contactEntryKeySelect.setValue(state, null);
|
||||
contactEntryValueField.setValue(state, null);
|
||||
} else {
|
||||
super.process(event);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void addPropertyWidgets();
|
||||
|
||||
private Table buildContactEntriesTable() {
|
||||
|
||||
final Table table = new Table();
|
||||
// {
|
||||
|
||||
// @Override
|
||||
// public boolean isVisible(final PageState state) {
|
||||
// return getSelectedAsset(state).isPresent();
|
||||
// }
|
||||
// };
|
||||
final TableColumnModel columnModel = table.getColumnModel();
|
||||
columnModel.add(new TableColumn(
|
||||
COL_CONTACT_ENTRIES_KEY,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.key",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_CONTACT_ENTRIES_VALUE,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.value",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_CONTACT_ENTRIES_REMOVE,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.remove",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
table.setModelBuilder(new ContactEntriesTableModelBuilder());
|
||||
|
||||
table
|
||||
.getColumn(COL_CONTACT_ENTRIES_REMOVE)
|
||||
.setCellRenderer(new ContactEntryRemoveCellRenderer());
|
||||
|
||||
table.setEmptyView(
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable.contactentries.none",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
table.addTableActionListener(new TableActionListener() {
|
||||
|
||||
@Override
|
||||
public void cellSelected(final TableActionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final Integer rowKey = (Integer) event.getRowKey();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final AbstractContactableEntityFormController<ContactableEntity> controller
|
||||
= (AbstractContactableEntityFormController<ContactableEntity>) getController();
|
||||
final PageState state = event.getPageState();
|
||||
final Long selectedId = getSelectedAssetId(state);
|
||||
if (selectedId != null) {
|
||||
controller.removeContactEntry(rowKey, selectedId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headSelected(final TableActionEvent event) {
|
||||
|
||||
// Nothing
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private class ContactEntriesTableModelBuilder
|
||||
extends LockableImpl implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table,
|
||||
final PageState state) {
|
||||
|
||||
final Long selectedId = getSelectedAssetId(state);
|
||||
if (selectedId == null) {
|
||||
throw new RuntimeException("No asset selected.");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final AbstractContactableEntityFormController<ContactableEntity> controller
|
||||
= (AbstractContactableEntityFormController<ContactableEntity>) getController();
|
||||
final List<String[]> contactEntries = controller
|
||||
.getContactEntries(selectedId, getSelectedLocale(state));
|
||||
|
||||
return new ContactEntriesTableModel(contactEntries);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ContactEntriesTableModel implements TableModel {
|
||||
|
||||
private final Iterator<String[]> contactEntries;
|
||||
|
||||
private String[] currentContactEntry;
|
||||
|
||||
public ContactEntriesTableModel(
|
||||
final List<String[]> contactEntries) {
|
||||
|
||||
this.contactEntries = contactEntries.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
|
||||
if (contactEntries.hasNext()) {
|
||||
currentContactEntry = contactEntries.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
|
||||
switch (columnIndex) {
|
||||
case COL_CONTACT_ENTRIES_KEY:
|
||||
return currentContactEntry[1];
|
||||
case COL_CONTACT_ENTRIES_VALUE:
|
||||
return currentContactEntry[2];
|
||||
case COL_CONTACT_ENTRIES_REMOVE:
|
||||
return new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.contactable"
|
||||
+ ".contactentries.remove",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)
|
||||
);
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Illegal column index %d.", columnIndex));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(int columnIndex) {
|
||||
return currentContactEntry[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ContactEntryRemoveCellRenderer implements TableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
return new ControlLink((Component) value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ContactEntryKeySelectPrintListener implements PrintListener {
|
||||
|
||||
@Override
|
||||
public void prepare(final PrintEvent event) {
|
||||
|
||||
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||
target.clearOptions();
|
||||
|
||||
target.addOption(
|
||||
new Option("",
|
||||
new Label(new GlobalizedMessage("cms.ui.select_one",
|
||||
CMS_BUNDLE)))
|
||||
);
|
||||
|
||||
final AbstractContactableEntityFormController<?> controller = (AbstractContactableEntityFormController<?>) getController();
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final List<String[]> keys = controller
|
||||
.findAvailableContactEntryKeys(getSelectedLocale(state));
|
||||
|
||||
for (final String[] key : keys) {
|
||||
target.addOption(new Option(key[0], new Text(key[1])));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,210 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.assets.ContactEntry;
|
||||
import org.librecms.assets.ContactEntryKey;
|
||||
import org.librecms.assets.ContactEntryKeyByLabelComparator;
|
||||
import org.librecms.assets.ContactEntryKeyRepository;
|
||||
import org.librecms.assets.ContactableEntity;
|
||||
import org.librecms.assets.ContactableEntityManager;
|
||||
import org.librecms.assets.ContactableEntityRepository;
|
||||
import org.librecms.assets.PostalAddress;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractContactableEntityFormController<T extends ContactableEntity>
|
||||
extends AbstractAssetFormController<T> {
|
||||
|
||||
protected static final String POSTAL_ADDRESS = "postalAddress";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Inject
|
||||
private ContactableEntityRepository contactableEntityRepository;
|
||||
|
||||
@Inject
|
||||
private ContactableEntityManager contactableEntityManager;
|
||||
|
||||
@Inject
|
||||
private ContactEntryKeyRepository keyRepository;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final T asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
final PostalAddress postalAddress = asset.getPostalAddress();
|
||||
if (postalAddress != null) {
|
||||
data.put(POSTAL_ADDRESS, postalAddress.getObjectId());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final T asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(POSTAL_ADDRESS)) {
|
||||
|
||||
final long addressId = (long) data.get(POSTAL_ADDRESS);
|
||||
final PostalAddress postalAddress = assetRepository
|
||||
.findById(addressId, PostalAddress.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No PostalAddress with ID %d found.", addressId)));
|
||||
|
||||
contactableEntityManager
|
||||
.addPostalAddressToContactableEntity(postalAddress, asset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact entries of the provided contentable entity for the
|
||||
* provided language.
|
||||
*
|
||||
* @param contactableId The ID of the contactable entity.
|
||||
* @param selectedLocale The selected locale.
|
||||
*
|
||||
* @return An list of the contact entires
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<String[]> getContactEntries(
|
||||
final Long contactableId, final Locale selectedLocale) {
|
||||
|
||||
Objects.requireNonNull(contactableId,
|
||||
"Can't get contact entries from null.");
|
||||
|
||||
final ContactableEntity entity = contactableEntityRepository
|
||||
.findById(contactableId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContactEntity with ID %d found.", contactableId)));
|
||||
|
||||
return entity
|
||||
.getContactEntries()
|
||||
.stream()
|
||||
.map(contactEntry -> toContactEntryArray(contactEntry,
|
||||
selectedLocale))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String[] toContactEntryArray(final ContactEntry entry,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final String key = entry.getKey().getEntryKey();
|
||||
final String label = entry.getKey().getLabel().getValue(selectedLocale);
|
||||
final String value = entry.getValue();
|
||||
|
||||
return new String[]{key, label, value};
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addContactEntry(final String contactEntryKey,
|
||||
final String contactEntryValue,
|
||||
final Long toContactableEntityWithId) {
|
||||
|
||||
final ContactableEntity contactable = contactableEntityRepository
|
||||
.findById(toContactableEntityWithId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContactableEntity with ID %d found",
|
||||
toContactableEntityWithId)));
|
||||
|
||||
final ContactEntryKey key = keyRepository
|
||||
.findByEntryKey(contactEntryKey)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContactEntryKey with key \"%s\" found.", contactEntryKey)));
|
||||
final ContactEntry entry = new ContactEntry();
|
||||
entry.setKey(key);
|
||||
entry.setValue(contactEntryValue);
|
||||
entry.setOrder(contactable.getContactEntries().size());
|
||||
|
||||
contactableEntityManager
|
||||
.addContactEntryToContactableEntity(entry, contactable);
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void removeContactEntry(final int withIndex,
|
||||
final Long fromContactableEntityWithId) {
|
||||
|
||||
final ContactableEntity contactable = contactableEntityRepository
|
||||
.findById(fromContactableEntityWithId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContactableEntity with ID %d found",
|
||||
fromContactableEntityWithId)));
|
||||
|
||||
if (contactable.getContactEntries().size() > withIndex) {
|
||||
|
||||
final ContactEntry contactEntry = contactable
|
||||
.getContactEntries()
|
||||
.get(withIndex);
|
||||
contactableEntityManager.removeContactEntryFromContactableEntity(
|
||||
contactEntry, contactable
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public List<String[]> findAvailableContactEntryKeys(
|
||||
final Locale selectedLocale) {
|
||||
|
||||
return keyRepository
|
||||
.findAll()
|
||||
.stream()
|
||||
.sorted(new ContactEntryKeyByLabelComparator(selectedLocale))
|
||||
.map(key -> buildContactEntryKeyArray(key,
|
||||
selectedLocale))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String[] buildContactEntryKeyArray(
|
||||
final ContactEntryKey contactEntryKey, final Locale selectedLocale) {
|
||||
|
||||
final String key = contactEntryKey.getEntryKey();
|
||||
final String label = contactEntryKey.getLabel().getValue(selectedLocale);
|
||||
|
||||
return new String[]{key, label};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.AudioAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class AudioForm extends AbstractBinaryAssetForm<AudioAsset> {
|
||||
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public AudioForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.audio.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (data.containsKey(AudioFormController.LEGAL_METADATA_ID)) {
|
||||
|
||||
final Long legalMetadataId = (Long) data
|
||||
.get(AudioFormController.LEGAL_METADATA_ID);
|
||||
if (legalMetadataId != null) {
|
||||
assetSearchWidget.setValue(state, legalMetadataId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<AudioAsset> getAssetClass() {
|
||||
return AudioAsset.class;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected Asset createAsset(final FormSectionEvent event)
|
||||
// throws FormProcessException {
|
||||
//
|
||||
// final AudioAsset audioAsset = (AudioAsset) super.createAsset(event);
|
||||
//
|
||||
// final PageState state = event.getPageState();
|
||||
//
|
||||
// updateData(audioAsset, state);
|
||||
//
|
||||
// return audioAsset;
|
||||
// }
|
||||
// @Override
|
||||
// protected void updateAsset(final Asset asset,
|
||||
// final FormSectionEvent event)
|
||||
// throws FormProcessException {
|
||||
//
|
||||
// super.updateAsset(asset, event);
|
||||
//
|
||||
// final PageState state = event.getPageState();
|
||||
//
|
||||
// final AudioAsset audioAsset = (AudioAsset) asset;
|
||||
//
|
||||
// updateData(audioAsset, state);
|
||||
// }
|
||||
|
||||
// protected void updateData(final AudioAsset audioAsset,
|
||||
// final PageState state) {
|
||||
//
|
||||
// final Long legalMetadataId = (Long) assetSearchWidget.getValue(state);
|
||||
// if (legalMetadataId != null) {
|
||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final AssetRepository assetRepo = cdiUtil.findBean(
|
||||
// AssetRepository.class);
|
||||
// final LegalMetadata legalMetadata = (LegalMetadata) assetRepo
|
||||
// .findById(legalMetadataId)
|
||||
// .orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
// "No LegalMetadata asset with ID %d in the database.",
|
||||
// legalMetadataId)));
|
||||
//
|
||||
// audioAsset.setLegalMetadata(legalMetadata);
|
||||
// }
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// protected BinaryAsset createBinaryAsset(final PageState state) {
|
||||
// return new AudioAsset();
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.AudioAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
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
|
||||
@IsControllerForAssetType(AudioAsset.class)
|
||||
public class AudioFormController extends AbstractBinaryAssetFormController<AudioAsset> {
|
||||
|
||||
protected static final String LEGAL_METADATA_ID = "legalMetadataId";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final AudioAsset asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
|
||||
final LegalMetadata legalMetadata = asset.getLegalMetadata();
|
||||
if (legalMetadata != null) {
|
||||
data.put(LEGAL_METADATA_ID, legalMetadata.getObjectId());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final AudioAsset asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(LEGAL_METADATA_ID)) {
|
||||
|
||||
final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID);
|
||||
|
||||
final LegalMetadata legalMetadata = assetRepository
|
||||
.findById(legalMetadataId, LegalMetadata.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata with ID %d found.", legalMetadataId)));
|
||||
|
||||
asset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
|
||||
import org.librecms.assets.Bookmark;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class BookmarkForm extends AbstractBookmarkForm<Bookmark> {
|
||||
|
||||
// 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 void initForm(final PageState state,
|
||||
// final Optional<Bookmark> selectedAsset) {
|
||||
//
|
||||
// if (selectedAsset.isPresent()) {
|
||||
//
|
||||
// if (!(selectedAsset.get() instanceof Bookmark)) {
|
||||
// throw new IllegalArgumentException(String.format(
|
||||
// "The provided asset must be an instanceof of class '%s' or "
|
||||
// + "an subclass but is an instanceof of class '%s'.",
|
||||
// Bookmark.class.getName(),
|
||||
// selectedAsset.get().getClass().getName()));
|
||||
// }
|
||||
//
|
||||
// final Bookmark bookmark = selectedAsset.get();
|
||||
//
|
||||
// description.setValue(state,
|
||||
// bookmark
|
||||
// .getDescription()
|
||||
// .getValue(getSelectedLocale(state)));
|
||||
// url.setValue(state, bookmark.getUrl());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void showLocale(final PageState state) {
|
||||
// final Optional<Bookmark> selectedAsset = getSelectedAsset(state);
|
||||
//
|
||||
// if (selectedAsset.isPresent()) {
|
||||
// if (!(getSelectedAsset(state).get() instanceof Bookmark)) {
|
||||
// throw new IllegalArgumentException(
|
||||
// "Selected asset is not a bookmark");
|
||||
// }
|
||||
//
|
||||
// final Bookmark bookmark = selectedAsset.get();
|
||||
//
|
||||
// description.setValue(state,
|
||||
// bookmark
|
||||
// .getDescription()
|
||||
// .getValue(getSelectedLocale(state)));
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Class<Bookmark> getAssetClass() {
|
||||
return Bookmark.class;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected Asset createAsset(final FormSectionEvent event)
|
||||
// throws FormProcessException {
|
||||
//
|
||||
// Objects.requireNonNull(event);
|
||||
//
|
||||
// final PageState state = event.getPageState();
|
||||
//
|
||||
// final Bookmark bookmark = new Bookmark();
|
||||
//
|
||||
// updateData(bookmark, state);
|
||||
//
|
||||
// return bookmark;
|
||||
// }
|
||||
// protected void updateData(final Bookmark bookmark,
|
||||
// final PageState state) {
|
||||
// bookmark
|
||||
// .getDescription()
|
||||
// .addValue(getSelectedLocale(state),
|
||||
// (String) description.getValue(state));
|
||||
//
|
||||
// bookmark.setUrl((String) url.getValue(state));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected void updateAsset(final Asset asset,
|
||||
// final FormSectionEvent event)
|
||||
// throws FormProcessException {
|
||||
//
|
||||
// Objects.requireNonNull(asset);
|
||||
// Objects.requireNonNull(event);
|
||||
//
|
||||
// final PageState state = event.getPageState();
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// updateData(bookmark, state);
|
||||
// }
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.Bookmark;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@IsControllerForAssetType(Bookmark.class)
|
||||
public class BookmarkFormController
|
||||
extends AbstractBookmarkFormController<Bookmark> {
|
||||
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.ExternalAudioAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
public class ExternalAudioAssetForm
|
||||
extends AbstractBookmarkForm<ExternalAudioAsset> {
|
||||
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public ExternalAudioAssetForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets() {
|
||||
super.addWidgets();
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.external_audio_asset.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
if (data.containsKey(
|
||||
ExternalAudioAssetFormController.LEGAL_METADATA_ID)) {
|
||||
|
||||
final long legalMetadataId = (long) data
|
||||
.get(ExternalAudioAssetFormController.LEGAL_METADATA_ID);
|
||||
|
||||
assetSearchWidget.setValue(state, legalMetadataId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ExternalAudioAsset> getAssetClass() {
|
||||
return ExternalAudioAsset.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
if (assetSearchWidget.getValue(state) != null) {
|
||||
|
||||
data.put(ExternalAudioAssetFormController.LEGAL_METADATA_ID,
|
||||
assetSearchWidget.getValue(state));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.ExternalAudioAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
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
|
||||
@IsControllerForAssetType(ExternalAudioAsset.class)
|
||||
public class ExternalAudioAssetFormController
|
||||
extends AbstractBookmarkFormController<ExternalAudioAsset> {
|
||||
|
||||
protected static final String LEGAL_METADATA_ID = "legalMetadataId";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final ExternalAudioAsset asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
|
||||
final LegalMetadata legalMetadata = asset.getLegalMetadata();
|
||||
if (legalMetadata != null) {
|
||||
data.put(LEGAL_METADATA_ID, legalMetadata.getObjectId());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final ExternalAudioAsset asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(LEGAL_METADATA_ID)) {
|
||||
|
||||
final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID);
|
||||
final LegalMetadata legalMetadata = assetRepository
|
||||
.findById(legalMetadataId, LegalMetadata.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata with ID %d found.", legalMetadataId)));
|
||||
|
||||
asset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
import org.librecms.assets.ExternalVideoAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ExternalVideoAssetForm
|
||||
extends AbstractBookmarkForm<ExternalVideoAsset> {
|
||||
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public ExternalVideoAssetForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets() {
|
||||
super.addWidgets();
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.external_video_asset.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
if (data.containsKey(
|
||||
ExternalVideoAssetFormController.LEGAL_METADATA_ID)) {
|
||||
assetSearchWidget.setValue(
|
||||
state,
|
||||
data.get(ExternalVideoAssetFormController.LEGAL_METADATA_ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ExternalVideoAsset> getAssetClass() {
|
||||
return ExternalVideoAsset.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (assetSearchWidget.getValue(state) != null) {
|
||||
data.put(ExternalAudioAssetFormController.LEGAL_METADATA_ID,
|
||||
assetSearchWidget.getValue(state));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.ExternalVideoAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
@IsControllerForAssetType(ExternalVideoAsset.class)
|
||||
public class ExternalVideoAssetFormController
|
||||
extends AbstractBookmarkFormController<ExternalVideoAsset> {
|
||||
|
||||
protected static final String LEGAL_METADATA_ID = "legalMetadataId";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final ExternalVideoAsset asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
if (asset.getLegalMetadata() != null) {
|
||||
|
||||
data.put(LEGAL_METADATA_ID, asset.getLegalMetadata().getObjectId());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final ExternalVideoAsset asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(LEGAL_METADATA_ID)) {
|
||||
|
||||
final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID);
|
||||
|
||||
final LegalMetadata legalMetadata = assetRepository
|
||||
.findById(legalMetadataId, LegalMetadata.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata with ID %d found.", legalMetadataId)));
|
||||
|
||||
asset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
|
||||
import org.librecms.assets.FileAsset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class FileAssetForm extends AbstractBinaryAssetForm<FileAsset> {
|
||||
|
||||
public FileAssetForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<FileAsset> getAssetClass() {
|
||||
return FileAsset.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.FileAsset;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@IsControllerForAssetType(FileAsset.class)
|
||||
public class FileAssetFormController extends AbstractBinaryAssetFormController<FileAsset> {
|
||||
|
||||
}
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
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.form.TextField;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.Image;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ImageForm extends AbstractBinaryAssetForm<Image> {
|
||||
|
||||
private TextField width;
|
||||
private TextField height;
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public ImageForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
super.addWidgets();
|
||||
|
||||
width = new TextField("width-text");
|
||||
height = new TextField("height-text");
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.image.width.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(width);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.image.height.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(height);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.image.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
if (data.containsKey(ImageFormController.WIDTH)) {
|
||||
final long widthValue = (long) data
|
||||
.get(ImageFormController.WIDTH);
|
||||
width.setValue(state, Long.toString(widthValue));
|
||||
}
|
||||
if (data.containsKey(ImageFormController.HEIGHT)) {
|
||||
final long heightValue = (long) data
|
||||
.get(ImageFormController.HEIGHT);
|
||||
height.setValue(state, Long.toString(heightValue));
|
||||
}
|
||||
|
||||
if (data.containsKey(ImageFormController.LEGAL_METADATA_ID)) {
|
||||
assetSearchWidget
|
||||
.setValue(state,
|
||||
data.get(ImageFormController.LEGAL_METADATA_ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Image> getAssetClass() {
|
||||
return Image.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final Map<String, Object> data = super.collectData(event);
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
data.put(ImageFormController.WIDTH, width.getValue(state));
|
||||
data.put(ImageFormController.HEIGHT, height.getValue(state));
|
||||
|
||||
if (assetSearchWidget.getValue(state) != null) {
|
||||
data.put(ImageFormController.LEGAL_METADATA_ID,
|
||||
assetSearchWidget.getValue(state));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.Image;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
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
|
||||
@IsControllerForAssetType(Image.class)
|
||||
public class ImageFormController
|
||||
extends AbstractBinaryAssetFormController<Image> {
|
||||
|
||||
protected static final String LEGAL_METADATA_ID = "legalMetadataId";
|
||||
protected static final String HEIGHT = "height";
|
||||
protected static final String WIDTH = "width";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final Image asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
|
||||
data.put(WIDTH, asset.getWidth());
|
||||
data.put(HEIGHT, asset.getHeight());
|
||||
|
||||
if (asset.getLegalMetadata() != null) {
|
||||
data.put(LEGAL_METADATA_ID,
|
||||
asset.getLegalMetadata().getObjectId());
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final Image asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(WIDTH)) {
|
||||
asset.setWidth((long) data.get(WIDTH));
|
||||
}
|
||||
|
||||
if (data.containsKey(HEIGHT)) {
|
||||
asset.setHeight((long) data.get(HEIGHT));
|
||||
}
|
||||
|
||||
if (data.containsKey(LEGAL_METADATA_ID)) {
|
||||
final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID);
|
||||
|
||||
final LegalMetadata legalMetadata = assetRepository
|
||||
.findById(legalMetadataId, LegalMetadata.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata with ID %d found.", legalMetadataId)));
|
||||
|
||||
asset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
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.form.TextArea;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class LegalMetadataForm extends AbstractAssetForm<LegalMetadata> {
|
||||
|
||||
private TextArea rightsHolder;
|
||||
private TextArea rights;
|
||||
private TextArea publisher;
|
||||
private TextArea creator;
|
||||
|
||||
public LegalMetadataForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL);
|
||||
|
||||
panel.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.legalmetadata.rightsholder",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
rightsHolder = new TextArea("legalmetadata-rightsholder");
|
||||
panel.add(rightsHolder);
|
||||
|
||||
panel.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.legalmetadata.rights",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
rights = new TextArea("legalmetadata-rights");
|
||||
panel.add(rights);
|
||||
|
||||
panel.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.legalmetadata.publisher",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
publisher = new TextArea("legalmetadata-rights");
|
||||
panel.add(publisher);
|
||||
|
||||
panel.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.legalmetadata.creator",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
creator = new TextArea("legalmetadata-creator");
|
||||
panel.add(creator);
|
||||
|
||||
add(panel);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
rightsHolder.setValue(
|
||||
state,
|
||||
data.get(LegalMetadataFormController.RIGHTS_HOLDER));
|
||||
rights.setValue(state,
|
||||
data.get(LegalMetadataFormController.RIGHTS));
|
||||
publisher.setValue(state,
|
||||
data.get(LegalMetadataFormController.PUBLISHER));
|
||||
creator.setValue(state,
|
||||
data.get(LegalMetadataFormController.CREATOR));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
|
||||
if (selectedAssetId != null) {
|
||||
|
||||
final Map<String, Object> data = getController()
|
||||
.getAssetData(selectedAssetId,
|
||||
LegalMetadata.class,
|
||||
getSelectedLocale(state));
|
||||
|
||||
rights.setValue(state,
|
||||
data.get(LegalMetadataFormController.RIGHTS));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<LegalMetadata> getAssetClass() {
|
||||
return LegalMetadata.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(LegalMetadataFormController.CREATOR, creator.getValue(state));
|
||||
data.put(LegalMetadataFormController.PUBLISHER,
|
||||
publisher.getValue(state));
|
||||
data.put(LegalMetadataFormController.RIGHTS,
|
||||
rights.getValue(state));
|
||||
data.put(LegalMetadataFormController.RIGHTS_HOLDER,
|
||||
rightsHolder.getValue(state));
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
import com.arsdigita.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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
|
||||
@IsControllerForAssetType(LegalMetadata.class)
|
||||
public class LegalMetadataFormController
|
||||
extends AbstractAssetFormController<LegalMetadata> {
|
||||
|
||||
protected static final String CONTRIBUTORS = "contributors";
|
||||
protected static final String CREATOR = "creator";
|
||||
protected static final String PUBLISHER = "publisher";
|
||||
protected static final String RIGHTS = "rights";
|
||||
protected static final String RIGHTS_HOLDER = "rightsHolder";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final LegalMetadata asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(RIGHTS_HOLDER, asset.getRightsHolder());
|
||||
data.put(RIGHTS, asset.getRights().getValue(selectedLocale));
|
||||
data.put(PUBLISHER, asset.getPublisher());
|
||||
data.put(CREATOR, asset.getCreator());
|
||||
data.put(CONTRIBUTORS, asset.getContributors());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final LegalMetadata asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(RIGHTS_HOLDER)) {
|
||||
asset.setRightsHolder((String) data.get(RIGHTS_HOLDER));
|
||||
}
|
||||
|
||||
if (data.containsKey(RIGHTS)) {
|
||||
asset.getRights().putValue(selectedLocale,
|
||||
(String) data.get(RIGHTS));
|
||||
}
|
||||
|
||||
if (data.containsKey(PUBLISHER)) {
|
||||
asset.setPublisher((String) data.get(PUBLISHER));
|
||||
}
|
||||
|
||||
if (data.containsKey(CREATOR)) {
|
||||
asset.setCreator((String) data.get(CREATOR));
|
||||
}
|
||||
|
||||
if (data.containsKey(CONTRIBUTORS)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<String> contributors = (List<String>) data
|
||||
.get(CONTRIBUTORS);
|
||||
asset.setContributors(contributors);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.Organization;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class OrganizationForm extends AbstractContactableEntityForm<Organization> {
|
||||
|
||||
private TextField organizationName;
|
||||
|
||||
public OrganizationForm(final AssetPane assetPane) {
|
||||
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
organizationName.setValue(
|
||||
state,
|
||||
data.get(OrganizationFormController.ORGANIZATION_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPropertyWidgets() {
|
||||
|
||||
add(new Label(
|
||||
new GlobalizedMessage("cms.ui.assets.organization.name",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
organizationName = new TextField("organization-name");
|
||||
add(organizationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Organization> getAssetClass() {
|
||||
|
||||
return Organization.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
// Organization has no localizable fields.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = super.collectData(event);
|
||||
data.put(OrganizationFormController.ORGANIZATION_NAME,
|
||||
organizationName.getValue(state));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.Organization;
|
||||
|
||||
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
|
||||
@IsControllerForAssetType(Organization.class)
|
||||
public class OrganizationFormController
|
||||
extends AbstractContactableEntityFormController<Organization> {
|
||||
|
||||
protected static final String ORGANIZATION_NAME = "organizationName";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final Organization asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
data.put(ORGANIZATION_NAME, asset.getName());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final Organization asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(ORGANIZATION_NAME)) {
|
||||
final String organizationName = (String) data.get(ORGANIZATION_NAME);
|
||||
asset.setName(organizationName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,323 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.Table;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.Date;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.librecms.assets.Person;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||
|
||||
private TextField surnameField;
|
||||
|
||||
private TextField givenNameField;
|
||||
|
||||
private TextField prefixField;
|
||||
|
||||
private TextField suffixField;
|
||||
|
||||
private Submit addPersonNameButton;
|
||||
|
||||
private Date birthdateField;
|
||||
|
||||
public PersonForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPropertyWidgets() {
|
||||
|
||||
final Label surnameLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.surname",
|
||||
CMS_BUNDLE));
|
||||
surnameField = new TextField("surname");
|
||||
add(surnameLabel);
|
||||
add(surnameField);
|
||||
|
||||
final Label givenNameLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.given_name",
|
||||
CMS_BUNDLE));
|
||||
givenNameField = new TextField("givenName");
|
||||
add(givenNameLabel);
|
||||
add(givenNameField);
|
||||
|
||||
final Label prefixLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.prefix",
|
||||
CMS_BUNDLE
|
||||
));
|
||||
prefixField = new TextField("prefix");
|
||||
add(prefixLabel);
|
||||
add(prefixField);
|
||||
|
||||
final Label suffixLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.suffix",
|
||||
CMS_BUNDLE
|
||||
));
|
||||
suffixField = new TextField("suffix");
|
||||
add(suffixLabel);
|
||||
add(suffixField);
|
||||
|
||||
add(buildPersonNamesTable());
|
||||
|
||||
addPersonNameButton = new Submit(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.add_name",
|
||||
CMS_BUNDLE));
|
||||
add(addPersonNameButton);
|
||||
|
||||
final Label birthdateLabel = new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.birthdate",
|
||||
CMS_BUNDLE));
|
||||
add(birthdateLabel);
|
||||
birthdateField = new Date("birthdate");
|
||||
final LocalDate today = LocalDate.now(ZoneId.systemDefault());
|
||||
birthdateField.setYearRange(1930, today.getYear());
|
||||
add(birthdateField);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<Person> getAssetClass() {
|
||||
return Person.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
// Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event) {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(PersonFormController.SURNAME, surnameField.getValue(state));
|
||||
data.put(PersonFormController.GIVENNAME,
|
||||
givenNameField.getValue(state));
|
||||
data.put(PersonFormController.PREFIX, prefixField.getValue(state));
|
||||
data.put(PersonFormController.SUFFIX, suffixField.getValue(state));
|
||||
|
||||
data.put(PersonFormController.BIRTHDATE,
|
||||
birthdateField.getValue(state));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (data.containsKey(PersonFormController.SURNAME)) {
|
||||
surnameField.setValue(state,
|
||||
data.get(PersonFormController.SURNAME));
|
||||
}
|
||||
|
||||
if (data.containsKey(PersonFormController.GIVENNAME)) {
|
||||
givenNameField.setValue(state,
|
||||
data.get(PersonFormController.GIVENNAME));
|
||||
}
|
||||
|
||||
if (data.containsKey(PersonFormController.PREFIX)) {
|
||||
prefixField.setValue(state, data.get(PersonFormController.PREFIX));
|
||||
}
|
||||
|
||||
if (data.containsKey(PersonFormController.SUFFIX)) {
|
||||
suffixField.setValue(state, data.get(PersonFormController.SUFFIX));
|
||||
}
|
||||
|
||||
if (data.containsKey(PersonFormController.BIRTHDATE)) {
|
||||
birthdateField.setValue(state,
|
||||
data.get(PersonFormController.BIRTHDATE));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event) throws
|
||||
FormProcessException {
|
||||
|
||||
if (addPersonNameButton.equals(event.getSource())) {
|
||||
|
||||
final PersonFormController controller
|
||||
= (PersonFormController) getController();
|
||||
controller.addPersonName(getSelectedAssetId(event.getPageState()));
|
||||
|
||||
} else {
|
||||
super.process(event);
|
||||
}
|
||||
}
|
||||
|
||||
private Table buildPersonNamesTable() {
|
||||
|
||||
final Table table = new Table() {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
return getSelectedAssetId(state) != null;
|
||||
}
|
||||
};
|
||||
|
||||
final TableColumnModel columnModel = table.getColumnModel();
|
||||
columnModel.add(new TableColumn(
|
||||
0,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.surname",
|
||||
CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
columnModel.add(new TableColumn(
|
||||
1,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.givenName",
|
||||
CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
columnModel.add(new TableColumn(
|
||||
2,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.prefix",
|
||||
CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
columnModel.add(new TableColumn(
|
||||
3,
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.suffix",
|
||||
CMS_BUNDLE
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
table.setModelBuilder(new PersonNamesTableModelBuilder());
|
||||
|
||||
table.setEmptyView(new Label(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.person.names.none")));
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private class PersonNamesTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
||||
final Long selectedPersonId = getSelectedAssetId(state);
|
||||
if (selectedPersonId == null) {
|
||||
throw new RuntimeException("No asset selected.");
|
||||
}
|
||||
|
||||
final PersonFormController controller
|
||||
= (PersonFormController) getController();
|
||||
final List<String[]> personNames = controller
|
||||
.getPersonNames(selectedPersonId);
|
||||
|
||||
return new PersonNamesTableModel(personNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class PersonNamesTableModel implements TableModel {
|
||||
|
||||
private final Iterator<String[]> personNames;
|
||||
|
||||
private String[] currentPersonName;
|
||||
|
||||
private int row;
|
||||
|
||||
public PersonNamesTableModel(final List<String[]> personNames) {
|
||||
|
||||
this.personNames = Objects
|
||||
.requireNonNull(personNames,
|
||||
"Can't create PersonNamesTableModel without a "
|
||||
+ "list of person names.")
|
||||
.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
|
||||
if (personNames.hasNext()) {
|
||||
currentPersonName = personNames.next();
|
||||
row++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
|
||||
return currentPersonName[columnIndex];
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.Person;
|
||||
import org.librecms.assets.PersonManager;
|
||||
import org.librecms.assets.PersonName;
|
||||
import org.librecms.assets.PersonRepository;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@IsControllerForAssetType(Person.class)
|
||||
public class PersonFormController
|
||||
extends AbstractContactableEntityFormController<Person> {
|
||||
|
||||
protected static final String SUFFIX = "suffix";
|
||||
|
||||
protected static final String PREFIX = "prefix";
|
||||
|
||||
protected static final String GIVENNAME = "givenName";
|
||||
|
||||
protected static final String SURNAME = "surname";
|
||||
|
||||
protected static final String BIRTHDATE = "birthdate";
|
||||
|
||||
protected static final String PERSON_NAMES = "personNames";
|
||||
|
||||
protected static final int SURNAME_INDEX = 0;
|
||||
|
||||
protected static final int GIVENNAME_INDEX = 1;
|
||||
|
||||
protected static final int PREFIX_INDEX = 2;
|
||||
|
||||
protected static final int SUFFIX_INDEX = 3;
|
||||
|
||||
@Inject
|
||||
private PersonRepository personRepository;
|
||||
|
||||
@Inject
|
||||
private PersonManager personManager;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final Person asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
|
||||
final PersonName personName = asset.getPersonName();
|
||||
data.put(SURNAME, personName.getSurname());
|
||||
data.put(GIVENNAME, personName.getGivenName());
|
||||
data.put(PREFIX, personName.getPrefix());
|
||||
data.put(SUFFIX, personName.getSuffix());
|
||||
|
||||
final List<String[]> names = asset
|
||||
.getPersonNames()
|
||||
.subList(0, asset.getPersonNames().size() - 1)
|
||||
.stream()
|
||||
.map(this::convertPersonName)
|
||||
.collect(Collectors.toList());
|
||||
data.put(PERSON_NAMES, names);
|
||||
|
||||
final LocalDate birthdate = asset.getBirthdate();
|
||||
if (birthdate != null) {
|
||||
final Instant instant = birthdate
|
||||
.atStartOfDay()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toInstant();
|
||||
final Date birthdateValue = Date.from(instant);
|
||||
data.put(BIRTHDATE, birthdateValue);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<String[]> getPersonNames(final Long personId) {
|
||||
|
||||
final Person person = personRepository
|
||||
.findById(personId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No Person with ID %d found.", personId)));
|
||||
|
||||
return person
|
||||
.getPersonNames()
|
||||
.subList(0, person.getPersonNames().size() - 1)
|
||||
.stream()
|
||||
.map(this::convertPersonName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String[] convertPersonName(final PersonName name) {
|
||||
|
||||
final String[] result = new String[4];
|
||||
|
||||
result[SURNAME_INDEX] = name.getSurname();
|
||||
result[GIVENNAME_INDEX] = name.getGivenName();
|
||||
result[PREFIX_INDEX] = name.getPrefix();
|
||||
result[SUFFIX_INDEX] = name.getSuffix();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final Person asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(BIRTHDATE)) {
|
||||
|
||||
final Date birthdateValue = (Date) data.get(BIRTHDATE);
|
||||
final Instant instant = birthdateValue.toInstant();
|
||||
final LocalDate birthdate = LocalDateTime
|
||||
.ofInstant(instant, ZoneId.systemDefault())
|
||||
.toLocalDate();
|
||||
|
||||
asset.setBirthdate(birthdate);
|
||||
}
|
||||
|
||||
final String surname = (String) data.get(SURNAME);
|
||||
final String givenName = (String) data.get(GIVENNAME);
|
||||
final String prefix = (String) data.get(PREFIX);
|
||||
final String suffix = (String) data.get(SUFFIX);
|
||||
|
||||
if (asset.getPersonName() == null) {
|
||||
final PersonName personName = new PersonName();
|
||||
personName.setGivenName(givenName);
|
||||
personName.setSuffix(suffix);
|
||||
personName.setPrefix(prefix);
|
||||
personName.setSurname(surname);
|
||||
personManager.addPersonName(asset, personName);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void addPersonName(final long personId) {
|
||||
final Person person = personRepository
|
||||
.findById(personId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No Person with ID %d found.", personId)));
|
||||
|
||||
personManager.addPersonName(person, new PersonName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.assets.PostalAddress;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class PostalAddressForm extends AbstractAssetForm<PostalAddress> {
|
||||
|
||||
private TextArea addressArea;
|
||||
private TextField postalCodeField;
|
||||
private TextField cityField;
|
||||
private TextField stateField;
|
||||
private TextField isoCountryCodeField;
|
||||
|
||||
public PostalAddressForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
super.addWidgets();
|
||||
|
||||
addressArea = new TextArea("address");
|
||||
addressArea.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.postaladdress.address", CMS_BUNDLE));
|
||||
addressArea.setCols(80);
|
||||
addressArea.setRows(10);
|
||||
add(addressArea);
|
||||
|
||||
postalCodeField = new TextField("postalCode");
|
||||
postalCodeField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.postaladdress.postalcode", CMS_BUNDLE));
|
||||
add(postalCodeField);
|
||||
|
||||
cityField = new TextField("city");
|
||||
cityField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.postaladdress.city", CMS_BUNDLE));
|
||||
add(cityField);
|
||||
|
||||
stateField = new TextField("state");
|
||||
stateField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.authoring.assets.postaladdress.state", CMS_BUNDLE));
|
||||
add(stateField);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<PostalAddress> getAssetClass() {
|
||||
return PostalAddress.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(PostalAddressFormController.ADDRESS,
|
||||
addressArea.getValue(state));
|
||||
data.put(PostalAddressFormController.CITY,
|
||||
cityField.getValue(state));
|
||||
data.put(PostalAddressFormController.POSTAL_CODE,
|
||||
postalCodeField.getValue(state));
|
||||
data.put(PostalAddressFormController.STATE,
|
||||
stateField.getValue(state));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
import com.arsdigita.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.PostalAddress;
|
||||
|
||||
import java.util.HashMap;
|
||||
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
|
||||
@IsControllerForAssetType(PostalAddress.class)
|
||||
public class PostalAddressFormController
|
||||
extends AbstractAssetFormController<PostalAddress> {
|
||||
|
||||
protected static final String STATE = "state";
|
||||
protected static final String CITY = "city";
|
||||
protected static final String POSTAL_CODE = "postalCode";
|
||||
protected static final String ADDRESS = "address";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final PostalAddress asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(ADDRESS, asset.getAddress());
|
||||
data.put(POSTAL_CODE, asset.getPostalCode());
|
||||
data.put(CITY, asset.getCity());
|
||||
data.put(STATE, asset.getState());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final PostalAddress asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(ADDRESS)) {
|
||||
asset.setAddress((String) data.get(ADDRESS));
|
||||
}
|
||||
|
||||
if (data.containsKey(POSTAL_CODE)) {
|
||||
asset.setPostalCode((String) data.get(POSTAL_CODE));
|
||||
}
|
||||
|
||||
if (data.containsKey(CITY)) {
|
||||
asset.setCity((String) data.get(CITY));
|
||||
}
|
||||
|
||||
if (data.containsKey(STATE)) {
|
||||
asset.setState((String) data.get(STATE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
|
||||
import org.librecms.assets.RelatedLink;
|
||||
import org.librecms.assets.SideNote;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class RelatedLinkForm extends AbstractAssetForm<RelatedLink>{
|
||||
|
||||
public RelatedLinkForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<RelatedLink> getAssetClass() {
|
||||
return RelatedLink.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event) throws
|
||||
FormProcessException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
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.form.TextArea;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.SideNote;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class SideNoteForm extends AbstractAssetForm<SideNote> {
|
||||
|
||||
private TextArea text;
|
||||
|
||||
public SideNoteForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
add(new Label(new GlobalizedMessage("cms.ui.assets.sidenote.text",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
text = new TextArea("sidenote-text");
|
||||
add(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
text.setValue(state, data.get(SideNoteFormController.TEXT));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
final Long selectedAssetId = getSelectedAssetId(state);
|
||||
final Map<String, Object> data = getController()
|
||||
.getAssetData(selectedAssetId,
|
||||
SideNote.class,
|
||||
getSelectedLocale(state));
|
||||
|
||||
text.setValue(state, data.get(SideNoteFormController.TEXT));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<SideNote> getAssetClass() {
|
||||
return SideNote.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
data.put(SideNoteFormController.TEXT, text.getValue(state));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.AbstractAssetFormController;
|
||||
import com.arsdigita.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.assets.SideNote;
|
||||
|
||||
import java.util.HashMap;
|
||||
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
|
||||
@IsControllerForAssetType(SideNote.class)
|
||||
public class SideNoteFormController
|
||||
extends AbstractAssetFormController<SideNote> {
|
||||
|
||||
protected static final String TEXT = "text";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final SideNote asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put(TEXT, asset.getText().getValue(selectedLocale));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final SideNote asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
if (data.containsKey(TEXT)) {
|
||||
|
||||
final String value = (String) data.get(TEXT);
|
||||
asset.getText().putValue(selectedLocale, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
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.form.TextField;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.VideoAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
*/
|
||||
public class VideoForm extends AbstractBinaryAssetForm<VideoAsset> {
|
||||
|
||||
private TextField width;
|
||||
private TextField height;
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public VideoForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
width = new TextField("width-text");
|
||||
height = new TextField("height-text");
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.width.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(width);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.height.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(height);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.initForm(state, data);
|
||||
|
||||
if (getSelectedAssetId(state) != null) {
|
||||
|
||||
final long widthValue = (long) data.get(VideoFormController.WIDTH);
|
||||
final long heightValue = (long) data
|
||||
.get(VideoFormController.HEIGHT);
|
||||
|
||||
width.setValue(state, Long.toString(widthValue));
|
||||
height.setValue(state, Long.toString(heightValue));
|
||||
|
||||
if (data.containsKey(VideoFormController.LEGAL_METADATA_ID)) {
|
||||
|
||||
assetSearchWidget.setValue(
|
||||
state,
|
||||
data.containsKey(VideoFormController.LEGAL_METADATA_ID));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<VideoAsset> getAssetClass() {
|
||||
return VideoAsset.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final Map<String, Object> data = super.collectData(event);
|
||||
|
||||
data.put(VideoFormController.WIDTH, width.getValue(state));
|
||||
data.put(VideoFormController.HEIGHT, height.getValue(state));
|
||||
|
||||
if (assetSearchWidget.getValue(state) != null) {
|
||||
|
||||
data.put(VideoFormController.LEGAL_METADATA_ID,
|
||||
assetSearchWidget.getValue(state));
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2019 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.cms.ui.assets.IsControllerForAssetType;
|
||||
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.assets.VideoAsset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@IsControllerForAssetType(VideoAsset.class)
|
||||
public class VideoFormController
|
||||
extends AbstractBinaryAssetFormController<VideoAsset> {
|
||||
|
||||
protected static final String LEGAL_METADATA_ID = "legalMetadataId";
|
||||
protected static final String HEIGHT = "height";
|
||||
protected static final String WIDTH = "width";
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepository;
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> getAssetData(final VideoAsset asset,
|
||||
final Locale selectedLocale) {
|
||||
|
||||
final Map<String, Object> data = super.getAssetData(asset,
|
||||
selectedLocale);
|
||||
|
||||
data.put(WIDTH, asset.getWidth());
|
||||
data.put(HEIGHT, asset.getHeight());
|
||||
|
||||
if (asset.getLegalMetadata() != null) {
|
||||
final long legalMetadataId = asset.getLegalMetadata().getObjectId();
|
||||
data.put(LEGAL_METADATA_ID, legalMetadataId);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAssetProperties(final VideoAsset asset,
|
||||
final Locale selectedLocale,
|
||||
final Map<String, Object> data) {
|
||||
|
||||
super.updateAssetProperties(asset, selectedLocale, data);
|
||||
|
||||
if (data.containsKey(WIDTH)) {
|
||||
final long width = (long) data.get(WIDTH);
|
||||
asset.setWidth(width);
|
||||
}
|
||||
|
||||
if (data.containsKey(HEIGHT)) {
|
||||
final long height = (long) data.get(HEIGHT);
|
||||
asset.setHeight(height);
|
||||
}
|
||||
|
||||
if (data.containsKey(LEGAL_METADATA_ID)) {
|
||||
|
||||
final LegalMetadata legalMetadata = assetRepository
|
||||
.findById((long) data.get(LEGAL_METADATA_ID),
|
||||
LegalMetadata.class)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata with ID %d found",
|
||||
data.get(LEGAL_METADATA_ID)
|
||||
)));
|
||||
asset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.searchpage;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.LongParameter;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
import java.util.List;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
/**
|
||||
* Page contains the widgets for selecting an asset.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class AssetSearchPage extends CMSPage {
|
||||
|
||||
private static final String QUERY_PARAM = "query";
|
||||
private static final String WIDGET_PARAM = "widget";
|
||||
private static final String ASSET_TYPE_PARAM = "assettype";
|
||||
|
||||
private static final int RESULTS_TABLE_COL_TITLE = 0;
|
||||
private static final int RESULTS_TABLE_COL_PLACE = 1;
|
||||
private static final int RESULTS_TABLE_COL_TYPE = 2;
|
||||
|
||||
private final LongParameter contentSectionId;
|
||||
|
||||
private TextField query;
|
||||
|
||||
public AssetSearchPage() {
|
||||
super(new Label(new GlobalizedMessage("cms.ui.assets.search_page.title",
|
||||
CmsConstants.CMS_BUNDLE)),
|
||||
new SimpleContainer());
|
||||
|
||||
addGlobalStateParam(new StringParameter(ASSET_TYPE_PARAM));
|
||||
addGlobalStateParam(new StringParameter(WIDGET_PARAM));
|
||||
addGlobalStateParam(new StringParameter(QUERY_PARAM));
|
||||
|
||||
contentSectionId = new LongParameter("content-section-id");
|
||||
|
||||
final LayoutPanel mainPanel = new LayoutPanel();
|
||||
|
||||
final Form queryForm = new Form("asset-search-page-query-form");
|
||||
queryForm.add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.query",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
query = new TextField("asset-search-page-query-form");
|
||||
queryForm.add(query);
|
||||
final Submit querySubmit = new Submit(new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.query.submit"));
|
||||
queryForm.add(querySubmit);
|
||||
|
||||
queryForm.addInitListener(new FormInitListener() {
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final FormData data = event.getFormData();
|
||||
|
||||
final String query = (String) data.get(QUERY_PARAM);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mainPanel.setLeft(queryForm);
|
||||
|
||||
final Table resultsTable = new Table();
|
||||
resultsTable.setEmptyView(
|
||||
new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.none",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
resultsTable.setClassAttr("dataTable");
|
||||
|
||||
final TableColumnModel columnModel = resultsTable.getColumnModel();
|
||||
columnModel.add(new TableColumn(
|
||||
RESULTS_TABLE_COL_TITLE,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.results_table.title",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
columnModel.add(new TableColumn(
|
||||
RESULTS_TABLE_COL_PLACE,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.results_table.place",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
columnModel.add(new TableColumn(
|
||||
RESULTS_TABLE_COL_TYPE,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.assets.search_page.results_table.type",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
resultsTable.setModelBuilder(new ResultsTableModelBuilder());
|
||||
|
||||
mainPanel.setBody(resultsTable);
|
||||
|
||||
}
|
||||
|
||||
private class ResultsTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AssetSearchPageController controller = cdiUtil
|
||||
.findBean(AssetSearchPageController.class);
|
||||
|
||||
final List<ResultsTableRow> rows = controller
|
||||
.findAssets((String) query.getValue(state));
|
||||
return new ResultsTableModel(rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TitleCellRenderer
|
||||
extends LockableImpl
|
||||
implements TableCellRenderer {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
if (value == null) {
|
||||
return new Text("???");
|
||||
}
|
||||
|
||||
final Link link = new Link(new Text(value.toString()), "");
|
||||
|
||||
return link;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.searchpage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.assets.AssetTypeInfo;
|
||||
import org.librecms.assets.AssetTypesManager;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetManager;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class AssetSearchPageController {
|
||||
|
||||
@Inject
|
||||
private AssetRepository assetRepo;
|
||||
|
||||
@Inject
|
||||
private AssetTypesManager assetTypesManager;
|
||||
|
||||
@Inject
|
||||
private AssetManager assetManager;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<ResultsTableRow> findAssets(final String title) {
|
||||
|
||||
final List<Asset> assets = assetRepo.findByTitle(title);
|
||||
|
||||
return assets
|
||||
.stream()
|
||||
.map(asset -> createRow(asset))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
private ResultsTableRow createRow(final Asset asset) {
|
||||
final ResultsTableRow row = new ResultsTableRow();
|
||||
|
||||
row.setAssetUuid(asset.getUuid());
|
||||
row.setTitle(globalizationHelper
|
||||
.getValueFromLocalizedString(asset.getTitle()));
|
||||
|
||||
final AssetTypeInfo typeInfo = assetTypesManager
|
||||
.getAssetTypeInfo(asset.getClass());
|
||||
final ResourceBundle bundle = ResourceBundle
|
||||
.getBundle(typeInfo.getLabelBundle(),
|
||||
globalizationHelper.getNegotiatedLocale());
|
||||
row.setType(bundle.getString(typeInfo.getLabelKey()));
|
||||
|
||||
row.setPlace(assetManager.getAssetPath(asset));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.searchpage;
|
||||
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class ResultsTableModel implements TableModel {
|
||||
|
||||
private static final int COL_TITLE = 0;
|
||||
private static final int COL_PLACE = 1;
|
||||
private static final int COL_TYPE = 2;
|
||||
|
||||
private final Iterator<ResultsTableRow> iterator;
|
||||
private ResultsTableRow currentRow;
|
||||
|
||||
public ResultsTableModel(final List<ResultsTableRow> rows) {
|
||||
iterator = rows.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
if (iterator.hasNext()) {
|
||||
currentRow = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
switch(columnIndex) {
|
||||
case COL_TITLE:
|
||||
return currentRow.getTitle();
|
||||
case COL_PLACE:
|
||||
return currentRow.getPlace();
|
||||
case COL_TYPE:
|
||||
return currentRow.getType();
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal column index.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
return currentRow.getAssetUuid();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.searchpage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class ResultsTableRow {
|
||||
|
||||
private String assetUuid;
|
||||
private String title;
|
||||
private String place;
|
||||
private String type;
|
||||
|
||||
public String getAssetUuid() {
|
||||
return assetUuid;
|
||||
}
|
||||
|
||||
public void setAssetUuid(final String assetUuid) {
|
||||
this.assetUuid = assetUuid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(final String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(final String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pagemodel.ContentItemComponent;
|
||||
|
||||
/**
|
||||
* Basic form for all subclasses of {@link ContentItemComponent}.
|
||||
*
|
||||
* @param <T>
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractContentItemComponentForm<T extends ContentItemComponent>
|
||||
extends AbstractComponentModelForm<T> {
|
||||
|
||||
/**
|
||||
* Constant for the name of the {@link #modeField}.
|
||||
*/
|
||||
private static final String ITEM_MODE = "itemMode";
|
||||
|
||||
/**
|
||||
* Text field for {@link ContentItemComponent#mode}.
|
||||
*/
|
||||
private TextField modeField;
|
||||
|
||||
public AbstractContentItemComponentForm(
|
||||
final String name,
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super(name, pageModelTab, selectedModelId, selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
modeField = new TextField(ITEM_MODE);
|
||||
modeField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.contentitem_component_form.mode.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
add(modeField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateComponentModel(final ContentItemComponent componentModel,
|
||||
final PageState state,
|
||||
final FormData data) {
|
||||
|
||||
final String modeValue = data.getString(ITEM_MODE);
|
||||
componentModel.setMode(modeValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final ContentItemComponent component = getComponentModel();
|
||||
|
||||
if (getComponentModel() != null) {
|
||||
modeField.setValue(state, component.getMode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.librecms.pagemodel.CategorizedItemComponent;
|
||||
|
||||
/**
|
||||
* Form for editing/creating a {@link CategorizedItemComponent}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class CategorizedItemComponentForm
|
||||
extends AbstractContentItemComponentForm<CategorizedItemComponent> {
|
||||
|
||||
public CategorizedItemComponentForm(
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super("CategorizedItemComponentForm",
|
||||
pageModelTab,
|
||||
selectedModelId,
|
||||
selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CategorizedItemComponent createComponentModel() {
|
||||
return new CategorizedItemComponent();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pagemodel.CategoryTreeComponent;
|
||||
|
||||
/**
|
||||
* Form for creating/editing a {@link CategoryTreeComponent}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class CategoryTreeComponentForm extends AbstractComponentModelForm<CategoryTreeComponent> {
|
||||
|
||||
private final static String SHOW_FULL_TREE_BOX = "showFullTreeBox";
|
||||
private final static String SHOW_FULL_TREE = "showFullTree";
|
||||
|
||||
private CheckboxGroup showFullTreeCheckbox;
|
||||
|
||||
public CategoryTreeComponentForm(
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super("CategoryTreeComponentForm", pageModelTab, selectedModelId,
|
||||
selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
showFullTreeCheckbox = new CheckboxGroup(SHOW_FULL_TREE_BOX);
|
||||
showFullTreeCheckbox.addOption(new Option(
|
||||
SHOW_FULL_TREE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.category_tree_component_form.show_full_tree.label",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
add(showFullTreeCheckbox);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CategoryTreeComponent createComponentModel() {
|
||||
return new CategoryTreeComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateComponentModel(
|
||||
final CategoryTreeComponent componentModel,
|
||||
final PageState state,
|
||||
final FormData data) {
|
||||
|
||||
final Object[] value = (Object[]) data.get(SHOW_FULL_TREE_BOX);
|
||||
if (value != null
|
||||
&& value.length != 0
|
||||
&& SHOW_FULL_TREE.equals(value[0])) {
|
||||
|
||||
componentModel.setShowFullTree(true);
|
||||
} else {
|
||||
componentModel.setShowFullTree(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final CategoryTreeComponent component = getComponentModel();
|
||||
|
||||
final Object[] showFullTreeValue;
|
||||
if (component != null && component.isShowFullTree()) {
|
||||
showFullTreeValue = new Object[]{SHOW_FULL_TREE};
|
||||
} else {
|
||||
showFullTreeValue = new Object[]{};
|
||||
}
|
||||
|
||||
showFullTreeCheckbox.setValue(state, showFullTreeValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.ItemSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.pagemodel.FixedContentItemComponent;
|
||||
|
||||
/**
|
||||
* Form for creating/editing a {@link FixedContentItemComponent}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class FixedContentItemComponentForm
|
||||
extends AbstractContentItemComponentForm<FixedContentItemComponent> {
|
||||
|
||||
private final static String ITEM_SEARCH = "itemSearch";
|
||||
|
||||
private ItemSearchWidget itemSearchWidget;
|
||||
|
||||
public FixedContentItemComponentForm(
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super("FixedContentItemComponentForm",
|
||||
pageModelTab,
|
||||
selectedModelId,
|
||||
selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
itemSearchWidget = new ItemSearchWidget(ITEM_SEARCH);
|
||||
itemSearchWidget.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.fixed_contentitem_component_form.itemsearch.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
add(itemSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FixedContentItemComponent createComponentModel() {
|
||||
return new FixedContentItemComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateComponentModel(
|
||||
final FixedContentItemComponent component,
|
||||
final PageState state,
|
||||
final FormData data) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentItemRepository itemRepo = cdiUtil
|
||||
.findBean(ContentItemRepository.class);
|
||||
|
||||
final long itemId = (long) itemSearchWidget.getValue(state);
|
||||
|
||||
final ContentItem item = itemRepo
|
||||
.findById(itemId)
|
||||
.orElseThrow(() -> new IllegalArgumentException());
|
||||
|
||||
component.setContentItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final FixedContentItemComponent component = getComponentModel();
|
||||
|
||||
if (component != null) {
|
||||
itemSearchWidget.setValue(state, component.getContentItem());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.validate(event);
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
final Object value = data.get(ITEM_SEARCH);
|
||||
|
||||
if (value == null) {
|
||||
data.addError(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.fixed_contentitem_component_form.error.no_item_selected",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.librecms.pagemodel.GreetingItemComponent;
|
||||
|
||||
/**
|
||||
* Form for creating/editing a {@link GreetingItemComponent}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class GreetingItemComponentForm
|
||||
extends AbstractContentItemComponentForm<GreetingItemComponent> {
|
||||
|
||||
public GreetingItemComponentForm(
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super("GreetingItemComponentForm",
|
||||
pageModelTab,
|
||||
selectedModelId,
|
||||
selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GreetingItemComponent createComponentModel() {
|
||||
return new GreetingItemComponent();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,207 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.pagemodel;
|
||||
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm;
|
||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.pagemodel.ComponentModelRepository;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.pagemodel.ItemListComponent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Form for adding/editing a {@link ItemListComponent}.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ItemListComponentForm
|
||||
extends AbstractComponentModelForm<ItemListComponent> {
|
||||
|
||||
private static final String DESCENDING_BOX = "descendingBox";
|
||||
private static final String DESCENDING = "descending";
|
||||
private static final String LIMIT_TO_TYPE = "limitToType";
|
||||
private static final String PAGE_SIZE = "pageSize";
|
||||
private static final String LIST_ORDER = "listOrder";
|
||||
|
||||
private CheckboxGroup descendingBox;
|
||||
private TextField limitToTypeField;
|
||||
private TextField pageSizeField;
|
||||
private TextArea listOrderArea;
|
||||
|
||||
public ItemListComponentForm(
|
||||
final PageModelsTab pageModelTab,
|
||||
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||
|
||||
super("ItemListComponentForm",
|
||||
pageModelTab,
|
||||
selectedModelId,
|
||||
selectedComponentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
descendingBox = new CheckboxGroup(DESCENDING_BOX);
|
||||
descendingBox.addOption(new Option(
|
||||
DESCENDING, new Label(
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.itemlist_component_form.descending.label",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
add(descendingBox);
|
||||
|
||||
limitToTypeField = new TextField(LIMIT_TO_TYPE);
|
||||
limitToTypeField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.itemlist_component_form.limit_to_type.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
add(limitToTypeField);
|
||||
|
||||
pageSizeField = new TextField(PAGE_SIZE);
|
||||
pageSizeField.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.itemlist_component_form.page_size.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
add(pageSizeField);
|
||||
|
||||
listOrderArea = new TextArea(LIST_ORDER);
|
||||
listOrderArea.setLabel(new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.itemlist_component_form.list_order.label",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
add(listOrderArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemListComponent createComponentModel() {
|
||||
return new ItemListComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateComponentModel(final ItemListComponent componentModel,
|
||||
final PageState state,
|
||||
final FormData data) {
|
||||
|
||||
final Object[] descendingValues = (Object[]) data.get(DESCENDING_BOX);
|
||||
final String limitToTypeValue = data.getString(LIMIT_TO_TYPE);
|
||||
final String pageSizeValue = data.getString(PAGE_SIZE);
|
||||
final String listOrderValue = data.getString(LIST_ORDER);
|
||||
|
||||
final boolean descendingValue = isDescending(descendingValues);
|
||||
final List<String> listOrder = Arrays
|
||||
.stream(listOrderValue.split("\n"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
componentModel.setDescending(descendingValue);
|
||||
componentModel.setLimitToType(limitToTypeValue);
|
||||
componentModel.setPageSize(Integer.parseInt(pageSizeValue));
|
||||
|
||||
componentModel.setListOrder(listOrder);
|
||||
}
|
||||
|
||||
private boolean isDescending(final Object[] descendingValues) {
|
||||
return descendingValues != null
|
||||
&& descendingValues.length != 0
|
||||
&& DESCENDING.equals(descendingValues[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
super.init(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final ItemListComponent component = getComponentModel();
|
||||
|
||||
if (component == null) {
|
||||
pageSizeField.setValue(state, "30");
|
||||
} else {
|
||||
final Object[] descendingValue;
|
||||
if (component.isDescending()) {
|
||||
descendingValue = new Object[]{DESCENDING};
|
||||
} else {
|
||||
descendingValue = new Object[]{};
|
||||
}
|
||||
descendingBox.setValue(state, descendingValue);
|
||||
|
||||
limitToTypeField.setValue(state, component.getLimitToType());
|
||||
|
||||
pageSizeField.setValue(state, Integer.toString(component
|
||||
.getPageSize()));
|
||||
|
||||
listOrderArea.setValue(state,
|
||||
String.join("\n", component.getListOrder()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemListComponent loadSelectedComponent(final long componentId) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ComponentModelRepository componentModelRepo = cdiUtil
|
||||
.findBean(ComponentModelRepository.class);
|
||||
|
||||
return componentModelRepo.findById(componentId,
|
||||
ItemListComponent.class,
|
||||
new String[]{"listOrder"})
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No ComponentModel with ID %d in the database.",
|
||||
componentId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.validate(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final FormData data = event.getFormData();
|
||||
|
||||
if (getSaveCancelSection().getSaveButton().isSelected(state)) {
|
||||
|
||||
final String pageSizeValue = data.getString(PAGE_SIZE);
|
||||
if (pageSizeValue != null
|
||||
&& !pageSizeValue.isEmpty()
|
||||
&& !pageSizeValue.matches("\\d*")) {
|
||||
|
||||
data.addError(
|
||||
PAGE_SIZE,
|
||||
new GlobalizedMessage(
|
||||
"cms.ui.pagemodel.itemlist_component_form.page_size.error.not_a_number",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
package com.arsdigita.london.terms.ui;
|
||||
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Generate part of the category tree. Used by Assign Category authoring step.
|
||||
*
|
||||
* Class is directly used by JSP page(s), eg. load-cat.jsp (currently in
|
||||
* ~/packages/content-section/www/admin, source in ccm-ldn-aplaws or
|
||||
* corresponding integration module).
|
||||
*
|
||||
* @author Alan Pevec
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class CategorySubtree extends SimpleComponent {
|
||||
|
||||
private static final Logger LOGGER = LogManager
|
||||
.getLogger(CategorySubtree.class);
|
||||
|
||||
private final StringParameter selectedCatsParam = new StringParameter(
|
||||
"selectedCats");
|
||||
private final StringParameter nodeIdParam = new StringParameter("nodeID");
|
||||
|
||||
@Override
|
||||
public void register(final Page page) {
|
||||
super.register(page);
|
||||
page.addGlobalStateParam(nodeIdParam);
|
||||
page.addGlobalStateParam(selectedCatsParam);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateXML(final PageState state, final Element parent) {
|
||||
|
||||
final String node = (String) state.getValue(nodeIdParam);
|
||||
final Set<Long> ids = new HashSet<>();
|
||||
|
||||
if (((String) state.getValue(selectedCatsParam)) != null) {
|
||||
StringTokenizer values = new StringTokenizer((String) state
|
||||
.getValue(selectedCatsParam), ",");
|
||||
while (values.hasMoreTokens()) {
|
||||
ids.add(Long.parseLong(values.nextToken().trim()));
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.debug("selected node = {}", node);
|
||||
final String[] pathElements = StringUtils.split(node, "-");
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
|
||||
final Category root = categoryRepo
|
||||
.findById(Long.parseLong(pathElements[pathElements.length - 1]))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
pathElements[pathElements.length - 1])));
|
||||
|
||||
LOGGER.debug("generating subtree for cat {}...", root.getObjectId());
|
||||
// TermWidget.generateSubtree(parent, root, ids);
|
||||
generateSubtreeXml(parent, root, ids);
|
||||
}
|
||||
|
||||
private void generateSubtreeXml(final Element parentElem,
|
||||
final Category root,
|
||||
final Set<Long> ids) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategorySubtreeController controller = cdiUtil
|
||||
.findBean(CategorySubtreeController.class);
|
||||
|
||||
final List<Category> subCategories = controller.getSubCategories(root);
|
||||
|
||||
final Element rootCategoryElem = generateCategoryXml(parentElem,
|
||||
root,
|
||||
ids);
|
||||
|
||||
controller
|
||||
.getSubCategories(root)
|
||||
.stream()
|
||||
.sorted((category1, category2) -> {
|
||||
return category1.getName().compareTo(category2.getName());
|
||||
})
|
||||
.forEach(subCategory -> generateCategoryXml(rootCategoryElem,
|
||||
root,
|
||||
ids));
|
||||
}
|
||||
|
||||
private Element generateCategoryXml(final Element parentElem,
|
||||
final Category category,
|
||||
final Set<Long> ids) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
.findBean(GlobalizationHelper.class);
|
||||
|
||||
final Element element = parentElem.newChildElement("cms:category",
|
||||
CMS.CMS_XML_NS);
|
||||
element.addAttribute("id", Long.toString(category.getObjectId()));
|
||||
element.addAttribute("name", category.getName());
|
||||
final String desc = globalizationHelper
|
||||
.getValueFromLocalizedString(category.getDescription());
|
||||
element.addAttribute("description", desc);
|
||||
if (ids.contains(category.getObjectId())) {
|
||||
element.addAttribute("isSelected", "1");
|
||||
} else {
|
||||
element.addAttribute("isSelected", "0");
|
||||
}
|
||||
if (category.isAbstractCategory()) {
|
||||
element.addAttribute("isAbstract", "1");
|
||||
} else {
|
||||
element.addAttribute("isAbstract", "0");
|
||||
}
|
||||
if (category.isEnabled()) {
|
||||
element.addAttribute("isEnabled", "1");
|
||||
} else {
|
||||
element.addAttribute("isEnabled", "0");
|
||||
}
|
||||
|
||||
final StringBuilder path = new StringBuilder(parentElem
|
||||
.getAttribute("fullname"));
|
||||
if (path.length() > 0) {
|
||||
path.append(" > ");
|
||||
}
|
||||
path.append(category.getName());
|
||||
element.addAttribute("fullname", path.toString());
|
||||
|
||||
final StringBuilder nodeId = new StringBuilder(parentElem
|
||||
.getAttribute("node-id"));
|
||||
if (nodeId.length() > 0) {
|
||||
nodeId.append("-");
|
||||
}
|
||||
nodeId.append(category.getObjectId());
|
||||
element.addAttribute("node-id", nodeId.toString());
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.london.terms.ui;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class CategorySubtreeController {
|
||||
|
||||
@Inject
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
protected List<Category> getSubCategories(final Category ofCategory) {
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(ofCategory.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Category with ID %d in the database.",
|
||||
ofCategory.getObjectId())));
|
||||
|
||||
return category.getSubCategories();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,13 +4,7 @@
|
|||
package org.librecms;
|
||||
|
||||
import com.arsdigita.cms.ContentCenterAppCreator;
|
||||
import com.arsdigita.cms.ContentCenterServlet;
|
||||
import com.arsdigita.cms.ContentCenterSetup;
|
||||
import com.arsdigita.cms.ui.pagemodel.CategorizedItemComponentForm;
|
||||
import com.arsdigita.cms.ui.pagemodel.CategoryTreeComponentForm;
|
||||
import com.arsdigita.cms.ui.pagemodel.FixedContentItemComponentForm;
|
||||
import com.arsdigita.cms.ui.pagemodel.GreetingItemComponentForm;
|
||||
import com.arsdigita.cms.ui.pagemodel.ItemListComponentForm;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
|
@ -22,7 +16,6 @@ import org.libreccm.modules.Module;
|
|||
import org.libreccm.modules.RequiredModule;
|
||||
import org.libreccm.modules.ShutdownEvent;
|
||||
import org.libreccm.modules.UnInstallEvent;
|
||||
import org.libreccm.pagemodel.PageModelComponentModel;
|
||||
import org.libreccm.ui.admin.contentsections.ContentSectionApplicationController;
|
||||
import org.libreccm.web.ApplicationType;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
|
|
@ -43,18 +36,11 @@ import org.librecms.assets.VideoAsset;
|
|||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionCreator;
|
||||
import org.librecms.contentsection.ContentSectionSetup;
|
||||
import org.librecms.contentsection.ui.admin.ApplicationInstanceForm;
|
||||
import org.librecms.contentsection.ui.admin.SettingsPane;
|
||||
import org.librecms.contenttypes.Article;
|
||||
import org.librecms.contenttypes.ContentTypes;
|
||||
import org.librecms.contenttypes.Event;
|
||||
import org.librecms.contenttypes.MultiPartArticle;
|
||||
import org.librecms.contenttypes.News;
|
||||
import org.librecms.pagemodel.CategorizedItemComponent;
|
||||
import org.librecms.pagemodel.CategoryTreeComponent;
|
||||
import org.librecms.pagemodel.FixedContentItemComponent;
|
||||
import org.librecms.pagemodel.GreetingItemComponent;
|
||||
import org.librecms.pagemodel.ItemListComponent;
|
||||
import org.librecms.pages.Pages;
|
||||
import org.librecms.pages.PagesCreator;
|
||||
|
||||
|
|
@ -71,24 +57,19 @@ import java.util.Properties;
|
|||
name = CmsConstants.CONTENT_CENTER_APP_TYPE,
|
||||
applicationClass = CcmApplication.class,
|
||||
descBundle = CmsConstants.CONTENT_CENTER_DESC_BUNDLE,
|
||||
creator = ContentCenterAppCreator.class,
|
||||
servlet = ContentCenterServlet.class
|
||||
creator = ContentCenterAppCreator.class
|
||||
),
|
||||
@ApplicationType(
|
||||
name = CmsConstants.CONTENT_SECTION_APP_TYPE,
|
||||
applicationClass = ContentSection.class,
|
||||
instanceForm = ApplicationInstanceForm.class,
|
||||
settingsPane = SettingsPane.class,
|
||||
descBundle = CmsConstants.CONTENT_SECTION_DESC_BUNDLE,
|
||||
creator = ContentSectionCreator.class,
|
||||
servletPath = "/templates/servlet/content-section",
|
||||
applicationController = ContentSectionApplicationController.class
|
||||
applicationController = ContentSectionApplicationController.class
|
||||
),
|
||||
@ApplicationType(
|
||||
name = "org.librecms.pages.Pages",
|
||||
applicationClass = Pages.class,
|
||||
instanceForm = ApplicationInstanceForm.class,
|
||||
settingsPane = SettingsPane.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey = "pages_application.title",
|
||||
creator = PagesCreator.class,
|
||||
|
|
@ -98,44 +79,6 @@ import java.util.Properties;
|
|||
configurations = {
|
||||
org.librecms.CMSConfig.class,
|
||||
org.librecms.assets.BinaryAssetConfig.class
|
||||
},
|
||||
pageModelComponentModels = {
|
||||
@PageModelComponentModel(
|
||||
modelClass = CategorizedItemComponent.class,
|
||||
editor = CategorizedItemComponentForm.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey
|
||||
= "cms.ui.pagemodel.components.categorized_item_component.title",
|
||||
descKey
|
||||
= "cms.ui.pagemodel.components.categorized_item_component.desc"),
|
||||
@PageModelComponentModel(
|
||||
modelClass = CategoryTreeComponent.class,
|
||||
editor = CategoryTreeComponentForm.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey
|
||||
= "cms.ui.pagemodel.components.category_tree_component.title",
|
||||
descKey = "cms.ui.pagemodel.components.category_tree_component.desc"),
|
||||
@PageModelComponentModel(
|
||||
modelClass = FixedContentItemComponent.class,
|
||||
editor = FixedContentItemComponentForm.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey
|
||||
= "cms.ui.pagemodel.components.fixed_contentitem_component.title",
|
||||
descKey
|
||||
= "cms.ui.pagemodel.components.fixed_contentitem_component.desc"),
|
||||
@PageModelComponentModel(
|
||||
modelClass = GreetingItemComponent.class,
|
||||
editor = GreetingItemComponentForm.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey
|
||||
= "cms.ui.pagemodel.components.greetingitem_component.title",
|
||||
descKey = "cms.ui.pagemodel.components.greetingitem_component.desc"),
|
||||
@PageModelComponentModel(
|
||||
modelClass = ItemListComponent.class,
|
||||
editor = ItemListComponentForm.class,
|
||||
descBundle = CmsConstants.CMS_BUNDLE,
|
||||
titleKey = "cms.ui.pagemodel.components.itemlist_component.title",
|
||||
descKey = "cms.ui.pagemodel.components.itemlist_component.desc")
|
||||
}
|
||||
)
|
||||
@ContentTypes({Article.class,
|
||||
|
|
|
|||
|
|
@ -43,15 +43,6 @@ import java.lang.annotation.Target;
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AssetType {
|
||||
|
||||
/**
|
||||
* The form for editing and creating an asset of the annotated class. This
|
||||
* parameter is required.
|
||||
*
|
||||
* @return The form for editing and creating assets of the annotated sub
|
||||
* class {@link org.librecms.contentsection.Asset}.
|
||||
*/
|
||||
Class<? extends AbstractAssetForm> assetForm();
|
||||
|
||||
/**
|
||||
* The key for the localised label of the asset type. If not set the default
|
||||
* value {@code label} is used.
|
||||
|
|
@ -88,7 +79,7 @@ public @interface AssetType {
|
|||
* {@code org.librecms.assets.ImageBundle}.
|
||||
*
|
||||
* @return The fully qualified name of the bundle providing the description
|
||||
* of the asset type.
|
||||
* of the asset type.
|
||||
*/
|
||||
String descriptionBundle() default "";
|
||||
|
||||
|
|
|
|||
|
|
@ -132,8 +132,6 @@ public class AssetTypesManager {
|
|||
} else {
|
||||
assetTypeInfo.setDescriptionKey(assetType.descriptionKey());
|
||||
}
|
||||
|
||||
assetTypeInfo.setAssetForm(assetType.assetForm());
|
||||
}
|
||||
|
||||
return assetTypeInfo;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.AudioForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.AudioAssetCreateStep;
|
||||
|
|
@ -44,11 +43,12 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
|||
@Entity
|
||||
@Table(name = "AUDIO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = AudioForm.class,
|
||||
@AssetType(
|
||||
labelKey = "audio_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "audio_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = AudioAssetCreateStep.class,
|
||||
editStep = AudioAssetEditStep.class
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.BookmarkForm;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
|
||||
|
|
@ -48,11 +47,12 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
*
|
||||
* @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")
|
||||
@AssetType(
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "bookmark.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "bookmark.description"
|
||||
)
|
||||
@Entity
|
||||
@Table(name = "BOOKMARKS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.ExternalAudioAssetForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.ExternalAudioAssetCreateStep;
|
||||
|
|
@ -47,11 +46,12 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
@Entity
|
||||
@Table(name = "EXTERNAL_AUDIO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = ExternalAudioAssetForm.class,
|
||||
labelKey = "external_audio_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "external_audio_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
@AssetType(
|
||||
labelKey = "external_audio_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "external_audio_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = ExternalAudioAssetCreateStep.class,
|
||||
editStep = ExternalAudioAssetEditStep.class
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.ExternalVideoAssetForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.ExternalVideoAssetCreateStep;
|
||||
|
|
@ -38,17 +37,18 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
|
||||
/**
|
||||
* An asset for external videos, like videos from YouTube.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "EXTERNAL_VIDEO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = ExternalVideoAssetForm.class,
|
||||
labelKey = "external_video_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "external_video_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
@AssetType(
|
||||
labelKey = "external_video_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "external_video_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = ExternalVideoAssetCreateStep.class,
|
||||
editStep = ExternalVideoAssetEditStep.class
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
* MA 02110-1301 USA
|
||||
*/package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.FileAssetForm;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -34,17 +33,18 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
|
||||
/**
|
||||
* An asset for making files available for download.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "FILES", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = FileAssetForm.class,
|
||||
labelKey = "fileasset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "fileasset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
@AssetType(
|
||||
labelKey = "fileasset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "fileasset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = FileAssetCreateStep.class,
|
||||
editStep = FileAssetEditStep.class
|
||||
|
|
@ -58,7 +58,7 @@ public class FileAsset extends BinaryAsset implements Serializable {
|
|||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
|
|
@ -76,11 +76,10 @@ public class FileAsset extends BinaryAsset implements Serializable {
|
|||
final FileAsset other = (FileAsset) obj;
|
||||
return other.canEqual(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof FileAsset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.ImageForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.ImageCreateStep;
|
||||
import org.librecms.ui.contentsections.assets.ImageEditStep;
|
||||
|
|
@ -39,7 +37,7 @@ import static org.librecms.CmsConstants.*;
|
|||
import static org.librecms.assets.AssetConstants.*;
|
||||
|
||||
/**
|
||||
* An asset for images (in a format which can be displayed by a browser, like
|
||||
* An asset for images (in a format which can be displayed by a browser, like
|
||||
* PNG, JPEG or GIF).
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -47,11 +45,12 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
@Entity
|
||||
@Table(name = "IMAGES", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = ImageForm.class,
|
||||
labelKey = "image.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "image.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
@AssetType(
|
||||
labelKey = "image.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "image.description",
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = ImageCreateStep.class,
|
||||
editStep = ImageEditStep.class
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.LegalMetadataForm;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
|
@ -56,7 +55,6 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
@Table(name = "LEGAL_METADATA", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(
|
||||
assetForm = LegalMetadataForm.class,
|
||||
labelKey = "legal_metadata.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "legal_metadata.description",
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.OrganizationForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
|
||||
|
|
@ -39,11 +38,12 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@AssetType(assetForm = OrganizationForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "organization.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "organization.description")
|
||||
@AssetType(
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "organization.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "organization.description"
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = OrganizationCreateStep.class,
|
||||
editStep = OrganizationEditStep.class
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.PersonForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
|
||||
|
|
@ -50,11 +49,10 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
@Table(name = "PERSONS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(
|
||||
assetForm = PersonForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "person.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "person.description"
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "person.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "person.description"
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = PersonCreateStep.class,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.PostalAddressForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.contentsection.Asset;
|
||||
|
|
@ -35,7 +34,6 @@ import javax.persistence.Table;
|
|||
import static org.librecms.CmsConstants.DB_SCHEMA;
|
||||
import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
||||
|
||||
|
||||
/**
|
||||
* A reuable postal address.
|
||||
*
|
||||
|
|
@ -45,11 +43,10 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
|||
@Audited
|
||||
@Table(name = "POSTAL_ADDRESSES", schema = DB_SCHEMA)
|
||||
@AssetType(
|
||||
assetForm = PostalAddressForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "postaladdress.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "postaladdress.description"
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "postaladdress.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "postaladdress.description"
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = PostalAddressCreateStep.class,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.RelatedLinkForm;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
|
@ -46,7 +45,6 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
|||
@Table(name = "RELATED_LINKS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(
|
||||
assetForm = RelatedLinkForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "relatedlink.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.SideNoteForm;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
|
@ -49,7 +48,6 @@ import static org.librecms.assets.AssetConstants.*;
|
|||
@Table(name = "SIDE_NOTES", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(
|
||||
assetForm = SideNoteForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "sidenote.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.AudioForm;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.ui.contentsections.assets.MvcAssetEditKit;
|
||||
|
|
@ -45,11 +44,12 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
|||
@Entity
|
||||
@Table(name = "VIDEO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = AudioForm.class,
|
||||
@AssetType(
|
||||
labelKey = "video_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "video_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
descriptionBundle = ASSETS_BUNDLE
|
||||
)
|
||||
@MvcAssetEditKit(
|
||||
createStep = VideoAssetCreateStep.class,
|
||||
editStep = VideoAssetEditStep.class
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public @interface Module {
|
|||
* @return An array containing all {@link ComponentModel}s provided by the
|
||||
* annotated module.
|
||||
*/
|
||||
@Deprecated
|
||||
PageModelComponentModel[] pageModelComponentModels() default {};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,8 +118,10 @@ public @interface ApplicationType {
|
|||
@SuppressWarnings("rawtypes") // Can't specify type here, otherwise problems in using classes.
|
||||
Class<? extends ApplicationCreator> creator();
|
||||
|
||||
@Deprecated
|
||||
Class<? extends AbstractAppInstanceForm> instanceForm() default DefaultApplicationInstanceForm.class;
|
||||
|
||||
@Deprecated
|
||||
Class<? extends AbstractAppSettingsPane> settingsPane() default DefaultApplicationSettingsPane.class;
|
||||
|
||||
Class<? extends ApplicationController> applicationController() default DefaultApplicationController.class;
|
||||
|
|
|
|||
Loading…
Reference in New Issue