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.opencms.frontend.templatetwo.CmsTemplateMenu.java

/**
 * Returns a lazy initialized map that provides the current elements as a key in the Map.<p> 
 * /*from w  w  w.j  a  v a 2  s.c  o  m*/
 * @return a lazy initialized map
 */
public Map getHasChildren() {

    if (m_children == null) {
        m_children = LazyMap.decorate(new HashMap(), new Transformer() {

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                CmsJspNavElement elem = (CmsJspNavElement) input;

                int currentLevel = elem.getNavTreeLevel();
                int index = getElements().indexOf(elem);

                if (index < getElements().size() - 1) {
                    CmsJspNavElement next = (CmsJspNavElement) getElements().get(index + 1);
                    if (next.getNavTreeLevel() > currentLevel) {
                        return new Boolean(true);
                    }
                }

                return new Boolean(false);
            }
        });
    }
    return m_children;
}

From source file:org.opencms.frontend.templatetwo.CmsTemplateMenu.java

/**
 * Returns a lazy initialized map that provides the current elements as a key in the Map.<p> 
 * /*ww w.  j av a2s . c  om*/
 * @return a lazy initialized map
 */
public Map getIsCurrent() {

    if (m_current == null) {
        m_current = LazyMap.decorate(new HashMap(), new Transformer() {

            /** The log object for this class. */
            private final Log LOGG = CmsLog.getLog(CmsTemplateMenu.class);

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                CmsJspNavElement elem = (CmsJspNavElement) input;

                String uri = getCmsObject().getRequestContext().getUri();
                CmsJspNavElement uriElem = null;
                try {
                    uriElem = new CmsJspNavElement(uri,
                            CmsProperty.toMap(getCmsObject().readPropertyObjects(uri, false)));
                } catch (CmsException e) {
                    // noop
                    LOGG.debug(e.getLocalizedMessage(), e);
                }

                // check if uri matches resource name
                if (elem.getResourceName().equals(uri)) {
                    return Boolean.TRUE;
                }

                // check if the default file for the uri matches the resource name
                String path = null;
                try {
                    CmsResource resource = getCmsObject().readDefaultFile(elem.getResourceName());
                    path = getCmsObject().getSitePath(resource);
                } catch (CmsException e) {
                    // resource not found or not enough permissions
                    LOGG.debug(e.getLocalizedMessage(), e);
                }
                if ((path == null) || ((uriElem != null) && uriElem.isInNavigation())) {
                    path = elem.getResourceName();
                }

                if (uri.equals(path)) {
                    return Boolean.TRUE;
                }

                // check if uri is in NOT in the navigation and so a parent folder will be marked as current
                CmsJspNavElement navElem = uriElem;
                while ((navElem != null) && !navElem.isInNavigation()) {

                    String parentPath = CmsResource.getParentFolder(navElem.getResourceName());
                    if (parentPath == null) {
                        break;
                    }
                    try {
                        navElem = new CmsJspNavElement(parentPath,
                                CmsProperty.toMap(getCmsObject().readPropertyObjects(parentPath, false)));
                    } catch (CmsException ex) {
                        break;
                    }
                }

                if ((navElem != null) && (uriElem != null) && !uriElem.isInNavigation()) {
                    return Boolean.valueOf(elem.equals(navElem));
                }

                return Boolean.FALSE;
            }
        });
    }
    return m_current;
}

From source file:org.opencms.frontend.templatetwo.CmsTemplateMenu.java

/**
 * Returns a lazy initialized map that provides the navigation text as a key in the Map.<p> 
 * //w ww. ja  v  a 2 s.c  o  m
 * @return a lazy initialized map
 */
public Map getNavText() {

    if (m_navText == null) {
        m_navText = LazyMap.decorate(new HashMap(), new Transformer() {

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                CmsJspNavElement elem = (CmsJspNavElement) input;

                String text = elem.getProperty(CmsPropertyDefinition.PROPERTY_NAVTEXT);
                if (CmsStringUtil.isEmptyOrWhitespaceOnly(text)) {
                    text = elem.getProperty(CmsPropertyDefinition.PROPERTY_TITLE);
                }

                return text;
            }
        });
    }
    return m_navText;
}

From source file:org.opencms.jsp.search.result.CmsSearchResourceBean.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResourceBean#getDateFields()
 *//*from  w w w .  j  av  a2  s. c  o  m*/
@Override
public Map<String, Date> getDateFields() {

    if (m_datefields == null) {
        m_datefields = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                return getSearchResource().getDateField(fieldName.toString());
            }
        });
    }
    return m_datefields;
}

From source file:org.opencms.jsp.search.result.CmsSearchResourceBean.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResourceBean#getFields()
 */// w  w  w .  j  av  a  2  s  .c o  m
@Override
public Map<String, String> getFields() {

    if (m_stringfields == null) {
        m_stringfields = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                return getSearchResource().getField(fieldName.toString());
            }
        });
    }
    return m_stringfields;
}

From source file:org.opencms.jsp.search.result.CmsSearchResourceBean.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResourceBean#getMultiValuedFields()
 *///w  ww. ja v a  2 s  .  c  om
@Override
public Map<String, List<String>> getMultiValuedFields() {

    if (m_multivaluedfields == null) {
        m_multivaluedfields = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                return getSearchResource().getMultivaluedField(fieldName.toString());
            }
        });

    }
    return m_multivaluedfields;
}

From source file:org.opencms.jsp.search.result.CmsSearchResourceBean.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResourceBean#getXmlContentInLocale()
 *///from  www  .j a v a 2 s . c  o m
public Map<String, CmsJspContentAccessBean> getXmlContentInLocale() {

    if (m_localizedContent == null) {
        m_localizedContent = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object locale) {

                CmsJspContentAccessBean accessBean = null;
                try {
                    accessBean = new CmsJspContentAccessBean(m_cmsObject,
                            CmsLocaleManager.getLocale((String) locale), m_searchResource);
                } catch (@SuppressWarnings("unused") Exception e) {
                    // simply return null
                }
                return accessBean;
            }
        });

    }
    return m_localizedContent;
}

From source file:org.opencms.jsp.search.result.CmsSearchResultWrapper.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResultWrapper#getFieldFacet()
 *//*from w  w  w. j  a  v  a  2  s.c  om*/
@Override
public Map<String, FacetField> getFieldFacet() {

    if (m_fieldFacetMap == null) {
        m_fieldFacetMap = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                return m_solrResultList == null ? null : m_solrResultList.getFacetField(fieldName.toString());
            }
        });
    }
    return m_fieldFacetMap;
}

From source file:org.opencms.jsp.search.result.CmsSearchResultWrapper.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResultWrapper#getMissingSelectedFieldFacetEntries()
 *//*from   ww w .j av  a  2 s .  c o  m*/
@Override
public Map<String, List<String>> getMissingSelectedFieldFacetEntries() {

    if (m_missingFieldFacetEntryMap == null) {
        m_missingFieldFacetEntryMap = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                FacetField facetResult = m_solrResultList == null ? null
                        : m_solrResultList.getFacetField(fieldName.toString());
                I_CmsSearchControllerFacetField facetController = m_controller.getFieldFacets()
                        .getFieldFacetController().get(fieldName.toString());
                List<String> result = new ArrayList<String>();

                if (null != facetController) {

                    List<String> checkedEntries = facetController.getState().getCheckedEntries();
                    if (null != facetResult) {
                        List<String> returnedValues = new ArrayList<String>(facetResult.getValues().size());
                        for (FacetField.Count value : facetResult.getValues()) {
                            returnedValues.add(value.getName());
                        }
                        for (String checked : checkedEntries) {
                            if (!returnedValues.contains(checked)) {
                                result.add(checked);
                            }
                        }
                    } else {
                        result = checkedEntries;
                    }
                }
                return result;
            }
        });
    }
    return m_missingFieldFacetEntryMap;
}

From source file:org.opencms.jsp.search.result.CmsSearchResultWrapper.java

/**
 * @see org.opencms.jsp.search.result.I_CmsSearchResultWrapper#getMissingSelectedRangeFacetEntries()
 *//*from  w  ww  .j  av a 2 s. c  om*/
public Map<String, List<String>> getMissingSelectedRangeFacetEntries() {

    if (m_missingRangeFacetEntryMap == null) {
        m_missingRangeFacetEntryMap = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

            @Override
            public Object transform(final Object fieldName) {

                @SuppressWarnings("rawtypes")
                RangeFacet facetResult = m_rangeFacetMap.get(fieldName);
                I_CmsSearchControllerFacetRange facetController = m_controller.getRangeFacets()
                        .getRangeFacetController().get(fieldName.toString());
                List<String> result = new ArrayList<String>();

                if (null != facetController) {

                    List<String> checkedEntries = facetController.getState().getCheckedEntries();
                    if (null != facetResult) {
                        List<String> returnedValues = new ArrayList<String>(facetResult.getCounts().size());
                        for (Object value : facetResult.getCounts()) {
                            //TODO: Should yield RangeFacet.Count - but somehow does not!?!?
                            // Hence, the cast should not be necessary at all.
                            returnedValues.add(((RangeFacet.Count) value).getValue());
                        }
                        for (String checked : checkedEntries) {
                            if (!returnedValues.contains(checked)) {
                                result.add(checked);
                            }
                        }
                    } else {
                        result = checkedEntries;
                    }
                }
                return result;
            }
        });
    }
    return m_missingRangeFacetEntryMap;

}