Skip to content

Commit 47e29ce

Browse files
committed
PDFBOX-2378: revert initial change (avoid rdf namespace declarations getting lost in serialization), it is no longer needed
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930042 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2258cbb commit 47e29ce

File tree

4 files changed

+24
-67
lines changed

4 files changed

+24
-67
lines changed

xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package org.apache.xmpbox;
2222

2323
import java.util.ArrayList;
24-
import java.util.Collections;
2524
import java.util.Iterator;
2625
import java.util.List;
2726
import java.util.Map;
@@ -64,8 +63,6 @@ public class XMPMetadata
6463

6564
private final List<XMPSchema> schemas;
6665

67-
private Map<String, String> rdfAttributeMap = Collections.emptyMap();
68-
6966
private final TypeMapping typeMapping;
7067

7168
/**
@@ -578,24 +575,4 @@ public void clearSchemas()
578575
{
579576
schemas.clear();
580577
}
581-
582-
/**
583-
* Get the rdf attribute map (namespace declarations). This is used in serialization.
584-
*
585-
* @return the rdf attribute map.
586-
*/
587-
public Map<String, String> getRdfAttributeMap()
588-
{
589-
return Collections.unmodifiableMap(rdfAttributeMap);
590-
}
591-
592-
/**
593-
* Set the rdf attribute map (namespace declarations). This is used in serialization.
594-
*
595-
* @param rdfAttributeMap an rdf attribute map.
596-
*/
597-
public void setRdfAttributeMap(Map<String, String> rdfAttributeMap)
598-
{
599-
this.rdfAttributeMap = rdfAttributeMap;
600-
}
601578
}

xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,6 @@ public XMPMetadata parse(InputStream input) throws XmpParsingException
195195
}
196196
}
197197

198-
// PDFBOX-2378: keep rdf namespace declarations for later serialization
199-
NamedNodeMap attributes = rdfRdf.getAttributes();
200-
if (attributes != null)
201-
{
202-
Map<String, String> rdfAttributeMap = new HashMap<>();
203-
for (int i = 0; i < attributes.getLength(); ++i)
204-
{
205-
Node item = attributes.item(i);
206-
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(item.getNamespaceURI()))
207-
{
208-
rdfAttributeMap.put(item.getNodeName(), item.getNodeValue());
209-
}
210-
}
211-
xmp.setRdfAttributeMap(rdfAttributeMap);
212-
}
213198
// find schema description
214199
PdfaExtensionHelper.populateSchemaMapping(xmp);
215200
// parse data description

xmpbox/src/main/java/org/apache/xmpbox/xml/XmpSerializer.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.OutputStream;
2424
import java.util.ArrayList;
2525
import java.util.List;
26-
import java.util.Map;
2726

2827
import javax.xml.XMLConstants;
2928
import javax.xml.parsers.DocumentBuilder;
@@ -98,12 +97,6 @@ public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket
9897
{
9998
rdf.appendChild(serializeSchema(doc, schema));
10099
}
101-
// PDFBOX-2378: avoid rdf namespace declarations getting lost in serialization
102-
Map<String, String> rdfAttributeMap = metadata.getRdfAttributeMap();
103-
for (Map.Entry<String, String> entry : rdfAttributeMap.entrySet())
104-
{
105-
rdf.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, entry.getKey(), entry.getValue());
106-
}
107100
// save
108101
save(doc, os, "UTF-8");
109102
}
@@ -166,7 +159,7 @@ public void serializeFields(Document doc, Element parent, List<AbstractField> fi
166159
}
167160
}
168161

169-
// PDFBOX-2378 part 2: add namespace declaration to the top
162+
// PDFBOX-2378: add namespace declaration to the top
170163
if (!field.getPrefix().isEmpty() && field.getNamespace() != null && !field.getNamespace().isEmpty())
171164
{
172165
rdf.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + field.getPrefix(), field.getNamespace());

xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
import org.junit.jupiter.api.Test;
5454
import org.apache.xmpbox.xml.XmpSerializer;
5555

56+
/**
57+
* DomXmpParser imports the XML into an internal representation. XmpSerializer exports this into
58+
* XML. The result may look different, but should be the same from a data point of view.
59+
*
60+
* @author Tilman Hausherr
61+
*/
5662
class DeserializationTest
5763
{
5864

@@ -93,7 +99,7 @@ void testStructuredRecursive() throws XmpParsingException, TransformerException,
9399
try (InputStream is = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/structured_recursive.xml"))
94100
{
95101
XMPMetadata metadata = xdb.parse(is);
96-
checkTransform(metadata, "52753264982056308826419701767667619100664406974698584945629426171445624909200", metadata.getAllSchemas().size());
102+
checkTransform(metadata, "62495942572014793625872774972947435765670563107818217447706375288846297812281", metadata.getAllSchemas().size());
97103
}
98104
}
99105

@@ -103,7 +109,7 @@ void testEmptyLi() throws XmpParsingException, TransformerException, NoSuchAlgor
103109
try (InputStream is = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/empty_list.xml"))
104110
{
105111
XMPMetadata metadata = xdb.parse(is);
106-
checkTransform(metadata, "19567447256605061134904612869562878052777123273535814661244629430271579345577", metadata.getAllSchemas().size());
112+
checkTransform(metadata, "95754993383010030299848397520773287413798669761891751126809013411187892693280", metadata.getAllSchemas().size());
107113
}
108114
}
109115

@@ -137,7 +143,7 @@ void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlg
137143
try (InputStream is = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml"))
138144
{
139145
XMPMetadata metadata = xdb.parse(is);
140-
checkTransform(metadata, "19154431745733679891721944365143324348437445906324353036103478292448653362772", metadata.getAllSchemas().size());
146+
checkTransform(metadata, "89123270336154452745819041017446278583816329940574853160909598044560152910018", metadata.getAllSchemas().size());
141147
}
142148
}
143149

@@ -180,7 +186,7 @@ void testIsartorStyleWithThumbs()
180186
assertEquals("JPEG", thumb.getFormat());
181187
assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
182188

183-
checkTransform(metadata, "84558386150683037967795120526515137256954964034058806864845109667021390825020", metadata.getAllSchemas().size());
189+
checkTransform(metadata, "64755266855514150823517184659364700851455308334441170957883187622624192802093", metadata.getAllSchemas().size());
184190
}
185191
}
186192

@@ -203,15 +209,12 @@ void testWithNoXPacketEnd() throws IOException
203209
{
204210
try (InputStream is = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacketend.xml"))
205211
{
206-
try
207-
{
208-
xdb.parse(is);
209-
fail("Should fail during parse");
210-
}
211-
catch (XmpParsingException e)
212-
{
213-
assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
214-
}
212+
xdb.parse(is);
213+
fail("Should fail during parse");
214+
}
215+
catch (XmpParsingException e)
216+
{
217+
assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
215218
}
216219
}
217220

@@ -223,7 +226,7 @@ void testWithNoRDFElement() throws XmpParsingException, IOException
223226
xdb.parse(is);
224227
fail("Should fail during parse");
225228
}
226-
catch(XmpParsingException e)
229+
catch (XmpParsingException e)
227230
{
228231
assertEquals(ErrorType.Format, e.getErrorType());
229232
}
@@ -330,7 +333,6 @@ void testRdfAboutFound() throws XmpParsingException, IOException
330333
@Test
331334
void testWithAttributesAsProperties() throws XmpParsingException, TransformerException, NoSuchAlgorithmException, IOException
332335
{
333-
// also serves as a test for the changes in PDFBOX-2378
334336
try (InputStream is = DomXmpParser.class.getResourceAsStream("/validxmp/attr_as_props.xml"))
335337
{
336338
XMPMetadata metadata = xdb.parse(is);
@@ -344,7 +346,7 @@ void testWithAttributesAsProperties() throws XmpParsingException, TransformerExc
344346
XMPBasicSchema basic = metadata.getXMPBasicSchema();
345347
assertNotNull(basic.getCreateDate());
346348

347-
checkTransform(metadata, "103011318952861241491609772230618389876889507758821590919505444434501582047075", metadata.getAllSchemas().size());
349+
checkTransform(metadata, "27499224985683016678197540524065114038595582230834506941950503218519476041225", metadata.getAllSchemas().size());
348350
}
349351
}
350352

@@ -353,20 +355,20 @@ void testSpaceTextValues() throws XmpParsingException, TransformerException, NoS
353355
{
354356
// check values with spaces at start or end
355357
// in this case, the value should not be trimmed
356-
try(InputStream is = DomXmpParser.class.getResourceAsStream("/validxmp/only_space_fields.xmp"))
358+
try (InputStream is = DomXmpParser.class.getResourceAsStream("/validxmp/only_space_fields.xmp"))
357359
{
358360
XMPMetadata metadata = xdb.parse(is);
359361
// check producer
360362
assertEquals(" ", metadata.getAdobePDFSchema().getProducer());
361363
// check creator tool
362364
assertEquals("Canon ", metadata.getXMPBasicSchema().getCreatorTool());
363365

364-
checkTransform(metadata, "35040104785033687813052387728441520994588808120158942942660631178163542677230", metadata.getAllSchemas().size());
366+
checkTransform(metadata, "9220923061800113567693538810355030344095407871190202111473587642358933618073", metadata.getAllSchemas().size());
365367
}
366368
}
367369

368370
@Test
369-
void testMetadataParsing() throws TransformerException, NoSuchAlgorithmException, XmpParsingException
371+
void testMetadataParsing() throws TransformerException, NoSuchAlgorithmException, XmpParsingException, IOException
370372
{
371373
XMPMetadata metadata = XMPMetadata.createXMPMetadata();
372374

@@ -391,7 +393,7 @@ void testMetadataParsing() throws TransformerException, NoSuchAlgorithmException
391393
* @throws NoSuchAlgorithmException
392394
*/
393395
@Test
394-
void testEmptyDate() throws XmpParsingException, TransformerException, NoSuchAlgorithmException
396+
void testEmptyDate() throws XmpParsingException, TransformerException, NoSuchAlgorithmException, IOException
395397
{
396398
String xmpmeta = "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n"
397399
+ "<x:xmpmeta x:xmptk=\"Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-20:48:00\" xmlns:x=\"adobe:ns:meta/\">\n"
@@ -403,7 +405,7 @@ void testEmptyDate() throws XmpParsingException, TransformerException, NoSuchAlg
403405
+ "</x:xmpmeta>\n"
404406
+ "<?xpacket end=\"w\"?>";
405407
XMPMetadata metadata = xdb.parse(xmpmeta.getBytes(StandardCharsets.UTF_8));
406-
checkTransform(metadata, "114563613226112098345006389295317658957506710850378716324758103164733276333281", metadata.getAllSchemas().size());
408+
checkTransform(metadata, "19030153876683461724958694183980892665426846590791273142114566290124997390122", metadata.getAllSchemas().size());
407409
}
408410

409411
private void checkTransform(XMPMetadata metadata, String expected, int expectedSchemaCount)

0 commit comments

Comments
 (0)