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 com.google.common.base.Preconditions;
11 import org.opendaylight.controller.netconf.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.w3c.dom.Element;
16 import org.w3c.dom.NodeList;
18 public final class EXIParameters {
19 private static final String EXI_PARAMETER_ALIGNMENT = "alignment";
20 static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned";
21 static final String EXI_PARAMETER_BIT_PACKED = "bit-packed";
22 static final String EXI_PARAMETER_COMPRESSED = "compressed";
23 static final String EXI_PARAMETER_PRE_COMPRESSION = "pre-compression";
25 private static final String EXI_PARAMETER_FIDELITY = "fidelity";
26 private static final String EXI_FIDELITY_DTD = "dtd";
27 private static final String EXI_FIDELITY_LEXICAL_VALUES = "lexical-values";
28 private static final String EXI_FIDELITY_COMMENTS = "comments";
29 private static final String EXI_FIDELITY_PIS = "pis";
30 private static final String EXI_FIDELITY_PREFIXES = "prefixes";
32 private final EXIOptions options;
34 private EXIParameters(final EXIOptions options) {
35 this.options = Preconditions.checkNotNull(options);
39 public static EXIParameters fromXmlElement(final XmlElement root) throws EXIOptionsException {
40 final EXIOptions options = new EXIOptions();
42 options.setAlignmentType(AlignmentType.bitPacked);
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_BIT_PACKED:
51 options.setAlignmentType(AlignmentType.bitPacked);
53 case EXI_PARAMETER_BYTE_ALIGNED:
54 options.setAlignmentType(AlignmentType.byteAligned);
56 case EXI_PARAMETER_COMPRESSED:
57 options.setAlignmentType(AlignmentType.compress);
59 case EXI_PARAMETER_PRE_COMPRESSION:
60 options.setAlignmentType(AlignmentType.preCompress);
65 if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
66 if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
67 options.setPreserveDTD(true);
69 if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
70 options.setPreserveLexicalValues(true);
72 if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
73 options.setPreserveComments(true);
75 if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
76 options.setPreservePIs(true);
78 if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
79 options.setPreserveNS(true);
82 return new EXIParameters(options);
85 public final EXIOptions getOptions() {