|
|
|
Не выдает ошибку на битый xml
|
|||
|---|---|---|---|
|
#18+
Доброго времени суток. В java выполняю либо xsl преобразование либо с помощью FOP трансформера генерю pdf Если подсунуть невалидный xml файл. Не выдается ошибка, а просто получается пустой файл. Как сделать чтобы ошибка возникала? Вот кусок кода TransformerFactory factory = TransformerFactory.newInstance(); // factory.setURIResolver(new MyURIResolver()); Transformer transformer = null; if (!xsl.exists()) { transformer = factory.newTransformer(); // identity transformer } else { Source xsltSrc = new StreamSource(xsl); transformer = factory.newTransformer(xsltSrc); // identity transformer } // Setup input stream Source src = new StreamSource(fo); // Resulting SAX events (the generated FO) must be piped through to FOP Result res = null; if (ext.equalsIgnoreCase("xml")) { res = new StreamResult(out); } else { res = new SAXResult(fop.getDefaultHandler()); } // Start XSLT transformation and FOP processing transformer.transform(src, res); ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 29.10.2007, 13:55:55 |
|
||
|
Не выдает ошибку на битый xml
|
|||
|---|---|---|---|
|
#18+
ORA-00942 Не выдается ошибка кто сказал ? все тама выдаеца... код не полный, где обработка ексепшенов? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 29.10.2007, 15:15:25 |
|
||
|
Не выдает ошибку на битый xml
|
|||
|---|---|---|---|
|
#18+
Вот полный код, и нифига не выдает. И главное не останавливается. Написал к нему ErrorListener, не помогло public class ExampleFO2PDF { ExampleFO2PDF() { } /** * Конструктор в котором создается и конфигурируется fopFactory и foUserAgent * @param loger логер * @param bd базовая директория, где хранится конфигурационный файл для FOP */ ExampleFO2PDF(Logger loger, String bd) { log = loger; fopFactory.setStrictValidation(false); try { cfg = cfgBuilder.buildFromFile(new File(bd + "userconfig.xml")); fopFactory.setUserConfig(cfg); } catch (IOException e) { log.warn("Configuration file " + bd + "userconfig.xml not found"); log.info("About config file see http://xmlgraphics.apache.org/fop/0.94/configuration.html"); log.info("Continue"); } catch (Exception e) { log.error(e.getMessage()); } foUserAgent = fopFactory.newFOUserAgent(); } private FopFactory fopFactory = FopFactory.newInstance(); private static Logger log = null; private DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); private Configuration cfg = null; private FOUserAgent foUserAgent = null; public void convertFO2PDF(Source src, ByteArrayOutputStream out, File xsl, String ext) throws IOException, Exception /*, FOPException*/ { try { log.info("Begin processing__________________________________________"); // System.out.println("Begin processing____________________________________________"); // Construct fop with desired output format Fop fop = null; if (ext.equalsIgnoreCase("rtf")) { fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, out); } else if (ext.equalsIgnoreCase("pdf")) { fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out); } else if (ext.equalsIgnoreCase("txt")) { fop = fopFactory.newFop(MimeConstants.MIME_PLAIN_TEXT, foUserAgent, out); } else if (ext.equalsIgnoreCase("xml")) { } else { // System.out.println("Unknown format!"); throw new Exception("Unknown format!"); } // Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); ErrorListener factoryListener = new TrErrorListener(log); factory.setErrorListener(factoryListener); Transformer transformer = null; if (!xsl.isFile()) { transformer = factory.newTransformer(); // identity transformer } else { Source xsltSrc = new StreamSource(xsl); transformer = factory.newTransformer(xsltSrc); // identity transformer } // Resulting SAX events (the generated FO) must be piped through to FOP Result res = null; if (ext.equalsIgnoreCase("xml")) { res = new StreamResult(out); } else { res = new SAXResult(fop.getDefaultHandler()); } // Start XSLT transformation and FOP processing transformer.transform(src, res); // System.out.println("End processing"); log.info("End processing____________________________________________"); // System.out.println("End processing____________________________________________"); } catch (Exception e) { if (log == null) { System.out.println(e.getMessage()); } else { throw e; } } finally { out.close(); } } } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 29.10.2007, 16:15:50 |
|
||
|
|

start [/forum/topic.php?fid=59&fpage=600&tid=2144189]: |
0ms |
get settings: |
12ms |
get forum list: |
20ms |
check forum access: |
6ms |
check topic access: |
6ms |
track hit: |
41ms |
get topic data: |
13ms |
get forum data: |
4ms |
get page messages: |
57ms |
get tp. blocked users: |
2ms |
| others: | 315ms |
| total: | 476ms |

| 0 / 0 |
