From: Jean-Marc V. <jm...@us...> - 2004-08-07 15:04:17
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1869/src/org/exist/client Modified Files: InteractiveClient.java Log Message: add XML Schema validation (commands putschema and validate) - test in progress Index: InteractiveClient.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/client/InteractiveClient.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** InteractiveClient.java 6 Aug 2004 15:34:30 -0000 1.34 --- InteractiveClient.java 7 Aug 2004 15:04:08 -0000 1.35 *************** *** 39,42 **** --- 39,43 ---- import java.io.StreamTokenizer; import java.io.StringReader; + import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; *************** *** 66,70 **** --- 67,75 ---- import org.apache.avalon.excalibur.cli.CLUtil; import org.apache.oro.io.GlobFilenameFilter; + import org.apache.xerces.parsers.DOMParser; + import org.apache.xml.serialize.OutputFormat; + import org.apache.xml.serialize.XMLSerializer; import org.exist.dom.XMLUtil; + import org.exist.schema.SchemaService; import org.exist.security.Permission; import org.exist.security.User; *************** *** 1039,1042 **** --- 1044,1068 ---- else if (args[0].equalsIgnoreCase("quit")) { return false; + + } else if (args[0].equalsIgnoreCase("validate")) { + if (args.length < 2) + messageln("missing document name."); + else { + SchemaService schemaService = (SchemaService) current.getService("SchemaService", "1.0"); + if (schemaService.validateResource(args[1])) + messageln("validated ok."); + else + messageln("there were errors."); + } + + } else if (args[0].equalsIgnoreCase("putschema")) { + if (args.length < 2) { + messageln("missing schema file name."); + } else { + importSchema(args[1]); + getResources(); + } + return true; + } else { messageln("unknown command"); *************** *** 1054,1057 **** --- 1080,1110 ---- } + /** + * @param String filename of the file that contains the schema + */ + private void importSchema(String filename) throws XMLDBException { + SchemaService schemaService = (SchemaService) current.getService("SchemaService", "1.0"); + if (schemaService != null) { + String schemaContents = null; + try { + DOMParser parser = new DOMParser(); + parser.parse(filename); + Document document = parser.getDocument(); + StringWriter sw = new StringWriter(); + XMLSerializer serializer = new XMLSerializer(sw, new OutputFormat(document, "UTF-8", true)); + serializer.serialize(document); + schemaContents = sw.toString(); + + schemaService.putSchema(schemaContents); + messageln("imported schema in file \"" + filename + "\"."); + + } catch (SAXException saxEx) { + messageln("Unable to parse schema in " + filename + ": " + saxEx.getMessage()); + } catch (IOException ioEx) { + messageln("Uable to parse schema in " + filename + ": " + ioEx.getMessage()); + } + } + } + private final ResourceSet find(String xpath) throws XMLDBException { if (xpath.charAt(xpath.length() - 1) == '\n') *************** *** 1301,1304 **** --- 1354,1362 ---- } + /** stores given Resource + * @param fileName simple file or directory + * @return + * @throws XMLDBException + */ protected synchronized boolean parse(String fileName) throws XMLDBException { fileName = fileName.replace('/', File.separatorChar).replace('\\', *************** *** 2118,2125 **** --- 2176,2187 ---- } catch (IOException ioe) { System.err.println(ioe); + } catch (Exception e) { + // TODO: handle exception + System.err.println(e); } try { Readline.writeHistoryFile(historyFile.getAbsolutePath()); } catch (Exception e) { + System.err.println("Could not write history File to " + historyFile.getAbsolutePath() ); } Readline.cleanup(); |