Example usage for java.util.prefs Preferences systemNodeForPackage

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

Introduction

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

Prototype

public static Preferences systemNodeForPackage(Class<?> c) 

Source Link

Document

Returns the preference node from the system preference tree that is associated (by convention) with the specified class's package.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // System preference nodes

    // Use a Class
    Preferences prefs = Preferences.systemNodeForPackage(java.lang.String.class);

    // Use an absolute path
    prefs = Preferences.systemRoot().node("/java/lang/String");

    // Use a relative path
    prefs = Preferences.systemRoot().node("/javax/swing");
    prefs = prefs.node("text/html");

    // User preference nodes

    // Use a class
    prefs = Preferences.userNodeForPackage(Main.class);

    // Use an absolute path
    prefs = Preferences.userRoot().node("/com/mycompany");

    // Use a relative path
    prefs = Preferences.userRoot().node("/javax/swing");
    prefs = prefs.node("text/html");
}

From source file:ar.com.init.agros.license.LicenseVerifier.java

public LicenseParam createLicenseParam() {
    final KeyStoreParam publicKeyStoreParam = new KeyStoreParam() {

        @Override//from   www .j  a  v a  2 s  .  c  om
        public InputStream getStream() throws IOException {
            final String resourceName = PUBLIC_KEYS_FILE;
            final InputStream in = getClass().getClassLoader().getResourceAsStream(resourceName);
            if (in == null) {
                throw new FileNotFoundException(resourceName);
            }
            return in;
        }

        @Override
        public String getAlias() {
            return new ObfuscatedString(
                    new long[] { 0x7EA563909082584BL, 0xED94506C09E16A28L, 0x80F968E843E57655L })
                            .toString(); /* => "osirisPublicCert" */
        }

        @Override
        public String getStorePwd() {
            return new ObfuscatedString(
                    new long[] { 0xC579552F883B2754L, 0x4CA65537938F47EAL, 0x487BCB3B0F3ACECBL })
                            .toString(); /* => "rnh7659wS3AK8Gz" */
        }

        @Override
        public String getKeyPwd() {
            // These parameters are not used to create any licenses.
            // Therefore there should never be a private key in the keystore
            // entry. To enforce this policy, we return null here.
            return null; // causes failure if private key is found in this entry
        }
    };

    final CipherParam cipherParam = new CipherParam() {

        @Override
        public String getKeyPwd() {
            return getInstance().generateUniqueKey();
        }
    };

    return new LicenseParam() {

        @Override
        public String getSubject() {
            return PRODUCT_SUBJECT;
        }

        @Override
        public Preferences getPreferences() {
            return Preferences.systemNodeForPackage(Application.class);
        }

        @Override
        public KeyStoreParam getKeyStoreParam() {
            return publicKeyStoreParam;
        }

        @Override
        public CipherParam getCipherParam() {
            return cipherParam;
        }
    };
}

From source file:de.elomagic.carafile.client.CaraCloud.java

private List<Path> checkLocalFolder(final Path basePath) throws IOException {
    Preferences preferences = Preferences.systemNodeForPackage(getClass());
    final long lastScanMillis = preferences.getLong("lastScan", 0);

    final List<Path> changedPathList = getLocalChangeList(basePath, lastScanMillis);

    for (Path path : basePath) {
        // xxx/*from   w  w  w .  j  a  v a 2s. c o m*/
    }

    return changedPathList;
}

From source file:com.delcyon.capo.Configuration.java

@SuppressWarnings({ "unchecked", "static-access" })
public Configuration(String... programArgs) throws Exception {

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilder = documentBuilderFactory.newDocumentBuilder();

    options = new Options();
    // the enum this is a little complicated, but it gives us a nice
    // centralized place to put all of the system parameters
    // and lets us iterate of the list of options and preferences
    PREFERENCE[] preferences = PREFERENCE.values();
    for (PREFERENCE preference : preferences) {
        // not the most elegant, but there is no default constructor, but
        // the has arguments value is always there
        OptionBuilder optionBuilder = OptionBuilder.hasArg(preference.hasArgument);
        if (preference.hasArgument == true) {
            String[] argNames = preference.arguments;
            for (String argName : argNames) {
                optionBuilder = optionBuilder.withArgName(argName);
            }//from w ww .  j av a2  s.co  m
        }

        optionBuilder = optionBuilder.withDescription(preference.getDescription());
        optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
        options.addOption(optionBuilder.create(preference.getOption()));

        preferenceHashMap.put(preference.toString(), preference);
    }

    //add dynamic options

    Set<String> preferenceProvidersSet = CapoApplication.getAnnotationMap()
            .get(PreferenceProvider.class.getCanonicalName());
    if (preferenceProvidersSet != null) {
        for (String className : preferenceProvidersSet) {
            Class preferenceClass = Class.forName(className).getAnnotation(PreferenceProvider.class)
                    .preferences();
            if (preferenceClass.isEnum()) {
                Object[] enumObjects = preferenceClass.getEnumConstants();
                for (Object enumObject : enumObjects) {

                    Preference preference = (Preference) enumObject;
                    //filter out any preferences that don't belong on this server or client.
                    if (preference.getLocation() != Location.BOTH) {
                        if (CapoApplication.isServer() == true && preference.getLocation() == Location.CLIENT) {
                            continue;
                        } else if (CapoApplication.isServer() == false
                                && preference.getLocation() == Location.SERVER) {
                            continue;
                        }
                    }
                    preferenceHashMap.put(preference.toString(), preference);
                    boolean hasArgument = false;
                    if (preference.getArguments() == null || preference.getArguments().length == 0) {
                        hasArgument = false;
                    } else {
                        hasArgument = true;
                    }

                    OptionBuilder optionBuilder = OptionBuilder.hasArg(hasArgument);
                    if (hasArgument == true) {
                        String[] argNames = preference.getArguments();
                        for (String argName : argNames) {
                            optionBuilder = optionBuilder.withArgName(argName);
                        }
                    }

                    optionBuilder = optionBuilder.withDescription(preference.getDescription());
                    optionBuilder = optionBuilder.withLongOpt(preference.getLongOption());
                    options.addOption(optionBuilder.create(preference.getOption()));
                }

            }
        }
    }

    // create parser
    CommandLineParser commandLineParser = new GnuParser();
    this.commandLine = commandLineParser.parse(options, programArgs);

    Preferences systemPreferences = Preferences
            .systemNodeForPackage(CapoApplication.getApplication().getClass());
    String capoDirString = null;
    while (true) {
        capoDirString = systemPreferences.get(PREFERENCE.CAPO_DIR.longOption, null);
        if (capoDirString == null) {

            systemPreferences.put(PREFERENCE.CAPO_DIR.longOption, PREFERENCE.CAPO_DIR.defaultValue);
            capoDirString = PREFERENCE.CAPO_DIR.defaultValue;
            try {
                systemPreferences.sync();
            } catch (BackingStoreException e) {
                //e.printStackTrace();            
                if (systemPreferences.isUserNode() == false) {
                    System.err.println("Problem with System preferences, trying user's");
                    systemPreferences = Preferences
                            .userNodeForPackage(CapoApplication.getApplication().getClass());
                    continue;
                } else //just bail out
                {
                    throw e;
                }

            }
        }
        break;
    }

    disableAutoSync = hasOption(PREFERENCE.DISABLE_CONFIG_AUTOSYNC);

    File capoDirFile = new File(capoDirString);
    if (capoDirFile.exists() == false) {
        if (disableAutoSync == false) {
            capoDirFile.mkdirs();
        }
    }
    File configDir = new File(capoDirFile, PREFERENCE.CONFIG_DIR.defaultValue);
    if (configDir.exists() == false) {
        if (disableAutoSync == false) {
            configDir.mkdirs();
        }
    }

    if (disableAutoSync == false) {
        capoConfigFile = new File(configDir, CONFIG_FILENAME);
        if (capoConfigFile.exists() == false) {

            Document configDocument = CapoApplication.getDefaultDocument("config.xml");

            FileOutputStream configFileOutputStream = new FileOutputStream(capoConfigFile);
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(new DOMSource(configDocument), new StreamResult(configFileOutputStream));
            configFileOutputStream.close();
        }

        configDocument = documentBuilder.parse(capoConfigFile);
    } else //going memory only, because of disabled auto sync
    {
        configDocument = CapoApplication.getDefaultDocument("config.xml");
    }
    if (configDocument instanceof CDocument) {
        ((CDocument) configDocument).setSilenceEvents(true);
    }
    loadPreferences();
    preferenceValueHashMap.put(PREFERENCE.CAPO_DIR.longOption, capoDirString);
    //print out preferences
    //this also has the effect of persisting all of the default values if a values doesn't already exist
    for (PREFERENCE preference : preferences) {
        if (getValue(preference) != null) {
            CapoApplication.logger.log(Level.CONFIG, preference.longOption + "='" + getValue(preference) + "'");
        }
    }

    CapoApplication.logger.setLevel(Level.parse(getValue(PREFERENCE.LOGGING_LEVEL)));
}

From source file:org.LexGrid.LexBIG.gui.LB_GUI.java

License:asdf

private void setSizeFromPreviousRun() {
    Preferences p = Preferences.systemNodeForPackage(this.getClass());
    int height = p.getInt("console_height", -1);
    int width = p.getInt("console_width", -1);
    if (height < 100 || width < 100) {
        shell_.setMaximized(true);//w  w  w .  j a v  a2 s . c o  m
        return;
    }

    shell_.setSize(width, height);

    int locX = p.getInt("console_loc_x", 0);
    int locY = p.getInt("console_loc_y", 0);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    if (locX < 0 || locX > d.width - 200) {
        locX = 0;
    }
    if (locY < 0 || locY > d.height - 150) {
        locY = 0;
    }
    shell_.setLocation(locX, locY);
}

From source file:org.LexGrid.LexBIG.gui.LB_GUI.java

License:asdf

private void init() throws LBInvocationException {
    try {//  www .j  ava 2  s .c om
        logViewer_ = new LogViewer(shell_);
    } catch (Exception e1) {
        log.error("There was a problem starting the log viewer", e1);
        System.err.println(e1);
    }
    codeSets = new ArrayList<CodeSet>();

    shell_.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            /*
             * Save the size and location of the main window.
             */
            int width = shell_.getSize().x;
            int height = shell_.getSize().y;
            int locX = shell_.getLocation().x;
            int locY = shell_.getLocation().y;

            Preferences p = Preferences.systemNodeForPackage(LB_GUI.this.getClass());
            p.putInt("console_width", width);
            p.putInt("console_height", height);
            p.putInt("console_loc_x", locX);
            p.putInt("console_loc_y", locY);
        }
    });
    GridLayout layout = new GridLayout(1, true);
    shell_.setLayout(layout);

    shell_.setImage(new Image(shell_.getDisplay(), this.getClass().getResourceAsStream("/icons/icon.gif")));

    errorHandler = new DialogHandler(shell_);

    SashForm topBottom = new SashForm(shell_, SWT.VERTICAL);
    topBottom.SASH_WIDTH = 5;
    topBottom.setLayout(new GridLayout());
    GridData gd = new GridData(GridData.FILL_BOTH);
    topBottom.setLayoutData(gd);
    topBottom.setVisible(true);

    // topBottom.setWeights(new int[] {5, 5});
    buildCodeSystemComposite(topBottom);

    SashForm leftRightBottom = new SashForm(topBottom, SWT.HORIZONTAL);
    leftRightBottom.SASH_WIDTH = 5;

    buildSetComposite(leftRightBottom);
    buildRestrictionComposite(leftRightBottom);

    buildMenus();

    PropertiesUtility.systemVariable = "LG_CONFIG_FILE";
    String filePath = PropertiesUtility.locatePropFile("config/" + SystemVariables.CONFIG_FILE_NAME,
            SystemResourceService.class.getName());
    if (filePath != null) {
        File file = new File(filePath);
        if (file.exists()) {
            refreshCodingSchemeList();
            try {
                PropertiesUtility.propertiesLocationKey = "CONFIG_FILE_LOCATION";
                currentProperties_ = PropertiesUtility.loadPropertiesFromFileOrURL(file.getAbsolutePath());
            } catch (IOException e) {
                log.error("Unexpected Error", e);
            }
        }
    } else {
        new Configure(LB_GUI.this, currentProperties_);
    }

}

From source file:org.LexGrid.LexBIG.gui.LB_VSD_GUI.java

private void init() throws LBInvocationException {
    try {/*from www.  j  a  va2 s  . c o  m*/
        logViewer_ = new LogViewer(shell_);
    } catch (Exception e1) {
        log.error("There was a problem starting the log viewer", e1);
        System.err.println(e1);
    }
    codeSets = new ArrayList<CodeSet>();

    shell_.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            /*
             * Save the size and location of the main window.
             */
            int width = shell_.getSize().x;
            int height = shell_.getSize().y;
            int locX = shell_.getLocation().x;
            int locY = shell_.getLocation().y;

            Preferences p = Preferences.systemNodeForPackage(LB_VSD_GUI.this.getClass());
            p.putInt("console_width", width);
            p.putInt("console_height", height);
            p.putInt("console_loc_x", locX);
            p.putInt("console_loc_y", locY);
        }
    });
    GridLayout layout = new GridLayout(1, true);
    shell_.setLayout(layout);

    shell_.setImage(new Image(shell_.getDisplay(), this.getClass().getResourceAsStream("/icons/icon.gif")));

    errorHandler = new DialogHandler(shell_);

    SashForm topBottom = new SashForm(shell_, SWT.VERTICAL);
    topBottom.SASH_WIDTH = 5;
    topBottom.setLayout(new GridLayout());
    GridData gd = new GridData(GridData.FILL_BOTH);
    topBottom.setLayoutData(gd);
    topBottom.setVisible(true);

    buildValueSetDefComposite(topBottom);

    SashForm leftRightBottom = new SashForm(topBottom, SWT.HORIZONTAL);
    leftRightBottom.SASH_WIDTH = 5;
    gd = new GridData(GridData.FILL_BOTH);
    leftRightBottom.setLayoutData(gd);
    leftRightBottom.setVisible(true);
    buildPickListComposite(leftRightBottom);

    buildMenus();

    PropertiesUtility.systemVariable = "LG_CONFIG_FILE";
    String filePath = PropertiesUtility.locatePropFile("config/" + SystemVariables.CONFIG_FILE_NAME,
            SystemResourceService.class.getName());
    if (filePath != null) {
        File file = new File(filePath);
        if (file.exists()) {
            refreshValueSetDefList();
            try {
                PropertiesUtility.propertiesLocationKey = "CONFIG_FILE_LOCATION";
                currentProperties_ = PropertiesUtility.loadPropertiesFromFileOrURL(file.getAbsolutePath());
            } catch (IOException e) {
                log.error("Unexpected Error", e);
            }
        }
    } else {
        new Configure(LB_VSD_GUI.this, currentProperties_);
    }

}

From source file:org.LexGrid.LexBIG.gui.ValueSetDefinitionDetails.java

public ValueSetDefinitionDetails(LB_VSD_GUI lb_vsd_gui, Shell parent, ValueSetDefinition vd) {
    this.lb_vsd_gui_ = lb_vsd_gui;
    vd_ = vd;//ww  w. ja v  a2  s.co m
    shell_ = new Shell(parent.getDisplay());

    Device device = Display.getCurrent();
    redColor_ = new Color(device, 255, 0, 0);

    errorHandler = new DialogHandler(shell_);
    shell_.setText("Value Set Definition Details " + Constants.version);
    shell_.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            /*
             * Save the size and location of the main window.
             */
            int width = shell_.getSize().x;
            int height = shell_.getSize().y;
            int locX = shell_.getLocation().x;
            int locY = shell_.getLocation().y;

            Preferences p = Preferences.systemNodeForPackage(this.getClass());
            p.putInt("console_width", width);
            p.putInt("console_height", height);
            p.putInt("console_loc_x", locX);
            p.putInt("console_loc_y", locY);
        }
    });

    GridLayout layout = new GridLayout(1, true);
    shell_.setLayout(layout);

    shell_.setImage(new Image(shell_.getDisplay(), this.getClass().getResourceAsStream("/icons/icon.gif")));

    SashForm topBottom = new SashForm(shell_, SWT.VERTICAL);
    topBottom.SASH_WIDTH = 5;
    topBottom.setLayout(new GridLayout());
    GridData gd = new GridData(GridData.FILL_BOTH);
    topBottom.setLayoutData(gd);
    topBottom.setVisible(true);

    buildValueSetsComposite(topBottom);

    SashForm leftRightBottom = new SashForm(topBottom, SWT.HORIZONTAL);
    leftRightBottom.SASH_WIDTH = 5;
    buildDefinitionEntryConposite(leftRightBottom);

    buildMenus();

    if (vd != null) {
        disableTextFields();
        enableRefButtons();
        enablePropertyButtons();
    } else {
        resolveButton_.setEnabled(false);
        enableTextFields();
        disableRefButtons();
        disablePropertyButtons();
    }

    shell_.open();
}

From source file:org.LexGrid.LexBIG.gui.valueSetsView.PropertyView.java

public PropertyView(LB_VSD_GUI lb_vsd_gui, ValueSetDefinitionDetails vsdDetails, Shell parent,
        ValueSetDefinition vd, Property property) {
    this.lb_vsd_gui_ = lb_vsd_gui;

    property_ = property;/*  ww  w.  j  a v a 2  s.com*/
    shell_ = new Shell(parent.getDisplay());
    vsdDetails_ = vsdDetails;
    oldProperty_ = property;

    Device device = Display.getCurrent();
    redColor_ = new Color(device, 255, 0, 0);

    errorHandler = new DialogHandler(shell_);
    shell_.setText("Property Details ");
    shell_.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            /*
             * Save the size and location of the main window.
             */
            int width = shell_.getSize().x;
            int height = shell_.getSize().y;
            int locX = shell_.getLocation().x;
            int locY = shell_.getLocation().y;

            Preferences p = Preferences.systemNodeForPackage(this.getClass());
            p.putInt("console_width", width);
            p.putInt("console_height", height);
            p.putInt("console_loc_x", locX);
            p.putInt("console_loc_y", locY);
        }
    });

    GridLayout layout = new GridLayout(1, true);
    shell_.setLayout(layout);

    shell_.setImage(new Image(shell_.getDisplay(), this.getClass().getResourceAsStream("/icons/icon.gif")));

    SashForm topBottom = new SashForm(shell_, SWT.VERTICAL);
    topBottom.SASH_WIDTH = 5;
    topBottom.setLayout(new GridLayout());
    GridData gd = new GridData(GridData.FILL_BOTH);
    topBottom.setLayoutData(gd);
    topBottom.setVisible(true);

    buildPropertyComposite(topBottom);

    SashForm leftRightBottom = new SashForm(topBottom, SWT.HORIZONTAL);
    leftRightBottom.SASH_WIDTH = 5;
    buildPropertyQualifierConposite(leftRightBottom);

    // disable all the text fields
    if (property != null) {
        disableTextFields();
        enablePropertyQualButtons();
    } else {
        enableTextFields();
        disablePropertyQualButtons();
    }

    shell_.open();
}