Example usage for org.apache.commons.collections Transformer Transformer

List of usage examples for org.apache.commons.collections Transformer Transformer

Introduction

In this page you can find the example usage for org.apache.commons.collections Transformer Transformer.

Prototype

Transformer

Source Link

Usage

From source file:org.fenixedu.academic.ui.faces.beans.coordinator.ListStudentThesis.java

private static List run(String degreeCurricularPlanID) throws FenixServiceException {

    DegreeCurricularPlan degreeCurricularPlan = FenixFramework.getDomainObject(degreeCurricularPlanID);

    List masterDegreeThesisDataVersions = MasterDegreeThesisDataVersion
            .readActiveMasterDegreeThesisDataVersions(degreeCurricularPlan);

    if (masterDegreeThesisDataVersions == null || masterDegreeThesisDataVersions.isEmpty()) {
        throw new NonExistingServiceException("error.exception.masterDegree.nonExistingMasterDegreeThesis");
    }/*from  w w w.j a va2 s.com*/

    CollectionUtils.transform(masterDegreeThesisDataVersions, new Transformer() {
        @Override
        public Object transform(Object arg0) {
            MasterDegreeThesisDataVersion masterDegreeThesisDataVersion = (MasterDegreeThesisDataVersion) arg0;
            return InfoMasterDegreeThesisDataVersionWithGuidersAndRespAndThesis
                    .newInfoFromDomain(masterDegreeThesisDataVersion);
        }
    });

    return masterDegreeThesisDataVersions;
}

From source file:org.geoserver.security.iride.entity.util.Utils.java

/**
 *
 * @param invalidTokenValuesMessageTemplate
 * @param invalidTokenValues/* w  w w. j a va  2s .c  o m*/
 * @return
 */
public static String toString(final String invalidTokenValuesMessageTemplate,
        IrideIdentityInvalidTokenValue... invalidTokenValues) {
    return StringUtils
            .join(CollectionUtils.collect(Arrays.asList(defaultToEmpty(invalidTokenValues)), new Transformer() {
                /*
                 * (non-Javadoc)
                 * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
                 */
                @Override
                public String transform(Object input) {
                    if (input == null) {
                        return "";
                    } else {
                        final IrideIdentityInvalidTokenValue invalidToken = (IrideIdentityInvalidTokenValue) input;

                        return String.format(invalidTokenValuesMessageTemplate, invalidToken.getToken(),
                                String.valueOf(invalidToken.getValue()));
                    }
                }
            }), SystemUtils.LINE_SEPARATOR);
}

From source file:org.geoserver.security.iride.util.IrideSecurityUtils.java

/**
 *
 * @param invalidTokenValuesMessageTemplate
 * @param invalidTokenValues//from w w  w .j a v a  2 s.  com
 * @return
 */
public static String toString(final String invalidTokenValuesMessageTemplate,
        IrideIdentityInvalidTokenValue... invalidTokenValues) {
    return StringUtils
            .join(CollectionUtils.collect(Arrays.asList(defaultToEmpty(invalidTokenValues)), new Transformer() {
                /*
                 * (non-Javadoc)
                 * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
                 */
                @Override
                public String transform(Object input) {
                    if (input == null) {
                        return StringUtils.EMPTY;
                    } else {
                        final IrideIdentityInvalidTokenValue invalidToken = (IrideIdentityInvalidTokenValue) input;

                        return String.format(invalidTokenValuesMessageTemplate, invalidToken.getToken(),
                                String.valueOf(invalidToken.getValue()));
                    }
                }
            }), SystemUtils.LINE_SEPARATOR);
}

From source file:org.itracker.services.implementations.ConfigurationServiceImpl.java

public Map<String, List<String>> getAvailableLanguages() {

    final TreeMap<String, List<String>> languages = new TreeMap<>();
    final List<Configuration> locales = getConfigurationItemsByType(Configuration.Type.locale);

    for (int i = 0; i < locales.size(); i++) {
        String baselocalestring = locales.get(i).getValue();
        if (baselocalestring.length() == 2) {
            List<String> languageList = new ArrayList<>();
            final String l = baselocalestring;

            languageList.addAll(CollectionUtils.collect(locales, new Transformer() {
                @Override//ww  w.j  a  va2 s .  co  m
                public Object transform(Object input) {
                    String val = ((Configuration) input).getValue();
                    if (val.length() > 2 && val.startsWith(l + "_")) {
                        return val;
                    }
                    return null;
                }
            }));
            CollectionUtils.filter(languageList, NotNullPredicate.getInstance());
            languages.put(baselocalestring, languageList);
        }
    }

    return languages;

}

From source file:org.jahia.ajax.gwt.helper.ContentDefinitionHelper.java

public GWTChoiceListInitializer getInitializerValues(ExtendedPropertyDefinition epd,
        ExtendedNodeType contextType, JCRNodeWrapper contextNode, JCRNodeWrapper contextParent,
        Map<String, List<GWTJahiaNodePropertyValue>> dependentValues, Locale uiLocale)
        throws RepositoryException {
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("contextType", contextType);
    context.put("contextNode", contextNode);
    context.put("contextParent", contextParent);
    for (Map.Entry<String, List<GWTJahiaNodePropertyValue>> entry : dependentValues.entrySet()) {
        context.put(entry.getKey(), CollectionUtils.collect(entry.getValue(), new Transformer() {
            public Object transform(Object input) {
                return input.toString();
            }//  w ww  . j ava2 s.  com
        }));
    }

    return getChoiceListInitializerValues(epd, context, uiLocale);
}

From source file:org.jahia.services.content.nodetypes.initializers.SubNodeTypesChoiceListInitializerImpl.java

@SuppressWarnings("unchecked")
public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param,
        List<ChoiceListValue> values, Locale locale, Map<String, Object> context) {
    final SortedSet<ChoiceListValue> listValues = new TreeSet<ChoiceListValue>();
    if (StringUtils.isEmpty(param)) {
        param = "jmix:editorialContent";
    }// w ww .j  a va  2 s. co  m
    try {
        String includedTypes = StringUtils.substringBefore(param, ";");

        Set<String> excludedTypes = new HashSet<String>();
        String exclusion = StringUtils.substringAfter(param, ";");
        if (StringUtils.isNotBlank(exclusion)) {
            excludedTypes.addAll(CollectionUtils.collect(
                    Arrays.asList(Patterns.COMMA.split(StringUtils.substringAfter(param, ";"))),
                    new Transformer() {
                        public Object transform(Object input) {
                            return ((String) input).trim();
                        }
                    }));
        }

        for (String nodeTypeName : Patterns.COMMA.split(includedTypes)) {
            nodeTypeName = nodeTypeName.trim();
            ExtendedNodeType nodeType = NodeTypeRegistry.getInstance().getNodeType(nodeTypeName);
            if (!isExcludedType(nodeType, excludedTypes)) {
                listValues.add(new ChoiceListValue(nodeType.getLabel(locale), nodeType.getName()));
            }
            NodeTypeIterator nti = nodeType.getSubtypes();
            while (nti.hasNext()) {
                ExtendedNodeType type = (ExtendedNodeType) nti.next();
                if (!isExcludedType(type, excludedTypes)) {
                    listValues.add(new ChoiceListValue(type.getLabel(locale), type.getName()));
                }
            }
        }
    } catch (NoSuchNodeTypeException e) {
        logger.error("Cannot get type", e);
    }

    return new LinkedList<ChoiceListValue>(listValues);
}

From source file:org.jahia.services.importexport.validation.ValidationResults.java

@SuppressWarnings("unchecked")
protected Map<String, ValidationResult> getResultsByClassName() {
    if (resultsByClassName == null) {
        resultsByClassName = LazyMap.decorate(new HashMap<String, ValidationResult>(0), new Transformer() {
            public Object transform(Object clazz) {
                for (ValidationResult result : results) {
                    if (clazz.equals(result.getClass().getName())) {
                        return result;
                    }/* w w  w .j av  a2s  .  c  om*/
                }
                return null;
            }
        });
    }

    return resultsByClassName;
}

From source file:org.jahia.services.render.filter.MarkedForDeletionFilter.java

protected String getTemplateOutput(RenderContext renderContext, Resource resource) {
    String out = StringUtils.EMPTY;
    try {/*from   ww w .ja v  a2s  .  c  o  m*/
        String template = getTemplateContent();
        resolvedTemplate = null;

        if (StringUtils.isEmpty(template)) {
            return StringUtils.EMPTY;
        }

        ScriptEngine engine = ScriptEngineUtils.getInstance().scriptEngine(templateExtension);
        ScriptContext ctx = new SimpleScriptContext();
        ctx.setWriter(new StringWriter());
        Bindings bindings = engine.createBindings();
        bindings.put("renderContext", renderContext);
        bindings.put("resource", resource);
        final ResourceBundle bundle = ResourceBundles.getInternal(renderContext.getUILocale());
        bindings.put("bundle", bundle);
        bindings.put("i18n", LazyMap.decorate(new HashMap<String, String>(2), new Transformer() {
            public Object transform(Object input) {
                String value = null;
                String key = String.valueOf(input);
                try {
                    value = bundle.getString(key);
                } catch (MissingResourceException e) {
                    value = key;
                }
                return value;
            }
        }));

        ctx.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        engine.eval(template, ctx);
        out = ((StringWriter) ctx.getWriter()).getBuffer().toString();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return out;
}

From source file:org.jahia.services.render.URLGenerator.java

@SuppressWarnings("unchecked")
public Map<String, String> getLanguages() {
    if (languages == null) {
        languages = LazyMap.decorate(new HashMap<String, String>(), new Transformer() {
            public Object transform(Object lang) {
                return getLanguage((String) lang);
            }//from  ww  w  .  java 2s . c  o m
        });
    }

    return languages;
}

From source file:org.jahia.services.render.URLGenerator.java

@SuppressWarnings("unchecked")
public Map<String, String> getTemplates() {
    if (templates == null) {
        templates = LazyMap.decorate(new HashMap<String, String>(), new Transformer() {
            public Object transform(Object template) {
                return getTemplate((String) template);
            }//ww w.j  av a2s . c  om
        });
    }
    return templates;
}