vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out);
/** * Start visitor (initialization) */ @Override public void start(int version) throws IOException { try { contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl()); StringBuilder bld = new StringBuilder(); bld.append(version); addString(bld.toString()); contentHandler.endElement("", "", "EDITS_VERSION"); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } }
/** * Start visitor (initialization) */ @Override void start() throws IOException { write("<?xml version=\"1.0\"?>\n"); }
/** * Visit a Token * * @param value a Token to visit */ @Override Tokenizer.Token visit(Tokenizer.Token value) throws IOException { EditsElement ele = value.getEditsElement(); if (ele == EditsElement.OPCODE) { printIndents(); write("<OFFSET>" + value.offset + "</OFFSET>\n"); } writeTag(value.getEditsElement().toString(), value.toString()); return value; }
/** * Write an XML tag * * @param tag a tag name * @param value a tag value */ private void writeTag(String tag, String value) throws IOException { printIndents(); if(value.length() > 0) { write("<" + tag + ">" + value + "</" + tag + ">\n"); } else { write("<" + tag + "/>\n"); } }
/** * Leave enclosing element */ @Override void leaveEnclosingElement() throws IOException { depthCounter.decLevel(); if(tagQ.size() == 0) throw new IOException("Tried to exit non-existent enclosing element " + "in EditLog file"); EditsElement element = tagQ.pop(); printIndents(); write("</" + element.toString() + ">\n"); }
/** * Factory function that creates an EditsVisitor object * * @param filename output filename * @param tokenizer input tokenizer * @return EditsVisitor for appropriate output format (binary, XML etc.) */ static public EditsVisitor getEditsVisitor(String filename, String processor, Tokenizer tokenizer, boolean printToScreen) throws IOException { if(processor.toLowerCase().equals("xml")) { return new XmlEditsVisitor(filename, tokenizer, printToScreen); } else if(processor.toLowerCase().equals("stats")) { return new StatisticsEditsVisitor(filename, tokenizer, printToScreen); } else if(processor.toLowerCase().equals("binary")) { return new BinaryEditsVisitor(filename, tokenizer, printToScreen); } else { throw new IOException("Unknown proccesor " + processor + " (valid processors: xml, binary, stats)"); } } }
/** * Start visitor (initialization) */ @Override public void start(int version) throws IOException { try { contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl()); StringBuilder bld = new StringBuilder(); bld.append(version); addString(bld.toString()); contentHandler.endElement("", "", "EDITS_VERSION"); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } }
/** * Visit an enclosing element (element that cntains other elements) * * @param value a Token to visit */ @Override void visitEnclosingElement(Tokenizer.Token value) throws IOException { printIndents(); write("<" + value.getEditsElement().toString() + ">\n"); tagQ.push(value.getEditsElement()); depthCounter.incLevel(); }
/** * Finish with error */ @Override void finishAbnormally() throws IOException { write("\n<!-- Error processing EditLog file. Exiting -->\n"); super.finishAbnormally(); }
vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out);
/** * Start visitor (initialization) */ @Override public void start(int version) throws IOException { try { contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl()); StringBuilder bld = new StringBuilder(); bld.append(version); addString(bld.toString()); contentHandler.endElement("", "", "EDITS_VERSION"); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } }
vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out);