[prev in list] [next in list] [prev in thread] [next in thread] 

List:       konq-bugs
Subject:    [Bug 63413] Some java applet parameters are not accessible -
From:       Petar Krasimirov <pkrasimirov () neterra ! net>
Date:       2003-09-04 15:13:59
[Download RAW message or body]

------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
     
http://bugs.kde.org/show_bug.cgi?id=63413     




------- Additional Comments From pkrasimirov@neterra.net  2003-09-04 17:13 -------
I think I have to explain a little how the applet works (sorry for not doing it earlier). It reads 
a set of parameters namely "statistical", "live", "livePassword", "templateItemId", 
"frameName", "mdigest", "timeZone", "timeBegin", "timeEnd", "timeEndRelative", 
"timeZoneName". It then reads another set of parameters: "curveTimes", "curveValues", 
"curveMaint", "curveDrawType", "curveDeviceParam", "curveMeasureName", 
"curveCaption", "curveMinValue", "curveMaxValue", "curveScaleType", 
"curveTreshName", "curveInterr", "curveColor", "curveId". But unlike the first set it 
appends numbers at the end of each: like "curveTimes0", "curveTimes1", "curveTimes2", 
"curveTimes3", ... 
These are for each curve. If an applet contains 4 curves (0,1,2 and 3) the applet will try to 
read "curveTimes4" AND "curveValues4". If both result null it will detect that there are no 
more curves. 
 
I will paste here part of the applet so you can see the code (including all getParameter 
invocations). Some notes: I wrote method getParameterFromChunks to avoid very long 
text lines in HTML (didn't help). If I'm able to provide any additional help just tell me. 
 
 
public class JGraphApplet extends JApplet { // applet class 
 
  // code skipped 
 
  private int getParameterAttempts = 0; 
  private int getParameterAttempts_failed = 0; 
 
  public void init() { 
    // Load parameters 
    DisplayGraph graph = createModelFromParameters(); 
    // code skipped 
  } 
 
  // This overrides the normal getParameter - I hoped 
  // that I could get the failing parameter if I retry few times... didn't help 
  public String getParameter(String name) { 
    return getParameter(name, 3); 
  } 
 
  private String getParameter(String name, int retrys) { 
    try { 
      String param = super.getParameter(name); 
      getParameterAttempts++; 
 
      for (int i = 0; param == null && i < retrys; i++, System.err.println("Couldn't get \"" + 
name + "\", retrying..."), Thread.sleep(1000 * i)) { 
        getParameterAttempts_failed++; 
        param = super.getParameter(name); 
        getParameterAttempts++; 
      } 
 
      return param; 
    } 
    catch (InterruptedException e) { 
      e.printStackTrace(); 
      throw new RuntimeException(e.toString()); 
    } 
  } 
 
  private DisplayGraph createModelFromParameters() { 
    statistical = "1".equals(getParameter("statistical")); 
    isZoomNew = "1".equals(getParameter("zoomNew", 0)); 
    isAsPlugin = "1".equals(getParameter("asPlugin", 0)); 
    boolean isLive = ("1".equals(getParameter("live", 0))); 
    String livePasswordParam = getParameter("livePassword", 0); 
    String templateItemId_String = getParameter("templateItemId"); 
    templateItemId = Long.parseLong(templateItemId_String); 
    frameNameParam = getParameter("frameName"); 
 
    String mdigestParam = getParameter("mdigest"); 
    try { 
      mdigest = Long.parseLong(mdigestParam); 
    } 
    catch (NumberFormatException e) { 
      // this should never happen 
      mdigest = -1; 
    } 
 
    String timeZoneStrParam = getParameter("timeZone"); 
    if (timeZoneStrParam == null) { 
      throw new IllegalArgumentException("timeZone is null"); 
    } 
    boolean gmtTime = !"Local".equals(timeZoneStrParam); 
    TimeZone timeZone = (gmtTime ? TimeZone.getTimeZone("GMT") : 
TimeZone.getDefault()); 
 
    String timeBeginParam = getParameter("timeBegin"); 
    long beginTimeSeconds; 
    try { beginTimeSeconds = Long.parseLong(timeBeginParam); } catch 
(NumberFormatException e) { throw new IllegalArgumentException("timeBegin==\"" + 
timeBeginParam + "\""); } 
 
    String timeEndParam = getParameter("timeEnd"); 
    long endTimeSeconds; 
    try { endTimeSeconds = Long.parseLong(timeEndParam); } catch 
(NumberFormatException e) { throw new IllegalArgumentException("timeEnd==\"" + 
timeEndParam + "\""); } 
 
    TimeInterval timeInterval = new TimeInterval(beginTimeSeconds, endTimeSeconds); 
 
    String timeEndRelativeParam = getParameter("timeEndRelative"); 
    boolean endsNow = false; 
    try { endsNow = Long.parseLong(timeEndRelativeParam) == 0; } catch 
(NumberFormatException e) { endsNow = false; } 
 
    String timeZoneStringParam = getParameter("timeZoneName"); 
    DisplayGraph graph = new DisplayGraph(timeInterval, !gmtTime, endsNow, 
timeZoneStringParam); 
 
    if (isLive && livePasswordParam != null) { 
      graph.setLiveUpdates(true); 
      graph.setLivePassword(livePasswordParam); 
      graph.setLiveServerAddr(getCodeBase().getHost()); 
    } 
 
    for (int curvesCount = 0; ; curvesCount++) { 
      String curveTimesParam = getParameterFromChunks("curveTimes" + curvesCount); 
      String curveValuesParam = getParameterFromChunks("curveValues" + 
curvesCount); 
 
      if (null == curveValuesParam || null == curveTimesParam) { 
System.out.println("DEBUG: \"" + "curveTimes" + curvesCount + "\" returned " + 
(curveTimesParam==null ? "" : "NOT") + " null"); 
System.out.println("DEBUG: \"" + "curveValues" + curvesCount + "\" returned " + 
(curveValuesParam==null ? "" : "NOT") + " null"); 
        break; 
      } 
 
      String curveMaintTimesParam = getParameter("curveMaint" + curvesCount); 
      if (curveMaintTimesParam == null) { 
        System.out.println("ERROR: \"" + "curveMaint" + curvesCount + "\" returned " + 
curveMaintTimesParam + "\""); 
        continue; 
      } 
      MarkedPeriod[] markedPeriods = parseMarkedPeriods(curveMaintTimesParam, 
timeZone); 
 
      String curveDrawTypeStringParam = getParameter("curveDrawType" + 
curvesCount); 
      int curveDrawTypeParam; 
      try { 
        curveDrawTypeParam = Integer.parseInt(curveDrawTypeStringParam); 
      } 
      catch (NumberFormatException e) { 
        System.out.println("ERROR: \"" + "curveDrawType" + curvesCount + "\" returned " + 
curveDrawTypeStringParam + "\""); 
        continue; 
      } 
      DisplayCurve.Style curveStyle = 
DisplayCurve.Style.getByValue(curveDrawTypeParam); 
 
      String dpParam = getParameter("curveDeviceParam" + curvesCount); 
      DeviceParam curveDeviceParam = parseDeviceParam(dpParam); 
      String measureNameParam = getParameter("curveMeasureName" + curvesCount); 
      Measure curveMeasure = parseMeasure(dpParam, measureNameParam); 
 
      String curveCaptionParam = getParameter("curveCaption" + curvesCount); 
      if (curveCaptionParam == null || curveCaptionParam.length() == 0) 
curveCaptionParam = "unnamed" + curvesCount; 
 
      // Get values scale 
      Scale curveValuesScale; 
      { 
        String minValueStr = getParameter("curveMinValue" + curvesCount); 
        if (minValueStr == null || minValueStr.length() == 0) { 
          System.out.println("ERROR: \"" + "curveMinValue" + curvesCount + "\" returned \"" 
+ minValueStr + "\""); 
          continue; 
        } 
        BigDecimal minValue = new BigDecimal(String.valueOf(minValueStr)); 
 
        String maxValueStr = getParameter("curveMaxValue" + curvesCount); 
        if (maxValueStr == null || maxValueStr.length() == 0) { 
          System.out.println("ERROR: \"" + "curveMaxValue" + curvesCount + "\" returned \"" 
+ maxValueStr + "\""); 
          continue; 
        } 
        BigDecimal maxValue = new BigDecimal(String.valueOf(maxValueStr)); 
 
        String curveScaleTypeStringParam = getParameter("curveScaleType" + 
curvesCount); 
        int curveScaleTypeParam; 
        try { 
          curveScaleTypeParam = Integer.parseInt(curveScaleTypeStringParam); 
        } 
        catch (NumberFormatException e) { 
          System.out.println("ERROR: \"" + "curveScaleType" + curvesCount + "\" returned 
\"" + curveScaleTypeStringParam + "\""); 
          continue; 
        } 
        Scale.Type scaleType = Scale.Type.getByValue(curveScaleTypeParam); 
        curveValuesScale = new Scale(minValue, maxValue, scaleType); 
      } 
/* 
      { 
        String treshNameStr = getParameter("curveTreshName" + curvesCount); 
        boolean hasThresh = null != treshNameStr && treshNameStr.length() > 0; 
        if (hasThresh) { 
          treshCount++; 
          curvesTreshName.addElement(treshNameStr); 
 
          String treshValueStr = getParameter("curveTreshValue" + curvesCount); 
          Object[] obj = bdVal(treshValueStr); 
          curvesTreshValue.addElement(new BigDecimal((BigInteger)obj[0], 
((Integer)obj[1]).intValue())); 
 
          String treshPosStr = getParameter("curveTreshPos" + curvesCount); 
          Integer treshPos = new Integer(treshPosStr); 
          curvesTreshPos.addElement(treshPos); 
 
          String showInterruptionsStr = getParameter("curveInterr" + curvesCount); 
 
          boolean showInterruptions = "1".equals(showInterruptionsStr); 
          if (showInterruptions) { 
            interrCount++; 
          } 
          curvesInterruptions.addElement(new Boolean(showInterruptions)); 
        } 
        else { 
          curvesTreshName.addElement(""); 
          curvesTreshValue.addElement(null); 
          curvesTreshPos.addElement(null); 
          curvesInterruptions.addElement(new Boolean(false)); 
        } 
      } 
*/ 
      String curveThresholdNameParam = getParameter("curveTreshName" + 
curvesCount); 
      if ("".equals(curveThresholdNameParam)) { 
        curveThresholdNameParam = null; 
      } 
 
      String showInterruptionsStrParam = getParameter("curveInterr" + curvesCount); 
      boolean curveShowInterruptionsReport = "1".equals(showInterruptionsStrParam); 
 
      String curveColorString = getParameter("curveColor" + curvesCount); 
      Color curveColor; 
      try { 
        curveColor = new Color(Integer.parseInt(curveColorString, 16)); 
      } 
      catch (NumberFormatException e) { 
        System.out.println("ERROR: \"" + "curveColor" + curvesCount + "\" returned \"" + 
curveColorString + "\""); 
        continue; 
      } 
 
      long curveId; 
 
      String curveIdParam = getParameter("curveId" + curvesCount); 
      try { 
        curveId = Long.parseLong(curveIdParam); 
      } 
      catch (NumberFormatException e) { 
        System.out.println("ERROR: \"" + "curveId" + curvesCount + "\" returned \"" + 
curveIdParam + "\""); 
        continue; 
      } 
 
      // Create curve 
      DisplayCurve curve = new DisplayCurve( 
              curveId, 
              curveValuesScale, 
              curveDeviceParam, 
              curveMeasure, 
              curveCaptionParam, 
              curveColor, 
              curveStyle 
      ); 
 
      curve.setThresholdName(curveThresholdNameParam); 
      curve.setShowInterruptionsReport(curveShowInterruptionsReport); 
 
      // Add points to curve 
      DisplayCurve.Point[] points = parsePoints(curveTimesParam, curveValuesParam); 
      for (int i = 0; i < points.length; i++) { 
        curve.addPoint(points[i]); 
      } 
 
      for (int i = 0; i < markedPeriods.length; i++) { 
        curve.addMarkedPeriod(markedPeriods[i]); 
      } 
 
      // Add curve to graph 
      graph.addCurve(curve); 
    } 
 
System.out.println("DEBUG: getParameterAttempts==" + getParameterAttempts + " (" + 
getParameterAttempts_failed + " failed)"); 
System.out.println("DEBUG: Constructed model with " + graph.getCurveCount() + " 
curves (applet==" + this.toString() + ")"); 
    return graph; 
  } 
 
 
  private String getParameterFromChunks(String paramPrefix) { 
    String noChunkString = getParameter(paramPrefix, 0); 
    if (noChunkString == null) return null; 
 
    StringBuffer buf = new StringBuffer(10000); 
    buf.append(noChunkString); 
 
    paramPrefix += "_"; 
 
    for (int chunkIndex = 0; ; chunkIndex++) { 
      String chunkString = getParameter(paramPrefix + chunkIndex, 0); 
 
      if (chunkString == null) break; 
 
      buf.append(chunkString); 
    } 
 
    return buf.toString(); 
  } 
 
} // class
_______________________________________________
Konq-bugs mailing list
Konq-bugs@mail.kde.org
http://mail.kde.org/mailman/listinfo/konq-bugs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic