So... Finally I made it. Still there is a small bug
SystemId Unknown; Line #-1; Column #-1; Premature end of file.
but I hope it is one not very difficult to fix.
As you can see below the output stream is now written to StringWriter, and then StringWriter is written to a XML file. Still I can't understand why there is no result (file is just cleared) if you pass a file to StreamResult. May be just my hands growing out of a wrong place. May be I'll make a little research tomorrow.
So, method executeWrite(...) was changed a lot
protected void executeWrite(PrintWriter out, ReadWriteLock readWriteLock, Transformer transformer)
throws HandledException {
Lock readLock = readWriteLock.readLock();
StringWriter outWriter = new StringWriter();
Transformer t = null;
try {
readLock.lock();
StreamSource xmlStream = new StreamSource(/*path to XML*/);
t = transformer;
t.transform(xmlStream, new StreamResult(outWriter));
} catch (TransformerException e) {
ExceptionHandler.logAndThrow(e, logger);
} finally {
readLock.unlock();
}
Lock writeLock = readWriteLock.writeLock();
FileWriter fileWriter = null;
try {
writeLock.lock();
fileWriter = new FileWriter(new File(/*path to XML*/));
fileWriter.write(outWriter.toString());
} catch (IOException e) {
ExceptionHandler.logAndThrow(e, logger);
} finally {
if (fileWriter != null) {
try {
fileWriter.close();
} catch (IOException e) {
ExceptionHandler.logAndThrow(e, logger);
}
}
writeLock.unlock();
}
}