Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2010 eXo Platform SAS.
   *
   * This 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 (at your option) any later version.
   *
   * This software 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 software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.wikbook.maven;
 
 
 import java.io.File;
 import java.net.URL;
 import java.util.List;
 import java.util.Set;

Author(s):
Julien Viet
Version:
$Revision$
Goal:
transform
Phase:
compile
RequiresDependencyResolution:
 
 public class WikBookMojo extends AbstractMojo
 {

   
The source directory.

Parameter:
 
    private File sourceDirectory;

   
The source file name.

Parameter:
 
    private String sourceFileName;

   
The syntax id.

Parameter:
 
    private String syntaxId;

   
The destination directory.

Parameter:
 
    private File destinationDirectory;

   
The destination file name.

Parameter:
 
    private String destinationFileName;

   
Turn on/off code highlighting

Parameter:
default-value="true"
   private boolean highlightCode;

   
Turn on/off code doctype generation of the DocBook document.

Parameter:
default-value="true"
   private boolean emitDoctype;

   
The wikbook validation mode, can either be lax or strict.

Parameter:
default-value="lax"
   private String validationMode;

   
Any XML that should be inserted before the book body.

Parameter:
default-value=""
   private String beforeBookBodyXML;

   
Any XML that should be inserted after the book body.

Parameter:
default-value=""
   private String afterBookBodyXML;

   
The charset name when reading wiki files, the default value is the UTF-8 charset.

Parameter:
default-value="UTF-8"
   private String charset;

   
INTERNAL : The representation of the maven execution.

Parameter:
expression="${session}"
Required:
Readonly:
   private MavenSession session;

   

Parameter:
expression="${plugin.artifacts}"
Required:
Readonly:
   private List pluginArtifacts;

   
The source directories containing the sources to be compiled.

Parameter:
default-value="${project.compileSourceRoots}"
Required:
Readonly:
   private List<StringcompileSourceRoots;

   
Project classpath.

Parameter:
default-value="${project.compileClasspathElements}"
Required:
Readonly:
   private List<StringcompileClasspathElements;

   
The source directories containing the sources to be compiled.

Parameter:
default-value="${project.testCompileSourceRoots}"
Required:
Readonly:
   private List<StringtestCompileSourceRoots;

   
Project classpath.

Parameter:
default-value="${project.testClasspathElements}"
Required:
Readonly:
   public void execute() throws MojoExecutionExceptionMojoFailureException
   {
      File src = new File();
      if (!src.exists())
      {
         throw new MojoFailureException("Source file " + src.getAbsolutePath() + " does not exist");
      }
      if (!src.isFile())
      {
         throw new MojoFailureException("Source file " + src.getAbsolutePath() + " is not a file");
      }
      //
      if (.exists())
      {
         if (!.isDirectory())
         {
            throw new MojoFailureException("Destination directory " + .getAbsolutePath() + " is not a directory");
         }
      }
      else
      {
         if (!.mkdirs())
         {
            throw new MojoFailureException("Could not create destination directory " + .getAbsolutePath());
         }
      }
      //
      WikbookConverter converter;
      try
      {
         converter = new WikbookConverter();
      }
      catch (Exception e)
      {
         throw new MojoFailureException(""e);
      }
      //
      converter.setEmitDoctype();
      converter.setSyntaxId();
      //
      File destination = new File();
      //
      FileWriter out = null;
      try
      {
         if (hasTrimmedContent())
         {
            DocumentFragment elt = load();
            converter.setBeforeBookBodyXML(elt);
         }
         //
         if (hasTrimmedContent())
         {
            DocumentFragment elt = load();
            converter.setAfterBookBodyXML(elt);
         }
         //
         out = new FileWriter(destination);
         StreamResult result = new StreamResult(out);
         converter.convert(result);
      }
      catch (Exception e)
      {
         MojoFailureException mfe = new MojoFailureException("Could not create destination file " + e.getMessage());
         mfe.initCause(e);
         throw mfe;
      }
      finally
      {
         if (out != null)
         {
            try
            {
               out.close();
            }
            catch (IOException e)
            {
               e.printStackTrace();
            }
         }
      }
   }
   private static boolean hasTrimmedContent(String xml)
   {
      return xml != null && xml.trim().length() > 0;
   }
   {
      xml = "<root>" + xml + "</root>";
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      dbf.setXIncludeAware(false);
      dbf.setValidating(false);
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(new InputSource(new StringReader(xml)));
      DocumentFragment fragment = doc.createDocumentFragment();
      XML.copyStandaloneNodes(doc.getDocumentElement(), fragment);
      return fragment;
   }
   {
      public void log(String msg)
      {
         getLog().info(msg);
      }
      public boolean getHighlightCode()
      {
         return ;
      }
      public ValidationMode getValidationMode()
      {
         if ("strict".equalsIgnoreCase())
         {
            return .;
         }
         else
         {
            return .;
         }
      }
      @Override
      public List<URLresolveResources(ResourceType typeIterable<StringpathString idthrows IOException
      {
         if (id.length() > 0)
         {
            out:
            switch (type)
            {
               case :
                  File current = ;
                  for (String segment : path)
                  {
                     File relative = new File(currentsegment);
                     if (relative.exists())
                     {
                        current = relative.getParentFile();
                     }
                     else
                     {
                        break out;
                     }
                  }
                  //
                  File resolved = new File(currentid);
                  if (resolved != null && resolved.isFile())
                  {
                     return Arrays.asList(resolved.toURI().toURL());
                  }
                  break;
               case :
               case :
               case :
                  if (id.startsWith("/"))
                  {
                     id = id.substring(1);
                  }
                  LinkedHashSet<URLurls = new LinkedHashSet<URL>();
                  //
                  List<Stringdirs = new ArrayList<String>();
                  dirs.addAll();
                  dirs.addAll();
                  dirs.addAll();
                  dirs.addAll();
                  //
                  for (String elt : dirs)
                  {
                     File eltFile = new File(elt);
                     if (eltFile.exists())
                     {
                        urls.add(eltFile.toURI().toURL());
                     }
                  }
                  //
                  for (Artifact artifact : (Set<Artifact>).getCurrentProject().getDependencyArtifacts())
                  {
                     urls.add(artifact.getFile().toURI().toURL());
                  }
                  //
                  ClassLoader cl = new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader());
                  Enumeration<URLfound = cl.getResources(id);
                  ArrayList<URLbilto = new ArrayList<URL>();
                  while (found.hasMoreElements())
                  {
                     bilto.add(found.nextElement());
                  }
                  //
                  return bilto;
            }
         }
         return Collections.emptyList();
      }
      public String getProperty(String propertyName)
      {
         Properties properties = .getCurrentProject().getProperties();
         return properties.getProperty(propertyName);
      }
      @Override
      protected String getCharsetName()
      {
         return ;
      }
   };
New to GrepCode? Check out our FAQ X