private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
示例#2
0
 void setFormData(WObject.FormData formData) {
   if (!(formData.values.length == 0)) {
     List<String> attributes = new ArrayList<String>();
     attributes = new ArrayList<String>(Arrays.asList(formData.values[0].split(";")));
     if (attributes.size() == 6) {
       try {
         this.volume_ = Double.parseDouble(attributes.get(0));
       } catch (RuntimeException e) {
         this.volume_ = -1;
       }
       try {
         this.current_ = Double.parseDouble(attributes.get(1));
       } catch (RuntimeException e) {
         this.current_ = -1;
       }
       try {
         this.duration_ = Double.parseDouble(attributes.get(2));
       } catch (RuntimeException e) {
         this.duration_ = -1;
       }
       this.playing_ = attributes.get(3).equals("0");
       this.ended_ = attributes.get(4).equals("1");
       try {
         this.readyState_ = intToReadyState(Integer.parseInt(attributes.get(5)));
       } catch (RuntimeException e) {
         throw new WException(
             "WAbstractMedia: error parsing: " + formData.values[0] + ": " + e.toString());
       }
     } else {
       throw new WException("WAbstractMedia: error parsing: " + formData.values[0]);
     }
   }
 }
 public Enumeration<String> getHeaders(String s) {
   String[] values = headerMap.get(s);
   if (values == null) {
     return null;
   }
   return Collections.enumeration(Arrays.asList(values));
 }
示例#4
0
 @Override
 public void flush() throws IOException {
   synchronized (statusLock) {
     // Make sure HTTP status and header is specified.
     statusLock.notifyAll();
   }
   byte[] b = Arrays.copyOf(buffer, offset);
   target.write(b);
   offset = 0;
 }
示例#5
0
 public String getPageIds(ClientRequest cr) {
   HttpSession session = cr.getServletRequest().getSession();
   PageState.AllPageInfo info = (PageState.AllPageInfo) session.getAttribute("fiz.PageState");
   if (info == null) {
     return "";
   }
   Object[] keys = info.keySet().toArray();
   Arrays.sort(keys);
   return StringUtil.join(keys, ", ");
 }
 @Override
 public String batchDelete(
     Model model,
     @RequestParam("items") Long[] items,
     HttpServletRequest request,
     HttpServletResponse response)
     throws RebirthException {
   List<CircleTopicEntity> list =
       circleService.findByIds(CircleTopicEntity.class, Arrays.asList(items));
   circleService.delete(list);
   return "circle/circleDeatil";
 }
 private InputStream getReport(
     HttpServletRequest request,
     HttpServletResponse response,
     Tab tab,
     TableModel tableModel,
     Integer columnCountLimit)
     throws ServletException, IOException {
   StringBuffer suri = new StringBuffer();
   suri.append("/xava/jasperReport");
   suri.append("?language=");
   suri.append(Locales.getCurrent().getLanguage());
   suri.append("&widths=");
   suri.append(Arrays.toString(getWidths(tableModel)));
   if (columnCountLimit != null) {
     suri.append("&columnCountLimit=");
     suri.append(columnCountLimit);
   }
   response.setCharacterEncoding(XSystem.getEncoding());
   return Servlets.getURIAsStream(request, response, suri.toString());
 }
 static void decodeTouches(String str, List<Touch> result) {
   if (str.length() == 0) {
     return;
   }
   List<String> s = new ArrayList<String>();
   s = new ArrayList<String>(Arrays.asList(str.split(";")));
   if (s.size() % 9 != 0) {
     logger.error(
         new StringWriter()
             .append("Could not parse touches array '")
             .append(str)
             .append("'")
             .toString());
     return;
   }
   try {
     for (int i = 0; i < s.size(); i += 9) {
       result.add(
           new Touch(
               asUInt(s.get(i + 0)),
               asInt(s.get(i + 1)),
               asInt(s.get(i + 2)),
               asInt(s.get(i + 3)),
               asInt(s.get(i + 4)),
               asInt(s.get(i + 5)),
               asInt(s.get(i + 6)),
               asInt(s.get(i + 7)),
               asInt(s.get(i + 8))));
     }
   } catch (NumberFormatException ee) {
     logger.error(
         new StringWriter()
             .append("Could not parse touches array '")
             .append(str)
             .append("'")
             .toString());
     return;
   }
 }
示例#9
0
  /**
   * Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to
   * the given directory, and limiting the upload size to the specified length. If the content is
   * too large, an IOException is thrown. This constructor actually parses the
   * <tt>multipart/form-data</tt> and throws an IOException if there's any problem reading or
   * parsing the request.
   *
   * <p>To avoid file collisions, this constructor takes an implementation of the FileRenamePolicy
   * interface to allow a pluggable rename policy.
   *
   * @param request the servlet request.
   * @param saveDirectory the directory in which to save any uploaded files.
   * @param maxPostSize the maximum size of the POST content.
   * @param encoding the encoding of the response, such as ISO-8859-1
   * @param policy a pluggable file rename policy
   * @exception IOException if the uploaded content is larger than <tt>maxPostSize</tt> or there's a
   *     problem reading or parsing the request.
   */
  public CosMultipartRequest(
      HttpServletRequest request,
      String saveDirectory,
      int maxPostSize,
      String encoding,
      FileRenamePolicy policy)
      throws IOException {
    // Sanity check values
    if (request == null) throw new IllegalArgumentException("request cannot be null");
    if (saveDirectory == null) throw new IllegalArgumentException("saveDirectory cannot be null");
    if (maxPostSize <= 0) {
      throw new IllegalArgumentException("maxPostSize must be positive");
    }

    // Save the dir
    File dir = new File(saveDirectory);

    // Check saveDirectory is truly a directory
    if (!dir.isDirectory()) throw new IllegalArgumentException("Not a directory: " + saveDirectory);

    // Check saveDirectory is writable
    if (!dir.canWrite()) throw new IllegalArgumentException("Not writable: " + saveDirectory);

    // Parse the incoming multipart, storing files in the dir provided,
    // and populate the meta objects which describe what we found
    MultipartParser parser = new MultipartParser(request, maxPostSize, true, true, encoding);

    // Some people like to fetch query string parameters from
    // MultipartRequest, so here we make that possible.  Thanks to
    // Ben Johnson, [email protected], for the idea.
    if (request.getQueryString() != null) {
      // Let HttpUtils create a name->String[] structure
      Map<String, String[]> queryParameters =
          RequestUtils.parseQueryString(request.getQueryString());
      // For our own use, name it a name->Vector structure
      for (Entry<String, String[]> entry : queryParameters.entrySet()) {
        parameters.put(entry.getKey(), Arrays.asList(entry.getValue()));
      }
    }

    Part part;
    while ((part = parser.readNextPart()) != null) {
      String name = part.getName();
      if (name == null) {
        throw new IOException("Malformed input: parameter name missing (known Opera 7 bug)");
      }
      if (part.isParam()) {
        // It's a parameter part, add it to the vector of values
        ParamPart paramPart = (ParamPart) part;
        String value = paramPart.getStringValue();
        List<String> existingValues = parameters.get(name);
        if (existingValues == null) {
          existingValues = new ArrayList<String>();
          parameters.put(name, existingValues);
        }
        existingValues.add(value);
      } else if (part.isFile()) {
        // It's a file part
        FilePart filePart = (FilePart) part;
        String fileName = filePart.getFileName();
        if (fileName != null) {
          filePart.setRenamePolicy(policy); // null policy is OK
          // The part actually contained a file
          filePart.writeTo(dir);
          files.put(
              name,
              new UploadedFile(
                  dir.toString(), filePart.getFileName(), fileName, filePart.getContentType()));
        } else {
          // The field did not contain a file
          files.put(name, new UploadedFile(null, null, null, null));
        }
      }
    }
  }
示例#10
0
 @Override
 public Collection<String> getHeaders(String name) {
   return Arrays.asList(this.response.getHeaders().get(name).split(","));
 }
示例#11
0
 public String getPropertyNames(PageState state) {
   Object[] keys = state.properties.keySet().toArray();
   Arrays.sort(keys);
   return StringUtil.join(keys, ", ");
 }