Search in sources :

Example 1 with FaceletException

use of jakarta.faces.view.facelets.FaceletException in project mojarra by eclipse-ee4j.

the class SAXCompiler method doCompile.

protected FaceletHandler doCompile(CompilationManager mngr, CompilationHandler handler, URL src, String alias) throws IOException {
    String encoding = getEncoding();
    try (InputStream is = new BufferedInputStream(src.openStream(), 1024)) {
        writeXmlDecl(is, encoding, mngr);
        SAXParser parser = createSAXParser(handler);
        parser.parse(is, handler);
    } catch (SAXException e) {
        throw new FaceletException("Error Parsing " + alias + ": " + e.getMessage(), e.getCause());
    } catch (ParserConfigurationException e) {
        throw new FaceletException("Error Configuring Parser " + alias + ": " + e.getMessage(), e.getCause());
    } catch (FaceletException e) {
        throw e;
    }
    FaceletHandler result = new EncodingHandler(mngr.createFaceletHandler(), encoding, mngr.getCompilationMessageHolder());
    mngr.setCompilationMessageHolder(null);
    return result;
}
Also used : FaceletException(jakarta.faces.view.facelets.FaceletException) FaceletHandler(jakarta.faces.view.facelets.FaceletHandler) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 2 with FaceletException

use of jakarta.faces.view.facelets.FaceletException in project myfaces by apache.

the class LoadBundleHandler method apply.

/**
 * See taglib documentation.
 *
 * See jakarta.faces.view.facelets.FaceletHandler#apply(jakarta.faces.view.facelets.FaceletContext,
 * jakarta.faces.component.UIComponent)
 */
@Override
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException {
    UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
    ResourceBundle bundle = null;
    try {
        ResourceBundle.Control bundleControl = MyfacesConfig.getCurrentInstance().getResourceBundleControl();
        String name = this.basename.getValue(ctx);
        ClassLoader cl = ClassUtils.getContextClassLoader();
        Locale locale = root != null && root.getLocale() != null ? root.getLocale() : Locale.getDefault();
        if (bundleControl == null) {
            bundle = ResourceBundle.getBundle(name, locale, cl);
        } else {
            bundle = ResourceBundle.getBundle(name, locale, cl, bundleControl);
        }
    } catch (Exception e) {
        throw new TagAttributeException(this.tag, this.basename, e);
    }
    ResourceBundleMap map = new ResourceBundleMap(bundle);
    FacesContext faces = ctx.getFacesContext();
    faces.getExternalContext().getRequestMap().put(this.var.getValue(ctx), map);
}
Also used : Locale(java.util.Locale) FacesContext(jakarta.faces.context.FacesContext) TagAttributeException(jakarta.faces.view.facelets.TagAttributeException) ResourceBundle(java.util.ResourceBundle) UIViewRoot(jakarta.faces.component.UIViewRoot) TagAttributeException(jakarta.faces.view.facelets.TagAttributeException) IOException(java.io.IOException) ELException(jakarta.el.ELException) FacesException(jakarta.faces.FacesException) FaceletException(jakarta.faces.view.facelets.FaceletException)

Example 3 with FaceletException

use of jakarta.faces.view.facelets.FaceletException in project myfaces by apache.

the class SAXCompiler method doCompile.

@Override
public CompilerResult doCompile(URL src, String alias) throws IOException, FaceletException, ELException, FacesException {
    CompilationManager mngr = null;
    InputStream is = null;
    String encoding = null;
    try {
        is = new BufferedInputStream(src.openStream(), 1024);
        mngr = new CompilationManager(alias, this, getFaceletsProcessingInstructions(src, alias));
        encoding = writeXmlDecl(is, mngr);
        CompilationHandler handler = new CompilationHandler(mngr, alias);
        SAXParser parser = this.createSAXParser(handler);
        parser.parse(is, handler);
    } catch (SAXException e) {
        throw new FaceletException("Error Parsing " + alias + ": " + e.getMessage(), e.getCause());
    } catch (ParserConfigurationException e) {
        throw new FaceletException("Error Configuring Parser " + alias + ": " + e.getMessage(), e.getCause());
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return new CompilerResult(new EncodingHandler(mngr.createFaceletHandler(), encoding), mngr.getDoctype());
}
Also used : FaceletException(jakarta.faces.view.facelets.FaceletException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 4 with FaceletException

use of jakarta.faces.view.facelets.FaceletException in project myfaces by apache.

the class SAXCompiler method doCompileCompositeComponentMetadata.

/**
 * @since 2.0.1
 */
@Override
protected CompilerResult doCompileCompositeComponentMetadata(URL src, String alias) throws IOException, FaceletException, ELException, FacesException {
    CompilationManager mngr = null;
    InputStream is = null;
    String encoding = null;
    try {
        is = new BufferedInputStream(src.openStream(), 1024);
        mngr = new CompilationManager(alias, this, getFaceletsProcessingInstructions(src, alias));
        encoding = getXmlDecl(is, mngr);
        CompositeComponentMetadataHandler handler = new CompositeComponentMetadataHandler(mngr, alias);
        SAXParser parser = this.createSAXParser(handler);
        parser.parse(is, handler);
    } catch (SAXException e) {
        throw new FaceletException("Error Parsing " + alias + ": " + e.getMessage(), e.getCause());
    } catch (ParserConfigurationException e) {
        throw new FaceletException("Error Configuring Parser " + alias + ": " + e.getMessage(), e.getCause());
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return new CompilerResult(new EncodingHandler(mngr.createFaceletHandler(), encoding), mngr.getDoctype());
}
Also used : FaceletException(jakarta.faces.view.facelets.FaceletException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 5 with FaceletException

use of jakarta.faces.view.facelets.FaceletException in project myfaces by apache.

the class SAXCompiler method doCompileViewMetadata.

/**
 * @since 2.0
 */
@Override
protected CompilerResult doCompileViewMetadata(URL src, String alias) throws IOException, FaceletException, ELException, FacesException {
    CompilationManager mngr = null;
    InputStream is = null;
    String encoding = null;
    try {
        is = new BufferedInputStream(src.openStream(), 1024);
        mngr = new CompilationManager(alias, this, getFaceletsProcessingInstructions(src, alias));
        encoding = getXmlDecl(is, mngr);
        final ViewMetadataHandler handler = new ViewMetadataHandler(mngr, alias);
        final SAXParser parser = this.createSAXParser(handler);
        if (System.getSecurityManager() != null) {
            try {
                final InputStream finalInputStream = is;
                AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
                    parser.parse(finalInputStream, handler);
                    return null;
                });
            } catch (PrivilegedActionException pae) {
                Exception e = pae.getException();
                if (e instanceof SAXException) {
                    throw new FaceletException("Error Parsing " + alias + ": " + e.getMessage(), e.getCause());
                } else if (e instanceof IOException) {
                    throw (IOException) e;
                }
            }
        } else {
            parser.parse(is, handler);
        }
    } catch (SAXException e) {
        throw new FaceletException("Error Parsing " + alias + ": " + e.getMessage(), e.getCause());
    } catch (ParserConfigurationException e) {
        throw new FaceletException("Error Configuring Parser " + alias + ": " + e.getMessage(), e.getCause());
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return new CompilerResult(new EncodingHandler(mngr.createFaceletHandler(), encoding), mngr.getDoctype());
}
Also used : FaceletException(jakarta.faces.view.facelets.FaceletException) PrivilegedActionException(java.security.PrivilegedActionException) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ELException(jakarta.el.ELException) FacesException(jakarta.faces.FacesException) FaceletException(jakarta.faces.view.facelets.FaceletException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) BufferedInputStream(java.io.BufferedInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

FaceletException (jakarta.faces.view.facelets.FaceletException)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStream (java.io.InputStream)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 SAXParser (javax.xml.parsers.SAXParser)4 SAXException (org.xml.sax.SAXException)4 ELException (jakarta.el.ELException)2 FacesException (jakarta.faces.FacesException)2 IOException (java.io.IOException)2 UIViewRoot (jakarta.faces.component.UIViewRoot)1 FacesContext (jakarta.faces.context.FacesContext)1 FaceletHandler (jakarta.faces.view.facelets.FaceletHandler)1 TagAttributeException (jakarta.faces.view.facelets.TagAttributeException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 SAXParseException (org.xml.sax.SAXParseException)1