* file.
*/
protected boolean analyze(final ModelRequest req, ModelResponse res, final String fileName, final String handlerId,
final boolean bulkImport, String xslt, final Properties properties) throws ModelException
{
final I18N i18n = (I18N) req.getSpringBean(I18N.ID);
final ImportManager im = (ImportManager) req.getSpringBean(ImportManager.ID);
FileTools.newAkteraFile("/var/tmp/iritgo").mkdirs();
final File lockFile = FileTools.newAkteraFile("/var/tmp/iritgo/import.lck");
if ("Y".equals(req.getParameter("force")))
{
lockFile.delete();
}
if (lockFile.exists())
{
return false;
}
try
{
lockFile.createNewFile();
File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");
reportFile.delete();
reportFile.createNewFile();
final PrintWriter reporter = new PrintWriter(new FileOutputStream(reportFile), true);
convertToXml(req, fileName, xslt);
if (im.validateXmlFile(new File(fileName)))
{
new Thread()
{
public void run()
{
boolean ok = true;
try
{
File file = new File(fileName);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
"file://" + file.getAbsolutePath());
if (doc.getChildNodes().getLength() > 0)
{
XPath xPath = XPathFactory.newInstance().newXPath();
Node importElem = (Node) xPath.evaluate("import", doc, XPathConstants.NODE);
if (importElem != null)
{
reporter.println(i18n.msg(req, "Aktera", "startingImportAnalysis"));
ok = im.analyzeImport(req, doc, importElem, reporter, i18n, handlerId, bulkImport, properties);
}
else
{
reporter.println(i18n
.msg(req, "AkteraImporter", "importErrorNoImportRootNodeFound"));
}
}
else
{
reporter.println(i18n.msg(req, "AkteraImporter", "importErrorNoImportRootNodeFound"));
}
}
catch (ParserConfigurationException x)
{
reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
}
catch (SAXException x)
{
reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
}
catch (IOException x)
{
reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
}
catch (XPathExpressionException x)
{
reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
}
catch (ModelException x)
{
reporter.println(i18n.msg(req, "Aktera", "importError", x.toString()));
}
reporter.println(i18n.msg(req, "Aktera", "finishedImportAnalysis"));
reporter.println();
reporter.println(i18n.msg(req, "Aktera", "reportFileResult", (ok ? "OK" : "ERROR")));
reporter.close();
lockFile.delete();
}
}.start();
}
else
{
reporter.println(i18n.msg(req, "Aktera", "importFileDoesntContainImportElement"));
reporter.println();
reporter.println(i18n.msg(req, "Aktera", "reportFileResult", "ERROR"));
reporter.close();
lockFile.delete();
}
}
catch (Exception x)
{
try
{
File reportFile = FileTools.newAkteraFile("/var/tmp/iritgo/import-report.txt");
PrintWriter out = new PrintWriter(reportFile);
out.println(i18n.msg(req, "Aktera", "importError", x.toString()));
out.println();
out.println(i18n.msg(req, "Aktera", "reportFileResult", "ERROR"));
out.close();
lockFile.delete();
}
catch (IOException xx)
{