All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kawanfw.sql.tomcat.util.LinkedProperties Maven / Gradle / Ivy

Go to download

AceQL HTTP is a framework of REST like http APIs that allow to access to remote SQL databases over http from any device that supports http. AceQL HTTP is provided with four client SDK: - The AceQL C# Client SDK allows to wrap the HTTP APIs using Microsoft SQL Server like calls in their code, just like they would for a local database. - The AceQL Java Client SDK allows to wrap the HTTP APIs using JDBC calls in their code, just like they would for a local database. - The AceQL Python Client SDK allows SQL calls to be encoded with standard unmodified DB-API 2.0 syntax

There is a newer version: 12.2
Show newest version
/*
 * Copyright (c)2022 KawanSoft S.A.S. All rights reserved.
 * 
 * Use of this software is governed by the Business Source License included
 * in the LICENSE.TXT file in the project's root directory.
 *
 * Change Date: 2026-11-01
 *
 * On the date above, in accordance with the Business Source License, use
 * of this software will be governed by version 2.0 of the Apache License.
 */
package org.kawanfw.sql.tomcat.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @author Nicolas de Pomereu
 * 
 *         Allows to read a properties with property names ordered on insertion
 *         order passed to constructor. (Just for reading, ordered store is not
 *         supported.)
 */

public class LinkedProperties extends Properties {

    /**
     * Generated serial ID
     */
    private static final long serialVersionUID = 6588861237819163772L;

    /** The ordered set of properties */
    private Set orderedPropNames = new LinkedHashSet();

    /**
     * Constructor
     * 
     * @param orderedPropNames
     *            the ordered properties names
     */
    public LinkedProperties(Set orderedPropNames) {
	this.orderedPropNames = orderedPropNames;
    }

    /**
     * Returns a set of keys in this property list where the key and its
     * corresponding value are strings, including distinct keys in the default
     * property list if a key of the same name has not already been found from
     * the main properties list. Properties whose key or value is not of type
     * String are omitted.
     * 

* The returned set is not backed by the Properties object. Changes * to this Properties are not reflected in the set, or vice versa. * * @return a set of keys in this property list where the key and its * corresponding value are strings, including the keys in the * default property list. * @see java.util.Properties#defaults */ @Override public Set stringPropertyNames() { Set orderedPropNamesNew = new LinkedHashSet(); for (Iterator iterator = orderedPropNames.iterator(); iterator .hasNext();) { String propertyName = (String) iterator.next(); if (super.containsKey(propertyName)) { orderedPropNamesNew.add(propertyName); } } return orderedPropNamesNew; } /* * (non-Javadoc) * * @see java.util.Properties#propertyNames() */ @Override public Enumeration propertyNames() { Set orderedPropNamesNew = new LinkedHashSet(); for (Iterator iterator = orderedPropNames.iterator(); iterator .hasNext();) { String propertyName = (String) iterator.next(); if (super.containsKey(propertyName)) { orderedPropNamesNew.add(propertyName); } } return Collections.enumeration(orderedPropNamesNew); } /* * (non-Javadoc) * * @see java.util.Hashtable#keys() */ @Override public synchronized Enumeration keys() { Set set = this.keySet(); return Collections.enumeration(set); } /* * (non-Javadoc) * * @see java.util.Hashtable#keySet() */ @Override public Set keySet() { Set set = new LinkedHashSet(); for (Iterator iterator = orderedPropNames.iterator(); iterator .hasNext();) { Object obj = (Object) iterator.next(); set.add(obj); } return set; } /** * Returns the properties name in the order of their position in a file. * * @param fileProperties * the file containing the properties * @return a Set of Strings backed by a LinkedHashSet ordererd by the * property position in the file * @throws IOException */ public static Set getLinkedPropertiesName(File fileProperties) throws IOException { Set linkedPropertiesName = new LinkedHashSet(); try (BufferedReader bufferedReader = new BufferedReader( new FileReader(fileProperties));) { String line = null; while ((line = bufferedReader.readLine()) != null) { if (line.isEmpty()) { continue; } if (line.startsWith("#")) { continue; } if (line.startsWith("!")) { continue; } if (!line.contains("=")) { continue; } line = StringUtils.substringBefore(line, "="); line = line.trim(); linkedPropertiesName.add(line); } } return linkedPropertiesName; } }