[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/io/xml sample-xml-file-spec.xml, 1.1, 1.2
Brought to you by:
suresh_pragada
|
From: Suresh <sur...@us...> - 2006-08-22 13:04:17
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29920 Modified Files: sample-xml-file-spec.xml XMLFileSpec.java XMLFileWriter.java Log Message: no message Index: sample-xml-file-spec.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/sample-xml-file-spec.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sample-xml-file-spec.xml 3 Jun 2006 13:14:42 -0000 1.1 --- sample-xml-file-spec.xml 22 Aug 2006 13:04:13 -0000 1.2 *************** *** 1,5 **** <?xml version="1.0" encoding="UTF-8"?> ! <file-spec file-type="xml" root-element="sample-root"> <record-spec record-type="header" record-xpath="/sample-root/sample-header"/> <record-spec record-type="detail" record-xpath="/sample-root/sample-detail"/> --- 1,5 ---- <?xml version="1.0" encoding="UTF-8"?> ! <file-spec file-type="xml" root-element="sample-root" indentation-engine="org.jmonks.batchserver.io.xml.PrettyXMLIndentationEngine"> <record-spec record-type="header" record-xpath="/sample-root/sample-header"/> <record-spec record-type="detail" record-xpath="/sample-root/sample-detail"/> Index: XMLFileWriter.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileWriter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** XMLFileWriter.java 16 Aug 2006 18:07:24 -0000 1.11 --- XMLFileWriter.java 22 Aug 2006 13:04:13 -0000 1.12 *************** *** 52,56 **** * Egnine to be used for the indentation. */ ! private XMLIndentationEngine indentationEngine=new PrettyXMLIndentationEngine(); private static Logger logger=Logger.getLogger(XMLFileWriter.class); --- 52,56 ---- * Egnine to be used for the indentation. */ ! private XMLIndentationEngine indentationEngine=null; private static Logger logger=Logger.getLogger(XMLFileWriter.class); *************** *** 82,87 **** this.writer=outputFactory.createXMLStreamWriter(writer); logger.debug("Writer has been created."); this.writer.writeStartDocument("ISO-8859-1", "1.0"); ! this.writer.writeCharacters(indentationEngine.startElement()); this.writer.writeStartElement(this.fileSpec.rootElement); } --- 82,88 ---- this.writer=outputFactory.createXMLStreamWriter(writer); logger.debug("Writer has been created."); + this.indentationEngine=this.getXMLIndentationEngine(this.fileSpec.getXMLIndentationEngineClassName()); this.writer.writeStartDocument("ISO-8859-1", "1.0"); ! this.writer.writeCharacters(this.indentationEngine.startElement()); this.writer.writeStartElement(this.fileSpec.rootElement); } *************** *** 254,258 **** logger.trace("Exiting close"); } ! /** --- 255,294 ---- logger.trace("Exiting close"); } ! ! /** ! * Instantiates and returns the instance of the given class name. If it couldnt be instantiated, ! * it returns default XMLIndentationEngine. ! * ! * @param xmlIndentationEngineClassName Class name of engine defined in the file spec. ! * ! * @return Returns the instance of xml indentation engine. ! */ ! private XMLIndentationEngine getXMLIndentationEngine(String xmlIndentationEngineClassName) ! { ! logger.trace("Entering getXMLindentationEngine = " + xmlIndentationEngineClassName); ! XMLIndentationEngine engine=null; ! if(xmlIndentationEngineClassName!=null) ! { ! try ! { ! engine=(XMLIndentationEngine)Class.forName(xmlIndentationEngineClassName).newInstance(); ! logger.debug("Successfully created engine from the configured class"); ! } ! catch(Exception exception) ! { ! exception.printStackTrace(); ! logger.error(exception.getMessage(),exception); ! logger.info("Unable to instantiate the configured xml indentation engine class. Creating the default xml indentation engine."); ! engine=new PrettyXMLIndentationEngine(); ! } ! } ! else ! { ! logger.info("No xml indentation engine class has been configured in file spec. Creating the default xml indentation engine."); ! engine=new PrettyXMLIndentationEngine(); ! } ! logger.trace("Exiting getXMLIndentationEngine = " + (engine!=null)); ! return engine; ! } /** *************** *** 330,337 **** /** ! * Creates an orphan record that can be added to the repeated element. ! * Once you are done working with this record, you should add this one to ! * either the list or any another element, but you can submit to the writer ! * for writing into the file. This will not be associated to the record by default. */ public WriterRecord createComplexElement() --- 366,376 ---- /** ! * Creates an orphan record that can be added to the record or repeated ! * element later. Once you are done working with this record, ! * you should add this one to either the list or any another element, ! * but you can not submit to the writer for writing this (orphan) record into the file. ! * This will not be associated to any record by default. ! * ! * @return Returns an XMLWriterRecord. */ public WriterRecord createComplexElement() Index: XMLFileSpec.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/io/xml/XMLFileSpec.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** XMLFileSpec.java 22 Jun 2006 22:52:01 -0000 1.5 --- XMLFileSpec.java 22 Aug 2006 13:04:13 -0000 1.6 *************** *** 44,50 **** --- 44,58 ---- protected String rootElement=null; /** + * Holds the class name of XMLIndentationEngine. + */ + protected String xmlIndentationEngineClassName=null; + /** * Constant defines the root element attribute name. */ public static final String ROOT_ELEMENT_ATTRIB_NAME = "root-element"; + /** + * Constant defines the xml indentation engine attribute name. + */ + public static final String XML_INDENTATION_ENGINE_ATTRIB_NAME = "indentation-engine"; private static Logger logger=Logger.getLogger(XMLFileSpec.class); *************** *** 67,70 **** --- 75,90 ---- /** + * Returns the XMLIndentationEngine class name to be used + * to format the output. This is optional in configuration. If + * none is specified default xml indentation engine will be used. + * + * @return Returns the class name of XMLIndentationEngine, null if not configured. + */ + public String getXMLIndentationEngineClassName() + { + return this.xmlIndentationEngineClassName; + } + + /** * Factory method to create the xml file spec object from the given * DOM Element representing the file-spec element. *************** *** 86,89 **** --- 106,111 ---- else throw new FileSpecException("XML FileSpec requires attribute root-element in element file-spec."); + + fileSpec.xmlIndentationEngineClassName=fileSpecElement.getAttribute(XMLFileSpec.XML_INDENTATION_ENGINE_ATTRIB_NAME); NodeList recordSpecNodeList=fileSpecElement.getElementsByTagName(RecordSpec.RECORD_SPEC_TAG_NAME); *************** *** 114,117 **** --- 136,140 ---- stringValue.append("[fileType = " + super.fileType.toString() + "]"); stringValue.append("[rootElement = " + this.rootElement + "]"); + stringValue.append("[xmlIndentationEngine = " + this.xmlIndentationEngineClassName + "]"); stringValue.append("[recordSpecList = "); for(Iterator iterator=recordSpecMap.values().iterator();iterator.hasNext();) |