alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.web.monitor.client; 

import java.util.*;
import javax.servlet.http.HttpUtils;
import org.netbeans.modules.web.monitor.data.*;


/**
 * Util.java
 *
 * For the next proper release of the monitor module, these methods
 * should move in with their respective data objects. I can't do that
 * for now because I would break compatibility with tomcat-monitor.jar
 * which include copies of the data files. 
 *
 * Created: Thu Aug 30 17:43:28 2001
 *
 * @author Ana von Klopp
 * @version
 */

public class Util  {

    private final static boolean debug = false;

    public Util() {}

    /**
     * We use this method to compose a query string from the
     * parameters instead of using the query string we recorded.  This
     * is used by edit/replay, and also as a workaround for regular
     * replay as getParameters() seems to be better implemented to
     * deal with multibyte than getQueryString()...  */

    public static void composeQueryString(RequestData rd) { 
	
	if(debug) System.out.println("Doing query string"); //NOI18N
	
	if(rd.sizeParam() == 0) return;
	
	Param[] params = rd.getParam();
	StringBuffer buf = new StringBuffer(512);
	String name, value;
	 
	for(int i=0; i < params.length; i++) {

	    try {
		name = params[i].getName().trim();
		if(debug) System.out.println("name: " + name); //NOI18N
		value = params[i].getValue(); 
		if(debug) System.out.println("value: " + value); //NOI18N
	    }
	    catch(Exception ex) { 
		continue;
	    }
	    if(name.equals("")) continue;  //NOI18N

	    if (value != null) value = value.trim();
	    else value = ""; //NOI18N
	    
	    if(i>0) buf.append('&'); // NOI18N
	    buf.append(name);
	    buf.append('=');  //NOI18N
	    buf.append(value);
	}
	rd.setAttributeValue("queryString", buf.toString());  //NOI18N
	rd.setParam(new Param[0]);
	
	if (debug) 
	    System.out.println("EditPanel::composedQueryString: [" +  //NOI18N
			       buf.toString() + "]");  //NOI18N
    }

    static boolean removeParametersFromQuery(RequestData rd) {
		 
	// Data wasn't parameterized
	if(rd.sizeParam() == 0) return false;
	
	String queryString =
	    rd.getAttributeValue("queryString");  //NOI18N

	// MULTIBYTE - I think this isn't working... 
	Hashtable ht = null;
	try {
	    ht = javax.servlet.http.HttpUtils.parseQueryString(queryString);
	}
	catch(IllegalArgumentException iae) {
	    // do nothing, that's OK
	    return false;
	}
	if(ht == null || ht.isEmpty()) return false;
	
	Enumeration e = ht.keys();

	while(e.hasMoreElements()) {
	    String name = (String)e.nextElement();
	    try {
		String[] value = (String[])(ht.get(name));
		for(int i=0; i 0) {
	    Enumeration e = ht.keys();
	    while(e.hasMoreElements()) {
		String name = (String)e.nextElement();
		String[] value = (String[])(ht.get(name));
		for(int i=0; i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.