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(); }
public void SetLastPrinted(string date) { part.SetLastPrintedProperty(date); }
public void SetLastPrinted(Nullable <DateTime> date) { part.SetLastPrintedProperty(date); }
// TODO Load element with XMLBeans or dynamic table // TODO Check every element/namespace for compliance public PackagePart Unmarshall(UnmarshallContext context, Stream in1) { PackagePropertiesPart coreProps = new PackagePropertiesPart(context .Package, context.PartName); // If the input stream is null then we try to get it from the // package. if (in1 == null) { if (context.ZipEntry != null) { in1 = ((ZipPackage)context.Package).ZipArchive .GetInputStream(context.ZipEntry); } else if (context.Package != null) { // Try to retrieve the part inputstream from the URI ZipEntry zipEntry; try { zipEntry = ZipHelper .GetCorePropertiesZipEntry((ZipPackage)context .Package); } catch (OpenXml4NetException) { throw new IOException( "Error while trying to get the part input stream."); } in1 = ((ZipPackage)context.Package).ZipArchive .GetInputStream(zipEntry); } else throw new IOException( "Error while trying to get the part input stream."); } XmlDocument xmlDoc = null; try { xmlDoc = DocumentHelper.LoadDocument(in1); nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("cp", namespaceCP); nsmgr.AddNamespace("dc", namespaceDC); nsmgr.AddNamespace("dcterms", namespaceDcTerms); nsmgr.AddNamespace("xsi", namespaceXSI); nsmgr.AddNamespace("cml", PackageNamespaces.MARKUP_COMPATIBILITY); nsmgr.AddNamespace("dcmitype", PackageNamespaces.DCMITYPE); //xmlDoc.ReadNode(reader); //try { //xmlDoc = xmlReader.read(in1); /* Check OPC compliance */ // Rule M4.2, M4.3, M4.4 and M4.5/ CheckElementForOPCCompliance(xmlDoc.DocumentElement); /* End OPC compliance */ //} catch (DocumentException e) { // throw new IOException(e.getMessage()); //} } catch (XmlException ex) { if (ex.Message.Contains("MaxCharactersFromEntities")) { // } else throw ex; } if (xmlDoc!=null && xmlDoc.DocumentElement != null) { coreProps.SetCategoryProperty(LoadCategory(xmlDoc)); coreProps.SetContentStatusProperty(LoadContentStatus(xmlDoc)); coreProps.SetContentTypeProperty(LoadContentType(xmlDoc)); coreProps.SetCreatedProperty(LoadCreated(xmlDoc)); coreProps.SetCreatorProperty(LoadCreator(xmlDoc)); coreProps.SetDescriptionProperty(LoadDescription(xmlDoc)); coreProps.SetIdentifierProperty(LoadIdentifier(xmlDoc)); coreProps.SetKeywordsProperty(LoadKeywords(xmlDoc)); coreProps.SetLanguageProperty(LoadLanguage(xmlDoc)); coreProps.SetLastModifiedByProperty(LoadLastModifiedBy(xmlDoc)); coreProps.SetLastPrintedProperty(LoadLastPrinted(xmlDoc)); coreProps.SetModifiedProperty(LoadModified(xmlDoc)); coreProps.SetRevisionProperty(LoadRevision(xmlDoc)); coreProps.SetSubjectProperty(LoadSubject(xmlDoc)); coreProps.SetTitleProperty(LoadTitle(xmlDoc)); coreProps.SetVersionProperty(LoadVersion(xmlDoc)); } return coreProps; }
// TODO Load element with XMLBeans or dynamic table // TODO Check every element/namespace for compliance public PackagePart Unmarshall(UnmarshallContext context, Stream in1) { PackagePropertiesPart coreProps = new PackagePropertiesPart(context .Package, context.PartName); // If the input stream is null then we try to get it from the // package. if (in1 == null) { if (context.ZipEntry != null) { in1 = ((ZipPackage)context.Package).ZipArchive .GetInputStream(context.ZipEntry); } else if (context.Package != null) { // Try to retrieve the part inputstream from the URI ZipEntry zipEntry; try { zipEntry = ZipHelper .GetCorePropertiesZipEntry((ZipPackage)context .Package); } catch (OpenXml4NetException) { throw new IOException( "Error while trying to get the part input stream."); } in1 = ((ZipPackage)context.Package).ZipArchive .GetInputStream(zipEntry); } else { throw new IOException( "Error while trying to get the part input stream."); } } XmlDocument xmlDoc = null; try { xmlDoc = DocumentHelper.LoadDocument(in1); nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("cp", namespaceCP); nsmgr.AddNamespace("dc", namespaceDC); nsmgr.AddNamespace("dcterms", namespaceDcTerms); nsmgr.AddNamespace("xsi", namespaceXSI); nsmgr.AddNamespace("cml", PackageNamespaces.MARKUP_COMPATIBILITY); nsmgr.AddNamespace("dcmitype", PackageNamespaces.DCMITYPE); //xmlDoc.ReadNode(reader); //try { //xmlDoc = xmlReader.read(in1); /* Check OPC compliance */ // Rule M4.2, M4.3, M4.4 and M4.5/ CheckElementForOPCCompliance(xmlDoc.DocumentElement); /* End OPC compliance */ //} catch (DocumentException e) { // throw new IOException(e.getMessage()); //} } catch (XmlException ex) { throw new IOException(ex.Message, ex); } if (xmlDoc != null && xmlDoc.DocumentElement != null) { coreProps.SetCategoryProperty(LoadCategory(xmlDoc)); coreProps.SetContentStatusProperty(LoadContentStatus(xmlDoc)); coreProps.SetContentTypeProperty(LoadContentType(xmlDoc)); coreProps.SetCreatedProperty(LoadCreated(xmlDoc)); coreProps.SetCreatorProperty(LoadCreator(xmlDoc)); coreProps.SetDescriptionProperty(LoadDescription(xmlDoc)); coreProps.SetIdentifierProperty(LoadIdentifier(xmlDoc)); coreProps.SetKeywordsProperty(LoadKeywords(xmlDoc)); coreProps.SetLanguageProperty(LoadLanguage(xmlDoc)); coreProps.SetLastModifiedByProperty(LoadLastModifiedBy(xmlDoc)); coreProps.SetLastPrintedProperty(LoadLastPrinted(xmlDoc)); coreProps.SetModifiedProperty(LoadModified(xmlDoc)); coreProps.SetRevisionProperty(LoadRevision(xmlDoc)); coreProps.SetSubjectProperty(LoadSubject(xmlDoc)); coreProps.SetTitleProperty(LoadTitle(xmlDoc)); coreProps.SetVersionProperty(LoadVersion(xmlDoc)); } return(coreProps); }