2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.nettyutil.handler.exi;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.config.util.xml.XmlElement;
12 import org.openexi.proc.common.AlignmentType;
13 import org.openexi.proc.common.EXIOptions;
14 import org.openexi.proc.common.EXIOptionsException;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.w3c.dom.Element;
18 import org.w3c.dom.NodeList;
20 public final class EXIParameters {
21 private static final String EXI_PARAMETER_ALIGNMENT = "alignment";
22 static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned";
23 static final String EXI_PARAMETER_BIT_PACKED = "bit-packed";
24 static final String EXI_PARAMETER_COMPRESSED = "compressed";
25 static final String EXI_PARAMETER_PRE_COMPRESSION = "pre-compression";
27 private static final String EXI_PARAMETER_FIDELITY = "fidelity";
28 private static final String EXI_FIDELITY_DTD = "dtd";
29 private static final String EXI_FIDELITY_LEXICAL_VALUES = "lexical-values";
30 private static final String EXI_FIDELITY_COMMENTS = "comments";
31 private static final String EXI_FIDELITY_PIS = "pis";
32 private static final String EXI_FIDELITY_PREFIXES = "prefixes";
34 private final EXIOptions options;
35 private static final Logger LOG = LoggerFactory.getLogger(EXIParameters.class);
37 private EXIParameters(final EXIOptions options) {
38 this.options = Preconditions.checkNotNull(options);
41 @SuppressWarnings("checkstyle:FallThrough")
42 public static EXIParameters fromXmlElement(final XmlElement root) throws EXIOptionsException {
43 final EXIOptions options = new EXIOptions();
44 final NodeList alignmentElements = root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT);
45 if (alignmentElements.getLength() > 0) {
46 final Element alignmentElement = (Element) alignmentElements.item(0);
47 final String alignmentTextContent = alignmentElement.getTextContent().trim();
49 switch (alignmentTextContent) {
50 case EXI_PARAMETER_BYTE_ALIGNED:
51 options.setAlignmentType(AlignmentType.byteAligned);
53 case EXI_PARAMETER_COMPRESSED:
54 options.setAlignmentType(AlignmentType.compress);
56 case EXI_PARAMETER_PRE_COMPRESSION:
57 options.setAlignmentType(AlignmentType.preCompress);
60 LOG.warn("Unexpected value in alignmentTextContent: {} , using default value",
61 alignmentTextContent);
62 case EXI_PARAMETER_BIT_PACKED:
63 options.setAlignmentType(AlignmentType.bitPacked);
67 options.setAlignmentType(AlignmentType.bitPacked);
70 final NodeList fidelityElements = root.getElementsByTagName(EXI_PARAMETER_FIDELITY);
71 if (fidelityElements.getLength() > 0) {
72 final Element fidelityElement = (Element) fidelityElements.item(0);
73 if (fidelityElement.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
74 options.setPreserveDTD(true);
76 if (fidelityElement.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
77 options.setPreserveLexicalValues(true);
79 if (fidelityElement.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
80 options.setPreserveComments(true);
82 if (fidelityElement.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
83 options.setPreservePIs(true);
85 if (fidelityElement.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
86 options.setPreserveNS(true);
89 return new EXIParameters(options);
92 public EXIOptions getOptions() {