Friday, January 7, 2011

How to replace Doctype of xml using sax ?

Using SAX Entity Resolver you can change the DOCTYPE of xml .

Example :

String OnixFile=onixfilename; 
   
XMLReader readers = XMLReaderFactory.createXMLReader();
   
readers.setContentHandler(this);
readers.setErrorHandler(this);

readers.setEntityResolver(new Resolver()); 
FileReader filereader=new FileReader(OnixFile);
InputSource is=new InputSource(filereader);
is.setEncoding("UTF-8");
readers.parse(is);


class Resolver implements EntityResolver{

@Override
public InputSource resolveEntity(String publicId,String systemId)
   throws SAXException, IOException {
  if(systemId.equalsIgnoreCase(
    "http://www.editeur.org/onix/2.1/short
                     /onix-international.dtd")){

   String path="/ONIX 2.1 Revision 03 
                        reference/onix-international.dtd";
       return new InputSource(path);
 }
  return null;
 }
 
}

How to get currently executing jobs In Quartz Schedular ?

Example:

import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;

Scheduler sch=new StdSchedulerFactory().getScheduler();
List jobsList=sch.getCurrentlyExecutingJobs();
Iterator jobsIterator=jobsList.listIterator();

while(jobsIterator.hasNext()){
 JobExecutionContext context = 
                 (JobExecutionContext) jobsIterator.next();
 System.out.println(context.getJobDetail().getName());
}