YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / IgnoreWhiteCharsDiffListener.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.impl;
9
10 import org.custommonkey.xmlunit.Difference;
11 import org.custommonkey.xmlunit.DifferenceConstants;
12 import org.custommonkey.xmlunit.DifferenceListener;
13
14 /**
15  * Implementatin of {@link DifferenceListener} ignoring white characters around text elements.
16  *
17  * @author mirehak
18  */
19 public class IgnoreWhiteCharsDiffListener implements DifferenceListener {
20
21     @Override
22     public void skippedComparison(org.w3c.dom.Node control,
23             org.w3c.dom.Node test) {
24         // do nothing
25     }
26
27     @Override
28     public int differenceFound(Difference diff) {
29
30         if (diff.getId() == DifferenceConstants.TEXT_VALUE.getId()) {
31             String control = diff.getControlNodeDetail().getValue();
32             if (control != null) {
33                 control = control.trim();
34                 if (diff.getTestNodeDetail().getValue() != null
35                     && control.equals(diff.getTestNodeDetail().getValue().trim())) {
36                     return
37                         DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
38                 }
39             }
40         }
41         return RETURN_ACCEPT_DIFFERENCE;
42     }
43 }