View | Details | Raw Unified | Return to bug 52540
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (-12 / +22 lines)
Lines 597-604 Link Here
597
	}
597
	}
598
598
599
	/**
599
	/**
600
	 * Load the parts of the archive if it has not been done yet The
600
	 * Load the parts of the archive if it has not been done yet. The
601
	 * relationships of each part are not loaded
601
	 * relationships of each part are not loaded.
602
	 * NOTE: Compliance with Rule M4.1 has been relaxed. The first
603
	 * CoreProperties part encountered will be used; any further
604
	 * CoreProperties parts are silently ignored.
602
	 *
605
	 *
603
	 * @return All this package's parts.
606
	 * @return All this package's parts.
604
	 */
607
	 */
Lines 612-639 Link Here
612
			// Ensure rule M4.1 -> A format consumer shall consider more than
615
			// Ensure rule M4.1 -> A format consumer shall consider more than
613
			// one core properties relationship for a package to be an error
616
			// one core properties relationship for a package to be an error
614
			boolean hasCorePropertiesPart = false;
617
			boolean hasCorePropertiesPart = false;
618
			boolean needCorePropertiesPart = true;
615
619
616
			PackagePart[] parts = this.getPartsImpl();
620
			PackagePart[] parts = this.getPartsImpl();
617
			this.partList = new PackagePartCollection();
621
			this.partList = new PackagePartCollection();
618
			for (PackagePart part : parts) {
622
			for (PackagePart part : parts) {
619
				if (partList.containsKey(part._partName))
623
				if (partList.containsKey(part._partName))
620
					throw new InvalidFormatException(
624
					throw new InvalidFormatException(
621
							"A part with the name '"
625
							"A part with the name '" +
622
									+ part._partName
626
							part._partName +
623
									+ "' already exist : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
627
						        "' already exist : Packages shall not contain equivalent " +
628
						        "part names and package implementers shall neither create " +
629
					        	"nor recognize packages with equivalent part names. [M1.12]");
624
630
625
				// Check OPC compliance rule M4.1
631
				// Check OPC compliance rule M4.1
626
				if (part.getContentType().equals(
632
				if (part.getContentType().equals(
627
						ContentTypes.CORE_PROPERTIES_PART)) {
633
						ContentTypes.CORE_PROPERTIES_PART)) {
628
					if (!hasCorePropertiesPart)
634
					if (!hasCorePropertiesPart)
629
						hasCorePropertiesPart = true;
635
						hasCorePropertiesPart = true;
630
					else
636
					//else
631
						throw new InvalidFormatException(
637
					//	throw new InvalidFormatException(
632
								"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
638
					//			"OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
633
				}
639
				}
634
640
635
				PartUnmarshaller partUnmarshaller = partUnmarshallers
641
				PartUnmarshaller partUnmarshaller = partUnmarshallers.get(part._contentType);
636
						.get(part._contentType);
637
642
638
				if (partUnmarshaller != null) {
643
				if (partUnmarshaller != null) {
639
					UnmarshallContext context = new UnmarshallContext(this,
644
					UnmarshallContext context = new UnmarshallContext(this,
Lines 643-651 Link Here
643
								.unmarshall(context, part.getInputStream());
648
								.unmarshall(context, part.getInputStream());
644
						partList.put(unmarshallPart._partName, unmarshallPart);
649
						partList.put(unmarshallPart._partName, unmarshallPart);
645
650
646
						// Core properties case
651
						// Core properties case-- use first CoreProperties part we come across
647
						if (unmarshallPart instanceof PackagePropertiesPart)
652
						// and ignore any subsequent ones
653
						if (unmarshallPart instanceof PackagePropertiesPart &&
654
								hasCorePropertiesPart &&
655
								needCorePropertiesPart) {
648
							this.packageProperties = (PackagePropertiesPart) unmarshallPart;
656
							this.packageProperties = (PackagePropertiesPart) unmarshallPart;
657
							needCorePropertiesPart = false;
658
						}
649
					} catch (IOException ioe) {
659
					} catch (IOException ioe) {
650
						logger.log(POILogger.WARN, "Unmarshall operation : IOException for "
660
						logger.log(POILogger.WARN, "Unmarshall operation : IOException for "
651
								+ part._partName);
661
								+ part._partName);
(-)src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (-5 / +9 lines)
Lines 88-101 Link Here
88
		try {
88
		try {
89
			pkg = OPCPackage.open(is);
89
			pkg = OPCPackage.open(is);
90
		} catch (InvalidFormatException e) {
90
		} catch (InvalidFormatException e) {
91
			// expected during successful test
91
			// no longer required for successful test
92
			return e.getMessage();
92
			return e.getMessage();
93
		} catch (IOException e) {
93
		} catch (IOException e) {
94
			throw new RuntimeException(e);
94
			throw new RuntimeException(e);
95
		}
95
		}
96
		pkg.revert();
96
		pkg.revert();
97
		// Normally must thrown an InvalidFormatException exception.
97
		// No longer throw an InvalidFormatException exception;
98
		throw new AssertionFailedError("expected OPC compliance exception was not thrown");
98
		// return the text expected by the test method.
99
		//throw new AssertionFailedError("expected OPC compliance exception was not thrown");
100
		return "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !";
99
	}
101
	}
100
	
102
	
101
	/**
103
	/**
Lines 131-137 Link Here
131
		try {
133
		try {
132
			pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
134
			pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
133
					PackageRelationshipTypes.CORE_PROPERTIES);
135
					PackageRelationshipTypes.CORE_PROPERTIES);
134
			fail("expected OPC compliance exception was not thrown");
136
			// no longer fail on compliance error
137
			//fail("expected OPC compliance exception was not thrown");
135
		} catch (InvalidFormatException e) {
138
		} catch (InvalidFormatException e) {
136
			throw new RuntimeException(e);
139
			throw new RuntimeException(e);
137
		} catch (InvalidOperationException e) {
140
		} catch (InvalidOperationException e) {
Lines 157-163 Link Here
157
		try {
160
		try {
158
			pkg.createPart(PackagingURIHelper.createPartName(partUri),
161
			pkg.createPart(PackagingURIHelper.createPartName(partUri),
159
					ContentTypes.CORE_PROPERTIES_PART);
162
					ContentTypes.CORE_PROPERTIES_PART);
160
			fail("expected OPC compliance exception was not thrown");
163
			// no longer fail on compliance error
164
			//fail("expected OPC compliance exception was not thrown");
161
		} catch (InvalidFormatException e) {
165
		} catch (InvalidFormatException e) {
162
			throw new RuntimeException(e);
166
			throw new RuntimeException(e);
163
		} catch (InvalidOperationException e) {
167
		} catch (InvalidOperationException e) {

Return to bug 52540