Project

General

Profile

GuiWebDriver.patch

Roger Borrello, 03/16/2021 09:15 AM

Download (4.08 KB)

View differences:

/home/rfb/projects/fwd/3821c_dev/src/com/goldencode/p2j/ui/client/gui/driver/web/GuiWebDriver.java
160 160
** 068 CA  20201011 Use a fast-access bitmap instead of an integer set.
161 161
**     EVL 20201027 Replacing hash map usage with simple array for storing scale cache to improve search time.
162 162
**     SBI 20210304 Changed openMimeResource according to its new specification.
163
**     RFB 20210316 Added handling of launcher protocol/mime-type using openLauncherResource helper for
164
**                  openMimeResource.
163 165
*/
164 166

  
165 167
/*
......
225 227
import java.io.*;
226 228
import java.lang.reflect.*;
227 229
import java.net.*;
230
import java.nio.charset.StandardCharsets;
228 231
import java.nio.channels.*;
229 232
import java.nio.file.*;
230 233
import java.util.function.*;
......
270 273
           DocumentOutputStorage,
271 274
           FileUploadStorage
272 275
{
276
   /** Special mime-type for the launcher. */
277
   private static final String LAUNCHER_MIME_TYPE = "application/fwd-local-launcher";
278

  
279
   /** Special scheme for launcher URI. */
280
   private static final String LAUNCHER_SCHEME = "launcher://";
281

  
273 282
   /** Taskbar height in pixels when it exists. */
274 283
   public static final int TASKBAR_HEIGHT = 32;
275 284
   
......
2752 2761
                                boolean embedded)
2753 2762
   throws URISyntaxException
2754 2763
   {
2755
      Uri wrappedUri = new Uri(uriString);
2756
      URI uri = wrappedUri.getUri();
2757
      boolean local = wrappedUri.isLocal();
2764
      URI uri;
2765
      boolean finalDelete = deleteContent;
2766
      String finalUri = uriString;
2767
      boolean finalEmbedded = embedded;
2768
      boolean local = true;
2769
      String launchFilePath = uriString;
2770
      String scheme = "file:///";
2771
      
2772
      try
2773
      {
2774
         uri = new URI(uriString);
2775
         scheme = uri.getScheme();
2776
         launchFilePath = uri.getPath();
2777
      }
2778
      catch(URISyntaxException e)
2779
      {
2780
         if (LAUNCHER_MIME_TYPE.equalsIgnoreCase(mimeType))
2781
         {
2782
             launchFilePath = uriString;
2783
         }
2784
      }
2785
      
2786
      if (LAUNCHER_MIME_TYPE.equalsIgnoreCase(mimeType) || LAUNCHER_SCHEME.equalsIgnoreCase(scheme))
2787
      {
2788
         finalDelete = true;
2789
         finalEmbedded = false;
2790
         try
2791
         {
2792
            finalUri = openLauncherResource(UiUtils.resolveLocalFileResource(launchFilePath));
2793
         }
2794
         catch(IOException e)
2795
         {
2796
             finalUri = uriString;
2797
         }
2798
      }
2799
      
2800
      Uri wrappedUri = new Uri(finalUri);
2801
      uri = wrappedUri.getUri();
2802
      local = wrappedUri.isLocal();
2758 2803
      
2759 2804
      String id = uri.toASCIIString();
2760 2805
      
......
2762 2807
      {
2763 2808
         File originalFile = Paths.get(uri).toFile();
2764 2809
         
2765
         id = resolveResourceId(deleteContent, mimeType, originalFile);
2766
      }
2767
      
2768
      websock.openMimeResource(id, mimeType, embedded, local);
2810
         id = resolveResourceId(finalDelete, mimeType, originalFile);
2811
      }
2812
      
2813
      websock.openMimeResource(id, mimeType, finalEmbedded, local);
2769 2814
   }
2770 2815
   
2771 2816
   /**
......
3090 3135
   }
3091 3136
   
3092 3137
   /**
3138
    * Create the wrapper for the launcher resource.
3139
    * 
3140
    * @param    uriString
3141
    *           The string presentation of the target resource.
3142
    * 
3143
    * @throws   IOException
3144
    *           If this string presentation of the target resource is not formatted strictly
3145
    *           according to to RFC2396 and cannot be converted to a URI.
3146
    * @throws   RuntimeException
3147
    *           For other IO errors during file operations.
3148
    */
3149
   private String openLauncherResource(String uriString)
3150
   throws IOException
3151
   {
3152
      Path wrapperFile  = Files.createTempFile("launcher", ".fwl");
3153
   
3154
      try
3155
      {
3156
         Files.write(wrapperFile, uriString.getBytes(StandardCharsets.UTF_8));
3157
         //wrapperFile.deleteOnExit();            
3158
      }
3159
      catch (IOException e)
3160
      {
3161
         e.printStackTrace();
3162
      }
3163
      
3164
      return "file:///" + wrapperFile.toString();
3165
   }
3166
   
3167
   /**
3093 3168
    * Detect MIME type of image.
3094 3169
    * 
3095 3170
    * @param   icon