Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
OW2 Util Copyright (C) 2007 Bull S.A.S. Contact: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------- $Id: 6167 2012-02-09 16:46:06Z sauthieg $ --------------------------------------------------------------------------
 package org.ow2.util.maven.plugin.propertyeditor;
Maven XML Editor Mojo.

Gael Lalire
 public abstract class AbstractPropertyEditorMojo extends AbstractMojo {
     private static final Log LOG = LogFactory.getLog(AbstractPropertyEditorMojo.class);


     private MavenProject mavenProject;

List of bundles to start after a given delay.

     private EditorConfiguration[] editorConfigurations = null;

write the document to a writer.

document the document to write
writer the writer
javax.xml.transform.TransformerException if transform failed
     public static void writeDocumentTo(final Document documentfinal Writer writerthrows TransformerException {
         Transformer transformer = TransformerFactory.newInstance().newTransformer();
         Properties properties = new Properties();
         DOMSource input = new DOMSource(document);
         Result output = new StreamResult(writer);
     public void execute() throws MojoExecutionExceptionMojoFailureException {
         for (EditorConfiguration editorConfiguration : ) {
             IStreamAccessor fileAccessor;
             String filePath = editorConfiguration.getFilePath();
            try {
                if (filePath == null) {
                    fileAccessor = new SystemFileAccessor(new File(editorConfiguration.getFileName()));
                } else {
                    String[] filePaths = filePath.split("!");
                    fileAccessor = new SystemFileAccessor(new File(filePaths[0]));
                    int length = filePaths.length;
                    for (int i = 1; i < lengthi++) {
                        fileAccessor = new DelegatorZipStreamAccessor(fileAccessorfilePaths[i]);
                    fileAccessor = new DelegatorZipStreamAccessor(fileAccessoreditorConfiguration.getFileName());
            } catch (IOException e) {
                throw new MojoExecutionException("Accessing xml file issue"e);
            try {
                Properties properties = new Properties();
                // read properties
                if (!editorConfiguration.isCreateFile()) {
                    try {
                        InputStream inputStream = fileAccessor.getInputStream();
                    } catch (IOException e) {
                        .info("property file access issue, try to create new file"e);
                // do replace stuff
                for (EditorOperation editorOperation : editorConfiguration.getEditorOperations()) {
                    if (editorOperation.getName().equals("set")) {
                        properties.put(editorOperation.getProperty(), editorOperation.getValue());
                // write properties
                OutputStream outputStream = fileAccessor.getOutputStream();
                System.out.println("On ecrit");
                writeDocumentTo(editor.getDocument(), new OutputStreamWriter(System.out));
            } catch (Exception e) {
                throw new MojoExecutionException("Unable to work with property file"e);
New to GrepCode? Check out our FAQ X