Exemplo n.º 1
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());

            pkg.Close();
        }
Exemplo n.º 2
0
        /**
         * Returns the core document properties, eg author
         */
        public String GetCorePropertiesText()
        {
            StringBuilder         text  = new StringBuilder();
            PackagePropertiesPart props =
                Document.GetProperties().CoreProperties.GetUnderlyingProperties();

            AppendIfPresent(text, "Category", props.GetCategoryProperty());
            AppendIfPresent(text, "Category", props.GetCategoryProperty());
            AppendIfPresent(text, "ContentStatus", props.GetContentStatusProperty());
            AppendIfPresent(text, "ContentType", props.GetContentTypeProperty());
            AppendIfPresent(text, "Created", props.GetCreatedProperty().Value);
            AppendIfPresent(text, "CreatedString", props.GetCreatedPropertyString());
            AppendIfPresent(text, "Creator", props.GetCreatorProperty());
            AppendIfPresent(text, "Description", props.GetDescriptionProperty());
            AppendIfPresent(text, "Identifier", props.GetIdentifierProperty());
            AppendIfPresent(text, "Keywords", props.GetKeywordsProperty());
            AppendIfPresent(text, "Language", props.GetLanguageProperty());
            AppendIfPresent(text, "LastModifiedBy", props.GetLastModifiedByProperty());
            AppendIfPresent(text, "LastPrinted", props.GetLastPrintedProperty());
            AppendIfPresent(text, "LastPrintedString", props.GetLastPrintedPropertyString());
            AppendIfPresent(text, "Modified", props.GetModifiedProperty());
            AppendIfPresent(text, "ModifiedString", props.GetModifiedPropertyString());
            AppendIfPresent(text, "Revision", props.GetRevisionProperty());
            AppendIfPresent(text, "Subject", props.GetSubjectProperty());
            AppendIfPresent(text, "Title", props.GetTitleProperty());
            AppendIfPresent(text, "Version", props.GetVersionProperty());

            return(text.ToString());
        }
Exemplo n.º 3
0
        /**
         * Marshall package core properties to an XML document. Always return
         * <code>true</code>.
         */
        public virtual bool Marshall(PackagePart part, Stream out1)
        {
            if (!(part is PackagePropertiesPart))
            {
                throw new ArgumentException(
                          "'part' must be a PackagePropertiesPart instance.");
            }
            _propsPart = (PackagePropertiesPart)part;

            // Configure the document
            XmlDoc = new XDocument();
            XNamespace ns = NamespaceCoreProperties;

            this.RootElem = new XElement(ns + "coreProperties",
                                         new XAttribute(XNamespace.Xmlns + "cp", PackagePropertiesPart.NAMESPACE_CP_URI),
                                         new XAttribute(XNamespace.Xmlns + "dc", PackagePropertiesPart.NAMESPACE_DC_URI),
                                         new XAttribute(XNamespace.Xmlns + "dcterms", PackagePropertiesPart.NAMESPACE_DCTERMS_URI),
                                         new XAttribute(XNamespace.Xmlns + "xsi", PackagePropertiesPart.NAMESPACE_XSI_URI)
                                         );
            //this.RootElem.Name =
            //    (XNamespace)NamespaceCoreProperties + RootElem.Name.LocalName;
            //using (var reader = XmlDoc.CreateReader())
            //{
            //	Nsmgr = new XmlNamespaceManager(reader.NameTable);
            //}
            //Nsmgr.AddNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI);
            //Nsmgr.AddNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI);
            //Nsmgr.AddNamespace("dcterms", PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
            //Nsmgr.AddNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI);

            XmlDoc.Add(RootElem);

            Prop(() => _propsPart.GetCategoryProperty(), NamespaceCoreProperties, "cp", KeywordCategory);
            Prop(() => _propsPart.GetContentStatusProperty(), NamespaceCoreProperties, "cp", KeywordContentStatus);
            Prop(() => _propsPart.GetContentTypeProperty(), NamespaceCoreProperties, "cp", KeywordContentType);
            var created = Prop(() => _propsPart.GetCreatedProperty(), NamespaceDcTerms, "dcterms", KeywordCreated,
                               () => _propsPart.GetCreatedPropertyString());

            created?.SetAttribute("type", NamespaceXsi, "dcterms:W3CDTF");
            Prop(() => _propsPart.GetCreatorProperty(), NamespaceDc, "dc", KeywordCreator);
            Prop(() => _propsPart.GetDescriptionProperty(), NamespaceDc, "dc", KeywordDescription);
            Prop(() => _propsPart.GetIdentifierProperty(), NamespaceDc, "dc", KeywordIdentifier);
            Prop(() => _propsPart.GetKeywordsProperty(), NamespaceCoreProperties, "cp", KeywordKeywords);
            Prop(() => _propsPart.GetLanguageProperty(), NamespaceDc, "dc", KeywordLanguage);
            Prop(() => _propsPart.GetLastModifiedByProperty(), NamespaceCoreProperties, "cp", KeywordLastModifiedBy);
            Prop(() => _propsPart.GetLastPrintedProperty(), NamespaceCoreProperties, "cp", KeywordLastPrinted,
                 () => _propsPart.GetLastPrintedPropertyString());
            var modified = Prop(() => _propsPart.GetModifiedProperty(), NamespaceDcTerms, "dcterms", KeywordModified,
                                () => _propsPart.GetModifiedPropertyString());

            modified?.SetAttribute("type", NamespaceXsi, "dcterms:W3CDTF");
            Prop(() => _propsPart.GetRevisionProperty(), NamespaceCoreProperties, "cp", KeywordRevision);
            Prop(() => _propsPart.GetSubjectProperty(), NamespaceDc, "dc", KeywordSubject);
            Prop(() => _propsPart.GetTitleProperty(), NamespaceDc, "dc", KeywordTitle);
            Prop(() => _propsPart.GetVersionProperty(), NamespaceCoreProperties, "cp", KeywordVersion);
            return(true);
        }
        /**
         * Add 'last printed' property if needed.
         *
         */
        private void AddLastPrinted()
        {
            if (propsPart.GetLastPrintedProperty() == null)
            {
                return;
            }

            XmlNodeList elems = xmlDoc.DocumentElement.GetElementsByTagName(KEYWORD_LAST_PRINTED, namespaceCoreProperties);
            XmlElement  elem  = null;

            if (elems.Count == 0)
            {
                // Missing, we Add it
                elem = xmlDoc.CreateElement("cp", KEYWORD_LAST_PRINTED, namespaceCoreProperties);
                xmlDoc.DocumentElement.AppendChild(elem);
            }
            else
            {
                elem          = (XmlElement)elems[0];
                elem.InnerXml = "";// clear the old value
            }
            elem.InnerText = propsPart.GetLastPrintedPropertyString();
        }
Exemplo n.º 5
0
 public DateTime?GetLastPrinted()
 {
     return(part.GetLastPrintedProperty());
 }