All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openfuxml.addon.wiki.parser.WikiTimelineParser Maven / Gradle / Ivy

The newest version!
package org.openfuxml.addon.wiki.parser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import net.sf.exlp.core.handler.EhResultContainer;
import net.sf.exlp.core.listener.LogListenerXml;
import net.sf.exlp.core.parser.AbstractLogParser;
import net.sf.exlp.interfaces.LogEventHandler;
import net.sf.exlp.interfaces.LogListener;
import net.sf.exlp.interfaces.LogParser;
import net.sf.exlp.util.io.LoggerInit;

import org.openfuxml.addon.wiki.data.jaxb.Ofxchart;
import org.openfuxml.addon.wiki.data.jaxb.Ofxchartcontainer;
import org.openfuxml.addon.wiki.data.jaxb.Ofxchartdata;
import org.openfuxml.addon.wiki.event.WikiChartEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WikiTimelineParser extends AbstractLogParser implements LogParser  
{
	final static Logger logger = LoggerFactory.getLogger(WikiTimelineParser.class);
	private static enum Section {none,bardata,plotdata};
	
	private Section section;
	private ArrayList alP,alPBarData,alPPlotData;
	
	private Ofxchart ofxChart;
	private StringBuffer sbParseLine;
	
	public WikiTimelineParser(LogEventHandler leh)
	{
		super(leh);
		alP=new ArrayList();
		alPBarData=new ArrayList();
		alPPlotData=new ArrayList();
		
		alP.add(Pattern.compile("BarData=(.*)"));
		alP.add(Pattern.compile("PlotData=(.*)"));
		
		alPBarData.add(Pattern.compile("[ ]*bar:(\\d*) text:([\\d\\w]*)(.*)"));
		
		alPPlotData.add(Pattern.compile("[ ]*bar:(\\d*) from:(\\d*) till: (\\d*)(.*)"));
		alPPlotData.add(Pattern.compile("[ ]*bar:(\\d*) at:(\\d*)(.*)"));
		alPPlotData.add(Pattern.compile("[ ]*color:(\\w*)(.*)"));
	}

	public void parseLine(String line)
	{
		sbParseLine.append(" parseLine:"+line);
		allLines++;
		boolean unknownPattern = true;
		for(int i=0;i item)
	{
		ofxChart = new Ofxchart();
		ofxChart.setType("bar");
		
		section = Section.none;
		logger.debug("Item received with "+item.size()+" entries");
		for(String line : item){parse(line);}
//		debug();
		WikiChartEvent event = new WikiChartEvent(ofxChart);
		leh.handleEvent(event);
	}
	
	@SuppressWarnings("unused")
	private void debug()
	{
		try
		{
			JAXBContext context = JAXBContext.newInstance(Ofxchart.class);
			Marshaller m = context.createMarshaller(); 
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
			m.marshal(ofxChart, System.out);
		}
		catch (JAXBException e) {logger.error("",e);}
	}
	
	public static void main(String args[])
	{
		LoggerInit loggerInit = new LoggerInit("log4j.xml");	
			loggerInit.addAltPath("resources/config");
			loggerInit.init();
			
		LogEventHandler leh = new EhResultContainer();
		LogParser lp = new WikiTimelineParser(leh);
		LogListener ll = new LogListenerXml("resources/data/timeline.xml",lp);
		ll.processMulti("/wikiinjection/wikicontent");
		EhResultContainer results = (EhResultContainer)leh;
		logger.debug("Results: "+results.getAlResults().size());
		WikiChartEvent event = (WikiChartEvent)results.getAlResults().get(0);
		Ofxchart ofxChart = event.getOfxChart();
		
		try
		{
			JAXBContext context = JAXBContext.newInstance(Ofxchart.class);
			Marshaller m = context.createMarshaller(); 
			m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 
			m.marshal(ofxChart, new File("resources/data/timeline-ofxchart.xml"));
		}
		catch (JAXBException e) {logger.error("",e);}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy