in batik-transcoder/src/main/java/org/apache/batik/transcoder/svg2svg/PrettyPrinter.java [532:823]
protected void printDoctype()
throws TranscoderException,
XMLException,
IOException {
switch (doctypeOption) {
default:
if (type == LexicalUnits.DOCTYPE_START) {
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
char[] space1 = getCurrentValue();
type = scanner.next();
if (type != LexicalUnits.NAME) {
throw fatalError("name", null);
}
char[] root = getCurrentValue();
char[] space2 = null;
String externalId = null;
char[] space3 = null;
char[] string1 = null;
char string1Delim = 0;
char[] space4 = null;
char[] string2 = null;
char string2Delim = 0;
char[] space5 = null;
type = scanner.next();
if (type == LexicalUnits.S) {
space2 = getCurrentValue();
type = scanner.next();
switch (type) {
case LexicalUnits.PUBLIC_IDENTIFIER:
externalId = "PUBLIC";
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
space3 = getCurrentValue();
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
string1 = getCurrentValue();
string1Delim = scanner.getStringDelimiter();
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
space4 = getCurrentValue();
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
string2 = getCurrentValue();
string2Delim = scanner.getStringDelimiter();
type = scanner.next();
if (type == LexicalUnits.S) {
space5 = getCurrentValue();
type = scanner.next();
}
break;
case LexicalUnits.SYSTEM_IDENTIFIER:
externalId = "SYSTEM";
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
space3 = getCurrentValue();
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
string1 = getCurrentValue();
string1Delim = scanner.getStringDelimiter();
type = scanner.next();
if (type == LexicalUnits.S) {
space4 = getCurrentValue();
type = scanner.next();
}
}
}
if (doctypeOption == DOCTYPE_CHANGE) {
if (publicId != null) {
externalId = "PUBLIC";
string1 = publicId.toCharArray();
string1Delim = '"';
if (systemId != null) {
string2 = systemId.toCharArray();
string2Delim = '"';
}
} else if (systemId != null) {
externalId = "SYSTEM";
string1 = systemId.toCharArray();
string1Delim = '"';
string2 = null;
}
}
output.printDoctypeStart(space1, root, space2,
externalId, space3,
string1, string1Delim,
space4,
string2, string2Delim,
space5);
if (type == LexicalUnits.LSQUARE_BRACKET) {
output.printCharacter('[');
type = scanner.next();
dtd: for (;;) {
switch (type) {
case LexicalUnits.S:
output.printSpaces(getCurrentValue(), true);
scanner.clearBuffer();
type = scanner.next();
break;
case LexicalUnits.COMMENT:
output.printComment(getCurrentValue());
scanner.clearBuffer();
type = scanner.next();
break;
case LexicalUnits.PI_START:
printPI();
break;
case LexicalUnits.PARAMETER_ENTITY_REFERENCE:
output.printParameterEntityReference(getCurrentValue());
scanner.clearBuffer();
type = scanner.next();
break;
case LexicalUnits.ELEMENT_DECLARATION_START:
scanner.clearBuffer();
printElementDeclaration();
break;
case LexicalUnits.ATTLIST_START:
scanner.clearBuffer();
printAttlist();
break;
case LexicalUnits.NOTATION_START:
scanner.clearBuffer();
printNotation();
break;
case LexicalUnits.ENTITY_START:
scanner.clearBuffer();
printEntityDeclaration();
break;
case LexicalUnits.RSQUARE_BRACKET:
output.printCharacter(']');
scanner.clearBuffer();
type = scanner.next();
break dtd;
default:
throw fatalError("xml", null);
}
}
}
char[] endSpace = null;
if (type == LexicalUnits.S) {
endSpace = getCurrentValue();
type = scanner.next();
}
if (type != LexicalUnits.END_CHAR) {
throw fatalError("end", null);
}
type = scanner.next();
output.printDoctypeEnd(endSpace);
} else {
if (doctypeOption == DOCTYPE_CHANGE) {
String externalId = "PUBLIC";
char[] string1 = SVGConstants.SVG_PUBLIC_ID.toCharArray();
char[] string2 = SVGConstants.SVG_SYSTEM_ID.toCharArray();
if (publicId != null) {
string1 = publicId.toCharArray();
if (systemId != null) {
string2 = systemId.toCharArray();
}
} else if (systemId != null) {
externalId = "SYSTEM";
string1 = systemId.toCharArray();
string2 = null;
}
output.printDoctypeStart(new char[] { ' ' },
new char[] { 's', 'v', 'g' },
new char[] { ' ' },
externalId,
new char[] { ' ' },
string1, '"',
new char[] { ' ' },
string2, '"',
null);
output.printDoctypeEnd(null);
}
}
break;
case DOCTYPE_REMOVE:
if (type == LexicalUnits.DOCTYPE_START) {
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
type = scanner.next();
if (type != LexicalUnits.NAME) {
throw fatalError("name", null);
}
type = scanner.next();
if (type == LexicalUnits.S) {
type = scanner.next();
switch (type) {
case LexicalUnits.PUBLIC_IDENTIFIER:
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
type = scanner.next();
if (type == LexicalUnits.S) {
type = scanner.next();
}
break;
case LexicalUnits.SYSTEM_IDENTIFIER:
type = scanner.next();
if (type != LexicalUnits.S) {
throw fatalError("space", null);
}
type = scanner.next();
if (type != LexicalUnits.STRING) {
throw fatalError("string", null);
}
type = scanner.next();
if (type == LexicalUnits.S) {
type = scanner.next();
}
}
}
if (type == LexicalUnits.LSQUARE_BRACKET) {
do {
type = scanner.next();
} while (type != LexicalUnits.RSQUARE_BRACKET);
}
if (type == LexicalUnits.S) {
type = scanner.next();
}
if (type != LexicalUnits.END_CHAR) {
throw fatalError("end", null);
}
}
type = scanner.next();
}
}