Package org.mortbay.resource

Examples of org.mortbay.resource.Resource


    public void scan() throws Exception
    {
        if (_contexts==null)
            throw new IllegalArgumentException("No HandlerContainer");

        Resource r=Resource.newResource(_webAppDir);
        if (!r.exists())
            throw new IllegalArgumentException("No such webapps resource "+r);

        if (!r.isDirectory())
            throw new IllegalArgumentException("Not directory webapps resource "+r);

        String[] files=r.list();

        files: for (int f=0; files!=null&&f<files.length; f++)
        {
            String context=files[f];

            if (context.equalsIgnoreCase("CVS/")||context.equalsIgnoreCase("CVS")||context.startsWith("."))
                continue;

            Resource app=r.addPath(r.encode(context));

            if (context.toLowerCase().endsWith(".war")||context.toLowerCase().endsWith(".jar"))
            {
                context=context.substring(0,context.length()-4);
                Resource unpacked=r.addPath(context);
                if (unpacked!=null&&unpacked.exists()&&unpacked.isDirectory())
                    continue;
            }
            else if (!app.isDirectory())
                continue;
View Full Code Here


            if (content!=null && content.isValid())
            {
                return content;
            }   
        }
        Resource resource=factory.getResource(pathInContext);
        return load(pathInContext,resource);
    }
View Full Code Here

            return;
           
        StringTokenizer tokenizer= new StringTokenizer(classPath, ",;");
        while (tokenizer.hasMoreTokens())
        {
            Resource resource= Resource.newResource(tokenizer.nextToken());
            if (Log.isDebugEnabled())
                Log.debug("Path resource=" + resource);

            // Resolve file path if possible
            File file= resource.getFile();
            if (file != null)
            {
                URL url= resource.getURL();
                addURL(url);
            }
            else
            {
                // Add resource or expand jar/
                if (!resource.isDirectory() && file == null)
                {
                    InputStream in= resource.getInputStream();
                    File tmp_dir=_context.getTempDirectory();
                    if (tmp_dir==null)
                    {
                        tmp_dir = File.createTempFile("jetty.cl.lib",null);
                        tmp_dir.mkdir();
                        tmp_dir.deleteOnExit();
                    }
                    File lib= new File(tmp_dir, "lib");
                    if (!lib.exists())
                    {
                        lib.mkdir();
                        lib.deleteOnExit();
                    }
                    File jar= File.createTempFile("Jetty-", ".jar", lib);
                   
                    jar.deleteOnExit();
                    if (Log.isDebugEnabled())
                        Log.debug("Extract " + resource + " to " + jar);
                    FileOutputStream out = null;
                    try
                    {
                        out= new FileOutputStream(jar);
                        IO.copy(in, out);
                    }
                    finally
                    {
                        IO.close(out);
                    }
                   
                    URL url= jar.toURL();
                    addURL(url);
                }
                else
                {
                    URL url= resource.getURL();
                    addURL(url);
                }
            }
        }
    }
View Full Code Here

        {
            String[] files=lib.list();
            for (int f=0;files!=null && f<files.length;f++)
            {
                try {
                    Resource fn=lib.addPath(files[f]);
                    String fnlc=fn.getName().toLowerCase();
                    if (fnlc.endsWith(".jar") || fnlc.endsWith(".zip"))
                    {
                      String jar=fn.toString();
                      jar=StringUtil.replace(jar, ",", "%2C");
                      jar=StringUtil.replace(jar, ";", "%3B");
                        addClassPath(jar);
                    }
                }
View Full Code Here

                String location = (String)iter.next();
                if (location!=null && location.toLowerCase().endsWith(".tld"))
                {
                    if (!location.startsWith("/"))
                        location="/WEB-INF/"+location;
                    Resource l=_context.getBaseResource().addPath(location);
                    tlds.add(l);
                }
            }
        }
       
        // Look for any tlds in WEB-INF directly.
        Resource web_inf = _context.getWebInf();
        if (web_inf!=null)
        {
            String[] contents = web_inf.list();
            for (int i=0;contents!=null && i<contents.length;i++)
            {
                if (contents[i]!=null && contents[i].toLowerCase().endsWith(".tld"))
                {
                    Resource l=_context.getWebInf().addPath(contents[i]);
                    tlds.add(l);
                }
               
            }
        }
       
        // Get the pattern for noTLDJars
        String no_TLD_attr = _context.getInitParameter("org.mortbay.jetty.webapp.NoTLDJarPattern");
        Pattern no_TLD_pattern = no_TLD_attr==null?null:Pattern.compile(no_TLD_attr);
       
        // Look for tlds in any jars
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        boolean parent=false;
       
        while (loader!=null)
        {
            if (loader instanceof URLClassLoader)
            {
                URL[] urls = ((URLClassLoader)loader).getURLs();

                if (urls!=null)
                {
                    for (int i=0;i<urls.length;i++)
                    {  
                        if (urls[i].toString().toLowerCase().endsWith(".jar"))
                        {

                            String jar = urls[i].toString();
                            int slash=jar.lastIndexOf('/');
                            jar=jar.substring(slash+1);

                            if (parent && (
                                    (!_context.isParentLoaderPriority() && jars.contains(jar)) ||
                                    (no_TLD_pattern!=null && no_TLD_pattern.matcher(jar).matches())))
                                continue;
                            jars.add(jar);
                           
                            Log.debug("TLD search of {}",urls[i]);
                           
                            File file=Resource.newResource(urls[i]).getFile();
                            if (file==null || !file.exists() || !file.canRead())
                                continue;
                           
                            JarFile jarfile = new JarFile(file);
                            try
                            {
                                Enumeration e = jarfile.entries();
                                while (e.hasMoreElements())
                                {
                                    ZipEntry entry = (ZipEntry)e.nextElement();
                                    String name = entry.getName();
                                    if (name.startsWith("META-INF/") && name.toLowerCase().endsWith(".tld"))
                                    {
                                        Resource tld=Resource.newResource("jar:"+urls[i]+"!/"+name);
                                        tlds.add(tld);
                                        Log.debug("TLD found {}",tld);
                                    }
                                }
                            }
                            finally
                            {
                                jarfile.close();
                            }  
                        }
                    }
                }
            }

            loader=loader.getParent();
            parent=true;
           
        }
       
        // Create a TLD parser
        XmlParser parser = new XmlParser(false);
        parser.redirectEntity("web-jsptaglib_1_1.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd", false));
        parser.redirectEntity("web-jsptaglib_1_2.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd", false));
        parser.redirectEntity("web-jsptaglib_2_0.xsd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd", false));
        parser.redirectEntity("web-jsptaglibrary_1_1.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd", false));
        parser.redirectEntity("web-jsptaglibrary_1_2.dtd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd", false));
        parser.redirectEntity("web-jsptaglibrary_2_0.xsd",Loader.getResource(TagLibConfiguration.class,"javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd", false));
        parser.setXpath("/taglib/listener/listener-class");
        // Parse all the discovered TLDs
        Iterator iter = tlds.iterator();
        while (iter.hasNext())
        {
            try
            {
                Resource tld = (Resource)iter.next();
                if (Log.isDebugEnabled()) Log.debug("TLD="+tld);
               
                XmlParser.Node root;
               
                try
                {
                    //xerces on apple appears to sometimes close the zip file instead
                    //of the inputstream, so try opening the input stream, but if
                    //that doesn't work, fallback to opening a new url
                    root = parser.parse(tld.getInputStream());
                }
                catch (Exception e)
                {
                    root = parser.parse(tld.getURL().toString());
                }

    if (root==null)
    {
        Log.warn("No TLD root in {}",tld);
View Full Code Here

        }

        /* ------------------------------------------------------------ */
        public void sendContent(Object content) throws IOException
        {
            Resource resource = null;

            if (_closed)
                throw new IOException("Closed");

            if (_generator.getContentWritten() > 0)
                throw new IllegalStateException("!empty");

            if (content instanceof HttpContent)
            {
                HttpContent c = (HttpContent)content;
                if (c.getContentType() != null && !_responseFields.containsKey(HttpHeaders.CONTENT_TYPE_BUFFER))
                    _responseFields.add(HttpHeaders.CONTENT_TYPE_BUFFER,c.getContentType());
                if (c.getContentLength() > 0)
                    _responseFields.putLongField(HttpHeaders.CONTENT_LENGTH_BUFFER,c.getContentLength());
                Buffer lm = c.getLastModified();
                long lml = c.getResource().lastModified();
                if (lm != null)
                    _responseFields.put(HttpHeaders.LAST_MODIFIED_BUFFER,lm,lml);
                else if (c.getResource() != null)
                {
                    if (lml != -1)
                        _responseFields.putDateField(HttpHeaders.LAST_MODIFIED_BUFFER,lml);
                }

                content = c.getBuffer();
                if (content == null)
                    content = c.getInputStream();
            }
            else if (content instanceof Resource)
            {
                resource = (Resource)content;
                _responseFields.putDateField(HttpHeaders.LAST_MODIFIED_BUFFER,resource.lastModified());
                content = resource.getInputStream();
            }

            if (content instanceof Buffer)
            {
                _generator.addContent((Buffer)content,HttpGenerator.LAST);
                commitResponse(HttpGenerator.LAST);
            }
            else if (content instanceof InputStream)
            {
                InputStream in = (InputStream)content;

                try
                {
                    int max = _generator.prepareUncheckedAddContent();
                    Buffer buffer = _generator.getUncheckedBuffer();

                    int len = buffer.readFrom(in,max);

                    while (len >= 0)
                    {
                        _generator.completeUncheckedAddContent();
                        _out.flush();

                        max = _generator.prepareUncheckedAddContent();
                        buffer = _generator.getUncheckedBuffer();
                        len = buffer.readFrom(in,max);
                    }
                    _generator.completeUncheckedAddContent();
                    _out.flush();
                }
                finally
                {
                    if (resource != null)
                        resource.release();
                    else
                        in.close();

                }
            }
View Full Code Here

            return;
        }
        String defaultsDescriptor=getWebAppContext().getDefaultsDescriptor();
        if(defaultsDescriptor!=null&&defaultsDescriptor.length()>0)
        {
            Resource dftResource=Resource.newSystemResource(defaultsDescriptor);
            if(dftResource==null)
                dftResource=Resource.newResource(defaultsDescriptor);
            configure(dftResource.getURL().toString());
            _defaultWelcomeFileList=_welcomeFiles!=null;
        }
    }
View Full Code Here

            configure(webxml.toString());
      
        String overrideDescriptor=getWebAppContext().getOverrideDescriptor();
        if(overrideDescriptor!=null&&overrideDescriptor.length()>0)
        {
            Resource orideResource=Resource.newSystemResource(overrideDescriptor);
            if(orideResource==null)
                orideResource=Resource.newResource(overrideDescriptor);
            _xmlParser.setValidating(false);
            configure(orideResource.getURL().toString());
        }
    }
View Full Code Here

    protected URL findWebXml() throws IOException, MalformedURLException
    {
        String descriptor=getWebAppContext().getDescriptor();
        if (descriptor!=null)
        {
            Resource web= Resource.newResource(descriptor);
            if (web.exists()&& !web.isDirectory())
                return web.getURL();
        }

        Resource web_inf=getWebAppContext().getWebInf();
        if(web_inf!=null && web_inf.isDirectory())
        {
            // do web.xml file
            Resource web=web_inf.addPath("web.xml");
            if(web.exists())
                return web.getURL();
            Log.debug("No WEB-INF/web.xml in "+getWebAppContext().getWar()
                    +". Serving files and default/dynamic servlets only");
        }
        return null;
    }
View Full Code Here

     */
    public Resource getResource(String pathInContext)
    {
        if (_resourceBase==null)
            return null;
        Resource r=null;
        try
        {
            r = _resourceBase.addPath(pathInContext);
            if (!_aliases && r.getAlias()!=null)
            {
                if (r.exists())
                    Log.warn("Aliased resource: "+r+"=="+r.getAlias());
                return null;
            }
            if (Log.isDebugEnabled()) Log.debug("RESOURCE="+r);
        }
        catch (IOException e)
View Full Code Here

TOP

Related Classes of org.mortbay.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.