Removed several depcrecated classes from ccm-cms
parent
7cd39aa321
commit
d11c4922ea
|
|
@ -21,7 +21,6 @@ package com.arsdigita.bebop;
|
|||
import com.arsdigita.bebop.page.PageTransformer;
|
||||
import com.arsdigita.bebop.util.BebopConstants;
|
||||
import com.arsdigita.templating.PresentationManager;
|
||||
import com.arsdigita.ui.SimplePage;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -57,7 +56,7 @@ public final class BebopConfig {
|
|||
descKey = "basePageClassName.desc",
|
||||
labelKey = "basePageClassName.label"
|
||||
)
|
||||
private String basePageClassName = SimplePage.class.getName();
|
||||
private String basePageClassName = "";
|
||||
|
||||
@Setting(
|
||||
descKey = "tidyConfigFile.desc",
|
||||
|
|
|
|||
|
|
@ -1,157 +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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.ChangeListener;
|
||||
import com.arsdigita.bebop.parameters.LongParameter;
|
||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.libreccm.core.CcmObjectRepository;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
*/
|
||||
public class CcmObjectSelectionModel<T extends CcmObject>
|
||||
implements SingleSelectionModel<Long> {
|
||||
|
||||
private final Class<T> clazz;
|
||||
private final SingleSelectionModel<Long> model;
|
||||
|
||||
public CcmObjectSelectionModel(final LongParameter parameter) {
|
||||
this(CcmObject.class.getName(), parameter);
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String parameterName) {
|
||||
this(CcmObject.class.getName(), new LongParameter(parameterName));
|
||||
}
|
||||
|
||||
// public CcmObjectSelectionModel(final SingleSelectionModel<T> model ) {
|
||||
// this(null, model);
|
||||
// }
|
||||
//
|
||||
public CcmObjectSelectionModel(final Class<T> clazz,
|
||||
final String parameterName) {
|
||||
this(clazz, new LongParameter(parameterName));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final String parameterName) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
model = new ParameterSingleSelectionModel<Long>(new LongParameter(
|
||||
parameterName));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final Class<T> clazz,
|
||||
final LongParameter parameter) {
|
||||
this(clazz, new ParameterSingleSelectionModel<>(parameter));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final LongParameter parameter) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
model = new ParameterSingleSelectionModel<>(parameter);
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final Class<T> clazz,
|
||||
final SingleSelectionModel<Long> model) {
|
||||
this.clazz = clazz;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final SingleSelectionModel<Long> model) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(final PageState state) {
|
||||
return model.isSelected(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSelectedKey(final PageState state) {
|
||||
final Object key = model.getSelectedKey(state);
|
||||
if (key == null) {
|
||||
return null;
|
||||
} else if (key instanceof Long) {
|
||||
return (Long) key;
|
||||
} else if (key instanceof String) {
|
||||
return Long.parseLong((String) key);
|
||||
} else {
|
||||
return Long.parseLong(key.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedKey(final PageState state, final Long key) {
|
||||
model.setSelectedKey(state, key);
|
||||
}
|
||||
|
||||
public T getSelectedObject(final PageState state) {
|
||||
final Long key = getSelectedKey(state);
|
||||
final CcmObjectRepository repository = CdiUtil.createCdiUtil().findBean(
|
||||
CcmObjectRepository.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
final T object = (T) repository.findObjectById(key).get();
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelection(final PageState state) {
|
||||
|
||||
model.clearSelection(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeListener(final ChangeListener changeListener) {
|
||||
model.addChangeListener(changeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChangeListener(final ChangeListener changeListener) {
|
||||
model.removeChangeListener(changeListener);;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterModel getStateParameter() {
|
||||
return model.getStateParameter();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.web.Web;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ReactApp extends SimpleComponent {
|
||||
|
||||
private final String appId;
|
||||
private final String scriptPath;
|
||||
|
||||
public ReactApp(final String appId, final String scriptPath) {
|
||||
super();
|
||||
|
||||
this.appId = appId;
|
||||
this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public String getScriptPath() {
|
||||
return scriptPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateXML(final PageState state, final Element parent) {
|
||||
|
||||
final Element reactAppElem = parent.newChildElement("bebop:reactApp",
|
||||
BEBOP_XML_NS);
|
||||
reactAppElem.addAttribute("appId", appId);
|
||||
reactAppElem.addAttribute("scriptPath",
|
||||
String.format("%s/%s",
|
||||
Web
|
||||
.getServletContext()
|
||||
.getContextPath(),
|
||||
scriptPath));
|
||||
|
||||
final String primaryUrl = getPrimaryUrl();
|
||||
|
||||
reactAppElem
|
||||
.addAttribute("ccmApplication", primaryUrl);
|
||||
|
||||
reactAppElem
|
||||
.addAttribute("dispatcherPrefix", Web.getWebappContextPath());
|
||||
}
|
||||
|
||||
private String getPrimaryUrl() {
|
||||
|
||||
final String primaryUrl = Web
|
||||
.getWebContext()
|
||||
.getApplication()
|
||||
.getPrimaryUrl();
|
||||
|
||||
if (primaryUrl.matches("^/(.*)/$")) {
|
||||
return primaryUrl.substring(1, primaryUrl.length() - 1);
|
||||
} else if (primaryUrl.matches("^/(.*)$")) {
|
||||
return primaryUrl.substring(1);
|
||||
} else if (primaryUrl.matches("^(.*)/$")) {
|
||||
return primaryUrl.substring(0, primaryUrl.length() - 1);
|
||||
} else {
|
||||
return primaryUrl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.ui;
|
||||
|
||||
import com.arsdigita.bebop.BasePage;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.util.Classes;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* SimplePage is a subclass of ApplicationPage providing a
|
||||
* simple page which can have custom, application independant
|
||||
* widgets added to it. The default styling for this
|
||||
* component provides a border layout with panels for the
|
||||
* top, bottom, left & right margins of the page.
|
||||
*
|
||||
* <h3>Configuration</h3>
|
||||
* The components to be added to a page are configured in the
|
||||
* enterprise.init file using two parameters. The first,
|
||||
* <code>defaultLayout</code>, specifies the site wide components,
|
||||
* the second, <code>applicationLayouts</code> allows individual
|
||||
* applications to be given a custom set of components.
|
||||
* <p>
|
||||
* The <code>defaultLayout</code> parameter is a list of components
|
||||
* & their associated layout tags. The values specified for the
|
||||
* layout tags are handled opaquely by the Java code, passing them
|
||||
* straight through to the output XML. Thus the exact values you
|
||||
* can specify are determined by the XSLT used for styling. For
|
||||
* the default styling rules, the allowable tags are 'top', 'bottom',
|
||||
* 'left' & 'right'.
|
||||
* <h3>Generated XML</h3>
|
||||
* To allow XSLT to easily distinguish the generic components for the
|
||||
* page borders from the application specific content, all components
|
||||
* added to the page are placed within one of two trivial containers.
|
||||
* <p>
|
||||
* All the application specific components (as added by the <code>add</code>
|
||||
* method) are placed within a single <code>ui:simplePageContent</code>
|
||||
* tag. The components for each position tag are placed within a
|
||||
* <code>ui:simplePagePanel</code> tag, with the <code>position</code>
|
||||
* attribute set accordingly.
|
||||
*
|
||||
*/
|
||||
public class SimplePage extends BasePage {
|
||||
|
||||
private static SimplePageLayout s_default = new SimplePageLayout();
|
||||
private static HashMap s_layouts = new HashMap();
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(SimplePage.class);
|
||||
|
||||
/**
|
||||
* Set the default layout for all applications, which haven't
|
||||
* got a specific layout configuration.
|
||||
*
|
||||
* @param layout the default layout policy
|
||||
*/
|
||||
static void setDefaultLayout(SimplePageLayout layout) {
|
||||
s_default = layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the application specific layout, overriding the default
|
||||
* layout.
|
||||
*
|
||||
* @param application the application name
|
||||
* @param layout the layout policy
|
||||
*/
|
||||
static void setLayout(String application,
|
||||
SimplePageLayout layout) {
|
||||
s_layouts.put(application, layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the layout policy for a particular application.
|
||||
* Looks for an application specific layout first, and if
|
||||
* that fails, opts for the default layout.
|
||||
*
|
||||
* @param application the application name
|
||||
* @return the applications layout
|
||||
*/
|
||||
static SimplePageLayout getLayout(String application) {
|
||||
SimplePageLayout layout = (SimplePageLayout)s_layouts.get(application);
|
||||
|
||||
if (layout == null) {
|
||||
layout = s_default;
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SimplePage object. This constructor
|
||||
* is only intended for subclasses & PageFactory. Applications should
|
||||
* call <code>PageFactory.buildPage</code> to obtain a suitable
|
||||
* instance of the com.arsdigita.bebop.Page class.
|
||||
*
|
||||
* @param application the application name
|
||||
* @param title label for the page title
|
||||
* @param id (optionally null) unique id for the page
|
||||
*/
|
||||
public SimplePage(String application,
|
||||
Label title,
|
||||
String id) {
|
||||
super(application, title, id);
|
||||
|
||||
setClassAttr("simplePage");
|
||||
|
||||
addLayoutComponents(application);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a component to the body of the page. To add a component
|
||||
* to header / footer / etc, set its classname in one of the
|
||||
* page layouts.
|
||||
* @param child the component to add to the body
|
||||
*/
|
||||
public void add(Component child) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Adding component to body " + child.getClass());
|
||||
}
|
||||
|
||||
super.add(child);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a component to the body of the page. To add a component
|
||||
* to header / footer / etc, set its classname in one of the
|
||||
* page layouts.
|
||||
* @param child the component to add to the body
|
||||
*/
|
||||
public void add(Component child,
|
||||
int constraints) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Adding component to body " + child.getClass());
|
||||
}
|
||||
|
||||
super.add(child, constraints);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configure this page object, adding the pre-configured
|
||||
* components to its body
|
||||
*/
|
||||
private void addLayoutComponents(String application) {
|
||||
SimplePageLayout layout = getLayout(application);
|
||||
|
||||
Iterator tags = layout.getPositionTags();
|
||||
while (tags.hasNext()) {
|
||||
String tag = (String)tags.next();
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Adding component with tag " + tag);
|
||||
}
|
||||
|
||||
|
||||
Iterator i = layout.getComponents(tag);
|
||||
while (i.hasNext()) {
|
||||
Class klass = (Class)i.next();
|
||||
SimpleComponent child = (SimpleComponent)Classes.newInstance(klass);
|
||||
child.setMetaDataAttribute("tag", tag);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Adding component " + child.getClass());
|
||||
}
|
||||
|
||||
super.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.kernel.security.SecurityConfig;
|
||||
import com.arsdigita.web.Web;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import static com.arsdigita.ui.UI.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class SiteBanner extends SimpleComponent {
|
||||
|
||||
@Override
|
||||
public void generateXML(final PageState state, final Element parentElem) {
|
||||
final Element contentElem = parentElem.newChildElement("ui:siteBanner",
|
||||
UI_XML_NS);
|
||||
|
||||
exportAttributes(contentElem);
|
||||
|
||||
contentElem.addAttribute("hostname", getHostname());
|
||||
contentElem.addAttribute("sitename", getSiteName());
|
||||
}
|
||||
|
||||
protected String getHostname() {
|
||||
return Web.getConfig().getServer();
|
||||
}
|
||||
|
||||
protected String getSiteName() {
|
||||
return Web.getConfig().getSiteName();
|
||||
}
|
||||
}
|
||||
|
|
@ -75,28 +75,7 @@ public final class UIConfig {
|
|||
}
|
||||
|
||||
public SimplePageLayout buildDefaultLayout() {
|
||||
final SimplePageLayout layout = new SimplePageLayout();
|
||||
|
||||
defaultLayout.forEach(c -> {
|
||||
final String[] tokens = c.split(":");
|
||||
if (tokens.length != 2) {
|
||||
throw new ConfigurationException(
|
||||
"Default layout not provided in the correct format.");
|
||||
}
|
||||
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(tokens[1]);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new ConfigurationException(String.format(
|
||||
"Component \"%s\" not found.", tokens[1]),
|
||||
ex);
|
||||
}
|
||||
|
||||
layout.addComponent(clazz, tokens[0]);
|
||||
});
|
||||
|
||||
return layout;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getRootPageUrl() {
|
||||
|
|
|
|||
|
|
@ -1,37 +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.ui;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class UiInitializer {
|
||||
|
||||
public UiInitializer() {
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
final UIConfig uiConfig = UIConfig.getConfig();
|
||||
|
||||
SimplePage.setDefaultLayout(uiConfig.buildDefaultLayout());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,136 +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.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleComponent;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.web.URL;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.security.User;
|
||||
import org.libreccm.security.UserRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import static com.arsdigita.ui.UI.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class UserBanner extends SimpleComponent {
|
||||
|
||||
@Override
|
||||
public void generateXML(final PageState state,
|
||||
final Element parentElem) {
|
||||
|
||||
super.generateXML(state, parentElem);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final Subject subject = cdiUtil.findBean(Subject.class);
|
||||
|
||||
final Element contentElem = parentElem.newChildElement("ui:userBanner",
|
||||
UI_XML_NS);
|
||||
|
||||
exportAttributes(contentElem);
|
||||
|
||||
if (subject.isAuthenticated()) {
|
||||
final KernelConfig config = KernelConfig.getConfig();
|
||||
final UserRepository userRepository = cdiUtil.findBean(
|
||||
UserRepository.class);
|
||||
|
||||
final Optional<User> user;
|
||||
if ("email".equals(config.getPrimaryUserIdentifier())) {
|
||||
user = userRepository.findByEmailAddress(
|
||||
(String) subject.getPrincipal());
|
||||
} else {
|
||||
user = userRepository
|
||||
.findByName((String) subject.getPrincipal());
|
||||
}
|
||||
|
||||
if (user.isPresent()) {
|
||||
contentElem.addAttribute("givenName",
|
||||
user.get().getGivenName());
|
||||
contentElem.addAttribute("familyName",
|
||||
user.get().getFamilyName());
|
||||
contentElem.addAttribute("screenName",
|
||||
user.get().getName());
|
||||
contentElem.addAttribute("primaryEmail",
|
||||
user.get().getPrimaryEmailAddress()
|
||||
.getAddress());
|
||||
contentElem.addAttribute("userID",
|
||||
Long.toString(user.get().getPartyId()));
|
||||
}
|
||||
}
|
||||
|
||||
final HttpServletRequest request = state.getRequest();
|
||||
|
||||
contentElem.addAttribute("changePasswordLabel",
|
||||
(String) new GlobalizedMessage(
|
||||
"ui.admin.change_password",
|
||||
UI_BUNDLE_NAME).localize(request));
|
||||
|
||||
contentElem.addAttribute("helpLabel",
|
||||
(String) new GlobalizedMessage(
|
||||
"ui.admin.help",
|
||||
UI_BUNDLE_NAME).localize(request));
|
||||
|
||||
contentElem.addAttribute("portalLabel",
|
||||
(String) new GlobalizedMessage(
|
||||
"ui.admin.portal",
|
||||
UI_BUNDLE_NAME).localize(request));
|
||||
|
||||
contentElem.addAttribute("signoutLabel",
|
||||
(String) new GlobalizedMessage(
|
||||
"ui.admin.signout",
|
||||
UI_BUNDLE_NAME).localize(request));
|
||||
|
||||
contentElem.addAttribute("greeting",
|
||||
(String) new GlobalizedMessage(
|
||||
"ui.admin.greeting",
|
||||
UI_BUNDLE_NAME).localize(request));
|
||||
|
||||
contentElem.addAttribute("workspaceURL",
|
||||
URL.there(state.getRequest(),
|
||||
UI.getWorkspaceURL()).toString());
|
||||
|
||||
contentElem.addAttribute("loginURL",
|
||||
URL.there(state.getRequest(),
|
||||
"register/")
|
||||
.toString());
|
||||
|
||||
contentElem.addAttribute("logoutURL",
|
||||
URL.there(state.getRequest(),
|
||||
"register/logout")
|
||||
.toString());
|
||||
|
||||
contentElem.addAttribute("changePasswordURL",
|
||||
URL.there(state.getRequest(),
|
||||
"register/change-password")
|
||||
.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -51,7 +51,6 @@ import java.util.Properties;
|
|||
com.arsdigita.mail.MailConfig.class,
|
||||
com.arsdigita.notification.NotificationConfig.class,
|
||||
com.arsdigita.templating.TemplatingConfig.class,
|
||||
com.arsdigita.ui.UIConfig.class,
|
||||
com.arsdigita.web.WebConfig.class,
|
||||
com.arsdigita.workflow.simple.WorkflowConfig.class,
|
||||
com.arsdigita.xml.XmlConfig.class,
|
||||
|
|
|
|||
Loading…
Reference in New Issue