示例#1
0
 public void SetCategory(String category)
 {
     part.SetCategoryProperty(category);
 }
        // 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);
        }