Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix CRLF

  • Loading branch information...
commit a9b7180c58de282b8fd009381998c5044ea139e2 1 parent ce9821a
Dennis Pfisterer authored
110 README
... ... @@ -1,55 +1,55 @@
1   -----------------------------------------
2   - CONNEXION
3   -----------------------------------------
4   -Data exchange between resource constrained devices is often realized
5   -using efficient hand-crafted binary encodings of the transmitted data.
6   -On the other hand, information exchange in distributed systems on the
7   -Internet is increasingly done using the widespread text-based XML
8   -format. XML files are simple text files; using them as a means to
9   -exchanging data is therefore relatively inefficient in terms of data size
10   -and not suitable for devices with limited resources. Currently the W3C is
11   -finalizing the EXI standard (http://www.w3.org/XML/EXI/) which promises
12   -efficient encoding and compression of XML files.
13   -
14   -Connexion is a BSD-licensed implementation of the W3C EXI standard in the Java
15   -programming language. The version implemented by Connexion is currently the
16   -Working Draft 26.03.2008 (http://www.w3.org/TR/2008/WD-exi-20080326/).
17   -Please note that this is not compatible with the latest draft/specification.
18   -Contributions are welcome.
19   -
20   -----------------------------------------
21   -CONTACT
22   -----------------------------------------
23   -Any feedback will be greatly appreciated, at the GitHub project page
24   -(https://github.com/pfisterer/exi-connexion) or by contacting
25   -Dennis Pfisterer (exi-connexion__A_T__farberg__de).
26   -
27   -----------------------------------------
28   -INSTALLATION / BUILDING
29   -----------------------------------------
30   -No installation is required. To build it, you need Java 6 and
31   -Maven (http://maven.apache.org/).
32   -
33   -To build, run "mvn install", this will build it and place the
34   -generated jar file in target/ and in your local Maven repository.
35   -
36   -----------------------------------------
37   -USAGE
38   -----------------------------------------
39   -
40   - java -jar core/target/exi-connexion-1.0.one-jar.jar --help
41   -
42   -----------------------------------------
43   -LICENSE
44   -----------------------------------------
45   -Connexion is licenced under a BSD license. For details, see
46   -src/etc/license-header.txt. If you use it for scientific publications,
47   -we appreciate if you cite connexion with the following information:
48   -
49   - @techreport{exi-connexion,
50   - author = {Marco Wegner and Dennis Pfisterer},
51   - title = {Connexion - An implementation of the {Efficient XML Interchange (EXI) W3C} Standard},
52   - institution = {Institute of Telematics, University of Luebeck, Germany},
53   - note = {\url{https://github.com/pfisterer/exi-connexion}},
54   - year = {2008}
55   - }
  1 +----------------------------------------
  2 + CONNEXION
  3 +----------------------------------------
  4 +Data exchange between resource constrained devices is often realized
  5 +using efficient hand-crafted binary encodings of the transmitted data.
  6 +On the other hand, information exchange in distributed systems on the
  7 +Internet is increasingly done using the widespread text-based XML
  8 +format. XML files are simple text files; using them as a means to
  9 +exchanging data is therefore relatively inefficient in terms of data size
  10 +and not suitable for devices with limited resources. Currently the W3C is
  11 +finalizing the EXI standard (http://www.w3.org/XML/EXI/) which promises
  12 +efficient encoding and compression of XML files.
  13 +
  14 +Connexion is a BSD-licensed implementation of the W3C EXI standard in the Java
  15 +programming language. The version implemented by Connexion is currently the
  16 +Working Draft 26.03.2008 (http://www.w3.org/TR/2008/WD-exi-20080326/).
  17 +Please note that this is not compatible with the latest draft/specification.
  18 +Contributions are welcome.
  19 +
  20 +----------------------------------------
  21 +CONTACT
  22 +----------------------------------------
  23 +Any feedback will be greatly appreciated, at the GitHub project page
  24 +(https://github.com/pfisterer/exi-connexion) or by contacting
  25 +Dennis Pfisterer (exi-connexion__A_T__farberg__de).
  26 +
  27 +----------------------------------------
  28 +INSTALLATION / BUILDING
  29 +----------------------------------------
  30 +No installation is required. To build it, you need Java 6 and
  31 +Maven (http://maven.apache.org/).
  32 +
  33 +To build, run "mvn install", this will build it and place the
  34 +generated jar file in target/ and in your local Maven repository.
  35 +
  36 +----------------------------------------
  37 +USAGE
  38 +----------------------------------------
  39 +
  40 + java -jar core/target/exi-connexion-1.0.one-jar.jar --help
  41 +
  42 +----------------------------------------
  43 +LICENSE
  44 +----------------------------------------
  45 +Connexion is licenced under a BSD license. For details, see
  46 +src/etc/license-header.txt. If you use it for scientific publications,
  47 +we appreciate if you cite connexion with the following information:
  48 +
  49 + @techreport{exi-connexion,
  50 + author = {Marco Wegner and Dennis Pfisterer},
  51 + title = {Connexion - An implementation of the {Efficient XML Interchange (EXI) W3C} Standard},
  52 + institution = {Institute of Telematics, University of Luebeck, Germany},
  53 + note = {\url{https://github.com/pfisterer/exi-connexion}},
  54 + year = {2008}
  55 + }
282 pom.xml
... ... @@ -1,141 +1,141 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -
3   -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4   - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5   - http://maven.apache.org/xsd/maven-4.0.0.xsd">
6   -
7   - <modelVersion>4.0.0</modelVersion>
8   -
9   - <name>Connexion - an EXI implementation</name>
10   - <groupId>de.uniluebeck.itm.connexion</groupId>
11   - <artifactId>exi-connexion</artifactId>
12   -
13   - <packaging>jar</packaging>
14   - <version>1.0</version>
15   -
16   - <dependencies>
17   -
18   - <dependency>
19   - <groupId>commons-cli</groupId>
20   - <artifactId>commons-cli</artifactId>
21   - <version>1.1</version>
22   - </dependency>
23   -
24   - <dependency>
25   - <groupId>log4j</groupId>
26   - <artifactId>log4j</artifactId>
27   - <version>1.2.16</version>
28   - </dependency>
29   -
30   - <dependency>
31   - <groupId>junit</groupId>
32   - <artifactId>junit</artifactId>
33   - <version>4.8.1</version>
34   - <scope>test</scope>
35   - </dependency>
36   -
37   - </dependencies>
38   -
39   - <build>
40   - <plugins>
41   -
42   - <plugin>
43   - <groupId>org.dstovall</groupId>
44   - <artifactId>onejar-maven-plugin-rc8fix2</artifactId>
45   - <version>1.4.5</version>
46   - <executions>
47   - <execution>
48   - <phase>package</phase>
49   - <configuration>
50   - <mainClass>exi.ExiMain</mainClass>
51   - <onejarVersion>0.97-RC10</onejarVersion>
52   - <attachToBuild>true</attachToBuild>
53   - <classifier>onejar</classifier>
54   - </configuration>
55   - <goals>
56   - <goal>one-jar</goal>
57   - </goals>
58   - </execution>
59   - </executions>
60   - </plugin>
61   -
62   - <plugin>
63   - <groupId>org.apache.maven.plugins</groupId>
64   - <artifactId>maven-compiler-plugin</artifactId>
65   - <version>2.0.2</version>
66   - <configuration>
67   - <source>1.6</source>
68   - <target>1.6</target>
69   - </configuration>
70   - </plugin>
71   -
72   - <!-- mvn license:check / mvn license:format -->
73   - <plugin>
74   - <groupId>com.mycila.maven-license-plugin</groupId>
75   - <version>1.9.0</version>
76   - <artifactId>maven-license-plugin</artifactId>
77   - <configuration>
78   - <strictCheck>true</strictCheck>
79   - <header>src/etc/license-header.txt</header>
80   - </configuration>
81   - <executions>
82   - <execution>
83   - <goals>
84   - <goal>check</goal>
85   - </goals>
86   - </execution>
87   - </executions>
88   -
89   - </plugin>
90   -
91   - </plugins>
92   - </build>
93   -
94   - <repositories>
95   -
96   -
97   - <repository>
98   - <id>itm-maven-repository-releases</id>
99   - <url>http://www.itm.uni-luebeck.de/projects/maven/releases/</url>
100   - <releases>
101   - <enabled>true</enabled>
102   - </releases>
103   - <snapshots>
104   - <enabled>false</enabled>
105   - </snapshots>
106   - </repository>
107   -
108   - <repository>
109   - <id>itm-maven-repository-snapshots</id>
110   - <url>http://www.itm.uni-luebeck.de/projects/maven/snapshots/</url>
111   - <releases>
112   - <enabled>false</enabled>
113   - </releases>
114   - <snapshots>
115   - <enabled>true</enabled>
116   - </snapshots>
117   - </repository>
118   -
119   - <repository>
120   - <id>repository.jboss.org</id>
121   - <url>http://repository.jboss.org/nexus/content/groups/public/</url>
122   - <snapshots>
123   - <enabled>false</enabled>
124   - </snapshots>
125   - </repository>
126   -
127   - <repository>
128   - <id>maven2-repository.dev.java.net</id>
129   - <name>Java.net Repository for Maven 2</name>
130   - <url>http://download.java.net/maven/2/</url>
131   - </repository>
132   -
133   - </repositories>
134   -
135   - <properties>
136   - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
137   - </properties>
138   -
139   -</project>
140   -
141   -
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
  5 + http://maven.apache.org/xsd/maven-4.0.0.xsd">
  6 +
  7 + <modelVersion>4.0.0</modelVersion>
  8 +
  9 + <name>Connexion - an EXI implementation</name>
  10 + <groupId>de.uniluebeck.itm.connexion</groupId>
  11 + <artifactId>exi-connexion</artifactId>
  12 +
  13 + <packaging>jar</packaging>
  14 + <version>1.0</version>
  15 +
  16 + <dependencies>
  17 +
  18 + <dependency>
  19 + <groupId>commons-cli</groupId>
  20 + <artifactId>commons-cli</artifactId>
  21 + <version>1.1</version>
  22 + </dependency>
  23 +
  24 + <dependency>
  25 + <groupId>log4j</groupId>
  26 + <artifactId>log4j</artifactId>
  27 + <version>1.2.16</version>
  28 + </dependency>
  29 +
  30 + <dependency>
  31 + <groupId>junit</groupId>
  32 + <artifactId>junit</artifactId>
  33 + <version>4.8.1</version>
  34 + <scope>test</scope>
  35 + </dependency>
  36 +
  37 + </dependencies>
  38 +
  39 + <build>
  40 + <plugins>
  41 +
  42 + <plugin>
  43 + <groupId>org.dstovall</groupId>
  44 + <artifactId>onejar-maven-plugin-rc8fix2</artifactId>
  45 + <version>1.4.5</version>
  46 + <executions>
  47 + <execution>
  48 + <phase>package</phase>
  49 + <configuration>
  50 + <mainClass>exi.ExiMain</mainClass>
  51 + <onejarVersion>0.97-RC10</onejarVersion>
  52 + <attachToBuild>true</attachToBuild>
  53 + <classifier>onejar</classifier>
  54 + </configuration>
  55 + <goals>
  56 + <goal>one-jar</goal>
  57 + </goals>
  58 + </execution>
  59 + </executions>
  60 + </plugin>
  61 +
  62 + <plugin>
  63 + <groupId>org.apache.maven.plugins</groupId>
  64 + <artifactId>maven-compiler-plugin</artifactId>
  65 + <version>2.0.2</version>
  66 + <configuration>
  67 + <source>1.6</source>
  68 + <target>1.6</target>
  69 + </configuration>
  70 + </plugin>
  71 +
  72 + <!-- mvn license:check / mvn license:format -->
  73 + <plugin>
  74 + <groupId>com.mycila.maven-license-plugin</groupId>
  75 + <version>1.9.0</version>
  76 + <artifactId>maven-license-plugin</artifactId>
  77 + <configuration>
  78 + <strictCheck>true</strictCheck>
  79 + <header>src/etc/license-header.txt</header>
  80 + </configuration>
  81 + <executions>
  82 + <execution>
  83 + <goals>
  84 + <goal>check</goal>
  85 + </goals>
  86 + </execution>
  87 + </executions>
  88 +
  89 + </plugin>
  90 +
  91 + </plugins>
  92 + </build>
  93 +
  94 + <repositories>
  95 +
  96 +
  97 + <repository>
  98 + <id>itm-maven-repository-releases</id>
  99 + <url>http://www.itm.uni-luebeck.de/projects/maven/releases/</url>
  100 + <releases>
  101 + <enabled>true</enabled>
  102 + </releases>
  103 + <snapshots>
  104 + <enabled>false</enabled>
  105 + </snapshots>
  106 + </repository>
  107 +
  108 + <repository>
  109 + <id>itm-maven-repository-snapshots</id>
  110 + <url>http://www.itm.uni-luebeck.de/projects/maven/snapshots/</url>
  111 + <releases>
  112 + <enabled>false</enabled>
  113 + </releases>
  114 + <snapshots>
  115 + <enabled>true</enabled>
  116 + </snapshots>
  117 + </repository>
  118 +
  119 + <repository>
  120 + <id>repository.jboss.org</id>
  121 + <url>http://repository.jboss.org/nexus/content/groups/public/</url>
  122 + <snapshots>
  123 + <enabled>false</enabled>
  124 + </snapshots>
  125 + </repository>
  126 +
  127 + <repository>
  128 + <id>maven2-repository.dev.java.net</id>
  129 + <name>Java.net Repository for Maven 2</name>
  130 + <url>http://download.java.net/maven/2/</url>
  131 + </repository>
  132 +
  133 + </repositories>
  134 +
  135 + <properties>
  136 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  137 + </properties>
  138 +
  139 +</project>
  140 +
  141 +
40 src/etc/license-header.txt
... ... @@ -1,20 +1,20 @@
1   -Copyright (c) 2010, Marco Wegner and Dennis Pfisterer, Institute of Telematics, University of Luebeck
2   -All rights reserved.
3   -
4   -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5   -following conditions are met:
6   -
7   - - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8   - disclaimer.
9   - - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10   - following disclaimer in the documentation and/or other materials provided with the distribution.
11   - - Neither the name of the University of Luebeck nor the names of its contributors may be used to endorse or promote
12   - products derived from this software without specific prior written permission.
13   -
14   -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15   -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16   -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17   -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
18   -GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19   -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
20   -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1 +Copyright (c) 2010, Marco Wegner and Dennis Pfisterer, Institute of Telematics, University of Luebeck
  2 +All rights reserved.
  3 +
  4 +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  5 +following conditions are met:
  6 +
  7 + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  8 + disclaimer.
  9 + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
  10 + following disclaimer in the documentation and/or other materials provided with the distribution.
  11 + - Neither the name of the University of Luebeck nor the names of its contributors may be used to endorse or promote
  12 + products derived from this software without specific prior written permission.
  13 +
  14 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15 +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  18 +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  20 +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1,008 src/main/java/exi/ExiEncoder.java
... ... @@ -1,504 +1,504 @@
1   -/**
2   - * Copyright (c) 2010, Marco Wegner and Dennis Pfisterer, Institute of Telematics, University of Luebeck
3   - * All rights reserved.
4   - *
5   - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6   - * following conditions are met:
7   - *
8   - * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9   - * disclaimer.
10   - * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11   - * following disclaimer in the documentation and/or other materials provided with the distribution.
12   - * - Neither the name of the University of Luebeck nor the names of its contributors may be used to endorse or promote
13   - * products derived from this software without specific prior written permission.
14   - *
15   - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16   - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17   - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18   - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19   - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20   - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21   - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22   - */
23   -package exi;
24   -
25   -import java.math.BigInteger;
26   -
27   -import javax.xml.namespace.QName;
28   -
29   -import org.apache.log4j.Logger;
30   -
31   -import exi.ExiOptions.FidelityOption;
32   -import exi.events.ExiAttribute;
33   -import exi.events.ExiCharacters;
34   -import exi.events.ExiComment;
35   -import exi.events.ExiEndDocument;
36   -import exi.events.ExiEndElement;
37   -import exi.events.ExiEvent;
38   -import exi.events.ExiEventCode;
39   -import exi.events.ExiEventHandler;
40   -import exi.events.ExiNamespaceDeclaration;
41   -import exi.events.ExiProcessingInstruction;
42   -import exi.events.ExiStartDocument;
43   -import exi.events.ExiStartElement;
44   -import exi.grammar.ExiExtensibleGrammar;
45   -import exi.grammar.ExiGrammar;
46   -import exi.grammar.ExiGrammarGroup;
47   -import exi.grammar.ExiGrammarRule;
48   -import exi.grammar.ExiGrammarGroup.Size;
49   -import exi.io.ExiWriter;
50   -import exi.utils.ExiStringTable;
51   -import exi.utils.StringTablePartition;
52   -import exi.utils.ValuePartition;
53   -
54   -/**
55   - * This class represents an encoder for EXI events.
56   - *
57   - * @author Marco Wegner
58   - */
59   -public class ExiEncoder extends ExiEventHandler {
60   -
61   - // ------------------------------------------------------------------------
62   - // Static stuff
63   - // ------------------------------------------------------------------------
64   -
65   - /**
66   - * The EXI logger user for logging stuff.
67   - */
68   - public static Logger log = ExiLogger.getLogger(ExiEncoder.class);
69   -
70   - // ------------------------------------------------------------------------
71   - // Member variables
72   - // ------------------------------------------------------------------------
73   -
74   - /**
75   - * The EXI stream writer.
76   - */
77   - private final ExiWriter writer;
78   -
79   - // ------------------------------------------------------------------------
80   - // Constructor
81   - // ------------------------------------------------------------------------
82   -
83   - /**
84   - * Creates a new EXI event handler.
85   - * @param w The EXI stream writer.
86   - * @param options The EXI options to use.
87   - *
88   - * @throws Exception If something goes wrong during initialization.
89   - */
90   - public ExiEncoder(ExiWriter w, ExiOptions options) throws Exception {
91   - super(options);
92   - this.writer = w;
93   -
94   - log.debug("---");
95   - log.debug("--- EXI Encoder started");
96   - log.debug("--- Bytes written to stream so far: " + w.getOutputStream( ).size( ));
97   - log.debug("---");
98   - }
99   -
100   - // ------------------------------------------------------------------------
101   -
102   - /**
103   - * Handles an EXI event.
104   - *
105   - * @param event The EXI event to be handled.
106   - * @throws ExiException If something goes wrong during event handling.
107   - */
108   - public void handle(ExiEvent event) throws ExiException {
109   - switch (event.getEventType( )) {
110   - case Attribute:
111   - handle((ExiAttribute)event);
112   - break;
113   -
114   - case EndDocument:
115   - handle((ExiEndDocument)event);
116   - break;
117   -
118   - case EndElement:
119   - handle((ExiEndElement)event);
120   - break;
121   -
122   - case NamespaceDeclaration:
123   - handle((ExiNamespaceDeclaration)event);
124   - break;
125   -
126   - case ProcessingInstruction:
127   - handle((ExiProcessingInstruction)event);
128   - break;
129   -
130   - case StartDocument:
131   - handle((ExiStartDocument)event);
132   - break;
133   -
134   - case StartElement:
135   - handle((ExiStartElement)event);
136   - break;
137   - }
138   - }
139   -
140   - // ------------------------------------------------------------------------
141   -
142   - /**
143   - * Handles a Processing Instruction (PI) event.
144   - *
145   - * @param event The EXI Processing Instruction (PI) event to be handled.
146   - * @throws ExiException If something goes wrong during grammar handling.
147   - */
148   - public void handle(ExiProcessingInstruction event) throws ExiException {
149   - if (!getOptions( ).isSet(FidelityOption.PRESERVE_PROCESSING_INSTRUCTIONS)) {
150   - return;
151   - }
152   - String target = event.getTarget( );
153   - String data = event.getData( );
154   - log.debug(String.format("PI (target = %s; data = %s)", target, data));
155   -
156   - ExiGrammar g = getCurrentGrammar( );
157   - ExiGrammarRule rule = g.getMatchingRule(event);
158   -
159   - encodeEventCode(rule.getEventCode( ));
160   -
161   - g.moveToGroup(rule.getRightHandSide( ));
162   - }
163   -
164   - // ------------------------------------------------------------------------
165   -
166   - /**
167   - * Handles an EXI Start Document (SD) event.
168   - *
169   - * @param event The EXI Start Document (SD) event to be handled.
170   - * @throws ExiException If something goes wrong during grammar handling.
171   - */
172   - public void handle(ExiStartDocument event) throws ExiException {
173   - log.debug("SD");
174   -
175   - ExiGrammar g = getCurrentGrammar( );
176   - ExiGrammarRule rule = g.getMatchingRule(event);
177   -
178   - encodeEventCode(rule.getEventCode( ));
179   -
180   - g.moveToGroup(rule.getRightHandSide( ));
181   - }
182   -
183   - // ------------------------------------------------------------------------
184   -
185   - /**
186   - * Handles an EXI Start Element (SE) event.
187   - *
188   - * @param event The EXI Start Element (SE) event to be handled.
189   - * @throws ExiException If something goes wrong during grammar handling.
190   - */
191   - public void handle(ExiStartElement event) throws ExiException {
192   -
193   - log.debug(event.getEventTypeString( ));
194   -
195   - QName qname = event.getQualifiedName( );
196   - pushQName(qname);
197   -
198   - ExiGrammar g = getCurrentGrammar( );
199   - ExiGrammarRule rule = g.getMatchingRule(event);
200   -
201   - encodeEventCode(rule.getEventCode( ));
202   -
203   - if (rule.isGeneral( )) {
204   -
205   - encodeOptimizedForHits(getStringTable( ).getUriPartition( ), qname.getNamespaceURI( ), "uri");
206   - encodeLocalName(qname);
207   -
208   - if ((g instanceof ExiExtensibleGrammar)) {
209   - extendGrammar(g, rule, event);
210   - }
211   - }
212   -
213   - g.moveToGroup(rule.getRightHandSide( ));
214   - pushElementGrammar(qname);
215   - }
216   -
217   - // ------------------------------------------------------------------------
218   -
219   - /**
220   - * Handles an EXI Attribute (AT) event.
221   - *
222   - * @param event The EXI Attribute (AT) event to be handled.
223   - * @throws ExiException If something goes wrong during grammar handling.
224   - */
225   - public void handle(ExiAttribute event) throws ExiException {
226   -
227   - QName qname = event.getQualifiedName( );
228   - String value = event.getValue( );
229   -
230   - log.debug(String.format(
231   - "AT (name = %s, value = %s)",
232   - qname.getLocalPart( ),
233   - value
234   - ));
235   -
236   - ExiGrammar g = getCurrentGrammar( );
237   - ExiGrammarRule rule = g.getMatchingRule(event);
238   -
239   - encodeEventCode(rule.getEventCode( ));
240   -
241   - boolean general = rule.isGeneral( );
242   - if (general) {
243   - encodeOptimizedForHits(getStringTable( ).getUriPartition( ), qname.getNamespaceURI( ), "uri");
244   - encodeLocalName(qname);
245   - }
246   -
247   - encodeValue(qname, value);
248   -
249   - if ((g instanceof ExiExtensibleGrammar) && general) {
250   - extendGrammar(g, rule, event);
251   - }
252   -
253   - g.moveToGroup(rule.getRightHandSide( ));
254   - }
255   -
256   - // ------------------------------------------------------------------------
257   -
258   - /**
259   - * Handles an EXI Namespace Declaration (NS) event.
260   - *
261   - * @param event The EXI Namespace Declaration (NS) event to be handled.
262   - * @throws ExiException If something goes wrong during grammar handling.
263   - */
264   - public void handle(ExiNamespaceDeclaration event) throws ExiException {
265   - if (!getOptions( ).isSet(FidelityOption.PRESERVE_PREFIXES)) {
266   - return;
267   - }
268   -
269   - String prefix = event.getNamespacePrefix( );
270   -
271   - log.debug(String.format(
272   - "NS (prefix = %s, uri = %s)",
273   - prefix, event.getNamespaceURI( )
274   - ));
275   -
276   - ExiGrammar g = getCurrentGrammar( );
277   - ExiGrammarRule rule = g.getMatchingRule(event);
278   -
279   - encodeEventCode(rule.getEventCode( ));
280   -
281   - encodeOptimizedForHits(getStringTable( ).getUriPartition( ), event.getNamespaceURI( ).toString( ), "uri");
282   - encodeOptimizedForHits(getStringTable( ).getPrefixPartition( ), prefix, "prefix");
283   -
284   - g.moveToGroup(rule.getRightHandSide( ));
285   - }
286   -
287   - // ------------------------------------------------------------------------
288   -
289   - /**
290   - * Handles a Character (CH) event.
291   - *
292   - * @param event The Character (CH) event to be handled.
293   - * @throws ExiException If something goes wrong during grammar handling.
294   - */
295   - public void handle(ExiCharacters event) throws ExiException {
296   -
297   - String characters = event.getData( );
298   -
299   - /*
300   - * Not so sure whether this is actually such a good thing to do. But we
301   - * need to get rid of character data which just consists of a line
302   - * break character and a few indentation whitespace characters.
303   - */
304   - if (characters.matches("\n[\\s]*")) {
305   - return;
306   - }
307   -
308   - log.debug(String.format("CH: \"%s\"", characters));
309   -
310   - ExiGrammar g = getCurrentGrammar( );
311   - ExiGrammarRule rule = g.getMatchingRule(event);
312   -
313   - encodeEventCode(rule.getEventCode( ));
314   -
315   - encodeValue(getCurrentQName( ), characters);
316   -
317   - if ((g instanceof ExiExtensibleGrammar) && rule.getEventCode( ).getLength( ) > 1) {
318   - extendGrammar(g, rule, event);
319   - }
320   -
321   - g.moveToGroup(rule.getRightHandSide( ));
322   - }
323   -
324   - // ------------------------------------------------------------------------
325   -
326   - /**
327   - * Handles an EXI End Element (EE) event.
328   - *
329   - * @param event The EXI End Element (EE) event to be handled.
330   - * @throws ExiException If something goes wrong during grammar handling.
331   - */
332   - public void handle(ExiEndElement event) throws ExiException {
333   - log.debug("EE");
334   -
335   - ExiGrammar g = getCurrentGrammar( );
336   - ExiGrammarRule rule = g.getMatchingRule(event);
337   -
338   - encodeEventCode(rule.getEventCode( ));
339   -
340   - popQName( );
341   - popGrammar( );
342   - }
343   -
344   - // ------------------------------------------------------------------------
345   -
346   - /**
347   - * Handles an EXI End Document (ED) event.
348   - *
349   - * @param event The EXI End Document (ED) event to be handled.
350   - * @throws ExiException If something goes wrong during grammar handling.
351   - */
352   - public void handle(ExiEndDocument event) throws ExiException {
353   - log.debug("ED");
354   -
355   - ExiGrammar g = getCurrentGrammar( );
356   - ExiGrammarRule rule = g.getMatchingRule(event);
357   -
358   - encodeEventCode(rule.getEventCode( ));
359   -
360   - popGrammar( ); // document grammar
361   - }
362   -
363   - // ------------------------------------------------------------------------
364   -
365   - /**
366   - * Handles a EXI Comment (CM) event.
367   - *
368   - * @param event The EXI Comment (CM) event.
369   - * @throws ExiException If something goes wrong during grammar handling.
370   - */
371   - public void handle(ExiComment event) throws ExiException {
372   - if (!getOptions( ).isSet(FidelityOption.PRESERVE_COMMENTS)) {
373   - return;
374   - }
375   - String comment = event.getText( );
376   - log.debug(String.format("CM: \"%s\"", comment));
377   -
378   - ExiGrammar g = getCurrentGrammar( );
379   - ExiGrammarRule rule = g.getMatchingRule(event);
380   -
381   - encodeEventCode(rule.getEventCode( ));
382   -
383   - this.writer.writeComment(comment);
384   -
385   - g.moveToGroup(rule.getRightHandSide( ));
386   - }
387   -
388   - // ------------------------------------------------------------------------
389   -
390   - /**
391   - * Handles a DocType (DT) event.
392   - */
393   - public void handleDocType( ) {
394   - //
395   - }
396   -
397   - // ------------------------------------------------------------------------
398   -
399   - /**
400   - * Handles an Entity Reference (ER) event.
401   - */
402   - public void handleEntityReference( ) {
403   - //
404   - }
405   -
406   - /**
407   - * Encodes a single event code to the EXI stream.
408   - * @param eventCode The event code.
409   - */
410   - private void encodeEventCode(ExiEventCode eventCode) {
411   - ExiGrammarGroup activeGroup = getCurrentGrammar( ).getActiveGroup( );
412   - Size groupSize = activeGroup.getGroupSize( );
413   - this.writer.writeEventCode(eventCode, groupSize);
414   - }
415   -
416   - // ------------------------------------------------------------------------
417   -
418   - /**
419   - * <p>
420   - * Handles a string in a partition which is of the type Optimized For
421   - * Compact identifier (or Optimized For Hits).
422   - * </p>
423   - * <p>
424   - * This includes URI and prefix partitions. The actions taken are the same
425   - * for both partition types.
426   - * <p>
427   - *
428   - * @param part The string table partition
429   - * @param s The string.
430   - * @param msg The partition identifier. This string is merely used for log
431   - * messages.
432   - */
433   - private void encodeOptimizedForHits(StringTablePartition part, String s, String msg) {
434   - int size = part.getSize( );
435   - if (part.lookup(s)) {
436   - int id = part.getID(s);
437   - this.writer.writeCompactStringHit(id, size);
438   - log.debug(String.format("%s hit -- writing %d(%d)", msg, BigInteger.valueOf(id + 1), (int)Math.ceil(Math.log(size+1)/Math.log(2))));
439   - } else {
440   - this.writer.writeCompactStringMiss(s, size);
441   - log.debug(String.format("\"%s\" (%s miss)", s, msg));
442   - part.add(s);
443   - }
444   - }
445   -
446   - // ------------------------------------------------------------------------
447   -
448   - /**
449   - * Handles a local name string.
450   - *
451   - * @param qname The QName.
452   - */
453   - private void encodeLocalName(QName qname) {
454   - String s = qname.getLocalPart( );
455   - StringTablePartition part = getStringTable( ).getLocalNamesPartition(qname.getNamespaceURI( ));
456   - if (part.lookup(s)) {
457   - log.debug("local-name hit");
458   - int id = part.getID(s);
459   - int size = part.getSize( );
460   - this.writer.writeLocalNameHit(id, size);
461   - } else {
462   - log.debug(String.format("\"%s\" (local-name miss)", s));
463   - this.writer.writeLocalNameMiss(s);
464   - part.add(s);
465   - }
466   - }
467   -
468   - // ------------------------------------------------------------------------
469   -
470   - /**
471   - * <p>
472   - * Handles a value string.
473   - * </p>
474   - * <p>
475   - * The string is looked up in both the local and the global value partition
476   - * if necessary. If these look-ups have not been successful, then actual
477   - * string is written to the stream.
478   - * </p>
479   - *
480   - * @param qname The QName associated to this value. This can either be the
481   - * attribute's QName or, in case of character data, the enclosing
482   - * element's QName.
483   - * @param s The string.
484   - */
485   - private void encodeValue(QName qname, String s) {
486   - ExiStringTable table = getStringTable( );
487   - ValuePartition local = table.getValuePartition(qname);
488   - if (local.lookup(s)) {
489   - log.debug("value hit");
490   - this.writer.writeValueHitLocal(qname, local.getID(s), local.getSize( ));
491   - } else {
492   - ValuePartition global = table.getValuePartition( );
493   - if (global.lookup(s)) {
494   - log.debug("global-value hit");
495   - this.writer.writeValueHitGlobal(qname, global.getID(s), global.getSize( ));
496   - } else {
497   - log.debug(String.format("\"%s\" (value miss)", s));
498   - this.writer.writeValueMiss(qname, s);
499   - local.add(s);
500   - global.add(s);
501   - }
502   - }
503   - }
504   -}
  1 +/**
  2 + * Copyright (c) 2010, Marco Wegner and Dennis Pfisterer, Institute of Telematics, University of Luebeck
  3 + * All rights reserved.
  4 + *
  5 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
  6 + * following conditions are met:
  7 + *
  8 + * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  9 + * disclaimer.
  10 + * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
  11 + * following disclaimer in the documentation and/or other materials provided with the distribution.
  12 + * - Neither the name of the University of Luebeck nor the names of its contributors may be used to endorse or promote
  13 + * products derived from this software without specific prior written permission.
  14 + *
  15 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16 + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  19 + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22 + */
  23 +package exi;
  24 +
  25 +import java.math.BigInteger;
  26 +
  27 +import javax.xml.namespace.QName;
  28 +
  29 +import org.apache.log4j.Logger;
  30 +
  31 +import exi.ExiOptions.FidelityOption;
  32 +import exi.events.ExiAttribute;
  33 +import exi.events.ExiCharacters;
  34 +import exi.events.ExiComment;
  35 +import exi.events.ExiEndDocument;
  36 +import exi.events.ExiEndElement;
  37 +import exi.events.ExiEvent;
  38 +import exi.events.ExiEventCode;
  39 +import exi.events.ExiEventHandler;
  40 +import exi.events.ExiNamespaceDeclaration;
  41 +import exi.events.ExiProcessingInstruction;
  42 +import exi.events.ExiStartDocument;
  43 +import exi.events.ExiStartElement;
  44 +import exi.grammar.ExiExtensibleGrammar;
  45 +import exi.grammar.ExiGrammar;
  46 +import exi.grammar.ExiGrammarGroup;
  47 +import exi.grammar.ExiGrammarRule;
  48 +import exi.grammar.ExiGrammarGroup.Size;
  49 +import exi.io.ExiWriter;
  50 +import exi.utils.ExiStringTable;
  51 +import exi.utils.StringTablePartition;
  52 +import exi.utils.ValuePartition;
  53 +
  54 +/**
  55 + * This class represents an encoder for EXI events.
  56 + *
  57 + * @author Marco Wegner
  58 + */
  59 +public class ExiEncoder extends ExiEventHandler {
  60 +
  61 + // ------------------------------------------------------------------------
  62 + // Static stuff
  63 + // ------------------------------------------------------------------------
  64 +
  65 + /**
  66 + * The EXI logger user for logging stuff.
  67 + */
  68 + public static Logger log = ExiLogger.getLogger(ExiEncoder.class);
  69 +
  70 + // ------------------------------------------------------------------------
  71 + // Member variables
  72 + // ------------------------------------------------------------------------
  73 +
  74 + /**
  75 + * The EXI stream writer.
  76 + */
  77 + private final ExiWriter writer;
  78 +
  79 + // ------------------------------------------------------------------------
  80 + // Constructor
  81 + // ------------------------------------------------------------------------
  82 +
  83 + /**
  84 + * Creates a new EXI event handler.
  85 + * @param w The EXI stream writer.
  86 + * @param options The EXI options to use.
  87 + *
  88 + * @throws Exception If something goes wrong during initialization.
  89 + */
  90 + public ExiEncoder(ExiWriter w, ExiOptions options) throws Exception {
  91 + super(options);
  92 + this.writer = w;
  93 +
  94 + log.debug("---");
  95 + log.debug("--- EXI Encoder started");
  96 + log.debug("--- Bytes written to stream so far: " + w.getOutputStream( ).size( ));
  97 + log.debug("---");
  98 + }
  99 +
  100 + // ------------------------------------------------------------------------
  101 +
  102 + /**
  103 + * Handles an EXI event.
  104 + *
  105 + * @param event The EXI event to be handled.
  106 + * @throws ExiException If something goes wrong during event handling.
  107 + */
  108 + public void handle(ExiEvent event) throws ExiException {
  109 + switch (event.getEventType( )) {
  110 + case Attribute:
  111 + handle((ExiAttribute)event);
  112 + break;
  113 +
  114 + case EndDocument:
  115 + handle((ExiEndDocument)event);
  116 + break;
  117 +
  118 + case EndElement:
  119 + handle((ExiEndElement)event);
  120 + break;
  121 +
  122 + case NamespaceDeclaration:
  123 + handle((ExiNamespaceDeclaration)event);
  124 + break;
  125 +
  126 + case ProcessingInstruction:
  127 + handle((ExiProcessingInstruction)event);
  128 + break;
  129 +
  130 + case StartDocument:
  131 + handle((ExiStartDocument)event);
  132 + break;
  133 +
  134 + case StartElement:
  135 + handle((ExiStartElement)event);
  136 + break;
  137 + }
  138 + }
  139 +
  140 + // ------------------------------------------------------------------------
  141 +
  142 + /**
  143 + * Handles a Processing Instruction (PI) event.
  144 + *
  145 + * @param event The EXI Processing Instruction (PI) event to be handled.
  146 + * @throws ExiException If something goes wrong during grammar handling.
  147 + */
  148 + public void handle(ExiProcessingInstruction event) throws ExiException {
  149 + if (!getOptions( ).isSet(FidelityOption.PRESERVE_PROCESSING_INSTRUCTIONS)) {
  150 + return;
  151 + }
  152 + String target = event.getTarget( );
  153 + String data = event.getData( );
  154 + log.debug(String.format("PI (target = %s; data = %s)", target, data));
  155 +
  156 + ExiGrammar g = getCurrentGrammar( );
  157 + ExiGrammarRule rule = g.getMatchingRule(event);
  158 +
  159 + encodeEventCode(rule.getEventCode( ));
  160 +
  161 + g.moveToGroup(rule.getRightHandSide( ));
  162 + }
  163 +
  164 + // ------------------------------------------------------------------------
  165 +
  166 + /**
  167 + * Handles an EXI Start Document (SD) event.
  168 + *
  169 + * @param event The EXI Start Document (SD) event to be handled.
  170 + * @throws ExiException If something goes wrong during grammar handling.
  171 + */
  172 + public void handle(ExiStartDocument event) throws ExiException {
  173 + log.debug("SD");
  174 +
  175 + ExiGrammar g = getCurrentGrammar( );
  176 + ExiGrammarRule rule = g.getMatchingRule(event);
  177 +
  178 + encodeEventCode(rule.getEventCode( ));
  179 +
  180 + g.moveToGroup(rule.getRightHandSide( ));
  181 + }
  182 +
  183 + // ------------------------------------------------------------------------
  184 +
  185 + /**
  186 + * Handles an EXI Start Element (SE) event.
  187 + *
  188 + * @param event The EXI Start Element (SE) event to be handled.
  189 + * @throws ExiException If something goes wrong during grammar handling.
  190 + */
  191 + public void handle(ExiStartElement event) throws ExiException {
  192 +
  193 + log.debug(event.getEventTypeString( ));
  194 +
  195 + QName qname = event.getQualifiedName( );
  196 + pushQName(qname);
  197 +
  198 + ExiGrammar g = getCurrentGrammar( );
  199 + ExiGrammarRule rule = g.getMatchingRule(event);
  200 +
  201 + encodeEventCode(rule.getEventCode( ));
  202 +
  203 + if (rule.isGeneral( )) {
  204 +
  205 + encodeOptimizedForHits(getStringTable( ).getUriPartition( ), qname.getNamespaceURI( ), "uri");
  206 + encodeLocalName(qname);
  207 +
  208 + if ((g instanceof ExiExtensibleGrammar)) {
  209 + extendGrammar(g, rule, event);
  210 + }
  211 + }
  212 +
  213 + g.moveToGroup(rule.getRightHandSide( ));
  214 + pushElementGrammar(qname);
  215 + }
  216 +
  217 + // ------------------------------------------------------------------------
  218 +
  219 + /**
  220 + * Handles an EXI Attribute (AT) event.
  221 + *
  222 + * @param event The EXI Attribute (AT) event to be handled.
  223 + * @throws ExiException If something goes wrong during grammar handling.
  224 + */
  225 + public void handle(ExiAttribute event) throws ExiException {
  226 +
  227 + QName qname = event.getQualifiedName( );
  228 + String value = event.getValue( );
  229 +
  230 + log.debug(String.format(
  231 + "AT (name = %s, value = %s)",
  232 + qname.getLocalPart( ),
  233 + value
  234 + ));
  235 +
  236 + ExiGrammar g = getCurrentGrammar( );
  237 + ExiGrammarRule rule = g.getMatchingRule(event);
  238 +
  239 + encodeEventCode(rule.getEventCode( ));
  240 +
  241 + boolean general = rule.isGeneral( );
  242 + if (general) {
  243 + encodeOptimizedForHits(getStringTable( ).getUriPartition( ), qname.getNamespaceURI( ), "uri");
  244 + encodeLocalName(qname);
  245 + }
  246 +
  247 + encodeValue(qname, value);
  248 +
  249 + if ((g instanceof ExiExtensibleGrammar) && general) {
  250 + extendGrammar(g, rule, event);
  251 + }
  252 +