/* * (C) Copyright IBM Corp. 1999-2000 All rights reserved. * * US Government Users Restricted Rights Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * * The program is provided "as is" without any warranty express or * implied, including the warranty of non-infringement and the implied * warranties of merchantibility and fitness for a particular purpose. * IBM will not be liable for any damages suffered by you as a result * of using the Program. In no event will IBM be liable for any * special, indirect or consequential damages or lost profits even if * IBM has been advised of the possibility of their occurrence. IBM * will not be liable for any third party claims against you. */ package asn1; import com.ibm.xml.asn1.ASN12SAX; import com.ibm.xml.asn1.ASN1Syntax2DTD; import com.ibm.xml.asn1.LabelSAX; import com.ibm.xml.asn1.ParseException; import com.ibm.xml.asn1.SAX2ASN1; import com.ibm.xml.asn1.SAXEventDumper; import com.ibm.xml.asn1.UnlabelSAX; import com.ibm.xml.parser.DTD; import com.ibm.xml.parser.Parser; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import org.apache.xerces.parsers.SAXParser; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; /** * This is a sample program to illustrate how to use this package. * This class enables the following: * * - Translation from DER encoded ASN.1 data to a plain XML document * or to a labeled one * * - Translation from a labeled XML document to a plain one or to DER * encoded ASN.1 data * * @author Takeshi IMAMURA */ public class Translator implements ErrorHandler { private String opt; // Option private String src; // Source file private String des; // Destination file private String dtd; // DTD file private String dtdName; // DTD name /** * Constructs an object and initializes some variables according to * the specified arguments. * * @param args arguments to this program. */ public Translator(String args[]) { if (args.length < 1) { printHelpAndExit(1); } String s = args[0]; int i = 1; if (s.equals("-a") || s.equals("-x") || s.equals("-xa") || s.equals("-d")) { if (args.length-i < 1) { printHelpAndExit(1); } opt = s; src = args[i++]; des = null; if (args.length-i > 0) { des = args[i]; } } else if (s.equals("-ax")) { if (args.length-i < 3) { printHelpAndExit(1); } opt = s; src = args[i++]; dtd = args[i++]; dtdName = args[i++]; des = null; if (args.length-i > 0) { des = args[i]; } } else if (s.equals("-help")) { printHelpAndExit(0); } else { printHelpAndExit(1); } } /** * Prints the help message and exits this program with a status. * * @param stat a status of this program. */ private void printHelpAndExit(int stat) { System.err.println("Usage: java asn1.Translator