Example usage for org.apache.commons.collections Factory create

List of usage examples for org.apache.commons.collections Factory create

Introduction

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

Prototype

public Object create();

Source Link

Document

Create a new object.

Usage

From source file:org.jopendocument.dom.ODXMLDocument.java

@SuppressWarnings("unchecked")
private void add(Factory elemF, int lindex, ODXMLDocument other, String rpath, ElementTransformer addTransf)
        throws JDOMException {
    final Element toAdd = other.getDescendant(rpath);
    // si on a qqchose  ajouter
    if (toAdd != null) {
        final List<Content> cloned = toAdd.cloneContent();
        final List<Content> listToAdd;
        if (addTransf == null) {
            listToAdd = cloned;// w  w w  .  j  av  a2 s . co  m
        } else {
            listToAdd = new ArrayList<Content>(cloned.size());
            final Iterator iter = cloned.iterator();
            while (iter.hasNext()) {
                final Content c = (Content) iter.next();
                if (c instanceof Element) {
                    final Element transformedElem = addTransf.transform((Element) c);
                    if (transformedElem != null)
                        listToAdd.add(transformedElem);
                }
            }
        }
        // on cre si besoin le "rcepteur"
        final Element thisElem = (Element) elemF.create();
        if (lindex < 0)
            thisElem.addContent(listToAdd);
        else
            thisElem.addContent(lindex, listToAdd);
    }
}

From source file:org.opencms.util.CmsMacroResolver.java

/**
 * @see org.opencms.util.I_CmsMacroResolver#getMacroValue(java.lang.String)
 *///from   w  w  w .j  ava 2 s .  c  om
public String getMacroValue(String macro) {

    if (m_messages != null) {
        if (macro.startsWith(CmsMacroResolver.KEY_LOCALIZED_PREFIX)) {
            String keyName = macro.substring(CmsMacroResolver.KEY_LOCALIZED_PREFIX.length());
            return m_messages.keyWithParams(keyName);
        }
    }

    if (m_factories != null) {
        Factory factory = m_factories.get(macro);
        if (factory != null) {
            String value = (String) factory.create();
            return value;
        }
    }

    if (m_jspPageContext != null) {

        if (m_jspPageContext.getRequest() != null) {
            if (macro.startsWith(CmsMacroResolver.KEY_REQUEST_PARAM)) {
                // the key is a request parameter  
                macro = macro.substring(CmsMacroResolver.KEY_REQUEST_PARAM.length());
                String result = m_jspPageContext.getRequest().getParameter(macro);
                if ((result == null) && macro.equals(KEY_PROJECT_ID)) {
                    result = m_cms.getRequestContext().getCurrentProject().getUuid().toString();
                }
                return result;
            }

            if ((m_cms != null) && macro.startsWith(CmsMacroResolver.KEY_PROPERTY_ELEMENT)) {

                // the key is a cms property to be read on the current element

                macro = macro.substring(CmsMacroResolver.KEY_PROPERTY_ELEMENT.length());
                CmsFlexController controller = CmsFlexController.getController(m_jspPageContext.getRequest());
                try {
                    CmsProperty property = m_cms
                            .readPropertyObject(controller.getCurrentRequest().getElementUri(), macro, false);
                    if (property != CmsProperty.getNullProperty()) {
                        return property.getValue();
                    }
                } catch (CmsException e) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(Messages.get().getBundle().key(Messages.LOG_PROPERTY_READING_FAILED_2, macro,
                                controller.getCurrentRequest().getElementUri()), e);
                    }
                }
            }
        }

        if (macro.startsWith(CmsMacroResolver.KEY_PAGE_CONTEXT)) {
            // the key is a page context object
            macro = macro.substring(CmsMacroResolver.KEY_PAGE_CONTEXT.length());
            int scope = m_jspPageContext.getAttributesScope(macro);
            return m_jspPageContext.getAttribute(macro, scope).toString();
        }
    }

    if (m_cms != null) {

        if (macro.startsWith(CmsMacroResolver.KEY_PROPERTY)) {
            // the key is a cms property to be read on the current request URI
            macro = macro.substring(CmsMacroResolver.KEY_PROPERTY.length());
            try {
                CmsProperty property = m_cms.readPropertyObject(m_cms.getRequestContext().getUri(), macro,
                        true);
                if (property != CmsProperty.getNullProperty()) {
                    return property.getValue();
                }
            } catch (CmsException e) {
                if (LOG.isWarnEnabled()) {
                    CmsMessageContainer message = Messages.get().container(
                            Messages.LOG_PROPERTY_READING_FAILED_2, macro, m_cms.getRequestContext().getUri());
                    LOG.warn(message.key(), e);
                }
            }
            return null;
        }

        if (macro.startsWith(CmsMacroResolver.KEY_ATTRIBUTE)) {
            // the key is an OpenCms runtime attribute
            macro = macro.substring(CmsMacroResolver.KEY_ATTRIBUTE.length());
            Object attribute = m_cms.getRequestContext().getAttribute(macro);
            if (attribute != null) {
                return attribute.toString();
            }
            return null;
        }

        if (macro.startsWith(CmsMacroResolver.KEY_OPENCMS)) {

            // the key is a shortcut for a cms runtime value

            String originalKey = macro;
            macro = macro.substring(CmsMacroResolver.KEY_OPENCMS.length());
            int index = VALUE_NAMES.indexOf(macro);
            String value = null;

            switch (index) {
            case 0:
                // "uri"
                value = m_cms.getRequestContext().getUri();
                break;
            case 1:
                // "filename"
                value = m_resourceName;
                break;
            case 2:
                // folder
                value = m_cms.getRequestContext().getFolderUri();
                break;
            case 3:
                // default.encoding
                value = OpenCms.getSystemInfo().getDefaultEncoding();
                break;
            case 4:
                // remoteaddress
                value = m_cms.getRequestContext().getRemoteAddress();
                break;
            case 5:
                // webapp
                value = OpenCms.getSystemInfo().getWebApplicationName();
                break;
            case 6:
                // webbasepath
                value = OpenCms.getSystemInfo().getWebApplicationRfsPath();
                break;
            case 7:
                // version
                value = OpenCms.getSystemInfo().getVersionNumber();
                break;
            default:
                // return the key "as is"
                value = originalKey;
                break;
            }

            return value;
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_NAME.equals(macro)) {
            // the key is the current users login name
            return m_cms.getRequestContext().getCurrentUser().getName();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_FIRSTNAME.equals(macro)) {
            // the key is the current users first name
            return m_cms.getRequestContext().getCurrentUser().getFirstname();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_LASTNAME.equals(macro)) {
            // the key is the current users last name
            return m_cms.getRequestContext().getCurrentUser().getLastname();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_DISPLAYNAME.equals(macro)) {
            // the key is the current users display name
            try {
                if (m_messages != null) {
                    return m_cms.getRequestContext().getCurrentUser().getDisplayName(m_cms,
                            m_messages.getLocale());
                } else {
                    return m_cms.getRequestContext().getCurrentUser().getDisplayName(m_cms,
                            m_cms.getRequestContext().getLocale());
                }
            } catch (CmsException e) {
                // ignore, macro can not be resolved
            }
        }

        if (CmsMacroResolver.KEY_CURRENT_ORGUNIT_FQN.equals(macro)) {
            // the key is the current organizational unit fully qualified name
            return m_cms.getRequestContext().getOuFqn();
        }

        if (CmsMacroResolver.KEY_CURRENT_ORGUNIT_DESCRIPTION.equals(macro)) {
            // the key is the current organizational unit description
            try {
                CmsOrganizationalUnit ou = OpenCms.getOrgUnitManager().readOrganizationalUnit(m_cms,
                        m_cms.getRequestContext().getOuFqn());
                if (m_messages != null) {
                    return ou.getDescription(m_messages.getLocale());
                } else {
                    return ou.getDescription(m_cms.getRequestContext().getLocale());
                }
            } catch (CmsException e) {
                // ignore, macro can not be resolved
            }
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_FULLNAME.equals(macro)) {
            // the key is the current users full name
            return m_cms.getRequestContext().getCurrentUser().getFullName();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_EMAIL.equals(macro)) {
            // the key is the current users email address
            return m_cms.getRequestContext().getCurrentUser().getEmail();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_STREET.equals(macro)) {
            // the key is the current users address
            return m_cms.getRequestContext().getCurrentUser().getAddress();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_ZIP.equals(macro)) {
            // the key is the current users zip code
            return m_cms.getRequestContext().getCurrentUser().getZipcode();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_COUNTRY.equals(macro)) {
            // the key is the current users country
            return m_cms.getRequestContext().getCurrentUser().getCountry();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_CITY.equals(macro)) {
            // the key is the current users city
            return m_cms.getRequestContext().getCurrentUser().getCity();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_LASTLOGIN.equals(macro) && (m_messages != null)) {
            // the key is the current users last login timestamp
            return m_messages.getDateTime(m_cms.getRequestContext().getCurrentUser().getLastlogin());
        }

        if (CmsMacroResolver.KEY_REQUEST_URI.equals(macro)) {
            // the key is the currently requested uri
            return m_cms.getRequestContext().getUri();
        }

        if (CmsMacroResolver.KEY_REQUEST_FOLDER.equals(macro)) {
            // the key is the currently requested folder
            return CmsResource.getParentFolder(m_cms.getRequestContext().getUri());
        }

        if (CmsMacroResolver.KEY_REQUEST_ENCODING.equals(macro)) {
            // the key is the current encoding of the request
            return m_cms.getRequestContext().getEncoding();
        }

        if (CmsMacroResolver.KEY_REQUEST_LOCALE.equals(macro)) {
            // the key is the current locale of the request
            return m_cms.getRequestContext().getLocale().toString();
        }

        if (CmsMacroResolver.KEY_CONTEXT_PATH.equals(macro)) {
            // the key is the OpenCms context path
            return OpenCms.getSystemInfo().getContextPath();
        }

        if (CmsMacroResolver.KEY_CURRENT_USER_INSTITUTION.equals(macro)) {
            // the key is the current users institution
            return m_cms.getRequestContext().getCurrentUser().getInstitution();
        }

    }

    if (CmsMacroResolver.KEY_CURRENT_TIME.equals(macro)) {
        // the key is the current system time
        return String.valueOf(System.currentTimeMillis());
    } else if (macro.startsWith(CmsMacroResolver.KEY_CURRENT_TIME)) {
        // the key starts with the current system time
        macro = macro.substring(CmsMacroResolver.KEY_CURRENT_TIME.length()).trim();
        char operator = macro.charAt(0);
        macro = macro.substring(1).trim();
        long delta = 0;
        try {
            delta = Long.parseLong(macro);
        } catch (NumberFormatException e) {
            // ignore, there will be no delta
        }
        long resultTime = System.currentTimeMillis();
        switch (operator) {
        case '+':
            // add delta to current time
            resultTime += delta;
            break;
        case '-':
            // subtract delta from current time
            resultTime -= delta;
            break;
        default:
            break;
        }
        return String.valueOf(resultTime);
    }

    if (m_additionalMacros != null) {
        return m_additionalMacros.get(macro);
    }

    return null;
}

From source file:org.opensingular.form.wicket.mapper.AbstractListMapper.java

public static void buildFooter(BSContainer<?> footer, WicketBuildContext ctx, Factory createAddButton) {
    if (canAddItems(ctx)) {
        final TemplatePanel template = footer.newTemplateTag(tp -> createButtonMarkup(ctx));
        template.add((Component) createAddButton.create());
    } else {/* w w  w  . j a  va2 s.c  o  m*/
        footer.setVisible(false);
    }
    personalizeCSS(footer);
}