Exemplo n.º 1
0
        static java.util.Properties loadFilePrefsImpl(java.io.File file)
        {
            Properties result = new Properties();

            if (!file.exists())
            {
                file.getParentFile().mkdirs();
                return(result);
            }

            if (file.canRead())
            {
                java.io.InputStream        inJ   = null;
                java.nio.channels.FileLock lockJ = null;
                try {
                    java.io.FileInputStream istream = new java.io.FileInputStream(file);
                    inJ = new java.io.BufferedInputStream(istream);
                    java.nio.channels.FileChannel channel = istream.getChannel();
                    lockJ = channel.lockJ(0L, java.lang.Long.MAX_VALUE, true);
                    org.w3c.dom.Document doc     = builder.parse(inJ);
                    org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(doc
                                                                                            .getDocumentElement(), "entry"); //$NON-NLS-1$
                    int length = entries.getLength();
                    for (int i = 0; i < length; i++)
                    {
                        org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item(i);
                        String key   = node.getAttribute("key");                        //$NON-NLS-1$
                        String value = node.getAttribute("value");                      //$NON-NLS-1$
                        result.setProperty(key, value);
                    }
                    return(result);
                } catch (java.io.IOException e) {
                } catch (org.xml.sax.SAXException e) {
                } catch (javax.xml.transform.TransformerException e) {
                    // transform shouldn't fail for xpath call
                    throw new java.lang.AssertionError(e);
                } finally {
                    releaseQuietly(lockJ);
                    closeQuietly(inJ);
                }
            }
            else
            {
                file.delete();
            }
            return(result);
        }
Exemplo n.º 2
0
        private static void loadNode(Preferences prefs, org.w3c.dom.Element node)
        {                                                                                                //throws TransformerException {
            // load preferences
            org.w3c.dom.NodeList children = org.apache.xpath.XPathAPI.selectNodeList(node, "node");      //$NON-NLS-1$
            org.w3c.dom.NodeList entries  = org.apache.xpath.XPathAPI.selectNodeList(node, "map/entry"); //$NON-NLS-1$
            int childNumber = children.getLength();

            Preferences[] prefChildren = new Preferences[childNumber];
            int           entryNumber  = entries.getLength();

            lock (((AbstractPreferences)prefs).lockJ) {
                if (((AbstractPreferences)prefs).isRemoved())
                {
                    return;
                }
                for (int i = 0; i < entryNumber; i++)
                {
                    org.w3c.dom.Element entry = (org.w3c.dom.Element)entries.item(i);
                    String key   = entry.getAttribute("key");                    //$NON-NLS-1$
                    String value = entry.getAttribute("value");                  //$NON-NLS-1$
                    prefs.put(key, value);
                }
                // get children preferences node
                for (int i = 0; i < childNumber; i++)
                {
                    org.w3c.dom.Element child = (org.w3c.dom.Element)children.item(i);
                    String name = child.getAttribute("name");                      //$NON-NLS-1$
                    prefChildren [i] = prefs.node(name);
                }
            }

            // load children nodes after unlock
            for (int i = 0; i < childNumber; i++)
            {
                loadNode(prefChildren [i], (org.w3c.dom.Element)children.item(i));
            }
        }
Exemplo n.º 3
0
        protected void buildReadPaths(org.w3c.dom.Node dataFileStoreNode)
        {
            javax.xml.xpath.XPathFactory pathFactory = javax.xml.xpath.XPathFactory.newInstance();
            javax.xml.xpath.XPath        pathFinder  = pathFactory.newXPath();

            try
            {
                org.w3c.dom.NodeList locationNodes = (org.w3c.dom.NodeList)pathFinder.evaluate(
                    "/dataFileStore/readLocations/location",
                    dataFileStoreNode.getFirstChild(),
                    javax.xml.xpath.XPathConstants.NODESET);
                for (int i = 0; i < locationNodes.getLength(); i++)
                {
                    org.w3c.dom.Node location       = locationNodes.item(i);
                    String           prop           = pathFinder.evaluate("@property", location);
                    String           wwDir          = pathFinder.evaluate("@wwDir", location);
                    String           append         = pathFinder.evaluate("@append", location);
                    String           isInstall      = pathFinder.evaluate("@isInstall", location);
                    String           isMarkWhenUsed = pathFinder.evaluate("@isMarkWhenUsed", location);

                    String path = buildLocationPath(prop, append, wwDir);
                    if (path == null)
                    {
                        Logging.logger().log(Level.WARNING, "FileStore.LocationInvalid",
                                             prop != null ? prop : Logging.getMessage("generic.Unknown"));
                        continue;
                    }

                    StoreLocation oldStore = this.storeLocationFor(path);
                    if (oldStore != null) // filter out duplicates
                    {
                        continue;
                    }

                    // Even paths that don't exist or are otherwise problematic are added to the list because they may
                    // become readable during the session. E.g., removable media. So add them to the search list.

                    java.io.File pathFile = new java.io.File(path);
                    if (pathFile.exists() && !pathFile.isDirectory())
                    {
                        Logging.logger().log(Level.WARNING, "FileStore.LocationIsFile", pathFile.getPath());
                    }

                    bool          pathIsInstall = isInstall != null && (isInstall.contains("t") || isInstall.contains("T"));
                    StoreLocation newStore      = new StoreLocation(pathFile, pathIsInstall);

                    // If the input parameter "markWhenUsed" is null or empty, then the StoreLocation should keep its
                    // default value. Otherwise the store location value is set to true when the input parameter contains
                    // "t", and is set to false otherwise.
                    if (isMarkWhenUsed != null && isMarkWhenUsed.length() > 0)
                    {
                        newStore.setMarkWhenUsed(isMarkWhenUsed.toLowerCase().contains("t"));
                    }

                    this.readLocations.add(newStore);
                }
            }
            catch (javax.xml.xpath.XPathExpressionException e)
            {
                String message = Logging.getMessage("FileStore.ExceptionReadingConfigurationFile");
                Logging.logger().severe(message);
                throw new IllegalStateException(message, e);
            }
        }