Package org.apache.maven.doxia.document

Examples of org.apache.maven.doxia.document.DocumentModel


     * Test the FO PDF generation with some special characters in company name.
     */
    public void testSpecialCharacters()
        throws IOException, TransformerException
    {
        DocumentModel model = new DocumentModel();
        DocumentCover cover = new DocumentCover();

        cover.setCompanyName( "Partner & Friends" );
        cover.setCoverTitle( "A Masterpice in Encoding Theory <>&" );
        cover.setCoverSubTitle( "Some nice Encodings & <METHODS>" );
        cover.setProjectName( "A Masterpice in Encoding Theory <>&" );
        cover.setAuthor( "Partner & Friends" );
        model.setCover( cover );

        File foFile = File.createTempFile( "fo-test", ".fo" );
        File pdfFile = File.createTempFile( "fo-test", ".pdf" );
        try
        {
View Full Code Here


        fo2pdf( "aggregate" );
    }

    private DocumentModel getModel()
    {
        DocumentModel model = new DocumentModel();
        model.setToc( getToc() );
        model.setMeta( getMeta() );
        return model;
    }
View Full Code Here

            context.put( "StringUtils", new StringUtils() );
            context.put( "i18n", i18n );
            context.put( "generateTOC", generateTOC );
            context.put( "validate", Boolean.valueOf( validate ) );

            final DocumentModel model = aggregate ? getDocumentModel( locale ) : null;

            try
            {
                // TODO use interface see DOXIASITETOOLS-30
                ( (AbstractDocumentRenderer) docRenderer ).render( siteDirectoryFile, workingDir, model, context );
View Full Code Here

    private DocumentModel getDocumentModel( Locale locale )
        throws MojoExecutionException
    {
        if ( docDescriptor.exists() )
        {
            DocumentModel doc = getDocumentModelFromDescriptor( locale );
            // TODO: descriptor model should get merged into default model, see MODELLO-63

            appendGeneratedReports( doc, locale );

            return doc;
        }

        DocumentModel model = new DocumentModelBuilder( project, getDefaultDecorationModel() ).getDocumentModel();

        model.getMeta().setGenerator( getDefaultGenerator() );
        model.getMeta().setLanguage( locale.getLanguage() );
        model.getCover().setCoverType( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.type" ) );
        model.getToc().setName( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.title" ) );

        appendGeneratedReports( model, locale );

        debugLogGeneratedModel( model );
View Full Code Here

     * @throws org.apache.maven.plugin.MojoExecutionException if the model could not be read.
     */
    private DocumentModel getDocumentModelFromDescriptor( Locale locale )
        throws MojoExecutionException
    {
        DocumentModel model = null;

        try
        {
            model =
                new DocumentDescriptorReader( project, getLog() ).readAndFilterDocumentDescriptor( docDescriptor );
        }
        catch ( XmlPullParserException ex )
        {
            throw new MojoExecutionException( "Error reading DocumentDescriptor!", ex );
        }
        catch ( IOException io )
        {
            throw new MojoExecutionException( "Error opening DocumentDescriptor!", io );
        }

        if ( model.getMeta() == null )
        {
            model.setMeta( new DocumentMeta() );
        }

        if ( StringUtils.isEmpty( model.getMeta().getLanguage() ) )
        {
            model.getMeta().setLanguage( locale.getLanguage() );
        }

        if ( StringUtils.isEmpty( model.getMeta().getGenerator() ) )
        {
            model.getMeta().setGenerator( getDefaultGenerator() );
        }

        return model;
    }
View Full Code Here

    private static DocumentModel getDocumentModel( MavenProject project,
            DecorationModel decorationModel, Date date )
    {
        final Date now = ( date == null ? new Date() : date );

        final DocumentModel docModel = new DocumentModel();

        docModel.setModelEncoding( getProjectModelEncoding( project ) );
        docModel.setOutputName( project == null || project.getArtifactId() == null
                ? "unnamed" : project.getArtifactId() );
        docModel.setMeta( getDocumentMeta( project, now ) );
        docModel.setCover( getDocumentCover( project, now ) );
        docModel.setToc( getDocumentTOC( decorationModel ) );

        return docModel;
    }
View Full Code Here

        outputDirectory.mkdirs();

        docRenderer = (PdfRenderer) lookup( PdfRenderer.ROLE, implementation );
        assertNotNull( docRenderer );

        DocumentModel descriptor = docRenderer.readDocumentModel( new File( siteDirectoryFile, "pdf.xml" ) );
        assertNotNull( descriptor );

        docRenderer.render( siteDirectoryFile, outputDirectory, descriptor );

        File pdf = new File( outputDirectory, descriptor.getOutputName() + ".pdf" );

        assertTrue( pdf.exists() );
        assertTrue( pdf.length() > 0 );
    }
View Full Code Here

    /** {@inheritDoc} */
    public DocumentModel readDocumentModel( File documentDescriptor )
        throws DocumentRendererException, IOException
    {
        DocumentModel documentModel;

        Reader reader = null;
        try
        {
            reader = ReaderFactory.newXmlReader( documentDescriptor );
View Full Code Here

            }
            render( siteDirectory, outputDirectory );
            return;
        }

        DocumentModel documentModel;
        Reader reader = null;
        try
        {
            reader = ReaderFactory.newXmlReader( documentDescriptor );
            documentModel = new DocumentXpp3Reader().read( reader );
        }
        catch ( XmlPullParserException e )
        {
            throw new DocumentRendererException( "Error parsing document descriptor", e );
        }
        catch ( IOException e )
        {
            throw new DocumentRendererException( "Error reading document descriptor", e );
        }
        finally
        {
            IOUtil.close( reader );
        }

        if ( documentModel.getOutputName() == null )
        {
            if ( getLogger().isInfoEnabled() )
            {
                getLogger().info( "No outputName is defined in the document descriptor. Using 'generated_itext'" );
            }
            documentModel.setOutputName( "generated_itext" );
        }

        if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) )
        {
            if ( getLogger().isInfoEnabled() )
            {
                getLogger().info( "No TOC is defined in the document descriptor. Merging all documents." );
            }
        }

        List<File> iTextFiles = new LinkedList<File>();
        Collection<SiteModule> modules = siteModuleManager.getSiteModules();
        for ( SiteModule module : modules )
        {
            File moduleBasedir = new File( siteDirectory, module.getSourceDirectory() );

            if ( moduleBasedir.exists() )
            {
                @SuppressWarnings ( "unchecked" )
                List<String> docs =
                    FileUtils.getFileNames( moduleBasedir, "**/*." + module.getExtension(), null, false );

                for ( String doc : docs )
                {
                    String fullPathDoc = new File( moduleBasedir, doc ).getPath();

                    String outputITextName = doc.substring( 0, doc.lastIndexOf( '.') + 1 ) + "xml";
                    File outputITextFile = new File( outputDirectory, outputITextName );

                    if ( ( documentModel.getToc() == null ) || ( documentModel.getToc().getItems() == null ) )
                    {
                        iTextFiles.add( outputITextFile );

                        if ( !outputITextFile.getParentFile().exists() )
                        {
                            outputITextFile.getParentFile().mkdirs();
                        }

                        parse( fullPathDoc, module, outputITextFile );
                    }
                    else
                    {
                        for ( Iterator<DocumentTOCItem> k = documentModel.getToc().getItems().iterator(); k.hasNext(); )
                        {
                            DocumentTOCItem tocItem = k.next();

                            if ( tocItem.getRef() == null )
                            {
                                if ( getLogger().isInfoEnabled() )
                                {
                                    getLogger().info( "No ref defined for an tocItem in the document descriptor." );
                                }
                                continue;
                            }

                            String outTmp = StringUtils.replace( outputITextFile.getAbsolutePath(), "\\", "/" );
                            outTmp = outTmp.substring( 0, outTmp.lastIndexOf( '.') );

                            String outRef = StringUtils.replace( tocItem.getRef(), "\\", "/" );
                            if ( outRef.lastIndexOf( '.') != -1 )
                            {
                                outRef = outRef.substring( 0, outRef.lastIndexOf( '.') );
                            }
                            else
                            {
                                outRef = outRef.substring( 0, outRef.length() );
                            }

                            if ( outTmp.indexOf( outRef ) != -1 )
                            {
                                iTextFiles.add( outputITextFile );

                                if ( !outputITextFile.getParentFile().exists() )
                                {
                                    outputITextFile.getParentFile().mkdirs();
                                }

                                parse( fullPathDoc, module, outputITextFile );
                            }
                        }
                    }
                }
            }
        }

        File iTextFile = new File( outputDirectory, documentModel.getOutputName() + ".xml" );
        File iTextOutput = new File( outputDirectory, documentModel.getOutputName() + "." + getOutputExtension() );
        Document document = generateDocument( iTextFiles );
        transform( documentModel, document, iTextFile );
        generateOutput( iTextFile, iTextOutput );
    }
View Full Code Here

    private DocumentModel getDocumentModel( Locale locale )
        throws MojoExecutionException
    {
        if ( docDescriptor.exists() )
        {
            DocumentModel doc = getDocumentModelFromDescriptor( locale );
            // TODO: descriptor model should get merged into default model, see MODELLO-63

            appendGeneratedReports( doc, locale );

            return doc;
        }

        DocumentModel model = new DocumentModelBuilder( project, getDefaultDecorationModel() ).getDocumentModel();

        model.getMeta().setGenerator( getDefaultGenerator() );
        model.getMeta().setLanguage( locale.getLanguage() );
        model.getCover().setCoverType( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.type" ) );
        model.getToc().setName( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.title" ) );

        appendGeneratedReports( model, locale );

        debugLogGeneratedModel( model );
View Full Code Here

TOP

Related Classes of org.apache.maven.doxia.document.DocumentModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.