Search in sources :

Example 1 with Parameter

use of org.apereo.portal.portletpublishing.xml.Parameter in project uPortal by Jasig.

the class PortletAdministrationHelper method cleanOptions.

public void cleanOptions(PortletDefinitionForm form, PortletRequest request) {
    // Add permission parameters to permissions collection
    form.clearPermissions();
    for (String activity : PORTLET_SUBSCRIBE_ACTIVITIES) {
        addPermissionsFromRequestToForm(form, request, activity);
    }
    //Names of valid preferences and parameters
    final Set<String> preferenceNames = new HashSet<String>();
    final Set<String> parameterNames = new HashSet<String>();
    //Read all of the submitted channel parameter and portlet preference names from the request
    for (final Enumeration<String> e = request.getParameterNames(); e.hasMoreElements(); ) {
        final String name = e.nextElement();
        final Matcher nameMatcher = PARAM_PATTERN.matcher(name);
        if (nameMatcher.matches()) {
            final String paramType = nameMatcher.group(1);
            final String paramName = nameMatcher.group(2);
            if ("portletPreferences".equals(paramType)) {
                preferenceNames.add(paramName);
            } else if ("parameters".equals(paramType)) {
                parameterNames.add(paramName);
            }
        }
    }
    //Add all of the parameter and preference names that have default values in the CPD into the valid name sets
    final PortletPublishingDefinition cpd = this.portletPublishingDefinitionDao.getChannelPublishingDefinition(form.getTypeId());
    for (final Step step : cpd.getSteps()) {
        final List<Parameter> parameters = step.getParameters();
        if (parameters != null) {
            for (final Parameter parameter : parameters) {
                final JAXBElement<? extends ParameterInputType> parameterInput = parameter.getParameterInput();
                if (parameterInput != null) {
                    final ParameterInputType parameterInputType = parameterInput.getValue();
                    if (parameterInputType != null && parameterInputType.getDefault() != null) {
                        parameterNames.add(parameter.getName());
                    }
                }
            }
        }
        final List<Preference> preferences = step.getPreferences();
        if (preferences != null) {
            for (final Preference preference : preferences) {
                final JAXBElement<? extends PreferenceInputType> preferenceInput = preference.getPreferenceInput();
                final PreferenceInputType preferenceInputType = preferenceInput.getValue();
                if (preferenceInputType instanceof MultiValuedPreferenceInputType) {
                    final MultiValuedPreferenceInputType multiValuedPreferenceInputType = (MultiValuedPreferenceInputType) preferenceInputType;
                    final List<String> defaultValues = multiValuedPreferenceInputType.getDefaults();
                    if (defaultValues != null && !defaultValues.isEmpty()) {
                        preferenceNames.add(preference.getName());
                    }
                } else if (preferenceInputType instanceof SingleValuedPreferenceInputType) {
                    final SingleValuedPreferenceInputType SingleValuedPreferenceInputType = (SingleValuedPreferenceInputType) preferenceInputType;
                    if (SingleValuedPreferenceInputType.getDefault() != null) {
                        preferenceNames.add(preference.getName());
                    }
                }
            }
        }
    }
    // - do it only if portlet doesn't support configMode
    if (!this.supportsConfigMode(form)) {
        final Map<String, StringListAttribute> portletPreferences = form.getPortletPreferences();
        final Map<String, BooleanAttribute> portletPreferencesOverrides = form.getPortletPreferenceReadOnly();
        for (final Iterator<Entry<String, StringListAttribute>> portletPreferenceEntryItr = portletPreferences.entrySet().iterator(); portletPreferenceEntryItr.hasNext(); ) {
            final Map.Entry<String, StringListAttribute> portletPreferenceEntry = portletPreferenceEntryItr.next();
            final String key = portletPreferenceEntry.getKey();
            final StringListAttribute valueAttr = portletPreferenceEntry.getValue();
            if (!preferenceNames.contains(key) || valueAttr == null) {
                portletPreferenceEntryItr.remove();
                portletPreferencesOverrides.remove(key);
            } else {
                final List<String> values = valueAttr.getValue();
                for (final Iterator<String> iter = values.iterator(); iter.hasNext(); ) {
                    String value = iter.next();
                    if (value == null) {
                        iter.remove();
                    }
                }
                if (values.size() == 0) {
                    portletPreferenceEntryItr.remove();
                    portletPreferencesOverrides.remove(key);
                }
            }
        }
    }
    final Map<String, Attribute> parameters = form.getParameters();
    for (final Iterator<Entry<String, Attribute>> parameterEntryItr = parameters.entrySet().iterator(); parameterEntryItr.hasNext(); ) {
        final Entry<String, Attribute> parameterEntry = parameterEntryItr.next();
        final String key = parameterEntry.getKey();
        final Attribute value = parameterEntry.getValue();
        if (!parameterNames.contains(key) || value == null || StringUtils.isBlank(value.getValue())) {
            parameterEntryItr.remove();
        }
    }
}
Also used : BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) Matcher(java.util.regex.Matcher) BooleanAttribute(org.apereo.portal.portlets.BooleanAttribute) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Attribute(org.apereo.portal.portlets.Attribute) PortletPublishingDefinition(org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition) Step(org.apereo.portal.portletpublishing.xml.Step) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) ParameterInputType(org.apereo.portal.portletpublishing.xml.ParameterInputType) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) SingleValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.SingleValuedPreferenceInputType) PreferenceInputType(org.apereo.portal.portletpublishing.xml.PreferenceInputType) MultiValuedPreferenceInputType(org.apereo.portal.portletpublishing.xml.MultiValuedPreferenceInputType) Preference(org.apereo.portal.portletpublishing.xml.Preference) IPortletPreference(org.apereo.portal.portlet.om.IPortletPreference) Parameter(org.apereo.portal.portletpublishing.xml.Parameter) StringListAttribute(org.apereo.portal.portlets.StringListAttribute) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Parameter

use of org.apereo.portal.portletpublishing.xml.Parameter in project uPortal by Jasig.

the class PortletDefinitionForm method setChannelPublishingDefinition.

/**
     * Sets the Java class name and parameter defaults based on the PortletPublishingDefinition.
     *
     * @param cpd
     */
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 = this.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) {
                        this.parameters.put(param.getName(), new Attribute(input.getDefault()));
                    }
                }
            }
        }
        if (step.getPreferences() != null) {
            for (Preference pref : step.getPreferences()) {
                // for a default in the CPD
                if (!this.portletPreferences.containsKey(pref.getName()) || this.portletPreferences.get(pref.getName()).getValue().size() == 0 || (this.portletPreferences.get(pref.getName()).getValue().size() == 1 && this.portletPreferences.get(pref.getName()).getValue().get(0).trim().equals(""))) {
                    if (!this.portletPreferences.containsKey(pref.getName())) {
                        this.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) {
                            this.portletPreferences.get(pref.getName()).getValue().add(singleValued.getDefault());
                        }
                    } else if (input instanceof MultiValuedPreferenceInputType) {
                        MultiValuedPreferenceInputType multiValued = (MultiValuedPreferenceInputType) input;
                        if (multiValued.getDefaults() != null) {
                            this.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

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 StringListAttribute (org.apereo.portal.portlets.StringListAttribute)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 IPortletDefinitionParameter (org.apereo.portal.portlet.om.IPortletDefinitionParameter)1 PortletPublishingDefinition (org.apereo.portal.portletpublishing.xml.PortletPublishingDefinition)1 PortletDescriptor (org.apereo.portal.xml.PortletDescriptor)1