Search in sources :

Example 1 with DecorationXpp3Reader

use of org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader in project maven-plugins by apache.

the class DocumentModelBuilderTest method getDecorationModelFromFile.

private DecorationModel getDecorationModelFromFile(File descriptorFile) throws IOException, XmlPullParserException {
    Reader reader = null;
    try {
        reader = ReaderFactory.newXmlReader(descriptorFile);
        final DecorationModel decorationModel = new DecorationXpp3Reader().read(reader);
        reader.close();
        reader = null;
        return decorationModel;
    } finally {
        IOUtil.close(reader);
    }
}
Also used : DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) Reader(java.io.Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)

Example 2 with DecorationXpp3Reader

use of org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader in project maven-plugins by apache.

the class PdfMojo method getDefaultDecorationModel.

/**
     * @return the DecorationModel instance from <code>site.xml</code>
     * @throws MojoExecutionException if any
     */
private DecorationModel getDefaultDecorationModel() throws MojoExecutionException {
    if (this.defaultDecorationModel == null) {
        final Locale locale = getDefaultLocale();
        final File descriptorFile = siteTool.getSiteDescriptor(siteDirectory, locale);
        DecorationModel decoration = null;
        if (descriptorFile.exists()) {
            XmlStreamReader reader = null;
            try {
                reader = new XmlStreamReader(descriptorFile);
                String siteDescriptorContent = IOUtil.toString(reader);
                reader.close();
                reader = null;
                siteDescriptorContent = siteTool.getInterpolatedSiteDescriptorContent(new HashMap<String, String>(2), project, siteDescriptorContent);
                decoration = new DecorationXpp3Reader().read(new StringReader(siteDescriptorContent));
            } catch (XmlPullParserException e) {
                throw new MojoExecutionException("Error parsing site descriptor", e);
            } catch (IOException e) {
                throw new MojoExecutionException("Error reading site descriptor", e);
            } catch (SiteToolException e) {
                throw new MojoExecutionException("Error when interpoling site descriptor", e);
            } finally {
                IOUtil.close(reader);
            }
        }
        this.defaultDecorationModel = decoration;
    }
    return this.defaultDecorationModel;
}
Also used : Locale(java.util.Locale) DecorationModel(org.apache.maven.doxia.site.decoration.DecorationModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) StringReader(java.io.StringReader) XmlStreamReader(org.apache.commons.io.input.XmlStreamReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) DecorationXpp3Reader(org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader) File(java.io.File) SiteToolException(org.apache.maven.doxia.tools.SiteToolException)

Aggregations

DecorationModel (org.apache.maven.doxia.site.decoration.DecorationModel)2 DecorationXpp3Reader (org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader)2 File (java.io.File)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 XmlStreamReader (org.apache.commons.io.input.XmlStreamReader)1 SiteToolException (org.apache.maven.doxia.tools.SiteToolException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1