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;
16 public final class EXIParameters {
17 private static final String EXI_PARAMETER_ALIGNMENT = "alignment";
18 private static final String EXI_PARAMETER_BYTE_ALIGNED = "byte-aligned";
19 private static final String EXI_PARAMETER_BIT_PACKED = "bit-packed";
20 private static final String EXI_PARAMETER_COMPRESSED = "compressed";
21 private static final String EXI_PARAMETER_PRE_COMPRESSION = "pre-compression";
23 private static final String EXI_PARAMETER_FIDELITY = "fidelity";
24 private static final String EXI_FIDELITY_DTD = "dtd";
25 private static final String EXI_FIDELITY_LEXICAL_VALUES = "lexical-values";
26 private static final String EXI_FIDELITY_COMMENTS = "comments";
27 private static final String EXI_FIDELITY_PIS = "pis";
28 private static final String EXI_FIDELITY_PREFIXES = "prefixes";
30 private final EXIOptions options;
32 private EXIParameters(final EXIOptions options) {
33 this.options = Preconditions.checkNotNull(options);
37 public static EXIParameters fromXmlElement(final XmlElement root) throws EXIOptionsException {
38 final EXIOptions options = new EXIOptions();
40 options.setAlignmentType(AlignmentType.bitPacked);
41 if (root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT).getLength() > 0) {
42 if (root.getElementsByTagName(EXI_PARAMETER_BIT_PACKED).getLength() > 0) {
43 options.setAlignmentType(AlignmentType.bitPacked);
44 } else if (root.getElementsByTagName(EXI_PARAMETER_BYTE_ALIGNED).getLength() > 0) {
45 options.setAlignmentType(AlignmentType.byteAligned);
46 } else if (root.getElementsByTagName(EXI_PARAMETER_COMPRESSED).getLength() > 0) {
47 options.setAlignmentType(AlignmentType.compress);
48 } else if (root.getElementsByTagName(EXI_PARAMETER_PRE_COMPRESSION).getLength() > 0) {
49 options.setAlignmentType(AlignmentType.preCompress);
53 if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
54 if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
55 options.setPreserveDTD(true);
57 if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
58 options.setPreserveLexicalValues(true);
60 if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
61 options.setPreserveComments(true);
63 if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
64 options.setPreservePIs(true);
66 if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
67 options.setPreserveNS(true);
70 return new EXIParameters(options);
73 public final EXIOptions getOptions() {