/******************************************************************************* * Copyright 2017 Graz University of Technology * EAAF-Core Components has been developed in a cooperation between EGIZ, * A-SIT Plus, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ /******************************************************************************* *******************************************************************************/ /******************************************************************************* *******************************************************************************/ package at.gv.egiz.eaaf.core.impl.gui; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.eaaf.core.api.gui.IGUIBuilderConfiguration; /** * @author tlenz * */ public abstract class AbstractGUIFormBuilderConfiguration implements IGUIBuilderConfiguration { private static final Logger log = LoggerFactory.getLogger(AbstractGUIFormBuilderConfiguration.class); public static final String PARAM_GROUP_FORM = "form"; public static final String PARAM_GROUP_ACTIONS = "actions"; public static final String PARAM_GROUP_PARAMS = "params"; public static final String PARAM_GROUP_UIOPTIONS = "uiOptions"; public static final String PARAM_GROUP_MSG = "msg"; public static final String PARAM_VIEWNAME = "viewName"; public static final String PARAM_AUTHCONTEXT = "contextPath"; public static final String PARAM_FORMSUBMITENDPOINT = "submitEndpoint"; @Deprecated public static final String PARAM_PENDINGREQUESTID_DEPRECATED = "pendingReqID"; public static final String PARAM_PENDINGREQUESTID = "pendingid"; private String authURL = null; private String viewName = null; private String formSubmitEndpoint = null; private final Map params = new HashMap(); /** * @param authURL IDP PublicURL-Prefix which should be used, but never null * @param viewName Name of the template (with suffix) but never null * @param formSubmitEndpoint EndPoint on which the form should be submitted, * or null if the form must not submitted * */ public AbstractGUIFormBuilderConfiguration(String authURL, String viewName, String formSubmitEndpoint) { if (viewName.startsWith("/")) this.viewName = viewName.substring(1); else this.viewName = viewName; if (authURL.endsWith("/")) this.authURL = authURL.substring(0, authURL.length() - 1); else this.authURL = authURL; if (StringUtils.isNotEmpty(formSubmitEndpoint)) { if (formSubmitEndpoint.startsWith("/")) this.formSubmitEndpoint = formSubmitEndpoint; else this.formSubmitEndpoint = "/" + formSubmitEndpoint; } } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.builder.IGUIBuilderConfiguration#getViewName() */ @Override public final String getViewName() { return this.viewName; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.auth.frontend.builder.IGUIBuilderConfiguration#getViewParameters() */ @Override public final Map getViewParameters() { //set generic parameters setViewParameter(PARAM_GROUP_FORM, PARAM_AUTHCONTEXT, this.authURL); setViewParameter(PARAM_GROUP_FORM, PARAM_FORMSUBMITENDPOINT, this.formSubmitEndpoint); setViewParameter(PARAM_GROUP_FORM, PARAM_VIEWNAME, this.viewName); //get parameters from detail implementation putSpecificViewParameters(); try { log.trace("Full view parameters: {}", StringUtils.join(params, ",")); } catch (final Exception e) { log.info("Can NOT trace view parameters. Reason: {}", e.getMessage() ); } return params; } /** * Define the parameters, which should be evaluated in the template
* IMPORTANT: external HTML escapetion is required, because it is NOT done internally during the building process * */ abstract protected void putSpecificViewParameters(); @SuppressWarnings("unchecked") protected void setViewParameter(String group, String key, Object value) { if (StringUtils.isNotEmpty(group)) { log.trace("Adding group object ... "); Object groupMap = params.get(group); if (groupMap == null) { groupMap = new HashMap();; log.trace("Build new group element"); } if (groupMap instanceof Map) { ((Map) groupMap).put(key, value); params.put(group, groupMap); } else log.warn("Can NOT add element: {} to group: {}, because group is of type: {}", key, group, groupMap.getClass().getName()); } else { log.trace("Add root object ... "); params.put(key, value); } } }