Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
OW2 Util Copyright (C) 2007 Bull S.A.S. Contact: easybeans@objectweb.org 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: AbstractPropertyEditorMojo.java 4483 2009-01-26 08:47:13Z gaellalire $ --------------------------------------------------------------------------
 
 
 /*
  * Copyright 2005-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.ow2.util.maven.plugin.propertyeditor;
 
 import java.io.File;
 import java.io.Writer;
 
 
Maven XML Editor Mojo.

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

    

Parameter:
expression="${project}"
Required:
Readonly:
 
     private MavenProject mavenProject;

    
List of bundles to start after a given delay.

Parameter:
Required:
 
     private EditorConfiguration[] editorConfigurations = null;

    
write the document to a writer.

Parameters:
document the document to write
writer the writer
Throws:
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();
        properties.put("method""xml");
        properties.put("version""1.0");
        properties.put("encoding""ISO-8859-1");
        properties.put("standalone""yes");
        properties.put("indent""yes");
        properties.put("omit-xml-declaration""no");
        transformer.setOutputProperties(properties);
        DOMSource input = new DOMSource(document);
        Result output = new StreamResult(writer);
        transformer.transform(inputoutput);
    }
    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) {
                e.printStackTrace();
                throw new MojoExecutionException("Accessing xml file issue"e);
            }
            try {
                Properties properties = new Properties();
                // read properties
                if (!editorConfiguration.isCreateFile()) {
                    try {
                        InputStream inputStream = fileAccessor.getInputStream();
                        properties.load(inputStream);
                        inputStream.close();
                    } 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();
                properties.store(outputStreamnull);
                /*
                System.out.println("On ecrit");
                writeDocumentTo(editor.getDocument(), new OutputStreamWriter(System.out));
                */
            } catch (Exception e) {
                e.printStackTrace();
                throw new MojoExecutionException("Unable to work with property file"e);
            }
        }
    }
New to GrepCode? Check out our FAQ X