Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

In this page you can find the example usage for java.util HashMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:com.android.volley.toolbox.AuthenticationChallengesProofHurlStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);//from  ww w.ja v  a 2 s. c o  m
    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);
    // Initialize HttpResponse with data from the HttpURLConnection.
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);

    /************************/
    /****** WORKAROUND ******/
    int responseCode;

    try {
        // Will throw IOException if server responds with 401.
        responseCode = connection.getResponseCode();
    } catch (IOException e) {
        // You can get the response code after an exception if you call .getResponseCode()
        // a second time on the connection object. This is because the first time you
        // call .getResponseCode() an internal state is set that enables .getResponseCode()
        // to return without throwing an exception.
        responseCode = connection.getResponseCode();
    }
    /************************/

    if (responseCode == -1) {
        // -1 is returned by getResponseCode() if the response code could not be retrieved.
        // Signal to the caller that something was wrong with the connection.
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }
    return response;
}

From source file:org.bpmscript.process.spring.ApplicationContextDefinitionConfigurationLookup.java

/**
 * @see org.bpmscript.process.IProperties#getProperty(java.lang.String, java.lang.String)
 *//* w ww .  ja va  2  s.co m*/
@SuppressWarnings("unchecked")
public IDefinitionConfiguration getDefinitionConfiguration(String definitionName) {
    if (context != null) {
        HashMap<String, IDefinitionConfiguration> beansOfType = new HashMap<String, IDefinitionConfiguration>();
        ApplicationContext temp = context;
        while (temp != null) {
            beansOfType.putAll(temp.getBeansOfType(IDefinitionConfiguration.class));
            temp = temp.getParent();
        }
        Object result = beansOfType.get(prefix + definitionName);
        if (result != null) {
            return (IDefinitionConfiguration) result;
        }
    }
    return new DefinitionConfiguration();
}

From source file:net.mlw.vlh.web.tag.ActionTag.java

/**
 * Make a final map of parameters for url encoder. At first ar added table
 * parameters, then are added tableId with paramName
 * ACTION_TEMP_PARAM_PREFIX, then customParams and finally are added
 * actionParams./*from   w w w .j a v  a2  s.com*/
 */
private HashMap getAllParameters(ValueListSpaceTag rootTag) {
    HashMap map = new HashMap();
    if (rootTag.getTableInfo().getParameters() != null) {
        map.putAll(rootTag.getTableInfo().getParameters());
    }
    //        if (rootTag.getTableInfo().getId() != TableInfo.DEFAULT_ID) {
    //            map.put(ACTION_TEMP_PARAM_PREFIX, rootTag.getTableInfo().getId());
    //        }
    if (customParameters != null) {
        map.putAll(customParameters);
    }

    //need to be last to overwrite the same params
    map.putAll(actionParameters);
    return map;
}

From source file:com.raise.orgs.impl.AbstractNativeQuery.java

private Map<String, Object> getParameterMap() {
    HashMap<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("sql", sqlStatement);
    parameterMap.putAll(parameters);
    return parameterMap;
}

From source file:org.xchain.namespaces.jsl.BaseTestSaxEvents.java

public void assertStartPrefixMappings(Iterator<SaxEventRecorder.SaxEvent> eventIterator,
        Map<String, String> prefixMappings, boolean allowOthers) throws Exception {
    // make sure that the event is there and of the proper type.
    assertTrue("There is not a start prefix event.", eventIterator.hasNext());
    SaxEventRecorder.SaxEvent event = eventIterator.next();
    assertEquals("There was not a start prefix mappings event.",
            SaxEventRecorder.EventType.START_PREFIX_MAPPING, event.getType());

    HashMap<String, String> eventMapping = new HashMap<String, String>();
    eventMapping.putAll(event.getPrefixMapping());

    for (Map.Entry<String, String> entry : prefixMappings.entrySet()) {
        String definedNamespace = eventMapping.remove(entry.getKey());
        assertEquals("The namespace for prefix " + entry.getKey() + " has the wrong definition.",
                entry.getValue(), definedNamespace);
    }/*from   w  w  w.  j  a v a 2s  . c  o  m*/

    if (!allowOthers && !eventMapping.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        sb.append("Extra prefixes found on element:");
        for (Map.Entry<String, String> entry : eventMapping.entrySet()) {
            sb.append(" xmlns:").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
        }
        fail(sb.toString());
    }
}

From source file:org.myframe.http.HttpConnectStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);/*  w w w. j ava 2 s  .  co m*/

    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);

    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());

    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            String value = "";
            for (String v : header.getValue()) {
                value += (v + "; ");
            }
            Header h = new BasicHeader(header.getKey(), value);
            response.addHeader(h);
        }
    }
    return response;
}

From source file:contrail.correct.InvokeQuakeForSingles.java

protected Map<String, ParameterDefinition> createParameterDefinitions() {
    HashMap<String, ParameterDefinition> defs = new HashMap<String, ParameterDefinition>();
    defs.putAll(super.createParameterDefinitions());
    ParameterDefinition quakeBiary = new ParameterDefinition("quake_binary", "any" + "Quake directory path",
            String.class, new String(""));
    ParameterDefinition bithashpath = new ParameterDefinition("bithashpath", "any" + "The path of bithash",
            String.class, new String(""));
    ParameterDefinition K = new ParameterDefinition("K", "any" + "Kmer length", Long.class, 0);
    for (ParameterDefinition def : new ParameterDefinition[] { quakeBiary, bithashpath, K }) {
        defs.put(def.getName(), def);/*from   w ww  .j a  va2 s.co m*/
    }
    for (ParameterDefinition def : ContrailParameters.getInputOutputPathOptions()) {
        defs.put(def.getName(), def);
    }
    return Collections.unmodifiableMap(defs);
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.QueryValuesLoader.java

/**
 * Create new Map with specified parameters, add only those which are used in query, find missing parameters and assign value Null to them.
 * This is done because we indicate Nothing selection in single select control as absence of parameter in map,
 * but QueryManipulator sets query to empty string and Executor throws exception if parameter is absent,
 * so we set Null as most suitable value as yet.
 *
 * @param query Query/*from w w  w .  ja v a  2  s  . c o m*/
 * @param parameters Map&lt;String, Object&gt;
 * @return Map&lt;String, Object&gt; copy of map, where missing parameters filled with Null values.
 */
protected Map<String, Object> filterAndFillMissingQueryParameters(Query query, Map<String, Object> parameters,
        Map<String, Object> domainSchemaParameters) {
    HashMap<String, Object> parametersWithSchema = new HashMap<String, Object>();
    parametersWithSchema.putAll(parameters);
    parametersWithSchema.putAll(domainSchemaParameters);
    Set<String> queryParameterNames = filterResolver.getParameterNames(query.getSql(), parametersWithSchema);
    HashMap<String, Object> resolvedParameters = new HashMap<String, Object>();
    for (String queryParameterName : queryParameterNames) {
        // If parameter is missing, set Null.
        resolvedParameters.put(queryParameterName, parameters.get(queryParameterName));
    }
    resolvedParameters.putAll(domainSchemaParameters);
    return resolvedParameters;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.NavigationController.java

Map<String, Object> getValues(Individual ind, OntModel displayOntModel, OntModel assertionModel,
        Map<String, Object> baseValues) {
    if (ind == null)
        return Collections.emptyMap();

    /* Figure out what ValueFactories are specified in the display ontology for this individual. */
    Set<ValueFactory> valueFactories = new HashSet<ValueFactory>();
    displayOntModel.enterCriticalSection(Model.READ);
    StmtIterator stmts = ind.listProperties(DisplayVocabulary.REQUIRES_VALUES);
    try {//from  w  w w.  j  a  va2 s  .  c  om
        while (stmts.hasNext()) {
            Statement stmt = stmts.nextStatement();
            RDFNode obj = stmt.getObject();
            valueFactories.addAll(getValueFactory(obj, displayOntModel));
        }
    } finally {
        stmts.close();
        displayOntModel.leaveCriticalSection();
    }

    /* Get values from the ValueFactories. */
    HashMap<String, Object> values = new HashMap<String, Object>();
    values.putAll(baseValues);
    for (ValueFactory vf : valueFactories) {
        values.putAll(vf.getValues(assertionModel, values));
    }
    return values;
}

From source file:com.scut.easyfe.network.kjFrame.http.HttpConnectStack.java

@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
        throws IOException {
    String url = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);//from ww w . ja va  2  s.  c  o  m

    if (mUrlRewriter != null) {
        String rewritten = mUrlRewriter.rewriteUrl(url);
        if (rewritten == null) {
            throw new IOException("URL blocked by rewriter: " + url);
        }
        url = rewritten;
    }
    URL parsedUrl = new URL(url);
    HttpURLConnection connection = openConnection(parsedUrl, request);
    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    setConnectionParametersForRequest(connection, request);

    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    int responseCode;
    try {
        responseCode = connection.getResponseCode();
    } catch (IOException e) {
        // 4.1.x/4.2.x/4.3.x ? (WWW-Authenticate: Basic realm="XXX")
        // ??401
        // java.io.IOException: No authentication challenges found
        // ?getResponseCode??
        responseCode = connection.getResponseCode();
    }
    if (responseCode == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }
    StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(),
            connection.getResponseMessage());

    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromConnection(connection));
    for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            String value = "";
            for (String v : header.getValue()) {
                value += (v + "; ");
            }
            Header h = new BasicHeader(header.getKey(), value);
            response.addHeader(h);
        }
    }
    return response;
}