Commit 417d6d92 authored by Christopher Hoskin's avatar Christopher Hoskin Committed by Emmanuel Bourg

Merge tag 'upstream/1.7'

Upstream version 1.7
parents 8f32c747 1b9256c2
// ------------------------------------------------------------------
// Transitive dependencies of this project determined from the
// maven pom organized by organization.
// ------------------------------------------------------------------
Doxia
This diff is collapsed.
Doxia
Copyright 2005-2016 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
package org.apache.maven.doxia.book;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import org.apache.maven.doxia.book.model.BookModel;
import java.io.File;
import java.util.List;
import java.util.Locale;
/**
* An interface to create books in different output formats from a book descriptor.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id: BookDoxia.java 748141 2009-02-26 13:29:10Z vsiveton $
*/
public interface BookDoxia
{
/** The plexus lookup role. */
String ROLE = BookDoxia.class.getName();
/**
* Load a BookModel from a descriptor file.
*
* @param bookDescriptor the book descriptor file.
* @return BookModel
* @throws org.apache.maven.doxia.book.BookDoxiaException if the model cannot be loaded.
*/
BookModel loadBook( File bookDescriptor )
throws BookDoxiaException;
/**
* Creates a book from a BookModel using the {@link Locale#getDefault()} and UTF-8 as default encoding.
*
* @param book the BookModel.
* @param bookRendererId the id of the output format.
* @param files a list of source files.
* @param outputDirectory the output directory.
* @throws org.apache.maven.doxia.book.BookDoxiaException if the model cannot be loaded.
* @see #renderBook(BookModel, String, List, File, Locale, String, String)
* @see Locale#getDefault()
*/
void renderBook( BookModel book, String bookRendererId, List files, File outputDirectory )
throws BookDoxiaException;
/**
* Creates a book from a BookModel.
*
* @param book the BookModel.
* @param bookRendererId the id of the output format.
* @param files a list of source files.
* @param outputDirectory the output directory.
* @param locale the wanted locale.
* @param inputEncoding the input encoding when processing <code>files</code>.
* @param outputEncoding the output encoding when writing files in <code>ouputDirectory</code>.
* @throws org.apache.maven.doxia.book.BookDoxiaException if the model cannot be loaded.
* @since 1.1
*/
void renderBook( BookModel book, String bookRendererId, List files, File outputDirectory, Locale locale,
String inputEncoding, String outputEncoding )
throws BookDoxiaException;
}
package org.apache.maven.doxia.book;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/**
* Wraps an exception when rendering books.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id: BookDoxiaException.java 740275 2009-02-03 11:17:28Z vsiveton $
*/
public class BookDoxiaException
extends Exception
{
/** serialVersionUID */
private static final long serialVersionUID = 87146681585045106L;
/**
* Construct a new BookDoxiaException with the specified detail message.
*
* @param message The detailed message. This can later be retrieved by the Throwable.getMessage() method.
*/
public BookDoxiaException( String message )
{
super( message );
}
/**
* Construct a new BookDoxiaException with the specified detail message and cause.
*
* @param message The detailed message. This can later be retrieved by the Throwable.getMessage() method.
* @param cause the cause. This can be retrieved later by the Throwable.getCause() method
* (a null value is permitted, and indicates that the cause is nonexistent or unknown).
*/
public BookDoxiaException( String message, Throwable cause )
{
super( message, cause );
}
}
package org.apache.maven.doxia.book;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import org.apache.maven.doxia.book.context.BookContext;
import org.apache.maven.doxia.book.model.BookModel;
import org.apache.maven.doxia.book.services.indexer.BookIndexer;
import org.apache.maven.doxia.book.services.io.BookIo;
import org.apache.maven.doxia.book.services.renderer.BookRenderer;
import org.apache.maven.doxia.book.services.validation.BookValidator;
import org.apache.maven.doxia.book.services.validation.ValidationResult;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* Default implementation of BookDoxia.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id: DefaultBookDoxia.java 740705 2009-02-04 11:57:33Z vsiveton $
* @plexus.component
*/
public class DefaultBookDoxia
extends AbstractLogEnabled
implements BookDoxia
{
/**
* @plexus.requirement
*/
private BookIo bookIo;
/**
* @plexus.requirement
*/
private BookValidator bookValidator;
/**
* @plexus.requirement
*/
private BookIndexer bookIndexer;
/**
* @plexus.requirement role="org.apache.maven.doxia.book.services.renderer.BookRenderer"
*/
private Map bookRenderers;
// ----------------------------------------------------------------------
// BookDoxia Implementation
// ----------------------------------------------------------------------
/** {@inheritDoc} */
public BookModel loadBook( File bookDescriptor )
throws BookDoxiaException
{
return bookIo.readBook( bookDescriptor );
}
/** {@inheritDoc} */
public void renderBook( BookModel book, String bookRendererId, List files, File outputDirectory )
throws BookDoxiaException
{
renderBook( book, bookRendererId, files, outputDirectory, Locale.getDefault(), "UTF-8", "UTF-8" );
}
/** {@inheritDoc} */
public void renderBook( BookModel book, String bookRendererId, List files, File outputDirectory, Locale locale,
String inputEncoding, String outputEncoding )
throws BookDoxiaException
{
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
ValidationResult validationResult = bookValidator.validateBook( book );
if ( !validationResult.isAllOk() )
{
throw new InvalidBookDescriptorException( validationResult );
}
// ----------------------------------------------------------------------
// Create and initialize the context
// ----------------------------------------------------------------------
BookContext context = new BookContext();
context.setBook( book );
context.setOutputDirectory( outputDirectory );
context.setLocale( locale );
context.setInputEncoding( inputEncoding );
context.setOutputEncoding( outputEncoding );
// -----------------------------------------------------------------------
//
// -----------------------------------------------------------------------
bookIo.loadFiles( context, files );
// ----------------------------------------------------------------------
// Generate indexes
// ----------------------------------------------------------------------
bookIndexer.indexBook( book, context );
// ----------------------------------------------------------------------
// Render the book
// ----------------------------------------------------------------------
BookRenderer bookRenderer = (BookRenderer) bookRenderers.get( bookRendererId );
if ( bookRenderer == null )
{
throw new BookDoxiaException( "No such book renderer '" + bookRendererId + "'." );
}
bookRenderer.renderBook( context );
}
/**
* Returns a Set of ids of the BookRenderers that are available in this BookDoxia.
*
* @return Set
*/
public Set getAvailableBookRenderers()
{
return Collections.unmodifiableSet( bookRenderers.keySet() );
}
}
package org.apache.maven.doxia.book.context;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import org.apache.maven.doxia.book.model.BookModel;
import java.io.File;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
/**
* Context to render a book.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id: BookContext.java 746976 2009-02-23 12:15:38Z vsiveton $
*/
public class BookContext
{
/** The BookModel of this context. */
private BookModel book;
/** The files. */
private Map files;
/** The output directory. */
private File outputDirectory;
/** The BookIndex of this context. */
private BookIndex index;
/** The Locale used to generate the navigation. */
private Locale locale;
/** The input encoding used to read Doxia file. */
private String inputEncoding;
/** The output encoding used to write the renderer files. */
private String outputEncoding;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
/** Represents a BookFile. */
public static class BookFile
{
/** The file. */
private File file;
/** The id of the parser. */
private String parserId;
/**
* Constructor.
*
* @param file the file.
* @param parserId the parser id.
*/
public BookFile( File file, String parserId )
{
this.file = file;
this.parserId = parserId;
}
/**
* Return the file of this BookFile.
*
* @return File.
*/
public File getFile()
{
return file;
}
/**
* Return the parserId of this BookFile.
*
* @return String.
*/
public String getParserId()
{
return parserId;
}
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
/**
* Return the BookModel of this BookContext.
*
* @return BookModel.
*/
public BookModel getBook()
{
return book;
}
/**
* Set the BookModel of this BookContext.
*
* @param book the BookModel.
*/
public void setBook( BookModel book )
{
this.book = book;
}
/**
* Return the files of this BookContext.
*
* @return Map. A new HashMap is constructed if the current Map is null.
*/
public Map getFiles()
{
if ( files == null )
{
files = new HashMap();
}
return files;
}
/**
* Set the files of this BookContext.
*
* @param files the Map of files.
*/
public void setFiles( Map files )
{
this.files = files;
}
/**
* Return the outputDirectory of this BookContext.
*
* @return File.
*/
public File getOutputDirectory()
{
return outputDirectory;
}
/**
* Set the outputDirectory of this BookContext.
*
* @param outputDirectory the output directory.
*/
public void setOutputDirectory( File outputDirectory )
{
this.outputDirectory = outputDirectory;
}
/**
* Return the index of this BookContext.
*
* @return BookIndex.
*/
public BookIndex getIndex()
{
return index;
}
/**
* Set the index of this BookContext.
*
* @param index the index to set.
*/
public void setIndex( BookIndex index )
{
this.index = index;
}
/**
* <p>Getter for the field <code>locale</code>.</p>
*
* @return the locale
* @since 1.1
*/
public Locale getLocale()
{
return locale;
}
/**
* <p>Setter for the field <code>locale</code>.</p>
*
* @param locale the locale to set
* @since 1.1
*/
public void setLocale( Locale locale )
{
this.locale = locale;
}
/**
* <p>Getter for the field <code>inputEncoding</code>.</p>
*
* @return the inputEncoding
* @since 1.1
*/
public String getInputEncoding()
{
return inputEncoding;
}
/**
* <p>Setter for the field <code>inputEncoding</code>.</p>