Package org.mortbay.util

Examples of org.mortbay.util.MultiMap


    /* ------------------------------------------------------------ */
    public void sendMessage(final Collection<String> toUsers,final String toChannel,final Object message)
    {
        // break toUsers in to shards
        MultiMap shard2users = new MultiMap();
        for (String userId:toUsers)
        {      
            ShardLocation shard = userId2Shard(userId);
            shard2users.add(shard,userId);
        }
       
        // for each shard
        for (Map.Entry<ShardLocation,Object> entry : (Set<Map.Entry<ShardLocation,Object>>)shard2users.entrySet())
        {
            // TODO, we could look at all users in shard to see if we
            // know a setiId for each, and if so, break the user list
            // up into a message for each seti-id. BUT it is probably
            // more efficient just to send to the entire shard (unless
View Full Code Here


        request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
       
        // TODO - allow stream or writer????
       
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            base_request.getConnection().include();
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, Handler.INCLUDE);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();
                            Object values=entry.getValue();
                            for (int i=0;i<LazyList.size(values);i++)
                                parameters.add(name, LazyList.get(values, i));
                        }
                       
                    }
                    base_request.setParameters(parameters);
                }
View Full Code Here

        String old_context_path=base_request.getContextPath();
        String old_servlet_path=base_request.getServletPath();
        String old_path_info=base_request.getPathInfo();
        String old_query=base_request.getQueryString();
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, dispatch);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                
                    boolean rewrite_old_query = false;

                    if( old_params == null )
                    {
                        base_request.getParameterNames();    // force parameters to be evaluated
                        old_params = base_request.getParameters();
                    }
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters; new parameters of the same name take precedence.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();

                            if (parameters.containsKey(name))
                                rewrite_old_query = true;
                            Object values=entry.getValue();
                            for (int i=0;i<LazyList.size(values);i++)
                                parameters.add(name, LazyList.get(values, i));
                        }
                    }
                   
                    if (old_query != null && old_query.length()>0)
                    {
                        if ( rewrite_old_query )
                        {
                            StringBuffer overridden_query_string = new StringBuffer();
                            MultiMap overridden_old_query = new MultiMap();
                            UrlEncoded.decodeTo(old_query,overridden_old_query,request.getCharacterEncoding());
   
                            MultiMap overridden_new_query = new MultiMap();
                            UrlEncoded.decodeTo(query,overridden_new_query,request.getCharacterEncoding());

                            Iterator iter = overridden_old_query.entrySet().iterator();
                            while (iter.hasNext())
                            {
                                Map.Entry entry = (Map.Entry)iter.next();
                                String name=(String)entry.getKey();
                                if(!overridden_new_query.containsKey(name))
                                {
                                    Object values=entry.getValue();
                                    for (int i=0;i<LazyList.size(values);i++)
                                    {
                                        overridden_query_string.append("&"+name+"="+LazyList.get(values, i));
View Full Code Here

    Log.warn("Could not generate SecureRandom for session-id randomness",e);
    _random=new Random();
    _weakRandom=true;
            }
        }
        _sessions=new MultiMap();
    }
View Full Code Here

     * Extract Paramters from query string and/or form _content.
     */
    private void extractParameters()
    {
        if (_baseParameters == null)
            _baseParameters = new MultiMap(16);
       
        if (_paramsExtracted)
        {
            if (_parameters==null)
                _parameters=_baseParameters;
View Full Code Here

            _filterNameMappings=null;
        }
        else
        {
            _filterPathMappings=new ArrayList();
            _filterNameMappings=new MultiMap();
            for (int i=0;i<_filterMappings.length;i++)
            {
                FilterHolder filter_holder = (FilterHolder)_filterNameMap.get(_filterMappings[i].getFilterName());
                if (filter_holder==null)
                    throw new IllegalStateException("No filter named "+_filterMappings[i].getFilterName());
View Full Code Here

                    _weakRandom=true;
                }
            }
        }
        _random.setSeed(_random.nextLong()^System.currentTimeMillis()^hashCode()^Runtime.getRuntime().freeMemory());
        _sessions=new MultiMap();
    }
View Full Code Here

       
        // TODO - handle encodings
       
        String boundary="--"+value(content_type.substring(content_type.indexOf("boundary=")));
        byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
        MultiMap params = new MultiMap();
       
        try
        {
            // Get first boundary
            byte[] bytes=TypeUtil.readLine(in);
            String line=bytes==null?null:new String(bytes,"UTF-8");
            if(line==null || !line.equals(boundary))
            {
                throw new IOException("Missing initial multi part boundary");
            }
           
            // Read each part
            boolean lastPart=false;
            String content_disposition=null;
            while(!lastPart)
            {
                while(true)
                {
                    bytes=TypeUtil.readLine(in);
                    // If blank line, end of part headers
                    if(bytes==null || bytes.length==0)
                        break;
                    line=new String(bytes,"UTF-8");
                   
                    // place part header key and value in map
                    int c=line.indexOf(':',0);
                    if(c>0)
                    {
                        String key=line.substring(0,c).trim().toLowerCase();
                        String value=line.substring(c+1,line.length()).trim();
                        if(key.equals("content-disposition"))
                            content_disposition=value;
                    }
                }
                // Extract content-disposition
                boolean form_data=false;
                if(content_disposition==null)
                {
                    throw new IOException("Missing content-disposition");
                }
               
                StringTokenizer tok=new StringTokenizer(content_disposition,";");
                String name=null;
                String filename=null;
                while(tok.hasMoreTokens())
                {
                    String t=tok.nextToken().trim();
                    String tl=t.toLowerCase();
                    if(t.startsWith("form-data"))
                        form_data=true;
                    else if(tl.startsWith("name="))
                        name=value(t);
                    else if(tl.startsWith("filename="))
                        filename=value(t);
                }
               
                // Check disposition
                if(!form_data)
                {
                    continue;
                }
                if(name==null||name.length()==0)
                {
                    continue;
                }
               
                OutputStream out=null;
                File file=null;
                try
                {
                    if (filename!=null && filename.length()>0)
                    {
                        file = File.createTempFile("MultiPart", "", tempdir);
                        out = new FileOutputStream(file);
                        if(_fileOutputBuffer>0)
                            out = new BufferedOutputStream(out, _fileOutputBuffer);
                        request.setAttribute(name,file);
                        params.put(name, filename);
                       
                        if (_deleteFiles)
                        {
                            file.deleteOnExit();
                            ArrayList files = (ArrayList)request.getAttribute(FILES);
                            if (files==null)
                            {
                                files=new ArrayList();
                                request.setAttribute(FILES,files);
                            }
                            files.add(file);
                        }
                       
                    }
                    else
                        out=new ByteArrayOutputStream();
                   
                    int state=-2;
                    int c;
                    boolean cr=false;
                    boolean lf=false;
                   
                    // loop for all lines`
                    while(true)
                    {
                        int b=0;
                        while((c=(state!=-2)?state:in.read())!=-1)
                        {
                            state=-2;
                            // look for CR and/or LF
                            if(c==13||c==10)
                            {
                                if(c==13)
                                    state=in.read();
                                break;
                            }
                            // look for boundary
                            if(b>=0&&b<byteBoundary.length&&c==byteBoundary[b])
                                b++;
                            else
                            {
                                // this is not a boundary
                                if(cr)
                                    out.write(13);
                                if(lf)
                                    out.write(10);
                                cr=lf=false;
                                if(b>0)
                                    out.write(byteBoundary,0,b);
                                b=-1;
                                out.write(c);
                            }
                        }
                        // check partial boundary
                        if((b>0&&b<byteBoundary.length-2)||(b==byteBoundary.length-1))
                        {
                            if(cr)
                                out.write(13);
                            if(lf)
                                out.write(10);
                            cr=lf=false;
                            out.write(byteBoundary,0,b);
                            b=-1;
                        }
                        // boundary match
                        if(b>0||c==-1)
                        {
                            if(b==byteBoundary.length)
                                lastPart=true;
                            if(state==10)
                                state=-2;
                            break;
                        }
                        // handle CR LF
                        if(cr)
                            out.write(13);
                        if(lf)
                            out.write(10);
                        cr=(c==13);
                        lf=(c==10||state==10);
                        if(state==10)
                            state=-2;
                    }
                }
                finally
                {
                    out.close();
                }
               
                if (file==null)
                {
                    bytes = ((ByteArrayOutputStream)out).toByteArray();
                    params.add(name,bytes);
                }
            }
       
            // handle request
            chain.doFilter(new Wrapper(srequest,params),response);
View Full Code Here

        request.removeAttribute(__JSP_FILE); // TODO remove when glassfish 1044 is fixed
       
        // TODO - allow stream or writer????
       
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            base_request.getConnection().include();
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, Handler.INCLUDE);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();
                            Object values=entry.getValue();
                            for (int i=0;i<LazyList.size(values);i++)
                                parameters.add(name, LazyList.get(values, i));
                        }
                       
                    }
                    base_request.setParameters(parameters);
                }
View Full Code Here

        String old_context_path=base_request.getContextPath();
        String old_servlet_path=base_request.getServletPath();
        String old_path_info=base_request.getPathInfo();
        String old_query=base_request.getQueryString();
        Attributes old_attr=base_request.getAttributes();
        MultiMap old_params=base_request.getParameters();
        try
        {
            if (_named!=null)
                _contextHandler.handle(_named, (HttpServletRequest)request, (HttpServletResponse)response, dispatch);
            else
            {
                String query=_dQuery;
               
                if (query!=null)
                {
                    MultiMap parameters=new MultiMap();
                    UrlEncoded.decodeTo(query,parameters,request.getCharacterEncoding());
                
                    boolean rewrite_old_query = false;

                    if( old_params == null )
                    {
                        base_request.getParameterNames();    // force parameters to be evaluated
                        old_params = base_request.getParameters();
                    }
                   
                    if (old_params!=null && old_params.size()>0)
                    {
                        // Merge parameters; new parameters of the same name take precedence.
                        Iterator iter = old_params.entrySet().iterator();
                        while (iter.hasNext())
                        {
                            Map.Entry entry = (Map.Entry)iter.next();
                            String name=(String)entry.getKey();
                           
                            if (parameters.containsKey(name))
                            {
                                rewrite_old_query = true;
                            }
                            else
                            {
                                Object values=entry.getValue();
                                for (int i=0;i<LazyList.size(values);i++)
                                {
                                    parameters.add(name, LazyList.get(values, i));
                                }
                            }
                        }
                    }
                   
                    if (old_query != null && old_query.length()>0)
                    {
                        if ( rewrite_old_query )
                        {
                            StringBuffer overridden_query_string = new StringBuffer();
                            MultiMap overridden_old_query = new MultiMap();
                            UrlEncoded.decodeTo(old_query,overridden_old_query,request.getCharacterEncoding());
   
                            MultiMap overridden_new_query = new MultiMap();
                            UrlEncoded.decodeTo(query,overridden_new_query,request.getCharacterEncoding());

                            Iterator iter = overridden_old_query.entrySet().iterator();
                            while (iter.hasNext())
                            {
                                Map.Entry entry = (Map.Entry)iter.next();
                                String name=(String)entry.getKey();
                                if(!overridden_new_query.containsKey(name))
                                {
                                    Object values=entry.getValue();
                                    for (int i=0;i<LazyList.size(values);i++)
                                    {
                                        overridden_query_string.append("&"+name+"="+LazyList.get(values, i));
View Full Code Here

TOP

Related Classes of org.mortbay.util.MultiMap

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.