2c8a16cbe1db93b57cef255bdec5e0eb774eb7d2
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / xml / EXIParameters.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.netconf.util.xml;
9
10 import org.openexi.proc.common.AlignmentType;
11 import org.openexi.proc.common.EXIOptions;
12 import org.openexi.proc.common.EXIOptionsException;
13
14 import com.google.common.base.Preconditions;
15
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";
22
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";
29
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";
34
35     private final EXIOptions options;
36
37     private EXIParameters(final EXIOptions options) {
38         this.options = Preconditions.checkNotNull(options);
39     }
40
41     public static EXIParameters forXmlElement(final XmlElement root) throws EXIOptionsException {
42         final EXIOptions options =  new EXIOptions();
43
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);
54             }
55         }
56
57         if (root.getElementsByTagName(EXI_PARAMETER_FIDELITY).getLength() > 0) {
58             if (root.getElementsByTagName(EXI_FIDELITY_DTD).getLength() > 0) {
59                 options.setPreserveDTD(true);
60             }
61             if (root.getElementsByTagName(EXI_FIDELITY_LEXICAL_VALUES).getLength() > 0) {
62                 options.setPreserveLexicalValues(true);
63             }
64             if (root.getElementsByTagName(EXI_FIDELITY_COMMENTS).getLength() > 0) {
65                 options.setPreserveComments(true);
66             }
67             if (root.getElementsByTagName(EXI_FIDELITY_PIS).getLength() > 0) {
68                 options.setPreservePIs(true);
69             }
70             if (root.getElementsByTagName(EXI_FIDELITY_PREFIXES).getLength() > 0) {
71                 options.setPreserveNS(true);
72             }
73         }
74
75         if (root.getElementsByTagName(EXI_PARAMETER_SCHEMA).getLength() > 0) {
76
77             //            GrammarFactory grammarFactory = GrammarFactory.newInstance();
78             //            if (operationElement
79             //                    .getElementsByTagName(EXI_PARAMETER_SCHEMA_NONE)
80             //                    .getLength() > 0) {
81             //                this.grammars = grammarFactory.createSchemaLessGrammars();
82             //            }
83             //
84             //            if (operationElement.getElementsByTagName(
85             //                    EXI_PARAMETER_SCHEMA_BUILT_IN).getLength() > 0) {
86             //                this.grammars = grammarFactory.createXSDTypesOnlyGrammars();
87             //            }
88             //
89             //            if (operationElement.getElementsByTagName(
90             //                    EXI_PARAMETER_SCHEMA_BASE_1_1).getLength() > 0) {
91             //                this.grammars = grammarFactory
92             //                        .createGrammars(NETCONF_XSD_LOCATION);
93             //            }
94
95         }
96
97         return new EXIParameters(options);
98     }
99
100     public final EXIOptions getOptions() {
101         return options;
102     }
103 }