/** Destructor. */
 public void remove() {
   for (Iterator<Map.Entry<Long, WImage>> it_it = this.grid_.entrySet().iterator();
       it_it.hasNext(); ) {
     Map.Entry<Long, WImage> it = it_it.next();
     ;
     if (it.getValue() != null) it.getValue().remove();
   }
   super.remove();
 }
 /**
  * Regenerates and redraws the image pieces.
  *
  * <p>This method invalidates all current grid images, and recreates them.
  */
 public void redrawAll() {
   for (Iterator<Map.Entry<Long, WImage>> it_it = this.grid_.entrySet().iterator();
       it_it.hasNext(); ) {
     Map.Entry<Long, WImage> it = it_it.next();
     ;
     if (it.getValue() != null) it.getValue().remove();
   }
   this.grid_.clear();
   this.generateGridItems(this.currentX_, this.currentY_);
 }
Example #3
0
 /**
  * OPTION requests are treated as CORS preflight requests
  *
  * @param req the original request
  * @param resp the response the answer are written to
  */
 @Override
 protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   Map<String, String> responseHeaders =
       requestHandler.handleCorsPreflightRequest(
           req.getHeader("Origin"), req.getHeader("Access-Control-Request-Headers"));
   for (Map.Entry<String, String> entry : responseHeaders.entrySet()) {
     resp.setHeader(entry.getKey(), entry.getValue());
   }
 }
  /**
   * Parses HTTP parameters in an appropriate format and return back map of values to predefined
   * list of names.
   *
   * @param req Request.
   * @return Map of parsed parameters.
   */
  @SuppressWarnings({"unchecked"})
  private Map<String, Object> parameters(ServletRequest req) {
    Map<String, String[]> params = req.getParameterMap();

    if (F.isEmpty(params)) return Collections.emptyMap();

    Map<String, Object> map = U.newHashMap(params.size());

    for (Map.Entry<String, String[]> entry : params.entrySet())
      map.put(entry.getKey(), parameter(entry.getValue()));

    return map;
  }
Example #5
0
  @Nullable
  public String getMapping() {
    final StringBuilder sb = new StringBuilder();

    for (Map.Entry<Pattern, ScopeMapping> patternAndMapping : _patternToMapping.entrySet()) {
      if (patternAndMapping.getKey() != null) {
        if (sb.length() > 0) {
          sb.append(",\n");
        }
        sb.append(patternAndMapping.getKey())
            .append('>')
            .append(patternAndMapping.getValue().getDefaultName());
      }
    }

    return sb.length() > 0 ? sb.toString() : null;
  }
 private void cleanGrid() {
   WVirtualImage.Rect cleanNb =
       this.neighbourhood(
           this.currentX_, this.currentY_, this.viewPortWidth_ * 3, this.viewPortHeight_ * 3);
   long i1 = cleanNb.x1 / this.gridImageSize_;
   long j1 = cleanNb.y1 / this.gridImageSize_;
   long i2 = cleanNb.x2 / this.gridImageSize_ + 1;
   long j2 = cleanNb.y2 / this.gridImageSize_ + 1;
   for (Iterator<Map.Entry<Long, WImage>> it_it = this.grid_.entrySet().iterator();
       it_it.hasNext(); ) {
     Map.Entry<Long, WImage> it = it_it.next();
     WVirtualImage.Coordinate coordinate = new WVirtualImage.Coordinate();
     this.decodeKey(it.getKey(), coordinate);
     if (coordinate.i < i1 || coordinate.i > i2 || coordinate.j < j1 || coordinate.j > j2) {;
       if (it.getValue() != null) it.getValue().remove();
       it_it.remove();
     } else {
     }
   }
 }
Example #7
0
 @Nullable
 protected ScopeMapping getMappingFor(@Nonnull String path) {
   ScopeMapping mapping;
   synchronized (_pathToMappingCache) {
     mapping = _pathToMappingCache.get(path);
   }
   if (mapping == null) {
     for (Map.Entry<Pattern, ScopeMapping> patternAndScope : _patternToMapping.entrySet()) {
       final Pattern pattern = patternAndScope.getKey();
       if (pattern != null && pattern.matcher(path).matches()) {
         mapping = patternAndScope.getValue();
         break;
       }
     }
     synchronized (_pathToMappingCache) {
       _pathToMappingCache.put(path, mapping);
     }
   }
   return mapping;
 }
  public ReaderHandler(LowLevelDbAccess lowLevelDbAccess, String webDir) {

    loginInfoDb = new LoginInfo.DB(lowLevelDbAccess);
    userDb = new User.DB(lowLevelDbAccess);
    feedDb = new Feed.DB(lowLevelDbAccess);
    articleDb = new Article.DB(lowLevelDbAccess);
    readArticlesCollDb = new ReadArticlesColl.DB(lowLevelDbAccess);
    userHelpers = new UserHelpers(loginInfoDb, userDb);

    setContextPath("/");

    File warPath = new File(webDir);
    setWar(warPath.getAbsolutePath());

    if (isInJar) {
      for (Map.Entry<String, String> entry : PATH_MAPPING.entrySet()) {
        addPrebuiltJsp(entry.getKey(), "jsp." + entry.getValue().replaceAll("_", "_005f") + "_jsp");
      }
    } else {
      for (Map.Entry<String, String> entry : PATH_MAPPING.entrySet()) {
        addServlet(
            new ServletHolder(new RedirectServlet("/" + entry.getValue() + ".jsp")),
            entry.getKey());
      }
    }

    setErrorHandler(new ReaderErrorHandler());
  }
  /**
   * Builds the vendor events tree.
   *
   * @param notice the selected notification so that events that match this notification can be
   *     preselected
   * @param vendorExcludeList a list of vendors to exclude from the result
   * @return an xml tree of vendors and their events
   */
  public String buildTree(Notification notice, List vendorExcludeList)
      throws IOException, FileNotFoundException {
    StringBuffer buffer = new StringBuffer();
    String itemPrefix = "i_";
    String sectionPrefix = "s_";
    int sid = 1, iid = 1;
    List ueiExcludeList = NotificationWizardServlet.getExcludeList();

    buffer
        .append("<xTree>")
        .append("<item id=\"")
        .append(sectionPrefix)
        .append(sid)
        .append("\">")
        .append("<itemPrimaryData><![CDATA[System Monitoring Events]]></itemPrimaryData>")
        .append("<subitems>");

    List vendors = EventConfigurationManager.getVendorNames();
    for (Iterator iter = vendors.iterator(); iter.hasNext(); ) {
      String vendor = (String) iter.next();

      // Don't show any excluded vendors
      if (vendorExcludeList != null && vendorExcludeList.contains(vendor)) {
        continue;
      }

      sid++;

      buffer
          .append("<item id=\"")
          .append(sectionPrefix)
          .append(sid)
          .append("\">")
          .append("<itemPrimaryData><![CDATA[<input type=\"checkbox\" id=\"c_")
          .append(sectionPrefix)
          .append(sid)
          .append("\" onClick=\"tcs('")
          .append(sectionPrefix)
          .append(sid)
          .append("');us()\">");

      // Write the vendor name
      buffer.append(vendor);

      buffer.append("]]></itemPrimaryData>").append("<subitems>");

      // Now write all the events for the vendor.
      List eventVendors = EventConfigurationManager.getEventsByVendor(vendor);
      SortedMap sortedEvents = (SortedMap) new TreeMap();
      for (Iterator iter2 = eventVendors.iterator(); iter2.hasNext(); ) {
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) iter2.next();
        sortedEvents.put(e.getLabel(), e);
      }

      for (Iterator iter2 = sortedEvents.entrySet().iterator(); iter2.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter2.next();
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) entry.getValue();
        String uei = e.getUei();

        if (!ueiExcludeList.contains(NotificationWizardServlet.stripUei(uei))) {
          iid++;
          boolean inNotification = NotificationWizardServlet.isEventInNotification(notice, e);

          buffer
              .append("<item id=\"")
              .append(itemPrefix)
              .append(iid)
              .append("\">")
              .append(
                  "<itemPrimaryData><![CDATA[<input type=\"checkbox\" name=\"tree_check\" id=\"c_")
              .append(itemPrefix)
              .append(iid)
              .append("\" value=\"")
              .append(e.getId())
              .append("\" onClick=\"us()\"")
              .append((inNotification ? " checked" : ""))
              .append(">");

          // Write the event info
          buffer.append(e.getLabel());

          buffer.append("]]></itemPrimaryData>").append("</item>");
        }
      }

      buffer.append("</subitems></item>");
    }

    buffer.append("</subitems></item></xTree>");

    return buffer.toString();
  }
Example #10
0
  private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds)
      throws IOException, DataSourceException, ServletException, DazzleException {

    DazzleReferenceSource drs = (DazzleReferenceSource) dds;

    List segments = DazzleTools.getSegments(dds, req, resp);
    if (segments.size() == 0) {
      throw new DazzleException(
          DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command");
    }

    // Fetch and validate the requests.

    Map segmentResults = new HashMap();
    for (Iterator i = segments.iterator(); i.hasNext(); ) {
      Segment seg = (Segment) i.next();

      try {
        Sequence seq = drs.getSequence(seg.getReference());
        if (seq.getAlphabet() != DNATools.getDNA()) {
          throw new DazzleException(
              DASStatus.STATUS_SERVER_ERROR,
              "Sequence " + seg.toString() + " is not in the DNA alphabet");
        }
        if (seg.isBounded()) {
          if (seg.getMin() < 1 || seg.getMax() > seq.length()) {
            throw new DazzleException(
                DASStatus.STATUS_BAD_COORDS,
                "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length());
          }
        }
        segmentResults.put(seg, seq);
      } catch (NoSuchElementException ex) {
        throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex);
      } catch (DataSourceException ex) {
        throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex);
      }
    }

    //
    // Looks okay -- generate the response document
    //

    XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd");

    try {
      xw.openTag("DASDNA");
      for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry me = (Map.Entry) i.next();
        Segment seg = (Segment) me.getKey();
        Sequence seq = (Sequence) me.getValue();

        xw.openTag("SEQUENCE");
        xw.attribute("id", seg.getReference());
        xw.attribute("version", drs.getLandmarkVersion(seg.getReference()));
        if (seg.isBounded()) {
          xw.attribute("start", "" + seg.getStart());
          xw.attribute("stop", "" + seg.getStop());
        } else {
          xw.attribute("start", "" + 1);
          xw.attribute("stop", "" + seq.length());
        }

        SymbolList syms = seq;
        if (seg.isBounded()) {
          syms = syms.subList(seg.getMin(), seg.getMax());
        }
        if (seg.isInverted()) {
          syms = DNATools.reverseComplement(syms);
        }

        xw.openTag("DNA");
        xw.attribute("length", "" + syms.length());

        for (int pos = 1; pos <= syms.length(); pos += 60) {
          int maxPos = Math.min(syms.length(), pos + 59);
          xw.println(syms.subStr(pos, maxPos));
        }

        xw.closeTag("DNA");
        xw.closeTag("SEQUENCE");
      }
      xw.closeTag("DASDNA");
      xw.close();
    } catch (Exception ex) {
      throw new DazzleException(ex, "Error writing DNA document");
    }
  }