Java by API/javax.xml.transform/SourceLocator

Материал из Java эксперт
Версия от 14:17, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

SourceLocator: getColumnNumber()

  
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
  public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
      Transformer xformer = template.newTransformer();
      Source source = new StreamSource(new FileInputStream(inFilename));
      Result result = new StreamResult(new FileOutputStream(outFilename));
      xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
      SourceLocator locator = e.getLocator();
      int col = locator.getColumnNumber();
      int line = locator.getLineNumber();
      String publicId = locator.getPublicId();
      String systemId = locator.getSystemId();
    }
  }
}





SourceLocator: getLineNumber()

  
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
  public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
      Transformer xformer = template.newTransformer();
      Source source = new StreamSource(new FileInputStream(inFilename));
      Result result = new StreamResult(new FileOutputStream(outFilename));
      xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
      SourceLocator locator = e.getLocator();
      int col = locator.getColumnNumber();
      int line = locator.getLineNumber();
      String publicId = locator.getPublicId();
      String systemId = locator.getSystemId();
    }
  }
}





SourceLocator: getPublicId()

  
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
  public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
      Transformer xformer = template.newTransformer();
      Source source = new StreamSource(new FileInputStream(inFilename));
      Result result = new StreamResult(new FileOutputStream(outFilename));
      xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
      SourceLocator locator = e.getLocator();
      int col = locator.getColumnNumber();
      int line = locator.getLineNumber();
      String publicId = locator.getPublicId();
      String systemId = locator.getSystemId();
    }
  }
}





SourceLocator: getSystemId()

  
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Main {
  public static void xsl(String inFilename, String outFilename, String xslFilename) {
    try {
      TransformerFactory factory = TransformerFactory.newInstance();
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename)));
      Transformer xformer = template.newTransformer();
      Source source = new StreamSource(new FileInputStream(inFilename));
      Result result = new StreamResult(new FileOutputStream(outFilename));
      xformer.transform(source, result);
    } catch (FileNotFoundException e) {
    } catch (TransformerConfigurationException e) {
    } catch (TransformerException e) {
      SourceLocator locator = e.getLocator();
      int col = locator.getColumnNumber();
      int line = locator.getLineNumber();
      String publicId = locator.getPublicId();
      String systemId = locator.getSystemId();
    }
  }
}