001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bstefanescu 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.webengine.install; 021 022import java.io.File; 023import java.io.FileOutputStream; 024import java.io.IOException; 025 026import org.nuxeo.common.utils.FileUtils; 027import org.nuxeo.common.xmap.annotation.XNode; 028import org.nuxeo.common.xmap.annotation.XObject; 029 030/** 031 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 032 */ 033@XObject("append") 034public class AppendOperation { 035 036 @XNode("@path") 037 protected String path; 038 039 @XNode("@target") 040 protected String target; 041 042 @XNode("@appendNewLine") 043 protected boolean appendNewLine = true; 044 045 public void run(Installer installer, File bundleDir, File installDir) throws IOException { 046 // ctx.getBundle().getEntryPaths(path); 047 File src = new File(bundleDir, path); 048 if (src.isFile()) { 049 String text = FileUtils.readFile(src); 050 if (appendNewLine) { 051 String crlf = System.getProperty("line.separator"); 052 text = crlf + text + crlf; 053 } 054 File file = new File(installDir, target); 055 File parent = file.getParentFile(); 056 if (!parent.isDirectory()) { 057 parent.mkdirs(); 058 } 059 boolean append = file.exists(); 060 FileOutputStream out = new FileOutputStream(file, append); 061 try { 062 out.write(text.getBytes()); 063 } finally { 064 out.close(); 065 } 066 } else { 067 installer.logWarning("Could not find path: " + path + " to append"); 068 } 069 } 070 071}