Search in sources :

Example 6 with StringListAttribute

use of org.apereo.portal.portlets.StringListAttribute in project uPortal by Jasig.

the class PortletDefinitionForm method setChannelPublishingDefinition.

/**
 * Sets the Java class name and parameter defaults based on the PortletPublishingDefinition.
 */
public void setChannelPublishingDefinition(PortletPublishingDefinition cpd) {
    // portlet, the applicationId is /uPortal.
    if (cpd.getPortletDescriptor() != null) {
        final PortletDescriptor pDesc = cpd.getPortletDescriptor();
        // PortletDescriptor is a class generated from XSD.  The value of
        // isIsFramework() will commonly be null.
        final boolean isFramework = pDesc.isIsFramework() != null ? pDesc.isIsFramework() : false;
        applicationId = isFramework ? FRAMEWORK_PORTLET_URL : pDesc.getWebAppName();
        portletName = pDesc.getPortletName();
    }
    // set default values for all portlet parameters
    for (Step step : cpd.getSteps()) {
        if (step.getParameters() != null) {
            for (Parameter param : step.getParameters()) {
                // if this parameter doesn't currently have a value, check
                // for a default in the CPD
                Attribute attribute = parameters.get(param.getName());
                if (attribute == null || attribute.getValue() == null || attribute.getValue().trim().equals("")) {
                    // use the default value if one exists
                    ParameterInputType input = param.getParameterInput().getValue();
                    if (input != null) {
                        parameters.put(param.getName(), new Attribute(input.getDefault()));
                    }
                }
            }
        }
        if (step.getPreferences() != null) {
            for (Preference pref : step.getPreferences()) {
                // for a default in the CPD
                if (!portletPreferences.containsKey(pref.getName()) || portletPreferences.get(pref.getName()).getValue().size() == 0 || (portletPreferences.get(pref.getName()).getValue().size() == 1 && portletPreferences.get(pref.getName()).getValue().get(0).trim().equals(""))) {
                    if (!portletPreferences.containsKey(pref.getName())) {
                        portletPreferences.put(pref.getName(), new StringListAttribute());
                    }
                    // use the default value if one exists
                    PreferenceInputType input = pref.getPreferenceInput().getValue();
                    if (input instanceof SingleValuedPreferenceInputType) {
                        SingleValuedPreferenceInputType singleValued = (SingleValuedPreferenceInputType) input;
                        if (singleValued.getDefault() != null) {
                            portletPreferences.get(pref.getName()).getValue().add(singleValued.getDefault());
                        }
                    } else if (input instanceof MultiValuedPreferenceInputType) {
                        MultiValuedPreferenceInputType multiValued = (MultiValuedPreferenceInputType) input;
                        if (multiValued.getDefaults() != null) {
                            portletPreferences.get(pref.getName()).getValue().addAll(multiValued.getDefaults());
                        }
                    }
                }
            }
        }
    }
}
Also used : ParameterInputType(org.apereo.portal.portletpublishing.xml.ParameterInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) PortletDescriptor(org.apereo.portal.xml.PortletDescriptor) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) Attribute(org.apereo.portal.portlets.Attribute) Preference(org.apereo.portal.portletpublishing.xml.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) PreferenceInputType(org.apereo.portal.portletpublishing.xml.PreferenceInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) Parameter(org.apereo.portal.portletpublishing.xml.Parameter) IPortletDefinitionParameter(org.apereo.portal.portlet.om.IPortletDefinitionParameter) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Step(org.apereo.portal.portletpublishing.xml.Step) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)

Aggregations

StringListAttribute (org.apereo.portal.portlets.StringListAttribute)6 HashMap (java.util.HashMap)2 IPortletPreference (org.apereo.portal.portlet.om.IPortletPreference)2 MultiValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType)2 Parameter (org.apereo.portal.portletpublishing.xml.Parameter)2 ParameterInputType (org.apereo.portal.portletpublishing.xml.ParameterInputType)2 Preference (org.apereo.portal.portletpublishing.xml.Preference)2 PreferenceInputType (org.apereo.portal.portletpublishing.xml.PreferenceInputType)2 SingleValuedPreferenceInputType (org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType)2 Step (org.apereo.portal.portletpublishing.xml.Step)2 Attribute (org.apereo.portal.portlets.Attribute)2 BooleanAttribute (org.apereo.portal.portlets.BooleanAttribute)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 ILocalAccountPerson (org.apereo.portal.persondir.ILocalAccountPerson)1 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)1 PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)1