private String _generateFaceletTagDoc()

in maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocContentMojo.java [1083:1223]


    private String _generateFaceletTagDoc(VelocityEngine velocityEngine, 
            VelocityContext baseContext, Model model, FaceletTagMeta faceletTag)
            throws Exception
    {
        String name = faceletTag.getName(); 
        if (name == null)
        {
            return null;
        }
        
        if (faceletTag.getComponentClass() != null)
        {
            ComponentMeta comp = model.findComponentByClassName(faceletTag.getComponentClass());
            if (name.equals(comp.getName()))
            {
                //Exists in JSP and in facelets, but has specific facelets properties
                return null;
            }
        }
        if (faceletTag.getConverterClass() != null)
        {
            ConverterMeta comp = model.findConverterByClassName(faceletTag.getConverterClass());
            if (name.equals(comp.getName()))
            {
                //Exists in JSP and in facelets, but has specific facelets properties
                return null;
            }            
        }
        if (faceletTag.getValidatorClass() != null)
        {
            ValidatorMeta comp = model.findValidatorByClassName(faceletTag.getValidatorClass());
            if (name.equals(comp.getName()))
            {
                //Exists in JSP and in facelets, but has specific facelets properties
                return null;
            }            
        }
        if (faceletTag.getBehaviorClass() != null)
        {
            BehaviorMeta comp = model.findBehaviorByClassName(faceletTag.getBehaviorClass());
            if (name.equals(comp.getName()))
            {
                //Exists in JSP and in facelets, but has specific facelets properties
                return null;
            }
        }
        if (faceletTag.getTagClass() != null)
        {
            TagMeta comp = model.findTagByClassName(faceletTag.getTagClass());
            if (name.equals(comp.getName()))
            {
                //Exists in JSP and in facelets, but has specific facelets properties
                return null;
            }
        }

        String pageName = _toPageName(faceletTag.getName());
        
        Context context = new VelocityContext(baseContext);
        context.put("faceletTag", faceletTag);
        context.put("jsf20", new Boolean(_is20()));
        
        String baseContent = "";
        
        File xmlBaseFile = new File(baseFilesSourceDirectory, 
                _platformAgnosticPath(pageName + "-base.xml"));
        
        if (xmlBaseFile != null && xmlBaseFile.exists())
        {
            if (getLog().isDebugEnabled())
            {
                getLog().debug("using base content file: "+xmlBaseFile.getPath());
            }
            
            Reader reader = null;
            try
            {
                reader = new FileReader(xmlBaseFile);
                Xpp3Dom root = Xpp3DomBuilder.build(reader);
                
                StringWriter writer = new StringWriter();
                
                Xpp3Dom [] children = root.getChild("body").getChildren();
                
                for (int i = 0; i< children.length; i++)
                {
                    Xpp3Dom dom = children[i];
                    Xpp3DomWriter.write(writer, dom);
                }
                baseContent = writer.toString();
                writer.close();
            }
            catch (XmlPullParserException e)
            {
                throw new MojoExecutionException(
                        "Error parsing base file: " + e.getMessage(), e);
            }
            finally
            {
                reader.close();
            }
        }
        
        baseContext.put("baseContent", baseContent);        
        
        Writer out = null;
        
        try
        {        
            File targetDir = new File(outputDirectory.getParentFile(),
                    _platformAgnosticPath("generated-site/xdoc/"
                            + _DOC_SUBDIRECTORY));
            
            if ( !targetDir.exists() )
            {
                targetDir.mkdirs();
            }
            File targetFile = new File(targetDir, pageName + ".xml");
    
            out = new OutputStreamWriter(new FileOutputStream(targetFile),
                    "UTF-8");
            
            Template template = velocityEngine.getTemplate(getTemplateFaceletTag());
            
            template.merge(context, out);
            
            out.flush();
        }
        catch (Exception e)
        {
            throw new MojoExecutionException(
                    "Error merging velocity templates: " + e.getMessage(), e);
        }
        finally
        {
            IOUtil.close(out);
            out = null;
        }

        return pageName;
    }