Package org.codehaus.plexus.util.xml

Examples of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter


     */
    public void testWriteRdfResourceElement()
        throws Exception
    {
        StringWriter w = new StringWriter();
        XMLWriter writer = new PrettyPrintXMLWriter( w );
        DoapUtil.writeRdfResourceElement( writer, null, "name", "value" );
        w.close();
        assertEquals( w.toString(), "<name " + DoapUtil.RDF_RESOURCE + "=\"value\"/>" );

        w = new StringWriter();
        writer = new PrettyPrintXMLWriter( w );
        try
        {
            DoapUtil.writeRdfResourceElement( writer, null, null, null );
            assertTrue( "Null not catched", false );
        }
View Full Code Here


        else
        {
            getLog().info( "Generating a pure DOAP file " + outputFile.getAbsolutePath() );
        }

        XMLWriter writer = new PrettyPrintXMLWriter( w, project.getModel().getModelEncoding(), null );

        // ----------------------------------------------------------------------------
        // Convert POM to DOAP
        // ----------------------------------------------------------------------------

        DoapUtil.writeHeader( writer );

        // Heading
        DoapUtil.writeStartElement( writer, "rdf", "RDF" );
        if ( Arrays.binarySearch( Locale.getISOLanguages(), lang ) < 0 )
        {
            messages.addMessage( new String[] { "doapOptions", "lang" }, lang, UserMessages.INVALID_ISO_DATE );
            throw new MojoExecutionException( messages.getErrorMessages().get( 0 ) );
        }
        writer.addAttribute( "xml:lang", lang );
        if ( StringUtils.isEmpty( doapOptions.getXmlnsNamespaceURI() ) )
        {
            messages.addMessage( new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED );
            throw new MojoExecutionException( messages.getErrorMessages().get( 0 ) );
        }
        writer.addAttribute( "xmlns"
                                 + ( StringUtils.isEmpty( doapOptions.getXmlnsPrefix() ) ? "" : ":"
                                     + doapOptions.getXmlnsPrefix() ), doapOptions.getXmlnsNamespaceURI() );
        writer.addAttribute( "xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" );
        writer.addAttribute( "xmlns:foaf", "http://xmlns.com/foaf/0.1/" );
        if ( asfExtOptions.isIncluded() )
        {
            if ( StringUtils.isEmpty( asfExtOptions.getXmlnsPrefix() ) )
            {
                messages.addMessage( new String[] { "doapOptions", "xmlnsPrefix" }, null, UserMessages.REQUIRED );
                throw new MojoExecutionException( messages.getErrorMessages().get( 0 ) );
            }
            if ( StringUtils.isEmpty( asfExtOptions.getXmlnsNamespaceURI() ) )
            {
                messages.addMessage( new String[] { "doapOptions", "xmlnsNamespaceURI" }, null, UserMessages.REQUIRED );
            }
            writer.addAttribute( "xmlns"
                                     + ( StringUtils.isEmpty( asfExtOptions.getXmlnsPrefix() ) ? "" : ":"
                                         + asfExtOptions.getXmlnsPrefix() ), asfExtOptions.getXmlnsNamespaceURI() );
        }
        if ( extOptions != null && extOptions.length > 0 && !extOptions[0].getExtensions().isEmpty() )
        {
            for ( ExtOptions extOption : extOptions )
            {
                if ( StringUtils.isEmpty( extOption.getXmlnsPrefix() ) )
                {
                    messages.addMessage( new String[] { "extOptions", "extOption", "xmlnsPrefix" }, null,
                                         UserMessages.REQUIRED );
                    throw new MojoExecutionException( messages.getErrorMessages().get( 0 ) );
                }
                if ( StringUtils.isEmpty( extOption.getXmlnsNamespaceURI() ) )
                {
                    messages.addMessage( new String[] { "extOptions", "extOption", "xmlnsNamespaceURI" }, null,
                                         UserMessages.REQUIRED );
                    throw new MojoExecutionException( messages.getErrorMessages().get( 0 ) );
                }
                writer.addAttribute( "xmlns"
                                         + ( StringUtils.isEmpty( extOption.getXmlnsPrefix() ) ? "" : ":"
                                             + extOption.getXmlnsPrefix() ),
                                     extOption.getXmlnsNamespaceURI() );
            }
        }

        // Project
        DoapUtil.writeStartElement( writer, doapOptions.getXmlnsPrefix(), "Project" );
        boolean added = false;
        if ( artifact != null )
        {
            String about_ = project.getUrl();

            if ( StringUtils.isNotEmpty( about_ ) )
            {
                try
                {
                    new URL( about_ );

                    writer.addAttribute( "rdf:about", about_ );
                    added = true;
                }
                catch ( MalformedURLException e )
                {
                }
            }

            if ( !added )
            {
                messages.getWarnMessages().add( "The project's url defined from " + artifact.toConfiguration()
                                                    + " is empty or not a valid URL, using <about/> parameter." );
            }
        }

        if ( !added )
        {
            if ( StringUtils.isNotEmpty( about ) )
            {
                try
                {
                    new URL( about );

                    writer.addAttribute( "rdf:about", about );
                }
                catch ( MalformedURLException e )
                {
                    messages.addMessage( new String[] { "about" }, about, UserMessages.INVALID_URL );
                }
                added = true;
            }
        }

        if ( !added )
        {
            messages.addMessage( new String[] { "about" }, null, UserMessages.RECOMMENDED );
        }

        // name
        writeName( writer, project );

        // description
        writeDescription( writer, project );

        // implements
        writeImplements( writer );

        // Audience
        writeAudience( writer );

        // Vendor
        writeVendor( writer, project );

        // created
        writeCreated( writer, project );

        // homepage and old-homepage
        writeHomepage( writer, project );

        // Blog
        writeBlog( writer );

        // licenses
        writeLicenses( writer, project );

        // programming-language
        writeProgrammingLanguage( writer, project );

        // category
        writeCategory( writer, project );

        // os
        writeOS( writer, project );

        // Plateform
        writePlateform( writer );

        // Language
        writeLanguage( writer );

        // SCM
        writeSourceRepositories( writer, project );

        // bug-database
        writeBugDatabase( writer, project );

        // mailing list
        writeMailingList( writer, project );

        // download-page and download-mirror
        writeDownloadPage( writer, project );

        // screenshots
        writeScreenshots( writer, project );

        // service-endpoint
        writeServiceEndpoint( writer );

        // wiki
        writeWiki( writer, project );

        // Releases
        writeReleases( writer, project );

        // Developers
        @SuppressWarnings( "unchecked" )
        List<Contributor> developers = project.getDevelopers();
        writeContributors( writer, developers );

        // Contributors
        @SuppressWarnings( "unchecked" )
        List<Contributor> contributors = project.getContributors();
        writeContributors( writer, contributors );

        // Extra DOAP
        @SuppressWarnings( "unchecked" )
        Map<String, String> map = doapOptions.getExtra();
        writeExtra( writer, project, "Extra DOAP vocabulary.", map, doapOptions.getXmlnsPrefix() );

        // ASFext
        writeASFext( writer, project );

        // Extra extensions
        writeExtensions( writer );

        writer.endElement(); // Project

        writeOrganizations( writer );

        writer.endElement(); // rdf:RDF

        try
        {
            w.close();
        }
View Full Code Here

        String encoding = "UTF-8";

        OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( outputFile ), encoding );

        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), encoding,
                                                     null );

        // ----------------------------------------------------------------------
        // <!-- comments -->
        // ----------------------------------------------------------------------

        AntBuildWriterUtil.writeHeader( writer );

        // ----------------------------------------------------------------------
        // <project/>
        // ----------------------------------------------------------------------

        writer.startElement( "project" );
        writer.addAttribute( "name", project.getArtifactId() + "-from-maven" );
        writer.addAttribute( "default", "package" );
        writer.addAttribute( "basedir", "." );

        XmlWriterUtil.writeLineBreak( writer );

        // ----------------------------------------------------------------------
        // <property/>
        // ----------------------------------------------------------------------

        writeProperties( writer );

        // ----------------------------------------------------------------------
        // <path/>
        // ----------------------------------------------------------------------

        writeBuildPathDefinition( writer );

        // ----------------------------------------------------------------------
        // <target name="clean" />
        // ----------------------------------------------------------------------

        writeCleanTarget( writer );

        // ----------------------------------------------------------------------
        // <target name="compile" />
        // ----------------------------------------------------------------------

        List compileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots( project.getCompileSourceRoots() );
        writeCompileTarget( writer, compileSourceRoots );

        // ----------------------------------------------------------------------
        // <target name="compile-tests" />
        // ----------------------------------------------------------------------

        List testCompileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots( project
            .getTestCompileSourceRoots() );
        writeCompileTestsTarget( writer, testCompileSourceRoots );

        // ----------------------------------------------------------------------
        // <target name="test" />
        // ----------------------------------------------------------------------

        writeTestTargets( writer, testCompileSourceRoots );

        // ----------------------------------------------------------------------
        // <target name="javadoc" />
        // ----------------------------------------------------------------------
        writeJavadocTarget( writer );

        // ----------------------------------------------------------------------
        // <target name="package" />
        // ----------------------------------------------------------------------
        writePackageTarget( writer );

        // ----------------------------------------------------------------------
        // <target name="get-deps" />
        // ----------------------------------------------------------------------
        writeGetDepsTarget( writer );

        XmlWriterUtil.writeLineBreak( writer );

        writer.endElement(); // project

        XmlWriterUtil.writeLineBreak( writer );

        IOUtil.close( w );
    }
View Full Code Here

        String encoding = "UTF-8";

        OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( outputFile ), encoding );

        XMLWriter writer = new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ), encoding,
                                                     null );

        // ----------------------------------------------------------------------
        // <!-- comments -->
        // ----------------------------------------------------------------------

        AntBuildWriterUtil.writeAntVersionHeader( writer );

        // ----------------------------------------------------------------------
        // <project/>
        // ----------------------------------------------------------------------

        writer.startElement( "project" );
        writer.addAttribute( "name", project.getArtifactId() );
        writer.addAttribute( "default", "package" );
        writer.addAttribute( "basedir", "." );

        XmlWriterUtil.writeLineBreak( writer );

        XmlWriterUtil.writeCommentText( writer, "Import " + DEFAULT_MAVEN_BUILD_FILENAME
            + " into the current project", 1 );

        writer.startElement( "import" );
        writer.addAttribute( "file", DEFAULT_MAVEN_BUILD_FILENAME );
        writer.endElement(); // import

        XmlWriterUtil.writeLineBreak( writer, 1, 1 );

        XmlWriterUtil.writeCommentText( writer, "Help target", 1 );

        writer.startElement( "target" );
        writer.addAttribute( "name", "help" );

        writer.startElement( "echo" );
        writer.addAttribute( "message", "Please run: $ant -projecthelp" );
        writer.endElement(); // echo

        writer.endElement(); // target

        XmlWriterUtil.writeLineBreak( writer, 2 );

        writer.endElement(); // project

        XmlWriterUtil.writeLineBreak( writer );

        IOUtil.close( w );
    }
View Full Code Here

    public void write( PlexusConfiguration configuration, Writer writer )
        throws IOException
    {
        int depth = 0;

        PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
        write( configuration, xmlWriter, depth );
    }
View Full Code Here

            dependenciesBuildFile.getParentFile().mkdirs();
        }
        outputStreamWriter = new OutputStreamWriter( new FileOutputStream( dependenciesBuildFile ), encoding );

        writer =
            new PrettyPrintXMLWriter( outputStreamWriter, StringUtils.repeat( " ", DEFAULT_INDENTATION_SIZE ),
                                      encoding, null );
        writer.startElement( "project" );
        writer.addAttribute( "name", name );
        writer.addAttribute( "default", defaultTarget );
View Full Code Here

        FileWriter writer = null;
        try
        {
            writer = new FileWriter( f );

            XMLWriter w = new PrettyPrintXMLWriter( writer );

            w.startElement( "plugin" );

            element( w, "description", pluginDescriptor.getDescription() );

            element( w, "groupId", pluginDescriptor.getGroupId() );

            element( w, "artifactId", pluginDescriptor.getArtifactId() );

            element( w, "version", pluginDescriptor.getVersion() );

            element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );

            element( w, "isolatedRealm", "" + pluginDescriptor.isIsolatedRealm() );

            element( w, "inheritedByDefault", "" + pluginDescriptor.isInheritedByDefault() );

            w.startElement( "mojos" );

            if ( pluginDescriptor.getMojos() != null )
            {
                for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
                {
                    MojoDescriptor descriptor = (MojoDescriptor) it.next();
                    processMojoDescriptor( descriptor, w );
                }
            }

            w.endElement();

            PluginUtils.writeDependencies( w, pluginDescriptor );

            w.endElement();

            writer.flush();
        }
        finally
        {
View Full Code Here

        }
    }

    private void writeOverview( FileWriter writer, PluginDescriptor pluginDescriptor )
    {
        XMLWriter w = new PrettyPrintXMLWriter( writer );

        w.startElement( "document" );

        // ----------------------------------------------------------------------
        //
        // ----------------------------------------------------------------------

        w.startElement( "properties" );

        w.startElement( "title" );

        // TODO: need a friendly name for a plugin
        w.writeText( pluginDescriptor.getArtifactId() + " - Overview" );

        w.endElement();

        w.endElement();

        // ----------------------------------------------------------------------
        //
        // ----------------------------------------------------------------------

        w.startElement( "body" );

        w.startElement( "section" );

        // TODO: need a friendly name for a plugin
        w.addAttribute( "name", pluginDescriptor.getArtifactId() );

        // TODO: description of plugin, examples?

        w.startElement( "p" );

        w.writeText( "Goals available: " );

        w.endElement();

        writeGoalTable( pluginDescriptor, w );

        w.endElement();

        w.endElement();
    }
View Full Code Here

        w.endElement();
    }

    private void writeBody( FileWriter writer, MojoDescriptor mojoDescriptor )
    {
        XMLWriter w = new PrettyPrintXMLWriter( writer );

        w.startElement( "document" );

        // ----------------------------------------------------------------------
        //
        // ----------------------------------------------------------------------

        w.startElement( "properties" );

        w.startElement( "title" );

        // TODO: need a friendly name for a plugin
        w.writeText( mojoDescriptor.getPluginDescriptor().getArtifactId() + " - " + mojoDescriptor.getFullGoalName() );

        w.endElement(); // title

        w.endElement(); // properties

        // ----------------------------------------------------------------------
        //
        // ----------------------------------------------------------------------

        w.startElement( "body" );

        w.startElement( "section" );

        w.addAttribute( "name", mojoDescriptor.getFullGoalName() );

        w.startElement( "p" );

        if ( mojoDescriptor.getDescription() != null )
        {
            w.writeMarkup( mojoDescriptor.getDescription() );
        }
        else
        {
            w.writeText( "No description." );
        }

        w.endElement(); // p

        w.startElement( "p" );

        w.writeText( "Parameters for the goal: " );

        w.endElement(); // p

        writeGoalParameterTable( mojoDescriptor, w );

        w.endElement(); // section

        w.endElement(); // body

        w.endElement(); // document
    }
View Full Code Here

            DecorationModel decorationModel = context.getDecoration();

            StringWriter w = new StringWriter();
            XMLWriter writer =
                new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
                                          decorationModel.getModelEncoding(), null );

            writeHeader( writer );

            writeEffectiveSite( decorationModel, writer );
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter

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.