Пример #1
0
 /**
  * @deprecated use {@link OPCPackage#open(InputStream)} 
  */
 public static Package Open(Stream in1)
 {
     Package pack = new ZipPackage(in1, PackageAccess.READ);
     if (pack.partList == null)
     {
         pack.GetParts();
     }
     return pack;
 }
Пример #2
0
        public void TestCoreProperties_bug51374()
        {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            String strDate = "2007-05-12T08:00:00Z";
            DateTime date = DateTime.Parse(strDate).ToUniversalTime();

            OPCPackage pkg = new ZipPackage();
            PackagePropertiesPart props = (PackagePropertiesPart)pkg.GetPackageProperties();

            // Created
            Assert.AreEqual("", props.GetCreatedPropertyString());
            Assert.IsNull(props.GetCreatedProperty());
            props.SetCreatedProperty((String)null);
            Assert.AreEqual("", props.GetCreatedPropertyString());
            Assert.IsNull(props.GetCreatedProperty());
            props.SetCreatedProperty(new Nullable<DateTime>());
            Assert.AreEqual("", props.GetCreatedPropertyString());
            Assert.IsNull(props.GetCreatedProperty());
            props.SetCreatedProperty(new Nullable<DateTime>(date));
            Assert.AreEqual(strDate, props.GetCreatedPropertyString());
            Assert.AreEqual(date, props.GetCreatedProperty());
            props.SetCreatedProperty(strDate);
            Assert.AreEqual(strDate, props.GetCreatedPropertyString());
            Assert.AreEqual(date, props.GetCreatedProperty());

            // lastPrinted
            Assert.AreEqual("", props.GetLastPrintedPropertyString());
            Assert.IsNull(props.GetLastPrintedProperty());
            props.SetLastPrintedProperty((String)null);
            Assert.AreEqual("", props.GetLastPrintedPropertyString());
            Assert.IsNull(props.GetLastPrintedProperty());
            props.SetLastPrintedProperty(new Nullable<DateTime>());
            Assert.AreEqual("", props.GetLastPrintedPropertyString());
            Assert.IsNull(props.GetLastPrintedProperty());
            props.SetLastPrintedProperty(new Nullable<DateTime>(date));
            Assert.AreEqual(strDate, props.GetLastPrintedPropertyString());
            Assert.AreEqual(date, props.GetLastPrintedProperty());
            props.SetLastPrintedProperty(strDate);
            Assert.AreEqual(strDate, props.GetLastPrintedPropertyString());
            Assert.AreEqual(date, props.GetLastPrintedProperty());

            // modified
            Assert.IsNull(props.GetModifiedProperty());
            props.SetModifiedProperty((String)null);
            Assert.IsNull(props.GetModifiedProperty());
            props.SetModifiedProperty(new Nullable<DateTime>());
            Assert.IsNull(props.GetModifiedProperty());
            props.SetModifiedProperty(new Nullable<DateTime>(date));
            Assert.AreEqual(strDate, props.GetModifiedPropertyString());
            Assert.AreEqual(date, props.GetModifiedProperty());
            props.SetModifiedProperty(strDate);
            Assert.AreEqual(strDate, props.GetModifiedPropertyString());
            Assert.AreEqual(date, props.GetModifiedProperty());
        }
Пример #3
0
        public void testTidyStreamOnInvalidFile()
        {
            // Spreadsheet has a good mix of alternate file types
            POIDataSamples files = POIDataSamples.GetSpreadSheetInstance();

            FileInfo[] notValidF = new FileInfo[] {
                files.GetFileInfo("SampleSS.ods"), files.GetFileInfo("SampleSS.txt")
            };
            Stream[] notValidS = new Stream[] {
                files.OpenResourceAsStream("SampleSS.ods"), files.OpenResourceAsStream("SampleSS.txt")
            };
            foreach (FileInfo notValid in notValidF)
            {
                ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
                Assert.IsNotNull(pkg.ZipArchive);
                Assert.IsFalse(pkg.ZipArchive.IsClosed);
                try
                {
                    pkg.GetParts();
                    Assert.Fail("Shouldn't work");
                }
                catch (ODFNotOfficeXmlFileException e)
                {
                }
                catch (NotOfficeXmlFileException ne) { }
                pkg.Close();

                Assert.IsNotNull(pkg.ZipArchive);
                Assert.IsTrue(pkg.ZipArchive.IsClosed);
            }
            foreach (InputStream notValid in notValidS)
            {
                ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
                Assert.IsNotNull(pkg.ZipArchive);
                Assert.IsFalse(pkg.ZipArchive.IsClosed);
                try
                {
                    pkg.GetParts();
                    Assert.Fail("Shouldn't work");
                }
                catch (ODFNotOfficeXmlFileException e)
                {
                }
                catch (NotOfficeXmlFileException ne) { }
                pkg.Close();

                Assert.IsNotNull(pkg.ZipArchive);
                Assert.IsTrue(pkg.ZipArchive.IsClosed);
            }
        }
Пример #4
0
        /**
         * @deprecated use {@link OPCPackage#open(String,PackageAccess)} 
         */
        public static Package Open(String path, PackageAccess access)
        {
            if (path == null || "".Equals(path.Trim())
                    || new DirectoryInfo(path).Exists)
                throw new ArgumentException("path");

            Package pack = new ZipPackage(path, access);
            if (pack.partList == null && access != PackageAccess.WRITE)
            {
                pack.GetParts();
            }
            pack.originalPackagePath = Path.GetFullPath(path);
            return pack;
        }
Пример #5
0
        /**
         * @deprecated use {@link OPCPackage#open(String,PackageAccess)}
         */
        public static Package Open(String path, PackageAccess access)
        {
            if (path == null || "".Equals(path.Trim()) ||
                new DirectoryInfo(path).Exists)
            {
                throw new ArgumentException("path");
            }

            Package pack = new ZipPackage(path, access);

            if (pack.partList == null && access != PackageAccess.WRITE)
            {
                pack.GetParts();
            }
            pack.originalPackagePath = Path.GetFullPath(path);
            return(pack);
        }
Пример #6
0
        /**
         * @deprecated use {@link OPCPackage#create(File)}
         */
        public static Package Create(string path)
        {
            if (new DirectoryInfo(path).Exists)
            {
                throw new ArgumentException("path");
            }

            if (File.Exists(path))
            {
                throw new InvalidOperationException(
                          "This package (or file) already exists : use the open() method or delete the file.");
            }

            // Creates a new package
            Package pkg = null;

            pkg = new ZipPackage();
            pkg.originalPackagePath = Path.GetFullPath(path);

            ConfigurePackage(pkg);
            return(pkg);
        }
Пример #7
0
        public static OPCPackage Create(Stream output)
        {
            OPCPackage pkg = null;
            pkg = new ZipPackage();
            pkg.originalPackagePath = null;
            pkg.output = output;

            ConfigurePackage(pkg);
            return pkg;
        }
Пример #8
0
        /**
         * Creates a new package.
         * 
         * @param file
         *            Path of the document.
         * @return A newly Created PackageBase ready to use.
         */
        public static OPCPackage Create(string path)
        {
            if (new DirectoryInfo(path).Exists)
                throw new ArgumentException("file");

            if (File.Exists(path))
            {
                throw new InvalidOperationException(
                        "This package (or file) already exists : use the open() method or delete the file.");
            }

            // Creates a new package
            OPCPackage pkg = null;
            pkg = new ZipPackage();
            pkg.originalPackagePath = (new FileInfo(path)).Name;

            ConfigurePackage(pkg);
            return pkg;
        }
Пример #9
0
        /**
        * Open a package.
        *
        * @param file
        *            The file to open.
        * @param access
        *            PackageBase access.
        * @return A PackageBase object, else <b>null</b>.
        * @throws InvalidFormatException
        *             If the specified file doesn't exist, and a parsing error
        *             occur.
        */
        public static OPCPackage Open(FileInfo file, PackageAccess access)
        {
            if (file == null || new DirectoryInfo(file.FullName).Exists)
                throw new ArgumentException("file");

            OPCPackage pack = new ZipPackage(file, access);
            if (pack.partList == null && access != PackageAccess.WRITE)
            {
                pack.GetParts();
            }
            pack.originalPackagePath = file.FullName;
            return pack;
        }
Пример #10
0
        /**
         * Open a package.
         * 
         * @param path
         *            The document path.
         * @param access
         *            PackageBase access.
         * @return A PackageBase object, else <b>null</b>.
         * @throws InvalidFormatException
         *             If the specified file doesn't exist, and a parsing error
         *             occur.
         */
        public static OPCPackage Open(String path, PackageAccess access)
        {
            if (path == null || "".Equals(path.Trim()))
                throw new ArgumentException("'path' must be given");

            if (new DirectoryInfo(path).Exists)
                throw new ArgumentException("path must not be a directory");


            OPCPackage pack = new ZipPackage(path, access);
            if (pack.partList == null && access != PackageAccess.WRITE)
            {
                pack.GetParts();
            }
            pack.originalPackagePath = new DirectoryInfo(path).FullName;
            return pack;
        }