Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shindig.config;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.io.IOUtils;
import org.apache.shindig.common.logging.i18n.MessageKeys;
import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.config.ContainerConfig.Transaction;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A class to build container configurations from JSON notation.
*
* See config/container.js for an example configuration.
*
* We use a cascading model, so you only have to specify attributes in your
* config that you actually want to change.
*
* String values may use expressions. The variable context defaults to the
* 'current' container, but parent values may be accessed through the special
* "parent" property.
*/
public class JsonContainerConfigLoader {
private static final String classname = JsonContainerConfigLoader.class.getName();
private static final Logger LOG = Logger.getLogger(classname, MessageKeys.MESSAGES);
private static final Splitter CRLF_SPLITTER = Splitter.onPattern("[\r\n]+");
public static final char FILE_SEPARATOR = ',';
public static final String SERVER_PORT = "SERVER_PORT";
public static final String SERVER_HOST = "SERVER_HOST";
public static final String CONTEXT_ROOT = "CONTEXT_ROOT";
private JsonContainerConfigLoader() {
}
/**
* Creates a transaction to append the contents of one or more files or
* resources to an existing configuration.
*
* @param containers The comma-separated list of files or resources to load
* the container configurations from.
* @param host The hostname where Shindig is running.
* @param port The port number where Shindig is receiving requests.
* @param contextRoot contextRoot where Shindig module is deployed
* @param containerConfig The container configuration to add the contents of
* the file to.
* @return A transaction to add the new containers to the configuration.
* @throws ContainerConfigException If there was a problem reading the files.
*/
public static Transaction getTransactionFromFile(
String containers, String host, String port, String contextRoot,ContainerConfig containerConfig)
throws ContainerConfigException {
return addToTransactionFromFile(containers, host, port, contextRoot,containerConfig.newTransaction());
}
/**
* Appends the contents of one or more files or resources to an transaction.
*
* @param containers The comma-separated list of files or resources to load
* the container configurations from.
* @param host The hostname where Shindig is running.
* @param port The port number where Shindig is receiving requests.
* @param transaction The transaction to add the contents of the file to.
* @return The transaction, to allow chaining.
* @throws ContainerConfigException If there was a problem reading the files.
*/
public static Transaction addToTransactionFromFile(
String containers, String host, String port, String contextRoot, Transaction transaction)
throws ContainerConfigException {
List