Attachment 'twikidraw-1.103-utf8.diff'

Download

   1 diff -urP --ignore-space-change orig/src/CH/ifa/draw/appframe/Application.java moin-utf8/src/CH/ifa/draw/appframe/Application.java
   2 --- orig/src/CH/ifa/draw/appframe/Application.java	2005-03-08 17:48:42.000000000 +0000
   3 +++ moin-utf8/src/CH/ifa/draw/appframe/Application.java	2005-11-27 23:42:26.000000000 +0000
   4 @@ -24,6 +24,6 @@
   5                   String fileName,
   6                   String type,
   7                   String path,
   8 -                 String content,
   9 +                 byte[] content,
  10                   String comment) throws IOException;
  11  }
  12 diff -urP --ignore-space-change orig/src/CH/ifa/draw/standard/CompositeFigure.java moin-utf8/src/CH/ifa/draw/standard/CompositeFigure.java
  13 --- orig/src/CH/ifa/draw/standard/CompositeFigure.java	2003-02-02 10:16:46.000000000 +0000
  14 +++ moin-utf8/src/CH/ifa/draw/standard/CompositeFigure.java	2005-11-27 18:33:04.000000000 +0000
  15 @@ -395,7 +395,7 @@
  16  	String areas = "";
  17          Enumeration k = fFigures.elements();
  18          while (k.hasMoreElements())
  19 -            areas += ((Storable) k.nextElement()).getMap();
  20 +            areas = ((Storable) k.nextElement()).getMap() + areas;
  21  	return areas;
  22      }
  23  
  24 diff -urP --ignore-space-change orig/src/CH/ifa/draw/twiki/TWikiDraw.java moin-utf8/src/CH/ifa/draw/twiki/TWikiDraw.java
  25 --- orig/src/CH/ifa/draw/twiki/TWikiDraw.java	2005-03-08 18:00:56.000000000 +0000
  26 +++ moin-utf8/src/CH/ifa/draw/twiki/TWikiDraw.java	2005-11-27 23:44:38.000000000 +0000
  27 @@ -43,15 +43,23 @@
  28                          String fileName,
  29                          String type,
  30                          String path,
  31 -                        String content,
  32 +                        byte[] content,
  33                          String comment)
  34          throws IOException {
  35          
  36          String sep = "89692781418184";
  37 -        while (content.indexOf(sep) != -1)
  38 +        while (fileName.indexOf(sep) != -1)
  39 +            sep += "x";
  40 +        while (type.indexOf(sep) != -1)
  41 +            sep += "x";
  42 +        while (path.indexOf(sep) != -1)
  43 +            sep += "x";
  44 +        while (comment.indexOf(sep) != -1)
  45 +            sep += "x";
  46 +        while (indexOf(content, sep.getBytes()) != -1)
  47              sep += "x";
  48          
  49 -        String message = makeMimeForm(fileName, type,
  50 +        byte[] message = makeMimeForm(fileName, type,
  51                                        path, content, comment, sep);
  52          
  53          // for test
  54 @@ -73,14 +81,14 @@
  55                                        "multipart/form-data; boundary=" + sep);
  56          connection.setRequestProperty(
  57                                        "Content-length",
  58 -                                      Integer.toString(message.length()));
  59 +                                      Integer.toString(message.length));
  60          
  61          //System.out.println(url);
  62          String replyString = null;
  63          try {
  64 -            DataOutputStream out =
  65 -                new DataOutputStream(connection.getOutputStream());
  66 -            out.writeBytes(message);
  67 +            OutputStream out =
  68 +                connection.getOutputStream();
  69 +            out.write(message);
  70              out.close();
  71              //System.out.println("Wrote " + message.length() +
  72              //		   " bytes to\n" + connection);
  73 @@ -101,7 +109,7 @@
  74              }
  75          } catch (UnknownServiceException use) {
  76              replyString = use.getMessage();
  77 -            System.out.println(message);
  78 +            System.out.println(new String(message));
  79          }
  80          if (replyString != null) {
  81              //System.out.println("---- Reply " + replyString);
  82 @@ -144,22 +152,19 @@
  83      static String NLNL = NL + NL;
  84      
  85      /** Post the given message */
  86 -    private String makeMimeForm(
  87 +    private byte[] makeMimeForm(
  88                                  String fileName,
  89                                  String type,
  90                                  String path,
  91 -                                String content,
  92 +                                byte[] content,
  93                                  String comment,
  94                                  String sep) {
  95          
  96 -        String binary = "";
  97 -        if (type.equals("image/gif")) {
  98 -            binary = "Content-Transfer-Encoding: binary" + NL;
  99 -        }
 100 +        String binary = "Content-Transfer-Encoding: binary" + NL;
 101          
 102          String mime_sep = NL + "--" + sep + NL;
 103          
 104 -        return
 105 +        byte[] part1 = (
 106              "--" + sep + "\r\n" 
 107              + "Content-Disposition: form-data; name=\"filename\"" + NLNL
 108              + fileName
 109 @@ -170,12 +175,17 @@
 110              + "Content-Disposition: form-data; name=\"filepath\"; "
 111              + "filename=\"" + path + "\"" + NL
 112              + "Content-Type: " + type + NL
 113 -            + binary + NL
 114 -            + content
 115 -            + mime_sep
 116 +            + binary + NL).getBytes();
 117 +        byte[] part3 =
 118 +             (mime_sep
 119              + "Content-Disposition: form-data; name=\"filecomment\"" + NLNL
 120              + comment
 121 -            + NL + "--" + sep + "--" + NL;
 122 +            + NL + "--" + sep + "--" + NL).getBytes();
 123 +        byte[] res = new byte[part1.length + content.length + part3.length];
 124 +        System.arraycopy(part1, 0, res, 0, part1.length);
 125 +        System.arraycopy(content, 0, res, part1.length, content.length);
 126 +        System.arraycopy(part3, 0, res, part1.length + content.length, part3.length);
 127 +        return res;
 128      }
 129      
 130      /** Replace current app with a different URL */
 131 @@ -191,5 +201,25 @@
 132          }
 133      }
 134      
 135 +    private static int indexOf(byte[] searchin, byte[] searchfor){
 136 +        if(searchfor.length==0)
 137 +            return -1;
 138 +        if(searchfor.length>searchin.length)
 139 +            return -1;
 140 +        if(searchfor.length==searchin.length)
 141 +            return Arrays.equals(searchfor, searchin) ? 0 : -1;
 142 +        for(int i=0; i<=searchin.length-searchfor.length; i++)
 143 +            if((searchin[i]==searchfor[0]) && equals(searchin, i, searchfor))
 144 +                return i;
 145 +        return -1;
 146 +    }
 147 +
 148 +    private static boolean equals(byte[] left, int leftOfs, byte[] right) {
 149 +        for(int j=0; j<right.length; j++)
 150 +            if(left[leftOfs+j]!=right[j])
 151 +                return false;
 152 +        return true;
 153 +    }
 154 +
 155      static private String VIEWPATH_PARAMETER   = "viewpath";
 156  }
 157 diff -urP --ignore-space-change orig/src/CH/ifa/draw/twiki/TWikiFrame.java moin-utf8/src/CH/ifa/draw/twiki/TWikiFrame.java
 158 --- orig/src/CH/ifa/draw/twiki/TWikiFrame.java	2005-03-08 17:59:34.000000000 +0000
 159 +++ moin-utf8/src/CH/ifa/draw/twiki/TWikiFrame.java	2005-11-27 23:45:30.000000000 +0000
 160 @@ -20,6 +20,7 @@
 161  import CH.ifa.draw.applet.*;
 162  import CH.ifa.draw.contrib.*;
 163  //import SVG.wiki.*;
 164 +import com.keypoint.PngEncoderIndexed;
 165  
 166  import java.awt.*;
 167  import java.awt.event.*;
 168 @@ -37,8 +38,10 @@
 169      static private String UNTITLED_PARAMETER   = "untitled";
 170      static private String DRAWPATH_PARAMETER   = "drawpath";
 171      static private String GIFPATH_PARAMETER    = "gifpath";
 172 +    static private String PNGPATH_PARAMETER    = "pngpath";
 173      static private String SVGPATH_PARAMETER    = "svgpath";
 174      static private String SAVEPATH_PARAMETER   = "savepath";
 175 +    static private String BASENAME_PARAMETER   = "basename";
 176      static private String HELPPATH_PARAMETER   = "helppath";
 177      static private String BORDERSIZE_PARAMETER = "bordersize";
 178      
 179 @@ -361,8 +364,8 @@
 180      
 181      public boolean doSaveDrawing() {
 182          Application app = getApplication();
 183 -        boolean savedDraw, savedSvg, savedGif, savedMap;
 184 -        savedDraw = savedSvg = savedGif = savedMap = false;
 185 +        boolean savedDraw, savedSvg, savedGif, savedPng, savedMap;
 186 +        savedDraw = savedSvg = savedGif = savedPng = savedMap = false;
 187          
 188          // set wait cursor
 189          setCursor(new Cursor(Cursor.WAIT_CURSOR));
 190 @@ -387,14 +390,19 @@
 191              if (savePath == null)
 192                  savePath = "";
 193              
 194 +            // gets base filename
 195 +            String baseName = app.getParameter(BASENAME_PARAMETER);
 196 +            if (baseName == null)
 197 +                baseName = "SET_BASENAME_PARAM";
 198 +
 199              // submit POST command to the server three times:
 200 -            // *.draw, *.map and *.gif
 201 +            // *.draw, *.map, *.png and *.gif
 202              // first upload *.draw file
 203 -            showStatus("Saving .draw file " + drawingPath);
 204 +            showStatus("Saving " + baseName + ".draw");
 205              if (bPostEnabled)
 206                  savedDraw = app.post(
 207 -                                     savePath, "", "text/plain", drawingPath,
 208 -                                     out.toString(), "TWiki Draw draw file");
 209 +                                     savePath, baseName + ".draw", "text/plain", drawingPath,
 210 +                                     out.toByteArray(), "TWiki Draw draw file");
 211              
 212              // calculate the minimum size of the gif image
 213              Dimension d = new Dimension(0, 0); // not this.view().getSize();
 214 @@ -423,7 +431,7 @@
 215              String map = drawing().getMap();
 216              if (map.length() > 0) {
 217                  String mapPath = drawingPath.substring(0, drawingPath.length() - 5) + ".map";
 218 -                showStatus("Saving .map file " + mapPath);
 219 +                showStatus("Saving " + baseName + ".map");
 220                  // enclose the map and add editable border. Note that the
 221                  // edit border is added LAST so the earlier AREAs take
 222                  // precedence.
 223 @@ -452,12 +460,12 @@
 224                      
 225                      "</map>";
 226                  savedMap = app.post(
 227 -                                    savePath, "", "text/plain", mapPath,
 228 -                                    map, "TWiki Draw map file");
 229 +                                    savePath, baseName + ".map", "text/plain", mapPath + ".map",
 230 +                                    map.getBytes(), "TWiki Draw map file");
 231              } else {
 232                  // erase any previous map file
 233                  String mapPath = drawingPath.substring(0, drawingPath.length() - 5);
 234 -                savedMap = app.post( savePath, "", "text/plain", mapPath + ".map", "", "" );
 235 +                savedMap = app.post( savePath, baseName + ".map", "text/plain", mapPath + ".map", new byte[0], "" );
 236              }
 237              
 238              // get pathname of the SVG file
 239 @@ -477,24 +485,38 @@
 240              // gets pathname of the GIF image
 241              String gifPath = getApplication().getParameter(GIFPATH_PARAMETER);
 242              if (gifPath == null || gifPath.length() == 0)
 243 -                gifPath = "untitled.gif";
 244 -            
 245 -            // then create *.gif image and upload file
 246 -            showStatus("Saving .gif file " + gifPath);
 247 +                gifPath = null;
 248              
 249 -            // clear the selection so it doesn't appear
 250 -            view().clearSelection();
 251 -            
 252 -            final Image oImgBuffer =
 253 -                this.view().createImage(d.width + iBorder, d.height + iBorder);
 254 -            final char[] aChar = convertToGif(oImgBuffer);
 255 +            // gets pathname of the PNG image
 256 +            String pngPath = getApplication().getParameter(PNGPATH_PARAMETER);
 257 +            if (pngPath == null || pngPath.length() == 0) 
 258 +                pngPath = null;
 259 +
 260 +            if (gifPath != null || pngPath != null) {
 261 +                final Image oImgBuffer = createImage(d, iBorder);
 262 +            
 263 +                if (bPostEnabled && pngPath != null)
 264 +                {
 265 +                    // then create *.png image and upload file
 266 +                    showStatus("Saving " + baseName + ".png");
 267 +                    final byte[] aByte = convertToPng(oImgBuffer);
 268 +                    // upload *.png file
 269 +                    savedPng = app.post(savePath, baseName + ".png", "image/png",
 270 +                                        pngPath, aByte, 
 271 +                                        "TWiki Draw PNG file");
 272 +                }
 273              
 274 +                if (bPostEnabled && gifPath != null)
 275 +                {
 276 +                    // then create *.gif image and upload file
 277 +                    showStatus("Saving " + baseName + ".gif");
 278 +                    final byte[] aByte = convertToGif(oImgBuffer);
 279              // upload *.gif file
 280 -            if (bPostEnabled)
 281 -                savedGif = app.post(
 282 -                                    savePath, "", "image/gif",
 283 -                                    gifPath, String.valueOf(aChar, 0, aChar.length),
 284 +                    savedGif = app.post(savePath, baseName + ".gif", "image/gif",
 285 +                                        gifPath, aByte,
 286                                      "TWiki Draw GIF file");
 287 +                }
 288 +            }
 289          } catch (MalformedURLException e) {
 290              this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 291              showStatus("Bad Wiki servlet URL: "+e.getMessage());
 292 @@ -506,7 +528,8 @@
 293          this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 294          showStatus("Saved .draw " + (savedDraw ? "OK" : "Failed") +
 295                     " .map " + (savedMap ? "OK" : "Failed") +
 296 -                   " .gif " + (savedGif ? "OK" : "Failed"));
 297 +                   " .gif " + (savedGif ? "OK" : "Failed") +
 298 +                   " .png " + (savedPng ? "OK" : "Failed"));
 299          return savedDraw;
 300      }
 301      
 302 @@ -523,12 +546,11 @@
 303      	System.err.println("TWikiDraw:" + msg);
 304      }
 305      
 306 -    /**
 307 -     * convert Image to GIF-encoded data, reducing the number of colors
 308 -     * if needed. Added by Bertrand Delacretaz
 309 -     */
 310 -    private char [] convertToGif(Image oImgBuffer) throws IOException {
 311 -        debug("converting data to GIF...");
 312 +    private Image createImage(Dimension d, int iBorder) {
 313 +        // clear the selection so it doesn't appear
 314 +        view().clearSelection();
 315 +        final Image oImgBuffer =
 316 +           this.view().createImage(d.width + iBorder, d.height + iBorder);
 317          Graphics oGrf = oImgBuffer.getGraphics();
 318          this.view().enableGuides(false);
 319          this.view().drawAll(oGrf);
 320 @@ -539,8 +561,16 @@
 321          //tf.setImage(oImgBuffer);
 322          //tf.show();
 323  		
 324 -        ByteArrayOutputStream oOut = null;
 325 +        return oImgBuffer;
 326 +    }
 327  		
 328 +    /**
 329 +     * convert Image to GIF-encoded data, reducing the number of colors
 330 +     * if needed. Added by Bertrand Delacretaz
 331 +     */
 332 +    private byte [] convertToGif(Image oImgBuffer) throws IOException {
 333 +        debug("converting data to GIF...");
 334 +        ByteArrayOutputStream oOut = null;
 335          try {
 336              oOut = new ByteArrayOutputStream();
 337              new GifEncoder(oImgBuffer,oOut).encode();
 338 @@ -555,12 +585,19 @@
 339          }
 340          
 341          byte[] aByte = oOut.toByteArray();
 342 -        int size = oOut.size();
 343 -        char[] aChar = new char[size];
 344 -        for (int i = 0; i < size; i++) {
 345 -            aChar[i] = (char)aByte[i];
 346 -        }
 347          debug("conversion to GIF successful.");
 348 -        return aChar;
 349 +        return aByte;
 350 +    }
 351 +
 352 +    /**
 353 +     * convert Image to PNG-encoded data
 354 +     * Added by OliverGraf
 355 +     */
 356 +    private byte [] convertToPng(Image oImgBuffer) throws IOException {
 357 +        debug("converting data to PNG...");
 358 +        PngEncoderIndexed oEncode = new PngEncoderIndexed(oImgBuffer);
 359 +        byte[] aByte = oEncode.pngEncode();
 360 +        debug("conversion to PNG successful."); 
 361 +        return aByte;
 362      }
 363  }
 364 diff -urP --ignore-space-change orig/src/CH/ifa/draw/util/StorableInput.java moin-utf8/src/CH/ifa/draw/util/StorableInput.java
 365 --- orig/src/CH/ifa/draw/util/StorableInput.java	2004-11-22 16:00:00.000000000 +0000
 366 +++ moin-utf8/src/CH/ifa/draw/util/StorableInput.java	2005-11-27 23:46:28.000000000 +0000
 367 @@ -27,8 +27,12 @@
 368       * Initializes a Storable input with the given input stream.
 369       */
 370      public StorableInput(InputStream stream) {
 371 -        Reader r = new BufferedReader(new InputStreamReader(stream));
 372 +        try {
 373 +            Reader r = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
 374          fTokenizer = new StreamTokenizer(r);
 375 +        } catch(UnsupportedEncodingException ex) {
 376 +            throw new RuntimeException(ex.getMessage());
 377 +        }
 378          fMap = new Vector();
 379      }
 380  
 381 @@ -68,7 +72,7 @@
 382      public String readString() throws IOException {
 383          int token = fTokenizer.nextToken();
 384          if (token == StreamTokenizer.TT_WORD || token == '"') {
 385 -            return unescapeUnicode(fTokenizer.sval);
 386 +            return fTokenizer.sval;
 387          }
 388  
 389          String msg = "String expected in line: " + fTokenizer.lineno();
 390 diff -urP --ignore-space-change orig/src/CH/ifa/draw/util/StorableOutput.java moin-utf8/src/CH/ifa/draw/util/StorableOutput.java
 391 --- orig/src/CH/ifa/draw/util/StorableOutput.java	2004-11-22 16:01:38.000000000 +0000
 392 +++ moin-utf8/src/CH/ifa/draw/util/StorableOutput.java	2005-11-27 23:41:16.000000000 +0000
 393 @@ -28,7 +28,12 @@
 394       * Initializes the StorableOutput with the given output stream.
 395       */
 396      public StorableOutput(OutputStream stream) {
 397 -        fStream = new PrintWriter(stream);
 398 +        try {
 399 +            fStream = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
 400 +        } catch(UnsupportedEncodingException ex) {
 401 +            throw new RuntimeException(ex.getMessage());
 402 +        }
 403 +
 404          fMap = new Vector();
 405          fIndent = 0;
 406      }
 407 @@ -100,27 +105,14 @@
 408          for(int i = 0; i < s.length(); i++) {
 409              char c = s.charAt(i);
 410              switch(c) {
 411 -                // RobWalker 17 Jul 2003 - suppress \r
 412 -            case '\r': break;
 413 +            case '\r': fStream.print('\\'); fStream.print('r'); break;
 414              case '\n': fStream.print('\\'); fStream.print('n'); break;
 415              case '"' : fStream.print('\\'); fStream.print('"'); break;
 416              case '\\': fStream.print('\\'); fStream.print('\\'); break;
 417 -            case '\t': fStream.print('\\'); fStream.print('\t'); break;
 418 -            default:
 419 -                if ((c >= 0x0001) && (c <= 0x007F)) {
 420 -                    fStream.print(c);
 421 -                } else {
 422 -                    String hex = Integer.toHexString(c);
 423 -                    switch (hex.length()) {
 424 -                    case 1:  fStream.print("\\\\u000" + hex); break;
 425 -                    case 2:  fStream.print("\\\\u00" + hex); break;
 426 -                    case 3:  fStream.print("\\\\u0" + hex); break;
 427 -                    default: fStream.print("\\\\u" + hex); break;
 428 -                    }
 429 +            case '\t': fStream.print('\\'); fStream.print('t'); break;
 430 +            default: fStream.print(c);
 431  	            }
 432              }
 433 -
 434 -        }
 435          fStream.print('"');
 436          space();
 437      }
 438 --- orig/src/CH/ifa/draw/twiki/StandAlone.java	2005-03-08 18:10:00.000000000 +0000
 439 +++ moin-utf8/src/CH/ifa/draw/twiki/StandAlone.java	2005-11-28 22:11:50.000000000 +0000
 440 @@ -62,13 +62,13 @@
 441                          String fileName,
 442                          String type,
 443                          String path,
 444 -                        String content,
 445 +                        byte[] content,
 446                          String comment) {
 447          System.out.println("Post URL " + url +
 448                             " fileName " + fileName +
 449                             " type " + type +
 450                             " path " + path +
 451 -                           " content " + content +
 452 +                           " content " + new String(content) +
 453                             " comment " + comment);
 454          return false;
 455      }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-01-19 16:58:45, 10.0 KB) [[attachment:TO.tdraw]]
  • [get | view] (2005-11-28 21:54:52, 173.7 KB) [[attachment:TWikiDrawPlugin-1.103-OliverGraf-source.zip]]
  • [get | view] (2005-11-28 21:58:04, 174.0 KB) [[attachment:TWikiDrawPlugin-1.103-utf8-source.zip]]
  • [get | view] (2005-12-27 01:48:17, 170.3 KB) [[attachment:TWikiDrawPlugin-OliverGraf-SourceTree.zip]]
  • [get | view] (2009-09-19 19:46:07, 10.0 KB) [[attachment:anotherTest.tdraw]]
  • [get | view] (2004-02-07 18:31:10, 0.8 KB) [[attachment:mapname.diff]]
  • [get | view] (2012-10-22 07:10:47, 30.0 KB) [[attachment:meintest.tdraw]]
  • [get | view] (2010-09-20 14:11:48, 10.0 KB) [[attachment:mytest.tdraw]]
  • [get | view] (2010-12-28 18:33:16, 10.0 KB) [[attachment:new.tdraw]]
  • [get | view] (2005-09-12 16:36:38, 181.8 KB) [[attachment:newline_fix_twikidraw-sources.zip]]
  • [get | view] (2005-09-12 16:36:24, 205.5 KB) [[attachment:newline_fix_twikidraw.jar]]
  • [get | view] (2005-11-28 21:55:38, 185.3 KB) [[attachment:twikidraw-1.103-OliverGraf.jar]]
  • [get | view] (2005-11-28 21:56:32, 10.3 KB) [[attachment:twikidraw-1.103-full.diff]]
  • [get | view] (2005-11-28 21:58:29, 19.5 KB) [[attachment:twikidraw-1.103-utf8.diff]]
  • [get | view] (2005-11-28 21:57:38, 185.6 KB) [[attachment:twikidraw-1.103-utf8.jar]]
  • [get | view] (2004-02-07 20:44:17, 11.0 KB) [[attachment:twikidraw-full.diff]]
  • [get | view] (2004-02-07 20:44:26, 10.0 KB) [[attachment:twikidraw-png.zip]]
  • [get | view] (2004-02-07 20:44:47, 174.8 KB) [[attachment:twikidraw-sources.zip]]
  • [get | view] (2004-02-07 20:45:08, 184.3 KB) [[attachment:twikidraw.jar]]
  • [get | view] (2009-02-26 06:31:19, 1.1 KB) [[attachment:twikidrawbuild.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.