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.controller.netconf.nettyutil.handler.exi;
10 import org.opendaylight.controller.netconf.util.xml.XmlElement;
11 import org.openexi.proc.common.AlignmentType;
12 import org.openexi.proc.common.EXIOptions;
13 import org.openexi.proc.common.EXIOptionsException;
14 import org.w3c.dom.Element;
15 import org.w3c.dom.NodeList;
17 import com.google.common.base.Preconditions;
19 public final class EXIParameters {
20 private static final String EXI_PARAMETER_ALIGNMENT = "alignment";
21 static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned";
22 static final String EXI_PARAMETER_BIT_PACKED = "bit-packed";
23 static final String EXI_PARAMETER_COMPRESSED = "compressed";
24 static final String EXI_PARAMETER_PRE_COMPRESSION = "pre-compression";
26 private static final String EXI_PARAMETER_FIDELITY = "fidelity";
27 private static final String EXI_FIDELITY_DTD = "dtd";
28 private static final String EXI_FIDELITY_LEXICAL_VALUES = "lexical-values";
29 private static final String EXI_FIDELITY_COMMENTS = "comments";
30 private static final String EXI_FIDELITY_PIS = "pis";
31 private static final String EXI_FIDELITY_PREFIXES = "prefixes";
33 private final EXIOptions options;
35 private EXIParameters(final EXIOptions options) {
36 this.options = Preconditions.checkNotNull(options);
40 public static EXIParameters fromXmlElement(final XmlElement root) throws EXIOptionsException {
41 final EXIOptions options = new EXIOptions();
43 options.setAlignmentType(AlignmentType.bitPacked);
45 final NodeList alignmentElements = root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT);
46 if (alignmentElements.getLength() > 0) {
47 final Element alignmentElement = (Element) alignmentElements.item(0);
48 final String alignmentTextContent = alignmentElement.getTextContent().trim();
50 switch (alignmentTextContent) {
51 case EXI_PARAMETER_BIT_PACKED:
52 options.setAlignmentType(AlignmentType.bitPacked);
54 case EXI_PARAMETER_BYTE_ALIGNED:
55 options.setAlignmentType(AlignmentType.byteAligned);
57 case EXI_PARAMETER_COMPRESSED:
58 options.setAlignmentType(AlignmentType.compress);
60 case EXI_PARAMETER_PRE_COMPRESSION:
61 options.setAlignmentType(AlignmentType.preCompress);
66 if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
67 if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
68 options.setPreserveDTD(true);
70 if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
71 options.setPreserveLexicalValues(true);
73 if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
74 options.setPreserveComments(true);
76 if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
77 options.setPreservePIs(true);
79 if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
80 options.setPreserveNS(true);
83 return new EXIParameters(options);
86 public final EXIOptions getOptions() {