org.apache.jasper.compiler.Localizer Java Examples

The following examples show how to use org.apache.jasper.compiler.Localizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JspC.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void initWebXml() {
    try {
        if (webxmlLevel >= INC_WEBXML) {
            mapout = openWebxmlWriter(new File(webxmlFile));
            servletout = new CharArrayWriter();
            mappingout = new CharArrayWriter();
        } else {
            mapout = null;
            servletout = null;
            mappingout = null;
        }
        if (webxmlLevel >= ALL_WEBXML) {
            mapout.write(Localizer.getMessage("jspc.webxml.header"));
            mapout.flush();
        } else if ((webxmlLevel>= INC_WEBXML) && !addWebXmlMappings) {
            mapout.write(Localizer.getMessage("jspc.webinc.header"));
            mapout.flush();
        }
    } catch (IOException ioe) {
        mapout = null;
        servletout = null;
        mappingout = null;
    }
}
 
Example #2
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public int getAttributesScope(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (AccessController
                .doPrivileged(new PrivilegedAction<Integer>() {
                    @Override
                    public Integer run() {
                        return Integer.valueOf(doGetAttributeScope(name));
                    }
                })).intValue();
    } else {
        return doGetAttributeScope(name);
    }
}
 
Example #3
Source File: JspC.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void completeWebXml() {
    if (mapout != null) {
        try {
            servletout.writeTo(mapout);
            mappingout.writeTo(mapout);
            if (webxmlLevel >= ALL_WEBXML) {
                mapout.write(Localizer.getMessage("jspc.webxml.footer"));
            } else if (webxmlLevel >= FRG_WEBXML) {
                    mapout.write(Localizer.getMessage("jspc.webfrg.footer"));
            } else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) {
                mapout.write(Localizer.getMessage("jspc.webinc.footer"));
            }
            mapout.close();
        } catch (IOException ioe) {
            // nothing to do if it fails since we are done with it
        }
    }
}
 
Example #4
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public int getAttributesScope(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return (AccessController
                .doPrivileged(new PrivilegedAction<Integer>() {
                    @Override
                    public Integer run() {
                        return Integer.valueOf(doGetAttributeScope(name));
                    }
                })).intValue();
    } else {
        return doGetAttributeScope(name);
    }
}
 
Example #5
Source File: JspCompilationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public Class<?> load() throws JasperException {
    try {
        getJspLoader();

        String name = getFQCN();
        servletClass = jspLoader.loadClass(name);
    } catch (ClassNotFoundException cex) {
        throw new JasperException(Localizer.getMessage("jsp.error.unable.load"),
                cex);
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.unable.compile"),
                ex);
    }
    removed = false;
    return servletClass;
}
 
Example #6
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAttribute(final String name, final int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }
    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name, scope);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name, scope);
    }
}
 
Example #7
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private Enumeration<String> doGetAttributeNamesInScope(int scope) {
    switch (scope) {
    case PAGE_SCOPE:
        return Collections.enumeration(attributes.keySet());

    case REQUEST_SCOPE:
        return request.getAttributeNames();

    case SESSION_SCOPE:
        if (session == null) {
            throw new IllegalStateException(Localizer
                    .getMessage("jsp.error.page.noSession"));
        }
        return session.getAttributeNames();

    case APPLICATION_SCOPE:
        return context.getAttributeNames();

    default:
        throw new IllegalArgumentException("Invalid scope");
    }
}
 
Example #8
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void removeAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name);
    }
}
 
Example #9
Source File: JspRuntimeLibrary.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static Object getValueFromBeanInfoPropertyEditor(
                       Class<?> attrClass, String attrName, String attrValue,
                       Class<?> propertyEditorClass) 
    throws JasperException 
{
    try {
        PropertyEditor pe =
            (PropertyEditor)propertyEditorClass.newInstance();
        pe.setAsText(attrValue);
        return pe.getValue();
    } catch (Exception ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
Example #10
Source File: JspRuntimeLibrary.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public static Object handleGetProperty(Object o, String prop)
throws JasperException {
    if (o == null) {
        throw new JasperException(
                Localizer.getMessage("jsp.error.beans.nullbean"));
    }
    Object value = null;
    try {
        Method method = getReadMethod(o.getClass(), prop);
        value = method.invoke(o, (Object[]) null);
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException (ex);
    }
    return value;
}
 
Example #11
Source File: JspServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void handleMissingResource(HttpServletRequest request,
        HttpServletResponse response, String jspUri)
        throws ServletException, IOException {

    String includeRequestUri =
        (String)request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);

    if (includeRequestUri != null) {
        // This file was included. Throw an exception as
        // a response.sendError() will be ignored
        String msg =
            Localizer.getMessage("jsp.error.file.not.found",jspUri);
        // Strictly, filtering this is an application
        // responsibility but just in case...
        throw new ServletException(Escape.htmlElementContent(msg));
    } else {
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND,
                    request.getRequestURI());
        } catch (IllegalStateException ise) {
            log.error(Localizer.getMessage("jsp.error.file.not.found",
                    jspUri));
        }
    }
    return;
}
 
Example #12
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doRemoveAttribute(name);
                return null;
            }
        });
    } else {
        doRemoveAttribute(name);
    }
}
 
Example #13
Source File: JspCompilationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void createOutputDir() {
    String path = null;
    if (isTagFile()) {
        String tagName = tagInfo.getTagClassName();
        path = tagName.replace('.', File.separatorChar);
        path = path.substring(0, path.lastIndexOf(File.separatorChar));
    } else {
        path = getServletPackageName().replace('.',File.separatorChar);
    }

    // Append servlet or tag handler path to scratch dir
    try {
        File base = options.getScratchDir();
        baseUrl = base.toURI().toURL();
        outputDir = base.getAbsolutePath() + File.separator + path +
                File.separator;
        if (!makeOutputDir()) {
            throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"));
        }
    } catch (MalformedURLException e) {
        throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"), e);
    }
}
 
Example #14
Source File: JspContextWrapper.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setAttribute(String name, Object value, int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (scope == PAGE_SCOPE) {
        if (value != null) {
            pageAttributes.put(name, value);
        } else {
            removeAttribute(name, PAGE_SCOPE);
        }
    } else {
        rootJspCtxt.setAttribute(name, value, scope);
    }
}
 
Example #15
Source File: JspContextWrapper.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Object findAttribute(String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    Object o = pageAttributes.get(name);
    if (o == null) {
        o = rootJspCtxt.getAttribute(name, REQUEST_SCOPE);
        if (o == null) {
            if (getSession() != null) {
                o = rootJspCtxt.getAttribute(name, SESSION_SCOPE);
            }
            if (o == null) {
                o = rootJspCtxt.getAttribute(name, APPLICATION_SCOPE);
            }
        }
    }

    return o;
}
 
Example #16
Source File: JspC.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void completeWebXml() {
    if (mapout != null) {
        try {
            servletout.writeTo(mapout);
            mappingout.writeTo(mapout);
            if (webxmlLevel >= ALL_WEBXML) {
                mapout.write(Localizer.getMessage("jspc.webxml.footer"));
            } else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) {
                mapout.write(Localizer.getMessage("jspc.webinc.footer"));
            }
            mapout.close();
        } catch (IOException ioe) {
            // noting to do if it fails since we are done with it
        }
    }
}
 
Example #17
Source File: JspCompilationContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
protected void createOutputDir() {
    String path = null;
    if (isTagFile()) {
        String tagName = tagInfo.getTagClassName();
        path = tagName.replace('.', File.separatorChar);
        path = path.substring(0, path.lastIndexOf(File.separatorChar));
    } else {
        path = getServletPackageName().replace('.',File.separatorChar);
    }

        // Append servlet or tag handler path to scratch dir
        try {
            File base = options.getScratchDir();
            baseUrl = base.toURI().toURL();
            outputDir = base.getAbsolutePath() + File.separator + path +
                File.separator;
            if (!makeOutputDir()) {
                throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"));
            }
        } catch (MalformedURLException e) {
            throw new IllegalStateException(Localizer.getMessage("jsp.error.outputfolder"), e);
        }
}
 
Example #18
Source File: JspCompilationContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public Class<?> load() throws JasperException {
    try {
        getJspLoader();

        String name = getFQCN();
        servletClass = jspLoader.loadClass(name);
    } catch (ClassNotFoundException cex) {
        throw new JasperException(Localizer.getMessage("jsp.error.unable.load"),
                                  cex);
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage("jsp.error.unable.compile"),
                                  ex);
    }
    removed = 0;
    return servletClass;
}
 
Example #19
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void doRemoveAttribute(String name, int scope) {
    switch (scope) {
    case PAGE_SCOPE:
        attributes.remove(name);
        break;

    case REQUEST_SCOPE:
        request.removeAttribute(name);
        break;

    case SESSION_SCOPE:
        if (session == null) {
            throw new IllegalStateException(Localizer
                    .getMessage("jsp.error.page.noSession"));
        }
        session.removeAttribute(name);
        break;

    case APPLICATION_SCOPE:
        context.removeAttribute(name);
        break;

    default:
        throw new IllegalArgumentException("Invalid scope");
    }
}
 
Example #20
Source File: JspRuntimeLibrary.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static Object handleGetProperty(Object o, String prop)
throws JasperException {
    if (o == null) {
        throw new JasperException(
                Localizer.getMessage("jsp.error.beans.nullbean"));
    }
    Object value = null;
    try {
        Method method = getReadMethod(o.getClass(), prop);
        value = method.invoke(o, (Object[]) null);
    } catch (Exception ex) {
        Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
        ExceptionUtils.handleThrowable(thr);
        throw new JasperException (ex);
    }
    return value;
}
 
Example #21
Source File: PageContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void setAttribute(final String name, final Object attribute) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doSetAttribute(name, attribute);
                return null;
            }
        });
    } else {
        doSetAttribute(name, attribute);
    }
}
 
Example #22
Source File: ASCIIReader.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Read characters into a portion of an array.  This method will block
 * until some input is available, an I/O error occurs, or the end of the
 * stream is reached.
 *
 * @param      ch     Destination buffer
 * @param      offset Offset at which to start storing characters
 * @param      length Maximum number of characters to read
 *
 * @return     The number of characters read, or -1 if the end of the
 *             stream has been reached
 *
 * @exception  IOException  If an I/O error occurs
 */
@Override
public int read(char ch[], int offset, int length) throws IOException {
    if (length > fBuffer.length) {
        length = fBuffer.length;
    }
    int count = fInputStream.read(fBuffer, 0, length);
    for (int i = 0; i < count; i++) {
        int b0 = (0xff & fBuffer[i]); // Convert to unsigned
        if (b0 > 0x80) {
            throw new IOException(Localizer.getMessage("jsp.error.xml.invalidASCII",
                                                       Integer.toString(b0)));
        }
        ch[offset + i] = (char)b0;
    }
    return count;
}
 
Example #23
Source File: JspRuntimeLibrary.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static Object getValueFromPropertyEditorManager(
                 Class<?> attrClass, String attrName, String attrValue)
    throws JasperException
{
    try {
        PropertyEditor propEditor =
            PropertyEditorManager.findEditor(attrClass);
        if (propEditor != null) {
            propEditor.setAsText(attrValue);
            return propEditor.getValue();
        } else {
            throw new IllegalArgumentException(
                Localizer.getMessage("jsp.error.beans.propertyeditor.notregistered"));
        }
    } catch (IllegalArgumentException ex) {
        throw new JasperException(
            Localizer.getMessage("jsp.error.beans.property.conversion",
                                 attrValue, attrClass.getName(), attrName,
                                 ex.getMessage()));
    }
}
 
Example #24
Source File: JspServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void handleMissingResource(HttpServletRequest request,
        HttpServletResponse response, String jspUri)
        throws ServletException, IOException {

    String includeRequestUri =
        (String)request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);

    if (includeRequestUri != null) {
        // This file was included. Throw an exception as
        // a response.sendError() will be ignored
        String msg =
            Localizer.getMessage("jsp.error.file.not.found",jspUri);
        // Strictly, filtering this is an application
        // responsibility but just in case...
        throw new ServletException(SecurityUtil.filter(msg));
    } else {
        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND,
                    request.getRequestURI());
        } catch (IllegalStateException ise) {
            log.error(Localizer.getMessage("jsp.error.file.not.found",
                    jspUri));
        }
    }
    return;
}
 
Example #25
Source File: ASCIIReader.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Read characters into a portion of an array.  This method will block
 * until some input is available, an I/O error occurs, or the end of the
 * stream is reached.
 *
 * @param      ch     Destination buffer
 * @param      offset Offset at which to start storing characters
 * @param      length Maximum number of characters to read
 *
 * @return     The number of characters read, or -1 if the end of the
 *             stream has been reached
 *
 * @exception  IOException  If an I/O error occurs
 */
@Override
public int read(char ch[], int offset, int length) throws IOException {
    if (length > fBuffer.length) {
        length = fBuffer.length;
    }
    int count = fInputStream.read(fBuffer, 0, length);
    for (int i = 0; i < count; i++) {
        int b0 = (0xff & fBuffer[i]); // Convert to unsigned
        if (b0 > 0x80) {
            throw new IOException(Localizer.getMessage("jsp.error.xml.invalidASCII",
                                                       Integer.toString(b0)));
        }
        ch[offset + i] = (char)b0;
    }
    return count;
}
 
Example #26
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Object getAttribute(final String name) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return AccessController.doPrivileged(
                new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                return doGetAttribute(name);
            }
        });
    } else {
        return doGetAttribute(name);
    }

}
 
Example #27
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public Object getAttribute(final String name, final int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        return AccessController.doPrivileged(
                new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                return doGetAttribute(name, scope);
            }
        });
    } else {
        return doGetAttribute(name, scope);
    }

}
 
Example #28
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private Object doGetAttribute(String name, int scope) {
    switch (scope) {
    case PAGE_SCOPE:
        return attributes.get(name);

    case REQUEST_SCOPE:
        return request.getAttribute(name);

    case SESSION_SCOPE:
        if (session == null) {
            throw new IllegalStateException(Localizer
                    .getMessage("jsp.error.page.noSession"));
        }
        return session.getAttribute(name);

    case APPLICATION_SCOPE:
        return context.getAttribute(name);

    default:
        throw new IllegalArgumentException("Invalid scope");
    }
}
 
Example #29
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setAttribute(final String name, final Object attribute) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doSetAttribute(name, attribute);
                return null;
            }
        });
    } else {
        doSetAttribute(name, attribute);
    }
}
 
Example #30
Source File: PageContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void setAttribute(final String name, final Object o, final int scope) {

    if (name == null) {
        throw new NullPointerException(Localizer
                .getMessage("jsp.error.attribute.null_name"));
    }

    if (SecurityUtil.isPackageProtectionEnabled()) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                doSetAttribute(name, o, scope);
                return null;
            }
        });
    } else {
        doSetAttribute(name, o, scope);
    }

}