Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getString.

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.salesmanager.core.util.FileUtil.java

/**
 * Absolute file path// ww w .j a  v  a 2  s .  co m
 * @return
 */
public static String getSiteMapFilePath() {
    Configuration config = PropertiesUtil.getConfiguration();
    return new StringBuilder().append(getMediaPath()).append(config.getString("core.sitemap.filefolder"))
            .toString();
}

From source file:com.salesmanager.core.util.FileUtil.java

/**
 * returns original image//from www. j a v  a  2s  . c  o  m
 * 
 * @param merchantId
 * @param productImage
 * @return
 */
public static String getProductImagePath(int merchantId, String productImage) {
    if (StringUtils.isBlank(productImage)) {
        return "";
    } else {

        Configuration config = PropertiesUtil.getConfiguration();
        return new StringBuffer().append(IMAGE_PATH).append(config.getString("core.products.images.uri"))
                .append("/").append(merchantId).append("/").append(productImage).toString();
    }
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getSmallProductImagePath(int merchantId, String productImage) {

    if (StringUtils.isBlank(productImage)) {
        return "";
    } else {/*from  ww  w. j av  a 2  s.c o  m*/
        Configuration config = PropertiesUtil.getConfiguration();
        return new StringBuffer().append(IMAGE_PATH).append(config.getString("core.products.images.uri"))
                .append("/").append(merchantId).append("/")
                .append(config.getString("core.product.image.small.prefix")).append("-").append(productImage)
                .toString();
    }
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getLargeProductImagePath(int merchantId, String productImage) {
    if (StringUtils.isBlank(productImage)) {
        return "";
    } else {//  w  ww . j a v a  2 s . c  o m

        Configuration config = PropertiesUtil.getConfiguration();

        return new StringBuffer().append(IMAGE_PATH).append(config.getString("core.products.images.uri"))
                .append("/").append(merchantId).append("/")
                .append(config.getString("core.product.image.large.prefix")).append("-").append(productImage)
                .toString();
    }
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getSiteMapUrl() {
    Configuration config = PropertiesUtil.getConfiguration();
    StringBuilder builder = new StringBuilder().append(IMAGE_PATH).append(config.getString("core.sitemap.uri"))
            .append("/");
    return builder.toString();
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getBinServerUrl() {
    Configuration config = PropertiesUtil.getConfiguration();
    StringBuilder builder = new StringBuilder().append(IMAGE_PATH).append(config.getString("core.bin.uri"))
            .append("/");
    return builder.toString();
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getBinServerUrl(int merchantId, boolean isImage) {
    Configuration config = PropertiesUtil.getConfiguration();
    StringBuilder builder = new StringBuilder().append(IMAGE_PATH).append(config.getString("core.bin.uri"))
            .append("/").append((isImage ? "images" : "flash")).append("/").append(merchantId).append("/");
    return builder.toString();
}

From source file:com.salesmanager.core.util.FileUtil.java

/**
 * getFileTreeBinPath returns the Path to the bin folder of the merchant(specific to
 * merchantId) and also according to the type i.e. if isImage is true then
 * it gives the image path of that particular merchant else it gives the
 * shock-wave path./*from  ww w.ja v a 2 s  . c o  m*/
 * @param context
 *            ServletContext
 * @param merchantId
 *            int
 * @param isImage
 *            boolean
 * @return String path
 */
public static String getFileTreeBinPath() {
    Configuration config = PropertiesUtil.getConfiguration();
    StringBuilder builder = new StringBuilder().append(getMediaPath())
            .append(config.getString("core.bin.filetree.filefolder"));
    return builder.toString();
}

From source file:com.migo.utils.GenUtils.java

/**
 * ??/*  w w w  . ja v a2s .c o  m*/
 */
public static void generatorCode(Map<String, String> table, List<Map<String, String>> columns,
        ZipOutputStream zip) {
    //??
    Configuration config = getConfig();

    //?
    TableEntity tableEntity = new TableEntity();
    tableEntity.setTableName(table.get("tableName"));
    tableEntity.setComments(table.get("tableComment"));
    //????Java??
    String className = tableToJava(tableEntity.getTableName(), config.getString("tablePrefix"));
    tableEntity.setClassName(className);
    tableEntity.setClassname(StringUtils.uncapitalize(className));

    //?
    List<ColumnEntity> columsList = new ArrayList<>();
    for (Map<String, String> column : columns) {
        ColumnEntity columnEntity = new ColumnEntity();
        columnEntity.setColumnName(column.get("columnName"));
        columnEntity.setDataType(column.get("dataType"));
        columnEntity.setComments(column.get("columnComment"));
        columnEntity.setExtra(column.get("extra"));

        //????Java??
        String attrName = columnToJava(columnEntity.getColumnName());
        columnEntity.setAttrName(attrName);
        columnEntity.setAttrname(StringUtils.uncapitalize(attrName));

        //???Java
        String attrType = config.getString(columnEntity.getDataType(), "unknowType");
        columnEntity.setAttrType(attrType);

        //?
        if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null) {
            tableEntity.setPk(columnEntity);
        }

        columsList.add(columnEntity);
    }
    tableEntity.setColumns(columsList);

    //
    if (tableEntity.getPk() == null) {
        tableEntity.setPk(tableEntity.getColumns().get(0));
    }

    //velocity?
    Properties prop = new Properties();
    prop.put("file.resource.loader.class",
            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    Velocity.init(prop);

    //???
    Map<String, Object> map = new HashMap<>();
    map.put("tableName", tableEntity.getTableName());
    map.put("comments", tableEntity.getComments());
    map.put("pk", tableEntity.getPk());
    map.put("className", tableEntity.getClassName());
    map.put("classname", tableEntity.getClassname());
    map.put("pathName", tableEntity.getClassname().toLowerCase());
    map.put("columns", tableEntity.getColumns());
    map.put("package", config.getString("package"));
    map.put("author", config.getString("author"));
    map.put("email", config.getString("email"));
    map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
    VelocityContext context = new VelocityContext(map);

    //??
    List<String> templates = getTemplates();
    for (String template : templates) {
        //?
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, "UTF-8");
        tpl.merge(context, sw);

        try {
            //zip
            zip.putNextEntry(new ZipEntry(
                    getFileName(template, tableEntity.getClassName(), config.getString("package"))));
            IOUtils.write(sw.toString(), zip, "UTF-8");
            IOUtils.closeQuietly(sw);
            zip.closeEntry();
        } catch (IOException e) {
            throw new RRException("???" + tableEntity.getTableName(), e);
        }
    }
}

From source file:com.cisco.oss.foundation.message.RabbitMQMessagingFactory.java

static void connect() {
    try {/*from   w ww.  ja  v  a2 s . c o m*/
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setAutomaticRecoveryEnabled(true);
        connectionFactory.setTopologyRecoveryEnabled(true);

        Configuration configuration = ConfigurationFactory.getConfiguration();
        Configuration subsetBase = configuration.subset("service.rabbitmq");
        Configuration subsetSecurity = subsetBase.subset("security");

        int requestHeartbeat = subsetBase.getInt("requestHeartbeat", 10);
        connectionFactory.setRequestedHeartbeat(requestHeartbeat);

        String userName = subsetSecurity.getString("userName");
        String password = subsetSecurity.getString("password");
        boolean isEnabled = subsetSecurity.getBoolean("isEnabled");

        final Map<String, Map<String, String>> serverConnections = ConfigUtil
                .parseComplexArrayStructure("service.rabbitmq.connections");
        final ArrayList<String> serverConnectionKeys = Lists.newArrayList(serverConnections.keySet());
        Collections.sort(serverConnectionKeys);

        if (isEnabled) {
            connectionFactory.setUsername(userName);
            connectionFactory.setPassword(password);

        }

        List<Address> addresses = new ArrayList<>(5);

        for (String serverConnectionKey : serverConnectionKeys) {

            Map<String, String> serverConnection = serverConnections.get(serverConnectionKey);

            String host = serverConnection.get("host");
            int port = Integer.parseInt(serverConnection.get("port"));
            addresses.add(new Address(host, port));
            //              connectionFactory.setHost(host);
            //              connectionFactory.setPort(Integer.parseInt(port));
        }
        Address[] addrs = new Address[0];
        connection = connectionFactory.newConnection(addresses.toArray(addrs));
        connection.addBlockedListener(new BlockedListener() {
            public void handleBlocked(String reason) throws IOException {
                LOGGER.error("RabbitMQ connection is now blocked. Port: {}, Reason: {}", connection.getPort(),
                        reason);
                IS_BLOCKED.set(true);
            }

            public void handleUnblocked() throws IOException {
                LOGGER.info("RabbitMQ connection is now un-blocked. Port: {}", connection.getPort());
                IS_BLOCKED.set(false);
            }
        });

        connection.addShutdownListener(new ShutdownListener() {
            @Override
            public void shutdownCompleted(ShutdownSignalException cause) {
                LOGGER.error("Connection shutdown detected. Reason: {}", cause.toString(), cause);
            }
        });

        IS_CONNECTED.set(true);
        INIT_LATCH.countDown();

    } catch (Exception e) {
        LOGGER.error("can't create RabbitMQ Connection: {}", e, e);
        //            triggerReconnectThread();
        throw new QueueException(e);
    }
}