Browse Source

bug 61296: deduplicate ooxml schema constants

pull/1595/head
Antony Liu 4 weeks ago
parent
commit
1a5ecff505
  1. 2
      ooxml/Util/PackageHelper.cs
  2. 25
      ooxml/XWPF/Usermodel/XWPFRelation.cs
  3. 10
      openxml4Net/OPC/Internal/PackagePropertiesPart.cs
  4. 2
      openxml4Net/OPC/OPCPackage.cs
  5. 15
      openxml4Net/OPC/PackageProperties.cs
  6. 8
      testcases/openxml4net/TestPackageCoreProperties.cs
  7. 3
      testcases/openxml4net/TestRelationships.cs

2
ooxml/Util/PackageHelper.cs

@ -134,7 +134,7 @@ namespace NPOI.Util
* @param src source properties
* @param tgt target properties
*/
private static void CopyProperties(PackageProperties src, PackageProperties tgt)
private static void CopyProperties(IPackageProperties src, IPackageProperties tgt)
{
tgt.SetCategoryProperty(src.GetCategoryProperty());
tgt.SetContentStatusProperty(src.GetContentStatusProperty());

25
ooxml/XWPF/Usermodel/XWPFRelation.cs

@ -17,6 +17,7 @@
namespace NPOI.XWPF.UserModel
{
using NPOI.OpenXml4Net.OPC;
using System;
using System.Collections.Generic;
/**
@ -32,26 +33,26 @@ namespace NPOI.XWPF.UserModel
public static XWPFRelation DOCUMENT = new XWPFRelation(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
null
null
);
public static XWPFRelation TEMPLATE = new XWPFRelation(
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"/word/document.xml",
null
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
null
);
public static XWPFRelation MACRO_DOCUMENT = new XWPFRelation(
"application/vnd.ms-word.document.macroEnabled.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"application/vnd.ms-word.document.macroEnabled.main+xml",
PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
null
null
);
public static XWPFRelation MACRO_TEMPLATE_DOCUMENT = new XWPFRelation(
"application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
null
);

10
openxml4Net/OPC/Internal/PackagePropertiesPart.cs

@ -17,15 +17,13 @@ namespace NPOI.OpenXml4Net.OPC.Internal
* @author Julien Chable
* @version 1.0
*/
public class PackagePropertiesPart : PackagePart, PackageProperties
public class PackagePropertiesPart : PackagePart, IPackageProperties
{
public static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
public static String NAMESPACE_DC_URI = PackageProperties.NAMESPACE_DC;
public static String NAMESPACE_DC_URI = "http://purl.org/dc/elements/1.1/";
public static String NAMESPACE_CP_URI = PackageNamespaces.CORE_PROPERTIES;
public static String NAMESPACE_CP_URI = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
public static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/";
public static String NAMESPACE_DCTERMS_URI = PackageProperties.NAMESPACE_DCTERMS;
public static String NAMESPACE_XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
private static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

2
openxml4Net/OPC/OPCPackage.cs

@ -604,7 +604,7 @@ namespace NPOI.OpenXml4Net.OPC
*
* @return The PackageProperties part of this package.
*/
public PackageProperties GetPackageProperties()
public IPackageProperties GetPackageProperties()
{
this.ThrowExceptionIfWriteOnly();
// If no properties part has been found then we Create one

15
openxml4Net/OPC/PackageProperties.cs

@ -11,7 +11,7 @@ namespace NPOI.OpenXml4Net.OPC
* @version 1.0
* @see org.apache.poi.OpenXml4Net.opc.OPCPackage
*/
public interface PackageProperties
public interface IPackageProperties
{
/* Getters and Setters */
@ -198,4 +198,17 @@ namespace NPOI.OpenXml4Net.OPC
*/
void SetVersionProperty(String version);
}
public class PackageProperties
{
/**
* Dublin Core Terms URI.
*/
public static String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/";
/**
* Dublin Core namespace URI.
*/
public static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
}
}

8
testcases/openxml4net/TestPackageCoreProperties.cs

@ -66,7 +66,7 @@ namespace TestCases.OpenXml4Net.OPC
SimpleDateFormat msdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
msdf.TimeZone = TimeZoneInfo.Utc;
PackageProperties props = p.GetPackageProperties();
IPackageProperties props = p.GetPackageProperties();
//test various date formats
props.SetCreatedProperty("2007-05-12T08:00:00Z");
@ -133,7 +133,7 @@ namespace TestCases.OpenXml4Net.OPC
DateTime expectedDate = df.Parse("2007-05-12T08:00:00Z");
// Gets the core properties
PackageProperties props = p.GetPackageProperties();
IPackageProperties props = p.GetPackageProperties();
ClassicAssert.AreEqual("MyCategory", props.GetCategoryProperty());
ClassicAssert.AreEqual("MyContentStatus", props.GetContentStatusProperty()
);
@ -215,7 +215,7 @@ namespace TestCases.OpenXml4Net.OPC
{
// Open the namespace
OPCPackage pkg1 = OPCPackage.Open(OpenXml4NetTestDataSamples.OpenSampleStream("51444.xlsx"));
PackageProperties props1 = pkg1.GetPackageProperties();
IPackageProperties props1 = pkg1.GetPackageProperties();
ClassicAssert.AreEqual(null, props1.GetTitleProperty());
props1.SetTitleProperty("Bug 51444 fixed");
MemoryStream out1 = new MemoryStream();
@ -224,7 +224,7 @@ namespace TestCases.OpenXml4Net.OPC
pkg1.Close();
OPCPackage pkg2 = OPCPackage.Open(new MemoryStream(out1.ToArray()));
PackageProperties props2 = pkg2.GetPackageProperties();
IPackageProperties props2 = pkg2.GetPackageProperties();
props2.SetTitleProperty("Bug 51444 fixed");
pkg2.Close();
}

3
testcases/openxml4net/TestRelationships.cs

@ -258,8 +258,7 @@ namespace TestCases.OpenXml4Net.OPC
partB.GetRelationship("rId1").TargetUri.ToString());
// Check core too
ClassicAssert.AreEqual("/docProps/core.xml",
pkg.GetRelationshipsByType(
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties").GetRelationship(0).TargetUri.ToString());
pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_PROPERTIES).GetRelationship(0).TargetUri.ToString());
// Add some more
partB.AddExternalRelationship("http://poi.apache.org/new", "http://example/poi/new");

Loading…
Cancel
Save