String extension = fileName.substring(fileName.indexOf('.') + 1);
String fullPathToFolder = this.getFullPath(fullPath, workflowName,
extension, fileName);
fullPath = fullPathToFolder + "/" + fileName;
AssetItem item = getFileManager().getRepository().loadAssetByUUID(uuid);
InputStream in = item.getBinaryContentAttachment();
String fileContent = request.getParameter("fileContent");
ByteArrayOutputStream bais = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(bais);
JarInputStream jis = null;
try {
if (in == null) {
jos.putNextEntry(new JarEntry(fullPath));
ByteArrayInputStream i = new ByteArrayInputStream(fileContent
.getBytes());
int len = 0;
byte[] copyBuf = new byte[1024];
while (len != -1) {
len = i.read(copyBuf, 0, copyBuf.length);
if (len > 0) {
jos.write(copyBuf, 0, len);
}
}
i.close();
jos.closeEntry();
} else {
jis = new JarInputStream(in);
boolean found = false;
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
jos.putNextEntry(new JarEntry(entry.getName()));
String name = entry.getName();
if (fullPath.equals(name)) {
found = true;
ByteArrayInputStream i = new ByteArrayInputStream(
fileContent.getBytes());
int len = 0;
byte[] copyBuf = new byte[1024];
while (len != -1) {
len = i.read(copyBuf, 0, copyBuf.length);
if (len > 0) {
jos.write(copyBuf, 0, len);
}
}
i.close();
} else {
int len = 0;
byte[] copyBuf = new byte[1024];
while (len != -1) {
len = jis.read(copyBuf, 0, copyBuf.length);
if (len > 0) {
jos.write(copyBuf, 0, len);
}
}
}
jis.closeEntry();
jos.closeEntry();
}
// If the file is not found, add it
if (!found) {
jos.putNextEntry(new JarEntry(fullPath));
ByteArrayInputStream i = new ByteArrayInputStream(
fileContent.getBytes());
int len = 0;
byte[] copyBuf = new byte[1024];
while (len != -1) {
len = i.read(copyBuf, 0, copyBuf.length);
if (len > 0) {
jos.write(copyBuf, 0, len);
}
}
i.close();
jos.closeEntry();
}
}
item.updateBinaryContentAttachment(new ByteArrayInputStream(bais
.toByteArray()));
item.checkin("Updated " + fileName);
} catch (IOException e) {
throw new RulesRepositoryException(e);
} finally {
if (jis != null) {