1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.batch;
18
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.kew.util.Utilities;
21 import org.kuali.rice.kew.xml.XmlLoader;
22
23 import java.io.BufferedInputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26
27
28
29
30
31
32
33
34 public class XmlDigesterServiceImpl implements XmlDigesterService {
35 private static final Logger LOG = Logger.getLogger(XmlDigesterServiceImpl.class);
36
37 private static void addProcessingException(XmlDoc xmlDoc, String message, Throwable t) {
38 String msg = xmlDoc.getProcessingMessage();
39 if (msg == null) {
40 msg = "";
41 }
42 msg += message + "\n" + Utilities.collectStackTrace(t);
43 xmlDoc.setProcessingMessage(msg);
44 }
45
46 public void digest(XmlLoader xmlLoader, XmlDocCollection xmlDocCollection, String principalId) throws IOException {
47 for (XmlDoc xmlDoc : xmlDocCollection.getXmlDocs())
48 {
49 InputStream inputStream = null;
50 try
51 {
52 inputStream = new BufferedInputStream(xmlDoc.getStream());
53
54
55
56
57
58
59
60
61 xmlLoader.loadXml(inputStream, principalId);
62
63
64
65
66
67 xmlDoc.setProcessed(true);
68 } catch (Exception e)
69 {
70 xmlDoc.setProcessed(false);
71 addProcessingException(xmlDoc, "Caught Exception loading xml data from " + xmlDoc + ". Will move associated file to problem dir.", e);
72 LOG.error("Caught Exception loading xml data from " + xmlDoc + ". Will move associated file to problem dir.", e);
73 if (e instanceof RuntimeException)
74 {
75 throw (RuntimeException) e;
76 } else if (e instanceof IOException)
77 {
78 throw (IOException) e;
79 }
80 } finally
81 {
82 if (inputStream != null) try
83 {
84 inputStream.close();
85 } catch (IOException ioe)
86 {
87 LOG.warn("Error closing stream for xml doc: " + xmlDoc, ioe);
88 }
89 }
90 }
91 }
92 }