Skip to content

Commit

Permalink
Merge pull request #1391 from veraPDF/static_xmp_containers
Browse files Browse the repository at this point in the history
Add StaticXmpCoreContainers
  • Loading branch information
MaximPlusov authored and Git User committed Dec 11, 2023
1 parent ec1f40c commit f992b28
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 109 deletions.
5 changes: 3 additions & 2 deletions xmp-core/src/main/java/org/verapdf/xmp/XMPSchemaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ public interface XMPSchemaRegistry
* otherwise the existing prefix.
* @throws XMPException If the parameters are not accordingly set
*/
String registerNamespace(String namespaceURI, String suggestedPrefix) throws XMPException;
String registerStandardNamespace(String namespaceURI, String suggestedPrefix) throws XMPException;

String registerNamespace(String namespaceURI, String suggestedPrefix, boolean isStandard) throws XMPException;


/**
* Obtain the prefix for a registered namespace URI.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.verapdf.xmp.containers;

import java.util.*;

public class StaticXmpCoreContainers {

/**
* a map from a namespace URI to its registered prefix
*/
private static final ThreadLocal<Map<String, String>> namespaceToPrefixMap = new ThreadLocal<>();

/**
* a map from a prefix to the associated namespace URI
*/
private static final ThreadLocal<Map<String, String>> prefixToNamespaceMap = new ThreadLocal<>();

public static void clearAllContainers() {
namespaceToPrefixMap.set(new HashMap<>());
prefixToNamespaceMap.set(new HashMap<>());
}

public static Map<String, String> getNamespaceToPrefixMap() {
return namespaceToPrefixMap.get();
}

public static Map<String, String> getPrefixToNamespaceMap() {
return prefixToNamespaceMap.get();
}

public static void setNamespaceToPrefixMap(Map<String, String> namespaceToPrefixMap) {
StaticXmpCoreContainers.namespaceToPrefixMap.set(namespaceToPrefixMap);
}

public static void setPrefixToNamespaceMap(Map<String, String> prefixToNamespaceMap) {
StaticXmpCoreContainers.prefixToNamespaceMap.set(prefixToNamespaceMap);
}
}
2 changes: 1 addition & 1 deletion xmp-core/src/main/java/org/verapdf/xmp/impl/ParseRDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ private static XMPNode addChildNode(XMPMetaImpl xmp, XMPNode xmpParent, Node xml
if (prefix == null)
{
prefix = xmlNode.getPrefix() != null ? xmlNode.getPrefix() : DEFAULT_PREFIX;
prefix = registry.registerNamespace(namespace, prefix);
prefix = registry.registerNamespace(namespace, prefix, false);
}
childName = prefix + xmlNode.getLocalName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static XMPNode findSchemaNode(XMPNode tree, String namespaceURI, String suggeste
if (suggestedPrefix != null && suggestedPrefix.length() != 0)
{
prefix = XMPMetaFactory.getSchemaRegistry().registerNamespace(namespaceURI,
suggestedPrefix);
suggestedPrefix, false);
}
else
{
Expand Down
Loading

0 comments on commit f992b28

Please sign in to comment.