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.util.xml;
10 import org.openexi.proc.common.AlignmentType;
11 import org.openexi.proc.common.EXIOptions;
12 import org.openexi.proc.common.EXIOptionsException;
14 import com.google.common.base.Preconditions;
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 static final String EXI_PARAMETER_SCHEMA = "schema";
31 private static final String EXI_PARAMETER_SCHEMA_NONE = "none";
32 private static final String EXI_PARAMETER_SCHEMA_BUILT_IN = "builtin";
33 private static final String EXI_PARAMETER_SCHEMA_BASE_1_1 = "base:1.1";
35 private final EXIOptions options;
37 private EXIParameters(final EXIOptions options) {
38 this.options = Preconditions.checkNotNull(options);
41 public static EXIParameters forXmlElement(final XmlElement root) throws EXIOptionsException {
42 final EXIOptions options = new EXIOptions();
44 options.setAlignmentType(AlignmentType.bitPacked);
45 if (root.getElementsByTagName(EXI_PARAMETER_ALIGNMENT).getLength() > 0) {
46 if (root.getElementsByTagName(EXI_PARAMETER_BIT_PACKED).getLength() > 0) {
47 options.setAlignmentType(AlignmentType.bitPacked);
48 } else if (root.getElementsByTagName(EXI_PARAMETER_BYTE_ALIGNED).getLength() > 0) {
49 options.setAlignmentType(AlignmentType.byteAligned);
50 } else if (root.getElementsByTagName(EXI_PARAMETER_COMPRESSED).getLength() > 0) {
51 options.setAlignmentType(AlignmentType.compress);
52 } else if (root.getElementsByTagName(EXI_PARAMETER_PRE_COMPRESSION).getLength() > 0) {
53 options.setAlignmentType(AlignmentType.preCompress);
57 if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
58 if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
59 options.setPreserveDTD(true);
61 if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
62 options.setPreserveLexicalValues(true);
64 if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
65 options.setPreserveComments(true);
67 if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
68 options.setPreservePIs(true);
70 if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
71 options.setPreserveNS(true);
75 if (root.getElementsByTagName(EXI_PARAMETER_SCHEMA).getLength() > 0) {
77 // GrammarFactory grammarFactory = GrammarFactory.newInstance();
78 // if (operationElement
79 // .getElementsByTagName(EXI_PARAMETER_SCHEMA_NONE)
80 // .getLength() > 0) {
81 // this.grammars = grammarFactory.createSchemaLessGrammars();
84 // if (operationElement.getElementsByTagName(
85 // EXI_PARAMETER_SCHEMA_BUILT_IN).getLength() > 0) {
86 // this.grammars = grammarFactory.createXSDTypesOnlyGrammars();
89 // if (operationElement.getElementsByTagName(
90 // EXI_PARAMETER_SCHEMA_BASE_1_1).getLength() > 0) {
91 // this.grammars = grammarFactory
92 // .createGrammars(NETCONF_XSD_LOCATION);
97 return new EXIParameters(options);
100 public final EXIOptions getOptions() {