X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fhandler%2FNetconfMessageToXMLEncoder.java;fp=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fhandler%2FNetconfMessageToXMLEncoder.java;h=0000000000000000000000000000000000000000;hp=121ef8d7434eac609e55ff083a902e2a07cf92d8;hb=c3108b4e80ec9f6ee6c8cf96df3009bb91dc8bc0;hpb=04a788d2df5303c60cdbcff02254291f411566bd diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfMessageToXMLEncoder.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfMessageToXMLEncoder.java deleted file mode 100644 index 121ef8d743..0000000000 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/NetconfMessageToXMLEncoder.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.netconf.util.handler; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufOutputStream; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; - -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.util.xml.XmlUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Comment; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; - -public class NetconfMessageToXMLEncoder extends MessageToByteEncoder { - private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageToXMLEncoder.class); - private static final TransformerFactory FACTORY = TransformerFactory.newInstance(); - - private final Optional clientId; - - public NetconfMessageToXMLEncoder() { - this(Optional.absent()); - } - - public NetconfMessageToXMLEncoder(Optional clientId) { - this.clientId = clientId; - } - - @Override - @VisibleForTesting - public void encode(ChannelHandlerContext ctx, NetconfMessage msg, ByteBuf out) throws IOException, TransformerException { - LOG.trace("Sent to encode : {}", XmlUtil.toString(msg.getDocument())); - - if (clientId.isPresent()) { - Comment comment = msg.getDocument().createComment("clientId:" + clientId.get()); - msg.getDocument().appendChild(comment); - } - - try (OutputStream os = new ByteBufOutputStream(out)) { - Transformer transformer = FACTORY.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - - StreamResult result = new StreamResult(new OutputStreamWriter(os)); - DOMSource source = new DOMSource(msg.getDocument()); - transformer.transform(source, result); - } - } -}