Exemplo n.º 1
0
  private static void launchOtherOsFile(String filepath) throws IOException {
    String commandStr;
    if (MediaType.getVideoMediaType().isFilenameOf(filepath)) {
      commandStr = SystemToolsPrefs.OpenVideoCmdOtherOS.get();
    } else if (MediaType.getImageMediaType().isFilenameOf(filepath)) {
      commandStr = SystemToolsPrefs.OpenImageCmdOtherOS.get();
    } else if (MediaType.getAudioMediaType().isFilenameOf(filepath)) {
      commandStr = SystemToolsPrefs.OpenAudioCmdOtherOS.get();
    } else {
      commandStr = SystemToolsPrefs.OpenBrowserCmdOtherOS.get();
    }

    // Define a pattern which will split on spaces but respect quotes
    Pattern p = Pattern.compile("(\".*?\"|\\S+)", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(commandStr);
    List tokens = new LinkedList();
    while (m.find()) {
      tokens.add(m.group(1));
    }
    String[] result = new String[tokens.size()];
    tokens.toArray(result);

    StringBuffer replacedCmd = new StringBuffer();
    for (int i = 0; i < result.length; i++) {
      result[i] = StringUtils.replace(result[i], "%filepath%", filepath, -1);

      replacedCmd.append(result[i]);
      replacedCmd.append(" ");
    }
    NLogger.debug(SystemShellExecute.class, "Executing " + replacedCmd);
    Runtime.getRuntime().exec(result);
  }
 @Override
 public void setValue(Object value) {
   if (value instanceof MediaType) {
     MediaType mediaType = (MediaType) value;
     setText(Localizer.getString(mediaType.getName()));
     setToolTipText(mediaType.getFileTypesUIText());
   }
 }
 public MediaTypeModel() {
   conditionTypes = new Object[MediaType.getAllMediaTypes().length][2];
   MediaType[] mediaTypes = MediaType.getAllMediaTypes();
   Set types = condition.getTypes();
   for (int i = 0; i < mediaTypes.length; i++) {
     if (types.contains(mediaTypes[i])) {
       conditionTypes[i][0] = Boolean.TRUE;
     } else {
       conditionTypes[i][0] = Boolean.FALSE;
     }
     conditionTypes[i][1] = mediaTypes[i];
   }
 }