| 1 |
package com.thaiopensource.relaxng.output.xsd; |
| 2 |
|
| 3 |
import com.thaiopensource.relaxng.output.OutputFormat; |
| 4 |
import com.thaiopensource.relaxng.output.OutputDirectory; |
| 5 |
import com.thaiopensource.relaxng.output.OutputFailedException; |
| 6 |
import com.thaiopensource.relaxng.output.OutputDirectoryParamProcessor; |
| 7 |
import com.thaiopensource.relaxng.output.xsd.basic.Schema; |
| 8 |
import com.thaiopensource.relaxng.output.common.ErrorReporter; |
| 9 |
import com.thaiopensource.relaxng.edit.SchemaCollection; |
| 10 |
import com.thaiopensource.relaxng.translate.util.InvalidParamsException; |
| 11 |
import com.thaiopensource.relaxng.translate.util.ParamProcessor; |
| 12 |
import com.thaiopensource.relaxng.translate.util.AbstractParam; |
| 13 |
import com.thaiopensource.relaxng.translate.util.EnumParam; |
| 14 |
import org.xml.sax.ErrorHandler; |
| 15 |
import org.xml.sax.SAXException; |
| 16 |
|
| 17 |
import java.io.IOException; |
| 18 |
|
| 19 |
public class XsdOutputFormat implements OutputFormat { |
| 20 |
static private final boolean DEFAULT_ENABLE_ABSTRACT_ELEMENT = true; |
| 21 |
static private final String[] processContents = { "skip", "lax", "strict" }; |
| 22 |
public void output(SchemaCollection sc, OutputDirectory od, String[] params, String inputFormat, ErrorHandler eh) |
| 23 |
throws SAXException, IOException, OutputFailedException, InvalidParamsException { |
| 24 |
final Guide guide = new Guide(DEFAULT_ENABLE_ABSTRACT_ELEMENT); |
| 25 |
final BasicOutput.Options outputOptions = new BasicOutput.Options(); |
| 26 |
if ("dtd".equals(inputFormat)) |
| 27 |
outputOptions.anyProcessContents = "strict"; |
| 28 |
ParamProcessor pp = new OutputDirectoryParamProcessor(od); |
| 29 |
pp.declare("disable-abstract-elements", |
| 30 |
new AbstractParam() { |
| 31 |
public void set(boolean value) { |
| 32 |
guide.setDefaultGroupEnableAbstractElements(!value); |
| 33 |
} |
| 34 |
}); |
| 35 |
pp.declare("any-process-contents", |
| 36 |
new EnumParam(processContents) { |
| 37 |
protected void setEnum(int i) { |
| 38 |
outputOptions.anyProcessContents = getValues()[i]; |
| 39 |
} |
| 40 |
}); |
| 41 |
pp.declare("any-attribute-process-contents", |
| 42 |
new EnumParam(processContents) { |
| 43 |
protected void setEnum(int i) { |
| 44 |
outputOptions.anyAttributeProcessContents = getValues()[i]; |
| 45 |
} |
| 46 |
}); |
| 47 |
pp.process(params, eh); |
| 48 |
try { |
| 49 |
ErrorReporter er = new ErrorReporter(eh, XsdOutputFormat.class); |
| 50 |
SchemaInfo si = new SchemaInfo(sc, er); |
| 51 |
if (!er.getHadError()) { |
| 52 |
RefChecker.check(si, er); |
| 53 |
if (!er.getHadError()) { |
| 54 |
RestrictionsChecker.check(si, er); |
| 55 |
if (!er.getHadError()) { |
| 56 |
Schema schema = BasicBuilder.buildBasicSchema(si, guide, er); |
| 57 |
if (!er.getHadError()) { |
| 58 |
new Transformer(schema, er).transform(); |
| 59 |
if (!er.getHadError()) |
| 60 |
BasicOutput.output(schema, guide, new PrefixManager(si), od, outputOptions, er); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
if (er.getHadError()) |
| 66 |
throw new OutputFailedException(); |
| 67 |
} |
| 68 |
catch (ErrorReporter.WrappedSAXException e) { |
| 69 |
throw e.getException(); |
| 70 |
} |
| 71 |
} |
| 72 |
} |