Search in sources :

Example 6 with Source

use of org.eclipse.jetty.servlet.Source in project jetty.project by eclipse.

the class StandardDescriptorProcessor method visitJspConfig.

public void visitJspConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
    //Additive across web.xml and web-fragment.xml
    JspConfig config = (JspConfig) context.getServletContext().getJspConfigDescriptor();
    if (config == null) {
        config = new JspConfig();
        context.getServletContext().setJspConfigDescriptor(config);
    }
    for (int i = 0; i < node.size(); i++) {
        Object o = node.get(i);
        if (o instanceof XmlParser.Node && "taglib".equals(((XmlParser.Node) o).getTag()))
            visitTagLib(context, descriptor, (XmlParser.Node) o);
    }
    // Map URLs from jsp property groups to JSP servlet.
    // this is more JSP stupidness creeping into the servlet spec
    Iterator<XmlParser.Node> iter = node.iterator("jsp-property-group");
    List<String> paths = new ArrayList<String>();
    while (iter.hasNext()) {
        JspPropertyGroup jpg = new JspPropertyGroup();
        config.addJspPropertyGroup(jpg);
        XmlParser.Node group = iter.next();
        //url-patterns
        Iterator<XmlParser.Node> iter2 = group.iterator("url-pattern");
        while (iter2.hasNext()) {
            String url = iter2.next().toString(false, true);
            url = ServletPathSpec.normalize(url);
            paths.add(url);
            jpg.addUrlPattern(url);
        }
        jpg.setElIgnored(group.getString("el-ignored", false, true));
        jpg.setPageEncoding(group.getString("page-encoding", false, true));
        jpg.setScriptingInvalid(group.getString("scripting-invalid", false, true));
        jpg.setIsXml(group.getString("is-xml", false, true));
        jpg.setDeferredSyntaxAllowedAsLiteral(group.getString("deferred-syntax-allowed-as-literal", false, true));
        jpg.setTrimDirectiveWhitespaces(group.getString("trim-directive-whitespaces", false, true));
        jpg.setDefaultContentType(group.getString("default-content-type", false, true));
        jpg.setBuffer(group.getString("buffer", false, true));
        jpg.setErrorOnUndeclaredNamespace(group.getString("error-on-undeclared-namespace", false, true));
        //preludes
        Iterator<XmlParser.Node> preludes = group.iterator("include-prelude");
        while (preludes.hasNext()) {
            String prelude = preludes.next().toString(false, true);
            jpg.addIncludePrelude(prelude);
        }
        //codas
        Iterator<XmlParser.Node> codas = group.iterator("include-coda");
        while (codas.hasNext()) {
            String coda = codas.next().toString(false, true);
            jpg.addIncludeCoda(coda);
        }
        if (LOG.isDebugEnabled())
            LOG.debug(config.toString());
    }
    //add mappings to the jsp servlet from the property-group mappings
    if (paths.size() > 0) {
        ServletMapping jspMapping = null;
        for (ServletMapping m : _servletMappings) {
            if (m.getServletName().equals("jsp")) {
                jspMapping = m;
                break;
            }
        }
        if (jspMapping != null) {
            if (jspMapping.getPathSpecs() == null) {
                //no paths in jsp servlet mapping, we will add all of ours
                if (LOG.isDebugEnabled())
                    LOG.debug("Adding all paths from jsp-config to jsp servlet mapping");
                jspMapping.setPathSpecs(paths.toArray(new String[paths.size()]));
            } else {
                //check if each of our paths is already present in existing mapping
                ListIterator<String> piterator = paths.listIterator();
                while (piterator.hasNext()) {
                    String p = piterator.next();
                    if (jspMapping.containsPathSpec(p))
                        piterator.remove();
                }
                //any remaining paths, add to the jspMapping
                if (paths.size() > 0) {
                    for (String p : jspMapping.getPathSpecs()) paths.add(p);
                    if (LOG.isDebugEnabled())
                        LOG.debug("Adding extra paths from jsp-config to jsp servlet mapping");
                    jspMapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
                }
            }
        } else {
            //no mapping for jsp yet, make one
            ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
            mapping.setServletName("jsp");
            mapping.setPathSpecs(paths.toArray(new String[paths.size()]));
            _servletMappings.add(mapping);
        }
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) JspConfig(org.eclipse.jetty.servlet.ServletContextHandler.JspConfig) Node(org.eclipse.jetty.xml.XmlParser.Node) ArrayList(java.util.ArrayList) Node(org.eclipse.jetty.xml.XmlParser.Node) Constraint(org.eclipse.jetty.util.security.Constraint) Source(org.eclipse.jetty.servlet.Source) JspPropertyGroup(org.eclipse.jetty.servlet.ServletContextHandler.JspPropertyGroup)

Example 7 with Source

use of org.eclipse.jetty.servlet.Source in project jetty.project by eclipse.

the class StandardDescriptorProcessor method newListenerInstance.

public EventListener newListenerInstance(WebAppContext context, Class<? extends EventListener> clazz, Descriptor descriptor) throws Exception {
    ListenerHolder h = context.getServletHandler().newListenerHolder(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
    EventListener l = context.getServletContext().createInstance(clazz);
    h.setListener(l);
    context.getServletHandler().addListener(h);
    return l;
}
Also used : EventListener(java.util.EventListener) ListenerHolder(org.eclipse.jetty.servlet.ListenerHolder) Source(org.eclipse.jetty.servlet.Source)

Example 8 with Source

use of org.eclipse.jetty.servlet.Source in project jetty.project by eclipse.

the class StandardDescriptorProcessor method addServletMapping.

public ServletMapping addServletMapping(String servletName, XmlParser.Node node, WebAppContext context, Descriptor descriptor) {
    ServletMapping mapping = new ServletMapping(new Source(Source.Origin.DESCRIPTOR, descriptor.getResource().toString()));
    mapping.setServletName(servletName);
    mapping.setDefault(descriptor instanceof DefaultsDescriptor);
    List<String> paths = new ArrayList<String>();
    Iterator<XmlParser.Node> iter = node.iterator("url-pattern");
    while (iter.hasNext()) {
        String p = iter.next().toString(false, true);
        p = ServletPathSpec.normalize(p);
        //check if there is already a mapping for this path
        ListIterator<ServletMapping> listItor = _servletMappings.listIterator();
        boolean found = false;
        while (listItor.hasNext() && !found) {
            ServletMapping sm = listItor.next();
            if (sm.getPathSpecs() != null) {
                for (String ps : sm.getPathSpecs()) {
                    //If its a different servlet, this is only valid to do if the old mapping was from a default descriptor.
                    if (p.equals(ps) && (sm.isDefault() || servletName.equals(sm.getServletName()))) {
                        if (sm.isDefault()) {
                            if (LOG.isDebugEnabled())
                                LOG.debug("{} in mapping {} from defaults descriptor is overridden by ", ps, sm, servletName);
                        } else
                            LOG.warn("Duplicate mapping from {} to {}", p, servletName);
                        //remove ps from the path specs on the existing mapping
                        //if the mapping now has no pathspecs, remove it
                        String[] updatedPaths = ArrayUtil.removeFromArray(sm.getPathSpecs(), ps);
                        if (updatedPaths == null || updatedPaths.length == 0) {
                            if (LOG.isDebugEnabled())
                                LOG.debug("Removed empty mapping {}", sm);
                            listItor.remove();
                        } else {
                            sm.setPathSpecs(updatedPaths);
                            if (LOG.isDebugEnabled())
                                LOG.debug("Removed path {} from mapping {}", p, sm);
                        }
                        found = true;
                        break;
                    }
                }
            }
        }
        paths.add(p);
        context.getMetaData().setOrigin(servletName + ".servlet.mapping." + p, descriptor);
    }
    mapping.setPathSpecs((String[]) paths.toArray(new String[paths.size()]));
    if (LOG.isDebugEnabled())
        LOG.debug("Added mapping {} ", mapping);
    _servletMappings.add(mapping);
    return mapping;
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) Node(org.eclipse.jetty.xml.XmlParser.Node) ArrayList(java.util.ArrayList) Source(org.eclipse.jetty.servlet.Source)

Aggregations

Source (org.eclipse.jetty.servlet.Source)8 ArrayList (java.util.ArrayList)4 Node (org.eclipse.jetty.xml.XmlParser.Node)4 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 MetaData (org.eclipse.jetty.webapp.MetaData)3 XmlParser (org.eclipse.jetty.xml.XmlParser)3 EventListener (java.util.EventListener)2 WebInitParam (javax.servlet.annotation.WebInitParam)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 ListenerHolder (org.eclipse.jetty.servlet.ListenerHolder)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Constraint (org.eclipse.jetty.util.security.Constraint)2 DispatcherType (javax.servlet.DispatcherType)1 Filter (javax.servlet.Filter)1 MultipartConfigElement (javax.servlet.MultipartConfigElement)1 Servlet (javax.servlet.Servlet)1 ServletException (javax.servlet.ServletException)1 ServletRequestListener (javax.servlet.ServletRequestListener)1 WebFilter (javax.servlet.annotation.WebFilter)1 WebServlet (javax.servlet.annotation.WebServlet)1