java.util.prefs.InvalidPreferencesFormatException Java Examples

The following examples show how to use java.util.prefs.InvalidPreferencesFormatException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilePreferencesXmlSupport.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Import preferences from the specified input stream, which is assumed to
 * contain an XML document in the format described in the Preferences spec.
 *
 * @throws IOException
 *             if reading from the specified output stream results in an
 *             <tt>IOException</tt>.
 * @throws InvalidPreferencesFormatException
 *             Data on input stream does not constitute a valid XML document
 *             with the mandated document type.
 */
static void importPreferences(InputStream is) throws IOException, InvalidPreferencesFormatException {
    try {
        Document doc = loadPrefsDoc(is);
        String xmlVersion = doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION");
        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException("Exported preferences file format version " + xmlVersion
                    + " is not supported. This java installation can read" + " versions " + EXTERNAL_XML_VERSION
                    + " or older. You may need" + " to install a newer version of JDK.");

        Element xmlRoot = (Element) doc.getDocumentElement().getChildNodes().item(0);
        Preferences prefsRoot = (xmlRoot.getAttribute("type").equals("user") ? Preferences.userRoot()
                : Preferences.systemRoot());
        ImportSubtree(prefsRoot, xmlRoot);
    } catch (SAXException | BackingStoreException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #2
Source File: FilePreferencesXmlSupport.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Import Map from the specified input stream, which is assumed to contain a map
 * document as per the prefs DTD. This is used as the internal (undocumented)
 * format for FileSystemPrefs. The key-value pairs specified in the XML document
 * will be put into the specified Map. (If this Map is empty, it will contain
 * exactly the key-value pairs int the XML-document when this method returns.)
 *
 * @throws IOException
 *             if reading from the specified output stream results in an
 *             <tt>IOException</tt>.
 * @throws InvalidPreferencesFormatException
 *             Data on input stream does not constitute a valid XML document
 *             with the mandated document type.
 */
static void importMap(InputStream is, Map m) throws IOException, InvalidPreferencesFormatException {
    try {
        Document doc = loadPrefsDoc(is);
        Element xmlMap = doc.getDocumentElement();
        // check version
        String mapVersion = xmlMap.getAttribute("MAP_XML_VERSION");
        if (mapVersion.compareTo(MAP_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException("Preferences map file format version " + mapVersion
                    + " is not supported. This java installation can read" + " versions " + MAP_XML_VERSION
                    + " or older. You may need" + " to install a newer version of JDK.");

        NodeList entries = xmlMap.getChildNodes();
        for (int i = 0, numEntries = entries.getLength(); i < numEntries; i++) {
            Element entry = (Element) entries.item(i);
            m.put(entry.getAttribute("key"), entry.getAttribute("value"));
        }
    } catch (SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #3
Source File: XmlSupport.java    From java-scanner-access-twain with GNU Affero General Public License v3.0 6 votes vote down vote up
static void importPreferences(InputStream is)
    throws IOException, InvalidPreferencesFormatException
{
    try {
        Document doc = loadPrefsDoc(is);
        String xmlVersion =
            doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION");
        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException(
            "Exported preferences file format version " + xmlVersion +
            " is not supported. This java installation can read" +
            " versions " + EXTERNAL_XML_VERSION + " or older. You may need" +
            " to install a newer version of JDK.");

        Element xmlRoot = (Element) doc.getDocumentElement().
                                           getChildNodes().item(0);
        Preferences prefsRoot =
            (xmlRoot.getAttribute("type").equals("user") ?
                        Preferences.userRoot() : Preferences.systemRoot());
        ImportSubtree(prefsRoot, xmlRoot);
    } catch(SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #4
Source File: XmlSupport.java    From java-scanner-access-twain with GNU Affero General Public License v3.0 6 votes vote down vote up
static void importMap(InputStream is, Map m)
    throws IOException, InvalidPreferencesFormatException
{
    try {
        Document doc = loadPrefsDoc(is);
        Element xmlMap = doc.getDocumentElement();

        String mapVersion = xmlMap.getAttribute("MAP_XML_VERSION");
        if (mapVersion.compareTo(MAP_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException(
            "Preferences map file format version " + mapVersion +
            " is not supported. This java installation can read" +
            " versions " + MAP_XML_VERSION + " or older. You may need" +
            " to install a newer version of JDK.");

        NodeList entries = xmlMap.getChildNodes();
        for (int i=0, numEntries=entries.getLength(); i<numEntries; i++) {
            Element entry = (Element) entries.item(i);
            m.put(entry.getAttribute("key"), entry.getAttribute("value"));
        }
    } catch(SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #5
Source File: XmlSupport.java    From java-ocr-api with GNU Affero General Public License v3.0 6 votes vote down vote up
static void importPreferences(InputStream is)
    throws IOException, InvalidPreferencesFormatException
{
    try {
        Document doc = loadPrefsDoc(is);
        String xmlVersion =
            doc.getDocumentElement().getAttribute("EXTERNAL_XML_VERSION");
        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException(
            "Exported preferences file format version " + xmlVersion +
            " is not supported. This java installation can read" +
            " versions " + EXTERNAL_XML_VERSION + " or older. You may need" +
            " to install a newer version of JDK.");

        Element xmlRoot = (Element) doc.getDocumentElement().
                                           getChildNodes().item(0);
        Preferences prefsRoot =
            (xmlRoot.getAttribute("type").equals("user") ?
                        Preferences.userRoot() : Preferences.systemRoot());
        ImportSubtree(prefsRoot, xmlRoot);
    } catch(SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #6
Source File: XmlSupport.java    From java-ocr-api with GNU Affero General Public License v3.0 6 votes vote down vote up
static void importMap(InputStream is, Map m)
    throws IOException, InvalidPreferencesFormatException
{
    try {
        Document doc = loadPrefsDoc(is);
        Element xmlMap = doc.getDocumentElement();

        String mapVersion = xmlMap.getAttribute("MAP_XML_VERSION");
        if (mapVersion.compareTo(MAP_XML_VERSION) > 0)
            throw new InvalidPreferencesFormatException(
            "Preferences map file format version " + mapVersion +
            " is not supported. This java installation can read" +
            " versions " + MAP_XML_VERSION + " or older. You may need" +
            " to install a newer version of JDK.");

        NodeList entries = xmlMap.getChildNodes();
        for (int i=0, numEntries=entries.getLength(); i<numEntries; i++) {
            Element entry = (Element) entries.item(i);
            m.put(entry.getAttribute("key"), entry.getAttribute("value"));
        }
    } catch(SAXException e) {
        throw new InvalidPreferencesFormatException(e);
    }
}
 
Example #7
Source File: TestJavaUtilPreferences.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
// @Ignore("This doesn't actually assert that the substitute and export features work.")
public void testExport() throws IOException, BackingStoreException, InvalidPreferencesFormatException {
  Preferences userRoot = Preferences.userRoot();
  Preferences fromNode = userRoot.node("SemperUbi");
  assert fromNode instanceof PreferencesExt : "Factory not set = " + userRoot.getClass().getName();

  ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
  fromNode.exportNode(os);
  String xml = new String(os.toByteArray());
  xml = substitute(xml, "SemperUbi", "SubUbi");
  ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
  Preferences.importPreferences(is);
  userRoot.exportSubtree(System.out);
}
 
Example #8
Source File: GamaPreferences.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void applyPreferencesFrom(final String path, final Map<String, Object> modelValues) {
	// DEBUG.OUT("Apply preferences from " + path);
	try (final FileInputStream is = new FileInputStream(path);) {
		store.importPreferences(is);
		reloadPreferences(modelValues);
	} catch (final IOException | InvalidPreferencesFormatException e) {
		e.printStackTrace();
	}
}
 
Example #9
Source File: UPbReduxConfigurator.java    From ET_Redux with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @throws IOException
 * @throws InvalidPreferencesFormatException
 */
public static void InitializeConfiguration() throws IOException, InvalidPreferencesFormatException {

    myPreferences.put("URL_EARTHTIMEORG", URL_EARTHTIMEORG);

    myPreferences.put("URI_UPB_PUBLIC_DATA", URI_UPB_PUBLIC_DATA);

    myPreferences.put("URI_AliquotXMLSchema", URI_AliquotXMLSchema);
    myPreferences.put("URI_AliquotUThXMLSchema", URI_AliquotUThXMLSchema);

    myPreferences.put("URI_UPbReduxFractionXMLSchemaURL", URI_UPbReduxFractionXMLSchemaURL);

    myPreferences.put("URI_AnalysisFractionXMLSchemaURL", URI_AnalysisFractionXMLSchemaURL);

    myPreferences.put("URI_InitialPbModelXMLSchema", URI_InitialPbModelXMLSchema);
    myPreferences.put("URI_InitialPbModelETXMLSchema", URI_InitialPbModelETXMLSchema);

    myPreferences.put("URI_PbBlankXMLSchema", URI_PbBlankXMLSchema);
    myPreferences.put("URI_PbBlankICModelXMLSchema", URI_PbBlankICModelXMLSchema);

    myPreferences.put("URI_MineralStandardModelXMLSchemaURL", URI_MineralStandardModelXMLSchemaURL);
    myPreferences.put("URI_MineralStandardUPbModelXMLSchemaURL", URI_MineralStandardUPbModelXMLSchemaURL);

    myPreferences.put("URI_PhysicalConstantsXMLSchema", URI_PhysicalConstantsXMLSchema);
    myPreferences.put("URI_PhysicalConstantsModelXMLSchema", URI_PhysicalConstantsModelXMLSchema);

    myPreferences.put("URI_TracerXMLSchema", URI_TracerXMLSchema);
    myPreferences.put("URI_TracerUPbModelXMLSchema", URI_TracerUPbModelXMLSchema);

    myPreferences.put("URI_EARTHTIME_XMLTracers", URI_EARTHTIME_XMLTracers);

    myPreferences.put("URI_ValueModelXMLSchema", URI_ValueModelXMLSchema);

    myPreferences.put("URI_SampleMetaDataXMLSchema", URI_SampleMetaDataXMLSchema);

    myPreferences.put("URI_ReportSettingsXMLSchema", URI_ReportSettingsXMLSchema);

    myPreferences.put("URI_ReduxMatrixXMLSchemaURL", URI_ReduxMatrixXMLSchemaURL);
    
    myPreferences.put("URI_DetritalUraniumAndThoriumModelXMLSchema", URI_DetritalUraniumAndThoriumModelXMLSchema);
}