import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.Provider;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import org.opendaylight.netconf.sal.rest.api.Draft02;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.utils.patch.Draft16XmlToPATCHBodyReader;
+import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.w3c.dom.NodeList;
/**
- * @deprecated This class will be replaced by {@link Draft16XmlToPATCHBodyReader}
+ * @deprecated This class will be replaced by
+ * {@link org.opendaylight.restconf.jersey.providers.XmlToPATCHBodyReader}
*/
@Deprecated
@Provider
MessageBodyReader<PATCHContext> {
private final static Logger LOG = LoggerFactory.getLogger(XmlToPATCHBodyReader.class);
- private static final DocumentBuilderFactory BUILDERFACTORY;
-
- static {
- final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- try {
- factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
- factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
- factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
- factory.setXIncludeAware(false);
- factory.setExpandEntityReferences(false);
- } catch (final ParserConfigurationException e) {
- throw new ExceptionInInitializerError(e);
- }
- factory.setNamespaceAware(true);
- factory.setCoalescing(true);
- factory.setIgnoringElementContentWhitespace(true);
- factory.setIgnoringComments(true);
- BUILDERFACTORY = factory;
- }
@Override
public boolean isReadable(final Class<?> type, final Type genericType,
return new PATCHContext(path, null, null);
}
- final DocumentBuilder dBuilder;
- try {
- dBuilder = BUILDERFACTORY.newDocumentBuilder();
- } catch (final ParserConfigurationException e) {
- throw new IllegalStateException("Failed to parse XML document", e);
- }
- final Document doc = dBuilder.parse(entityStream);
-
+ final Document doc = UntrustedXML.newDocumentBuilder().parse(entityStream);
return parse(path, doc);
} catch (final RestconfDocumentedException e) {
throw e;
}
}
- private PATCHContext parse(final InstanceIdentifierContext<?> pathContext, final Document doc) {
+ private static PATCHContext parse(final InstanceIdentifierContext<?> pathContext, final Document doc) {
final List<PATCHEntity> resultCollection = new ArrayList<>();
final String patchId = doc.getElementsByTagName("patch-id").item(0).getFirstChild().getNodeValue();
final NodeList editNodes = doc.getElementsByTagName("edit");
* @param operation Name of current operation
* @return List of value elements
*/
- private List<Element> readValueNodes(@Nonnull final Element element, @Nonnull final String operation) {
+ private static List<Element> readValueNodes(@Nonnull final Element element, @Nonnull final String operation) {
final Node valueNode = element.getElementsByTagName("value").item(0);
- if (PATCHEditOperation.isPatchOperationWithValue(operation) && valueNode == null) {
+ if (PATCHEditOperation.isPatchOperationWithValue(operation) && (valueNode == null)) {
throw new RestconfDocumentedException("Error parsing input",
ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
- if (!PATCHEditOperation.isPatchOperationWithValue(operation) && valueNode != null) {
+ if (!PATCHEditOperation.isPatchOperationWithValue(operation) && (valueNode != null)) {
throw new RestconfDocumentedException("Error parsing input",
ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
* @param revision Module revision
* @return Non-conditional XPath
*/
- private String prepareNonCondXpath(@Nonnull final DataSchemaNode schemaNode, @Nonnull final String target,
- @Nonnull final Element value, @Nonnull final String namespace,
- @Nonnull String revision) {
+ private static String prepareNonCondXpath(@Nonnull final DataSchemaNode schemaNode, @Nonnull final String target,
+ @Nonnull final Element value, @Nonnull final String namespace, @Nonnull final String revision) {
final Iterator<String> args = Splitter.on("/").split(target.substring(target.indexOf(':') + 1)).iterator();
final StringBuilder nonCondXpath = new StringBuilder();
nonCondXpath.append(s);
childNode = ((DataNodeContainer) childNode).getDataChildByName(QName.create(namespace, revision, s));
- if (childNode instanceof ListSchemaNode && args.hasNext()) {
+ if ((childNode instanceof ListSchemaNode) && args.hasNext()) {
appendKeys(nonCondXpath, ((ListSchemaNode) childNode).getKeyDefinition().iterator(), args);
}
}
- if (childNode instanceof ListSchemaNode && value != null) {
+ if ((childNode instanceof ListSchemaNode) && (value != null)) {
final Iterator<String> keyValues = readKeyValues(value,
((ListSchemaNode) childNode).getKeyDefinition().iterator());
appendKeys(nonCondXpath, ((ListSchemaNode) childNode).getKeyDefinition().iterator(), keyValues);
* @param keys Iterator of list keys names
* @return Iterator of list keys values
*/
- private Iterator<String> readKeyValues(@Nonnull final Element value, @Nonnull final Iterator<QName> keys) {
+ private static Iterator<String> readKeyValues(@Nonnull final Element value, @Nonnull final Iterator<QName> keys) {
final List<String> result = new ArrayList<>();
while (keys.hasNext()) {
* @param keyNames Iterator of list keys names
* @param keyValues Iterator of list keys values
*/
- private void appendKeys(@Nonnull final StringBuilder nonCondXpath, @Nonnull final Iterator<QName> keyNames,
+ private static void appendKeys(@Nonnull final StringBuilder nonCondXpath, @Nonnull final Iterator<QName> keyNames,
@Nonnull final Iterator<String> keyValues) {
while (keyNames.hasNext()) {
nonCondXpath.append("[");