Example usage for java.util.prefs Preferences MAX_KEY_LENGTH

List of usage examples for java.util.prefs Preferences MAX_KEY_LENGTH

Introduction

In this page you can find the example usage for java.util.prefs Preferences MAX_KEY_LENGTH.

Prototype

int MAX_KEY_LENGTH

To view the source code for java.util.prefs Preferences MAX_KEY_LENGTH.

Click Source Link

Document

Maximum length of string allowed as a key (80 characters).

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Get maximum key length
    int keyMax = Preferences.MAX_KEY_LENGTH;

    // Get maximum value length
    int valueMax = Preferences.MAX_VALUE_LENGTH;

    // Get maximum length of byte array values
    int bytesMax = Preferences.MAX_VALUE_LENGTH * 3 / 4;
}

From source file:com.concursive.connect.config.ApplicationPrefs.java

/**
 * Description of the Method//from  w ww .j ava 2s .co  m
 *
 * @param context Description of the Parameter
 * @return Description of the Return Value
 */
private String retrieveFileLibraryLocation(ServletContext context) {
    String dir = ApplicationPrefs.getRealPath(context);
    try {
        if (dir == null) {
            dir = node;
        }
        // Read from Preferences
        LOG.info("Java preferences key: " + dir);
        Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class);
        // Check "dir" prefs first, based on the installed directory of this webapp
        String fileLibrary = null;
        if (dir.length() <= Preferences.MAX_KEY_LENGTH) {
            fileLibrary = javaPrefs.get(dir, null);
        } else {
            fileLibrary = javaPrefs.get(dir.substring(dir.length() - Preferences.MAX_KEY_LENGTH), null);
        }
        boolean doSave = false;
        // Preferences not found
        if (fileLibrary == null) {
            // Check in the current dir of the webapp for a pointer to the properties
            // NOTE: Some containers return null for getRealPath()
            String realPath = ApplicationPrefs.getRealPath(context);
            if (realPath != null) {
                fileLibrary = realPath + "WEB-INF" + fs + "fileLibrary" + fs;
                doSave = true;
            }
        }
        // See if properties exist
        if (fileLibrary != null) {
            File propertyFile = new File(fileLibrary + "build.properties");
            if (propertyFile.exists()) {
                if (doSave) {
                    saveFileLibraryLocation(dir, fileLibrary);
                }
                return fileLibrary;
            }
        }
    } catch (Exception e) {
        LOG.error("ApplicationPrefs", e);
        e.printStackTrace(System.out);
    }
    return null;
}

From source file:com.concursive.connect.config.ApplicationPrefs.java

/**
 * Save a name/value pair to the Java Preferences store
 *
 * @param instanceName        Description of the Parameter
 * @param fileLibraryLocation Description of the Parameter
 * @return Description of the Return Value
 *//*from   w ww  . ja v  a2s  .  c  o  m*/
public static boolean saveFileLibraryLocation(String instanceName, String fileLibraryLocation) {
    try {
        if (instanceName == null || fileLibraryLocation == null) {
            LOG.error("Invalid parameters: " + instanceName + "=" + fileLibraryLocation);
        }
        Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class);
        if (javaPrefs == null) {
            LOG.error("Couldn't create java preferences for: " + ApplicationPrefs.class);
        }
        if (instanceName.length() <= Preferences.MAX_KEY_LENGTH) {
            javaPrefs.put(instanceName, fileLibraryLocation);
        } else {
            javaPrefs.put(instanceName.substring(instanceName.length() - Preferences.MAX_KEY_LENGTH),
                    fileLibraryLocation);
        }
        javaPrefs.flush();
        return true;
    } catch (Exception e) {
        LOG.error("saveFileLibraryLocation", e);
        e.printStackTrace(System.out);
        return false;
    }
}

From source file:org.kuali.test.ui.base.BaseTable.java

private String getColumnPreferenceKey(int col, String name) {
    StringBuilder retval = new StringBuilder(64);

    retval.append(getConfig().getTableName());
    retval.append(".column.");
    retval.append(getConfig().getPropertyNames()[col]);
    retval.append(".");
    retval.append(name);// w  ww  .j av  a  2  s.co  m

    // do this to handle generated key names that are to long
    // so we do not get an exception
    if (retval.length() > Preferences.MAX_KEY_LENGTH) {
        retval.setLength(0);
        retval.append("");
    }

    return retval.toString();
}

From source file:org.openconcerto.sql.preferences.SQLPreferences.java

static private SQLCreateTable[] getCreateTables(final DBRoot root) throws SQLException {
    final SQLCreateTable createNodeT = new SQLCreateTable(root, PREF_NODE_TABLENAME);
    // don't need ORDER and ARCHIVE
    createNodeT.setPlain(true);/*ww  w.  j a  v  a  2  s . c  o m*/
    createNodeT.addColumn(SQLSyntax.ID_NAME, createNodeT.getSyntax().getPrimaryIDDefinition());
    // cannot use addForeignColumn() since it's a self-reference
    createNodeT.addColumn("ID_PARENT", createNodeT.getSyntax().getIDType() + " NULL");
    createNodeT.addVarCharColumn("NAME", Preferences.MAX_NAME_LENGTH);

    createNodeT.addForeignConstraint("ID_PARENT", new SQLName(createNodeT.getName()), SQLSyntax.ID_NAME);
    createNodeT.addUniqueConstraint("uniqNamePerParent", Arrays.asList("ID_PARENT", "NAME"));

    final SQLCreateTable createValueT = new SQLCreateTable(root, PREF_VALUE_TABLENAME);
    createValueT.setPlain(true);
    createValueT.addColumn("ID_NODE", createValueT.getSyntax().getIDType() + " NOT NULL");
    createValueT.addVarCharColumn("NAME", Preferences.MAX_KEY_LENGTH);
    createValueT.addVarCharColumn("VALUE", Preferences.MAX_VALUE_LENGTH, true);
    // unique name per node
    createValueT.setPrimaryKey("ID_NODE", "NAME");
    createValueT.addForeignConstraint("ID_NODE", new SQLName(createNodeT.getName()), SQLSyntax.ID_NAME);

    return new SQLCreateTable[] { createNodeT, createValueT };
}