Commit e18f9aa0 authored by Jos van den Oever's avatar Jos van den Oever

Clean up whitespace in RNG files.

parent ee735cea
......@@ -2,7 +2,6 @@ package odf;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
......
......@@ -27,8 +27,9 @@ public class OdfInfo {
private static @Nullable OdfRngInfo odfRngInfo;
private static @Nullable OdfRngInfo manifestRngInfo;
private static @Nullable OdfRngInfo rngRngInfo;
final boolean manifest;
final FileType fileType;
private @Nullable ValidationDriver driver12;
private @Nullable ValidationDriver driver11;
final ErrorHandler errorHandler;
......@@ -52,29 +53,38 @@ public class OdfInfo {
return driver;
}
OdfInfo(boolean manifest) {
this.manifest = manifest;
OdfInfo(FileType fileType) {
this.fileType = fileType;
errorHandler = new ErrorHandler();
version = "1.2";
}
enum FileType {
RNG, ODF, ODFMANIFEST
}
public OdfRngInfo getRngInfo(XML xml) throws FileNotFoundException,
SAXException, IOException, TransformerException {
synchronized (OdfInfo.class) {
if (manifest) {
if (fileType == FileType.ODFMANIFEST) {
if (manifestRngInfo != null) {
return manifestRngInfo;
}
manifestRngInfo = loadInfo(
"src/rng/OpenDocument-v1.2-os-manifest-schema.rng", xml);
return manifestRngInfo;
} else {
} else if (fileType == FileType.ODF) {
if (odfRngInfo != null) {
return odfRngInfo;
}
odfRngInfo = loadInfo(
"src/rng/OpenDocument-v1.2-os-schema.rng", xml);
return odfRngInfo;
} else if (fileType == FileType.RNG) {
rngRngInfo = loadInfo("src/rng/relaxng.rng", xml);
return rngRngInfo;
} else {
throw new RuntimeException();
}
}
}
......@@ -90,28 +100,35 @@ public class OdfInfo {
public ValidationDriver getDriver11() {
if (driver11 != null) {
return driver11;
} else if (manifest) {
} else if (fileType == FileType.ODFMANIFEST) {
driver11 = load("src/rng/OpenDocument-manifest-schema-v1.1.rng",
errorHandler);
return driver11;
} else {
driver11 = load("src/rng/OpenDocument-schema-v1.1-errata01-complete.rng",
} else if (fileType == FileType.ODF) {
driver11 = load(
"src/rng/OpenDocument-schema-v1.1-errata01-complete.rng",
errorHandler);
return driver11;
} else {
driver11 = load("src/rng/relaxng.rng", errorHandler);
return driver11;
}
}
public ValidationDriver getDriver12() {
if (driver12 != null) {
return driver12;
} else if (manifest) {
} else if (fileType == FileType.ODFMANIFEST) {
driver12 = load("src/rng/OpenDocument-v1.2-os-manifest-schema.rng",
errorHandler);
return driver12;
} else {
} else if (fileType == FileType.ODF) {
driver12 = load("src/rng/OpenDocument-v1.2-os-schema.rng",
errorHandler);
return driver12;
} else {
driver12 = load("src/rng/relaxng.rng", errorHandler);
return driver12;
}
}
}
......
......@@ -29,10 +29,12 @@ public class OdfNormalizer {
final XML xml = new XML();
final OdfInfo odfManifestInfo;
final OdfInfo odfInfo;
final OdfInfo rngInfo;
OdfNormalizer() {
odfManifestInfo = new OdfInfo(true);
odfInfo = new OdfInfo(false);
odfManifestInfo = new OdfInfo(OdfInfo.FileType.ODFMANIFEST);
odfInfo = new OdfInfo(OdfInfo.FileType.ODF);
rngInfo = new OdfInfo(OdfInfo.FileType.RNG);
}
static public LinkedList<String> cleanManifest(Document manifest) {
......
......@@ -197,10 +197,11 @@ class OdfRngInfoParser {
* @return
*/
static private QName parseQName(HashMap<String, String> nsmap, String qname) {
String uri = null, localName;
String uri, localName;
int p = qname.indexOf(":");
if (p == -1) {
localName = qname;
uri = nsmap.get("");
} else {
String prefix = qname.substring(0, p);
localName = qname.substring(p + 1);
......@@ -330,6 +331,9 @@ class OdfRngInfoParser {
final Attr a = (Attr) atts.item(i);
if (xmlns.equals(a.getNamespaceURI())) {
ns.put(a.getLocalName(), a.getValue());
} else if (a.getNamespaceURI() == null
&& a.getLocalName().equals("ns")) {
ns.put("", a.getValue());
}
}
return ns;
......
......@@ -38,12 +38,15 @@ public class OdfZipNormalizer {
throws TransformerException, XMLStreamException, IOException,
SAXException, NormalizeException {
FileInputStream in = new FileInputStream(input);
Document doc = odfNormalizer.xml.parse(in, odfNormalizer.odfInfo);
OdfInfo info = odfNormalizer.odfInfo;
if (input.getAbsolutePath().endsWith(".rng")) {
info = odfNormalizer.rngInfo;
}
Document doc = odfNormalizer.xml.parse(in, info);
in.close();
normalizeOdf(doc, odfNormalizer);
OdfHistory.pretty(doc, output,
odfNormalizer.odfInfo.getRngInfo(odfNormalizer.xml)
.getElementsWithNoText());
OdfHistory.pretty(doc, output, info.getRngInfo(odfNormalizer.xml)
.getElementsWithNoText());
}
public void normalize(Path input, Path output) throws ZipException,
......
......@@ -11,6 +11,8 @@ import java.util.Arrays;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.TransformerException;
import odf.OdfInfo.FileType;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
......@@ -41,8 +43,9 @@ public class Tester {
static private boolean runTest(Path beforePath, OdfNormalizer odfNormalizer)
throws TestFailException, XMLStreamException, SAXException {
Document doc;
OdfInfo odfInfo = new OdfInfo(beforePath.toString().contains(
"/manifest/"));
FileType type = beforePath.toString().contains("/manifest/") ? OdfInfo.FileType.ODFMANIFEST
: OdfInfo.FileType.ODF;
OdfInfo odfInfo = new OdfInfo(type);
try {
doc = odfNormalizer.xml.parse(
new FileInputStream(beforePath.toFile()), odfInfo);
......
......@@ -53,5 +53,4 @@ class WhitespaceHandler extends XMLFilterImpl {
public void ignorableWhitespace(@Nullable char[] ch, int start, int length)
throws SAXException {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment