Example usage for org.apache.commons.collections KeyValue getValue

List of usage examples for org.apache.commons.collections KeyValue getValue

Introduction

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

Prototype

Object getValue();

Source Link

Document

Gets the value from the pair.

Usage

From source file:gsn.beans.VSensorConfig.java

public void preprocess_addressing() {
    if (!addressing_processed) {
        for (KeyValue kv : getAddressing())
            if (kv.getKey().toString().equalsIgnoreCase("altitude"))
                cached_altitude = Double.parseDouble(kv.getValue().toString());
            else if (kv.getKey().toString().equalsIgnoreCase("longitude"))
                cached_longitude = Double.parseDouble(kv.getValue().toString());
            else if (kv.getKey().toString().equalsIgnoreCase("latitude"))
                cached_latitude = Double.parseDouble(kv.getValue().toString());
        addressing_processed = true;/*www. j  a v  a 2 s .  co m*/
    }
}

From source file:gsn.beans.VSensorConfig.java

public String toString() {
    final StringBuilder builder = new StringBuilder("Input Stream [");
    for (final InputStream inputStream : this.getInputStreams()) {
        builder.append("Input-Stream-Name").append(inputStream.getInputStreamName());
        builder.append("Input-Stream-Query").append(inputStream.getQuery());
        builder.append(" Stream-Sources ( ");
        if (inputStream.getSources() == null)
            builder.append("null");
        else//from   w w w  .j av  a  2  s  . co  m
            for (final StreamSource ss : inputStream.getSources()) {
                builder.append("Stream-Source Alias : ").append(ss.getAlias());
                for (final AddressBean addressing : ss.getAddressing()) {
                    builder.append("Stream-Source-wrapper >").append(addressing.getWrapper())
                            .append("< with addressign predicates : ");
                    for (final KeyValue keyValue : addressing.getPredicates())
                        builder.append("Key=").append(keyValue.getKey()).append("Value=")
                                .append(keyValue.getValue());
                }
                builder.append(" , ");
            }
        builder.append(")");
    }
    builder.append("]");
    return "VSensorConfig{" + "name='" + this.name + '\'' + ", priority=" + this.priority + ", mainClass='"
            + this.mainClass + '\'' + ", description='" + this.description + '\'' + ", outputStreamRate="
            + this.outputStreamRate + ", addressing=" + this.addressing + ", outputStructure="
            + this.outputStructure + ", storageHistorySize='" + this.storageHistorySize + '\''
            + builder.toString() + ", mainClassInitialParams=" + this.mainClassInitialParams + ", lastModified="
            + this.lastModified + ", fileName='" + this.fileName + '\'' + ", logger=" + this.logger
            + ", nameInitialized=" + this.nameInitialized + ", isStorageCountBased=" + this.isStorageCountBased
            + ", parsedStorageSize=" + this.parsedStorageSize + '}';
}

From source file:gsn.http.restapi.RequestHandler.java

private Map<String, String> createHeaderMap(VSensorConfig vsconf) {

    Map<String, String> metadata = new LinkedHashMap<String, String>();

    //vs name//  w  ww  . ja va2  s.c  o  m
    metadata.put(stringConstantsProperties.getProperty("VS_NAME"), vsconf.getName());

    //is_public
    String is_public_res = "IS_PUBLIC_TRUE";
    if (Main.getContainerConfig().isAcEnabled() && DataSource.isVSManaged(vsconf.getName()))
        is_public_res = "IS_PUBLIC_FALSE";
    metadata.put(stringConstantsProperties.getProperty("IS_PUBLIC"),
            stringConstantsProperties.getProperty(is_public_res));

    //predicates
    for (KeyValue df : vsconf.getAddressing()) {
        metadata.put(df.getKey().toString().toLowerCase().trim(), df.getValue().toString().trim());
    }

    //description
    metadata.put(stringConstantsProperties.getProperty("DESCRIPTION"), vsconf.getDescription());

    return metadata;
}

From source file:gsn.webservice.standard.GSNWebServiceSkeleton.java

/**
 * Auto generated method signature/*from   w  w w.j  a  v  a  2s .c o  m*/
 *
 * @param getVirtualSensorsDetails
 */

public gsn.webservice.standard.GetVirtualSensorsDetailsResponse getVirtualSensorsDetails(
        gsn.webservice.standard.GetVirtualSensorsDetails getVirtualSensorsDetails) {
    //throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#getVirtualSensorsDetails");
    //
    User user = getUserForAC(getVirtualSensorsDetails.getAcDetails());
    //
    GetVirtualSensorsDetailsResponse response = new GetVirtualSensorsDetailsResponse();
    //

    //
    HashMap<String, ArrayList<String>> vsAndFields = buildSelection(
            getVirtualSensorsDetails.getFieldSelector());
    for (Map.Entry<String, ArrayList<String>> selection : vsAndFields.entrySet()) {
        if (!Main.getContainerConfig().isAcEnabled()
                || (user != null && (user.hasReadAccessRight(selection.getKey()) || user.isAdmin()))) {
            VSensorConfig config = Mappings.getConfig(selection.getKey());
            if (config != null) {
                GSNWebService_VirtualSensorDetails details = new GSNWebService_VirtualSensorDetails();
                details.setVsname(selection.getKey());
                for (GSNWebService_DetailsType detail : getVirtualSensorsDetails.getDetailsType()) {
                    if ("INFO".equals(detail.getValue())) {
                        GSNWebService_ConfInfo info = new GSNWebService_ConfInfo();
                        info.setDescription(config.getDescription());
                        details.setInfo(info);
                    } else if ("PROCESSOR".equals(detail.getValue())) {
                        GSNWebService_ConfProcessor processor = new GSNWebService_ConfProcessor();
                        processor.setClassName(config.getProcessingClass());
                        for (Map.Entry<String, String> entry : config.getMainClassInitialParams().entrySet()) {
                            GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate();
                            predicate.setName(entry.getKey().toString());
                            predicate.setString(entry.getValue().toString());
                            processor.addInitParams(predicate);
                        }
                        details.setProcessor(processor);
                    } else if ("ADDRESSING".equals(detail.getValue())) {
                        GSNWebService_ConfAddressing addressing = new GSNWebService_ConfAddressing();
                        for (KeyValue kv : config.getAddressing()) {
                            GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate();
                            predicate.setName(kv.getKey().toString());
                            predicate.setString(kv.getValue().toString());
                            addressing.addPredicates(predicate);
                        }
                        details.setAddressing(addressing);
                    } else if ("OUTPUTSTRUCTURE".equals(detail.getValue())) {
                        GSNWebService_ConfOutputStructure outputstructure = new GSNWebService_ConfOutputStructure();
                        for (DataField df : config.getOutputStructure()) {
                            GSNWebService_DataField dataField = new GSNWebService_DataField();
                            if (df.getDescription() != null)
                                dataField.setDescription(df.getDescription());
                            if (df.getName() != null)
                                dataField.setName(df.getName());
                            if (df.getType() != null)
                                dataField.setType(df.getType());
                            dataField.setString("");
                            outputstructure.addFields(dataField);
                        }
                        details.setOutputStructure(outputstructure);
                    } else if ("WRAPPER".equals(detail.getValue())) {
                        GSNWebService_ConfWrapper wrapperConf = new GSNWebService_ConfWrapper();
                        for (gsn.beans.InputStream inputStream : config.getInputStreams()) {
                            for (gsn.beans.StreamSource source : inputStream.getSources()) {
                                AddressBean ab = source.getActiveAddressBean();
                                //
                                GSNWebService_WrapperDetails wd = new GSNWebService_WrapperDetails();
                                //
                                GSNWebService_WrapperURL wrapperURL = new GSNWebService_WrapperURL();
                                wrapperURL.setVirtualSensor(config.getName());
                                wrapperURL.setStream(inputStream.getInputStreamName());
                                wrapperURL.setSource(source.getAlias().toString());
                                wrapperURL.setWrapper(source.getActiveAddressBean().getWrapper());
                                wd.setWrapperURLs(wrapperURL);
                                //
                                for (KeyValue kv : ab.getPredicates()) {
                                    GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate();
                                    predicate.setName(kv.getKey().toString());
                                    predicate.setString(kv.getValue().toString());
                                    wd.addPredicates(predicate);
                                }
                                //
                                for (DataField df : source.getWrapper().getOutputFormat()) {
                                    GSNWebService_DataField dataField = new GSNWebService_DataField();
                                    if (df.getDescription() != null)
                                        dataField.setDescription(df.getDescription());
                                    if (df.getName() != null)
                                        dataField.setName(df.getName());
                                    if (df.getType() != null)
                                        dataField.setType(df.getType());
                                    dataField.setString("");
                                    wd.addOutputFormat(dataField);
                                }
                                wrapperConf.addWrapperDetails(wd);
                            }
                        }
                        details.setWrapper(wrapperConf);
                    }
                }
                response.addVirtualSensorDetails(details);
            }
        }
    }

    //

    //
    return response;
}

From source file:org.jahia.modules.tagcloud.taglibs.TagCloudTag.java

private QueryResultWrapper getNodesWithFacets(JCRNodeWrapper boundComponent, int minimumCardinalityForInclusion,
        int maxNumberOfTags, Map<String, List<KeyValue>> appliedFacets) throws RepositoryException {
    // retrieve all jmix:tagged nodes that descending from the bound component path
    final JCRSessionWrapper session = boundComponent.getSession();
    QueryObjectModelFactory factory = session.getWorkspace().getQueryManager().getQOMFactory();

    QOMBuilder qomBuilder = new QOMBuilder(factory, session.getValueFactory());
    boolean hadExisting = false;
    String selectorName = Constants.JAHIAMIX_TAGGED;

    final int scope = pageContext.getAttributesScope("moduleMap");
    if (scope != 0) {
        final Map moduleMap = (Map) pageContext.getAttribute("moduleMap", scope);
        if (moduleMap != null) {
            final Object listQuery = moduleMap.get("listQuery");
            if (listQuery instanceof QueryObjectModel) {
                QueryObjectModel existing = (QueryObjectModel) listQuery;
                final Selector selector = (Selector) existing.getSource();
                selectorName = selector.getSelectorName();
                qomBuilder.setSource(selector);
                qomBuilder.andConstraint(existing.getConstraint());
                hadExisting = true;/*from w  ww . j  av a  2 s . c  o  m*/
            }
        }
    }

    if (!hadExisting) {
        qomBuilder.setSource(factory.selector(Constants.JAHIAMIX_TAGGED, selectorName));
        qomBuilder.andConstraint(factory.descendantNode(selectorName, boundComponent.getPath()));
    }

    // faceting on the TAGS_PROPERTY_NAME field with specified minimum cardinality
    qomBuilder.getColumns().add(factory.column(selectorName, Constants.TAGS, "rep:facet(facet.nodetype="
            + Constants.JAHIAMIX_TAGGED + "&facet.mincount=" + minimumCardinalityForInclusion + "&key=1)"));

    // repeat applied facets
    if (appliedFacets != null) {
        for (Map.Entry<String, List<KeyValue>> appliedFacet : appliedFacets.entrySet()) {
            for (KeyValue keyValue : appliedFacet.getValue()) {
                final String propertyName = "rep:filter(" + Text.escapeIllegalJcrChars(appliedFacet.getKey())
                        + ")";
                qomBuilder.andConstraint(factory.fullTextSearch(selectorName, propertyName, factory
                        .literal(qomBuilder.getValueFactory().createValue(keyValue.getValue().toString()))));
            }
        }
    }

    // limiting the query to the specified maximum number of tags
    QueryObjectModel qom = qomBuilder.createQOM();
    qom.setLimit(maxNumberOfTags);
    return (QueryResultWrapper) qom.execute();
}

From source file:org.jahia.taglibs.facet.Functions.java

/**
 * Create the URL to remove the given facet from the facet filter query parameter
 *
 * @param facetValue  the applied facet value, which need to be removed again
 * @param queryString the current facet filter URL query parameter
 * @return the new facet filter URL query parameter
 *//*from w w  w  .  j  ava2s .  c  o  m*/
public static String getDeleteFacetUrl(KeyValue facetValue, String queryString) {
    // retrieve all facet Strings from query
    final String[] facets = FILTER_STRING_PATTERN.split(queryString);

    // rebuild a new query String omitting the facet String corresponding to the facet value we want to remove
    StringBuilder newQueryString = new StringBuilder(queryString.length());
    int index = 0;
    final int newFacetNumber = facets.length - 1;
    for (String facet : facets) {
        if (!facet.contains(facetValue.getValue().toString())) {
            newQueryString.append(facet);

            // only append the facet delim if we're not processing the last facet String
            if (index++ != newFacetNumber - 1) {
                newQueryString.append(FACET_DELIM);
            }
        }
    }
    return newQueryString.toString();
}

From source file:org.jahia.taglibs.facet.SetupQueryAndMetadataTag.java

@SuppressWarnings("unchecked")
@Override//from  w  w w  . ja  va2  s. c  om
public int doStartTag() throws JspException {
    try {
        final JCRNodeWrapper currentNode = getCurrentResource().getNode();
        final JCRSessionWrapper session = currentNode.getSession();
        QueryObjectModelFactory factory = session.getWorkspace().getQueryManager().getQOMFactory();
        QOMBuilder qomBuilder = new QOMBuilder(factory, session.getValueFactory());

        String selectorName;
        if (existing == null) {
            // here we assume that if existing is null, then bound component is not of type jnt:query
            String wantedNodeType = "jnt:content";
            if (currentNode.hasProperty("j:type")) {
                wantedNodeType = currentNode.getPropertyAsString("j:type");
            }

            selectorName = wantedNodeType;
            qomBuilder.setSource(factory.selector(wantedNodeType, selectorName));

            // replace the site name in bound component by the one from the render context
            String path = boundComponent.getPath();
            final String siteName = getRenderContext().getSite().getName();
            final int afterSites = "/sites/".length();
            final int afterSite = path.indexOf('/', afterSites + 1);
            if (afterSite > 0 && afterSite < path.length()) {
                String restOfPath = path.substring(afterSite);
                path = "/sites/" + siteName + restOfPath;
            }
            qomBuilder.andConstraint(factory.descendantNode(selectorName, path));
        } else {
            final Selector selector = (Selector) existing.getSource();
            selectorName = selector.getSelectorName();
            qomBuilder.setSource(selector);
            qomBuilder.andConstraint(existing.getConstraint());
        }

        // metadata for display, passed to JSP
        Map<String, ExtendedNodeType> facetValueNodeTypes = (Map<String, ExtendedNodeType>) pageContext
                .getAttribute("facetValueNodeTypes", PageContext.REQUEST_SCOPE);
        Map<String, String> facetLabels = (Map<String, String>) pageContext.getAttribute("facetLabels",
                PageContext.REQUEST_SCOPE);
        Map<String, String> facetValueLabels = (Map<String, String>) pageContext
                .getAttribute("facetValueLabels", PageContext.REQUEST_SCOPE);
        Map<String, String> facetValueFormats = (Map<String, String>) pageContext
                .getAttribute("facetValueFormats", PageContext.REQUEST_SCOPE);
        Map<String, String> facetValueRenderers = (Map<String, String>) pageContext
                .getAttribute("facetValueRenderers", PageContext.REQUEST_SCOPE);

        // specify query for unapplied facets
        final List<JCRNodeWrapper> facets = JCRContentUtils.getNodes(currentNode, "jnt:facet");
        for (JCRNodeWrapper facet : facets) {

            // extra query parameters
            String extra = null;

            // min count
            final String minCount = facet.getPropertyAsString("mincount");

            // field components
            final String field = facet.getPropertyAsString("field");
            final String[] fieldComponents = StringUtils.split(field, ";");
            int i = 0;
            final String facetNodeTypeName = fieldComponents != null && fieldComponents.length > 1
                    ? fieldComponents[i++]
                    : null;
            final String facetPropertyName = fieldComponents != null ? fieldComponents[i] : null;

            // are we dealing with a query facet?
            boolean isQuery = facet.hasProperty("query");

            // query value if it exists
            final String queryProperty = isQuery ? facet.getPropertyAsString("query") : null;

            // key used in metadata maps
            final String metadataKey = isQuery ? queryProperty : facetPropertyName;

            // get node type if we can
            ExtendedNodeType nodeType = null;
            if (StringUtils.isNotEmpty(facetNodeTypeName)) {
                // first check if we don't already have resolved the nodeType to avoid resolving it again
                if (facetValueNodeTypes != null) {
                    nodeType = (ExtendedNodeType) facetValueNodeTypes.get(metadataKey);
                }

                // since we haven't already resolved it, try that now
                if (nodeType == null) {
                    nodeType = NodeTypeRegistry.getInstance().getNodeType(facetNodeTypeName);
                    if (facetValueNodeTypes != null && StringUtils.isNotEmpty(metadataKey)) {
                        facetValueNodeTypes.put(metadataKey, nodeType);
                    }
                }
            }

            // label
            String currentFacetLabel = null;
            // use label property if it exists
            if (facet.hasProperty("label")) {
                currentFacetLabel = facet.getPropertyAsString("label");
            }
            // otherwise try to derive a label from node type and field name
            if (StringUtils.isEmpty(currentFacetLabel) && StringUtils.isNotEmpty(facetNodeTypeName)
                    && StringUtils.isNotEmpty(facetPropertyName)) {
                final String labelKey = facetNodeTypeName.replace(':', '_') + "."
                        + facetPropertyName.replace(':', '_');

                currentFacetLabel = getMessage(labelKey);
            }
            if (facetLabels != null && StringUtils.isNotEmpty(currentFacetLabel)) {
                facetLabels.put(metadataKey, currentFacetLabel);
            }

            // value format
            if (facetValueFormats != null && facet.hasProperty("labelFormat")) {
                facetValueFormats.put(metadataKey, facet.getPropertyAsString("labelFormat"));
            }

            // label renderer
            String labelRenderer = null;
            if (facetValueRenderers != null && facet.hasProperty("labelRenderer")) {
                labelRenderer = facet.getPropertyAsString("labelRenderer");
                facetValueRenderers.put(metadataKey, labelRenderer);
            }

            // value label
            if (facetValueLabels != null && facet.hasProperty("valueLabel")) {
                facetValueLabels.put(metadataKey, facet.getPropertyAsString("valueLabel"));
            }

            // is the current facet applied?
            final ExtendedPropertyDefinition propDef = nodeType != null
                    ? nodeType.getPropertyDefinition(facetPropertyName)
                    : null;
            final boolean isFacetApplied = Functions.isFacetApplied(metadataKey, activeFacets, propDef);

            if (nodeType != null && StringUtils.isNotEmpty(facetPropertyName) && !isFacetApplied) {
                StringBuilder extraBuilder = new StringBuilder();

                // deal with facets with labelRenderers, currently only jnt:dateFacet or jnt:rangeFacet
                String prefix = facet.isNodeType("jnt:dateFacet") ? "date."
                        : (facet.isNodeType("jnt:rangeFacet") ? "range." : "");
                if (StringUtils.isNotEmpty(labelRenderer)) {
                    extraBuilder.append(prefixedNameValuePair(prefix, "labelRenderer", labelRenderer));
                }

                for (ExtendedPropertyDefinition propertyDefinition : Functions.getPropertyDefinitions(facet)) {
                    final String name = propertyDefinition.getName();
                    if (facet.hasProperty(name)) {
                        final JCRPropertyWrapper property = facet.getProperty(name);

                        if (property.isMultiple()) {
                            // if property is multiple append prefixed name value pair to query
                            for (JCRValueWrapper value : property.getValues()) {
                                extraBuilder.append(prefixedNameValuePair(prefix, name, value.getString()));
                            }
                        } else {
                            String value = property.getString();

                            // adjust value for hierarchical facets
                            if (facet.isNodeType("jnt:fieldHierarchicalFacet") && name.equals("prefix")) {
                                final List<KeyValue> active = activeFacets != null
                                        ? this.activeFacets.get(facetPropertyName)
                                        : Collections.<KeyValue>emptyList();
                                if (active == null || active.isEmpty()) {
                                    value = Functions.getIndexPrefixedPath(value,
                                            getRenderContext().getWorkspace());
                                } else {
                                    value = Functions.getDrillDownPrefix(
                                            (String) active.get(active.size() - 1).getKey());
                                }
                            }

                            extraBuilder.append(prefixedNameValuePair(prefix, name, value));
                        }
                    }
                }

                extra = extraBuilder.toString();

            }

            if (isQuery && !isFacetApplied) {
                extra = "&facet.query=" + queryProperty;
            }

            // only add a column if the facet isn't already applied
            if (!isFacetApplied) {
                // key used in the solr query string
                final String key = isQuery ? facet.getName() : facetPropertyName;
                String query = buildQueryString(facetNodeTypeName, key, minCount, extra);
                final String columnPropertyName = StringUtils.isNotEmpty(facetPropertyName) ? facetPropertyName
                        : "rep:facet()";
                qomBuilder.getColumns().add(factory.column(selectorName, columnPropertyName, query));
            }
        }

        // repeat applied facets
        if (activeFacets != null) {
            for (Map.Entry<String, List<KeyValue>> appliedFacet : activeFacets.entrySet()) {
                for (KeyValue keyValue : appliedFacet.getValue()) {
                    final String propertyName = "rep:filter("
                            + Text.escapeIllegalJcrChars(appliedFacet.getKey()) + ")";
                    qomBuilder.andConstraint(factory.fullTextSearch(selectorName, propertyName, factory.literal(
                            qomBuilder.getValueFactory().createValue(keyValue.getValue().toString()))));
                }
            }
        }

        pageContext.setAttribute(var, qomBuilder.createQOM(), PageContext.REQUEST_SCOPE);
    } catch (RepositoryException e) {
        throw new JspException(e);
    }

    return SKIP_BODY;
}

From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java

public String getLabel(IQuestionnaireElement element, Locale locale, String key) {
    KeyValue keyValue = getKeyValue(element, locale, key);
    return keyValue == null ? null : keyValue.getValue();
}

From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java

private Map<Locale, Properties> toLocalePropertiesMap(Questionnaire questionnaire) {
    Map<Locale, Properties> mapLocaleProperties = new HashMap<Locale, Properties>();
    for (Locale locale : getLocales()) {
        Properties properties = new Properties();
        for (Map.Entry<IQuestionnaireElement, ListMultimap<Locale, KeyValue>> entry : getElementLabels()
                .entrySet()) {//from   w w  w .j a  v  a 2  s .c o  m
            IQuestionnaireElement element = entry.getKey();
            List<KeyValue> keyValueList = entry.getValue().get(locale);
            for (KeyValue keyValue : keyValueList) {
                String fullKey = questionnaire.getPropertyKeyProvider().getPropertyKey(element,
                        keyValue.getKey());
                String value = keyValue.getValue();
                properties.setProperty(fullKey, value != null ? value.replaceAll("\n", "<br/>") : "");
            }
        }
        mapLocaleProperties.put(locale, properties);
    }
    return mapLocaleProperties;
}

From source file:org.okj.commons.web.taglib.template.impl.CheckboxTemplate.java

protected String createCheckbox(KeyValue option, int index) {
    StringBuffer sb = new StringBuffer();
    sb.append("<input type=\"checkbox\" ");
    //id/*  w  ww. ja  v  a  2s. c o  m*/
    if (StringUtils.isNotBlank(attribute.getId())) {
        sb.append("id=\"").append(attribute.getId()).append("_").append(index).append("\" ");
    }
    //name
    sb.append("name=\"").append(getIndexName(attribute.getName(), index)).append("\" ");
    //class
    if (StringUtils.isNotBlank(attribute.getStyleClass())) {
        sb.append("class=\"").append(attribute.getStyleClass()).append("\" ");
    }
    sb.append("value=\"").append(option.getValue()).append("\" ");
    //
    if (isChecked(option)) {
        sb.append("checked=\"true\" ");
    }
    sb.append("/>");
    return sb.toString();
}