Package org.codehaus.plexus.util.xml

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


        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

       
        PluginDescriptor descriptor = new PluginDescriptor();
        descriptor.setDependencies( Collections.singletonList( dependency ) );

        StringWriter sWriter = new StringWriter();
        XMLWriter writer = new CompactXMLWriter( sWriter );

        PluginUtils.writeDependencies( writer, descriptor );

        String output = sWriter.toString();
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

        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

    public void write( File destinationFile, JbossConfiguration jbossConfiguration, List<EarModule> earModules )
        throws EarPluginException
    {
        final Writer w = initializeWriter( destinationFile );

        XMLWriter writer;
        if ( jbossConfiguration.isJbossThreeDotTwo() )
        {
            writer = initializeXmlWriter( w, DOCTYPE_3_2 );
        }
        else if ( jbossConfiguration.isJbossFour() )
        {
            writer = initializeXmlWriter( w, DOCTYPE_4 );
        }
        else if ( jbossConfiguration.isJbossFourDotTwo() )
        {
            writer = initializeXmlWriter( w, DOCTYPE_4_2 );
        }
        else
        {
            writer = initializeXmlWriter( w, DOCTYPE_5 );
        }
        writer.startElement( JBOSS_APP_ELEMENT );

        // Make sure to write the things in the right order so that the DTD validates

        // module-order (only available as from 4.2)
        if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null )
        {
            writer.startElement( JbossConfiguration.MODULE_ORDER );
            writer.writeText( jbossConfiguration.getModuleOrder() );
            writer.endElement();
        }

        // If JBoss 4, write the jboss4 specific stuff
        if ( jbossConfiguration.isJbossFourOrHigher() )
        {
            if ( jbossConfiguration.getSecurityDomain() != null )
            {
                writer.startElement( JbossConfiguration.SECURITY_DOMAIN );
                writer.writeText( jbossConfiguration.getSecurityDomain() );
                writer.endElement();
            }
            if ( jbossConfiguration.getUnauthenticatedPrincipal() != null )
            {
                writer.startElement( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL );
                writer.writeText( jbossConfiguration.getUnauthenticatedPrincipal() );
                writer.endElement();
            }
        }

        // classloader repository
        if ( jbossConfiguration.getLoaderRepository() != null || jbossConfiguration.getLoaderRepositoryConfig() != null )
        {
            writer.startElement( JbossConfiguration.LOADER_REPOSITORY );

            // classloader repository class
            if ( jbossConfiguration.getLoaderRepositoryClass() != null )
            {
                writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE,
                                     jbossConfiguration.getLoaderRepositoryClass() );
            }

            // we don't need to write any text if only the loader repo configuration is changed
            if ( jbossConfiguration.getLoaderRepository() != null )
            {
                writer.writeText( jbossConfiguration.getLoaderRepository() );
            }

            // classloader configuration
            if ( jbossConfiguration.getLoaderRepositoryConfig() != null )
            {
                writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG );

                // classloader configuration parser
                if ( jbossConfiguration.getConfigParserClass() != null )
                {
                    writer.addAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE,
                                         jbossConfiguration.getConfigParserClass() );
                }
                writer.writeText( jbossConfiguration.getLoaderRepositoryConfig() );
                writer.endElement();
            }

            writer.endElement();
        }

        // jmx name
        if ( jbossConfiguration.getJmxName() != null )
        {
            writer.startElement( JbossConfiguration.JMX_NAME );
            writer.writeText( jbossConfiguration.getJmxName() );
            writer.endElement();
        }

        // library-directory (only available as from 4.2)
        if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null )
        {
            writer.startElement( JbossConfiguration.LIBRARY_DIRECTORY );
            writer.writeText( jbossConfiguration.getLibraryDirectory() );
            writer.endElement();
        }

        // Modules

        List<String> dataSources = jbossConfiguration.getDataSources();
        // Write out data source modules first
        if ( dataSources != null )
        {
            for ( String dsPath : dataSources )
            {
                writer.startElement( MODULE_ELEMENT );
                writer.startElement( SERVICE_ELEMENT );
                writer.writeText( dsPath );
                writer.endElement();
                writer.endElement();
            }
        }

        // Write the JBoss specific modules
        for ( EarModule earModule : earModules )
        {
            if ( JbossEarModule.class.isInstance( earModule ) )
            {
                JbossEarModule jbossEarModule = (JbossEarModule) earModule;
                jbossEarModule.appendJbossModule( writer, jbossConfiguration.getVersion() );
            }
        }
        writer.endElement();

        close( w );
    }
View Full Code Here

    public void write( ApplicationXmlWriterContext context )
        throws EarPluginException
    {
        Writer w = initializeWriter( context.getDestinationFile() );

        XMLWriter writer = null;
        if ( JavaEEVersion.OneDotThree.eq( version ) )
        {
            writer = initializeRootElementOneDotThree( w );
        }
        else if ( JavaEEVersion.OneDotFour.eq( version ) )
        {
            writer = initializeRootElementOneDotFour( w );
        }
        else if ( JavaEEVersion.Five.eq( version ) )
        {
            writer = initializeRootElementFive( w );
        }
        else if ( JavaEEVersion.Six.eq( version ) )
        {
            writer = initializeRootElementSix( w );
        }
        else if ( JavaEEVersion.Seven.eq( version ) )
        {
            writer = initializeRootElementSeven( w );
        }

        // writer is still on root element, so we can still add this attribute
        if ( context.getApplicationId() != null )
        {
            writer.addAttribute( "id", context.getApplicationId() );
        }

        // As from JavaEE6
        if ( version.ge( JavaEEVersion.Six ) )
        {
            writeApplicationName( context.getApplicationName(), writer );
        }

        // IMPORTANT: the order of the description and display-name elements was
        // reversed between J2EE 1.3 and J2EE 1.4.
        if ( version.eq( JavaEEVersion.OneDotThree ) )
        {
            writeDisplayName( context.getDisplayName(), writer );
            writeDescription( context.getDescription(), writer );
        }
        else
        {
            writeDescription( context.getDescription(), writer );
            writeDisplayName( context.getDisplayName(), writer );
        }

        // As from JavaEE6
        if ( version.ge( JavaEEVersion.Six ) )
        {
            writeInitializeInOrder( context.getInitializeInOrder(), writer );
        }

        // Do not change this unless you really know what you're doing :)
        for ( EarModule module : context.getEarModules() )
        {
            module.appendModule( writer, version.getVersion(), generateModuleId );
        }

        for ( SecurityRole securityRole : context.getSecurityRoles() )
        {
            securityRole.appendSecurityRole( writer );
        }

        if ( version.ge( JavaEEVersion.Five ) )
        {
            writeLibraryDirectory( context.getLibraryDirectory(), writer );
        }

        if ( version.ge( JavaEEVersion.Six ) )
        {
            for ( EnvEntry envEntry : context.getEnvEntries() )
            {
                envEntry.appendEnvEntry( writer );
            }
        }

        writer.endElement();

        close( w );
    }
View Full Code Here

        }
    }

    private XMLWriter initializeRootElementOneDotThree( Writer w )
    {
        XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 );
        writer.startElement( APPLICATION_ELEMENT );
        return writer;
    }
View Full Code Here

TOP

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

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.