/**
         * Returns true if the specified file can be opened as an XML document, and calling {@link
         * #accept(org.w3c.dom.Document)} returns true.
         *
         * @param file the file in question.
         *
         * @return true if the file should be accepted; false otherwise.
         *
         * @throws ArgumentException if the file is null.
         */
        public bool accept(java.io.File file)
        {
            if (file == null)
            {
                String msg = Logging.getMessage("nullValue.FileIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            // First check the file path, optionally returning false if the path cannot be accepted for any reason.
            if (!this.acceptFilePath(file.getPath()))
            {
                return(false);
            }

            Document doc = null;

            try
            {
                doc = WWXML.openDocumentFile(file.getPath(), this.GetType());
            }
            catch (Exception e)
            {
                // Not interested in logging the exception. We just want to return false, indicating that the File cannot
                // be opened as an XML document.
            }

            return((doc != null) && (doc.getDocumentElement() != null) && this.accept(doc));
        }
Beispiel #2
0
        private static string GetPath(java.io.File file)
        {
            string path = file.getPath();

            if (path.StartsWith("file:/") || path.StartsWith("file:\\"))
            {
                path = path.Substring("file:/".Length);
            }

            return(path);
        }
Beispiel #3
0
 /// <summary>Constructs a new file using the specified directory and name.</summary>
 /// <remarks>Constructs a new file using the specified directory and name.</remarks>
 /// <param name="dir">the directory where the file is stored.</param>
 /// <param name="name">the file's name.</param>
 /// <exception cref="System.ArgumentNullException">
 /// if
 /// <code>name</code>
 /// is
 /// <code>null</code>
 /// .
 /// </exception>
 public File(java.io.File dir, string name)
     : this(dir == null ? null : dir.getPath(), name)
 {
 }
        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);
            }
        }