Exemple #1
0
 /**
  * Peturn parser to pool
  *
  * @param parser
  */
 protected void reuseParser(HtmlParser parser) {
   if (null != parser) {
     if (parser instanceof NekkoParser) {
       synchronized (_xhtmlParsersPool) {
         if (_xhtmlParsersPool.size() < STACK_SIZE) {
           ((NekkoParser) parser).reset();
           _xhtmlParsersPool.push(parser);
         }
       }
     }
   }
 }
Exemple #2
0
 /**
  * Factory method for create parsing object - contain chain of parsing, transformation and
  * serialization of response output
  *
  * @param string Encodings for parser
  * @return
  * @throws ServletException
  */
 protected HtmlParser getXmlParser(String mime) {
   // TODO make pool of parsers-transformers.
   NekkoParser parser;
   try {
     synchronized (_xhtmlParsersPool) {
       parser = (NekkoParser) _xhtmlParsersPool.pop();
     }
   } catch (EmptyStackException e) {
     parser = new NekkoParser();
     parser.setPublicId(getPublicid());
     parser.setSystemid(getSystemid());
     parser.setNamespace(getNamespace());
     // If tidy not handle all requests, disable reorganising of html
     //			parser.setMoveElements(isForcexml());
     parser.init();
   }
   parser.setMime(mime);
   // TODO - set header scripts/styles filter.
   return parser;
 }
Exemple #3
0
  public static List findCycles(DigraphIteration graph) {
    ArrayStack stack = new ArrayStack();
    ArrayStack path = new ArrayStack();
    Set seen = new HashSet();
    List cycles = new ArrayList();
    Iterator vertexIterator = graph.vertexIterator();

    while (vertexIterator.hasNext()) {
      while (vertexIterator.hasNext()) {
        Object vertex = vertexIterator.next();
        if (seen.add(vertex)) {
          stack.push(graph.outgoingIterator(vertex));
          path.push(vertex);
          break;
        }
      }

      while (!stack.isEmpty()) {
        ArcIterator i = (ArcIterator) stack.peek();
        Object origin = i.getOrigin();
        boolean subtreeIsTraversed = true;
        while (i.hasNext()) {
          i.next();
          Object dst = i.getDestination();
          int index = path.indexOf(dst);
          if (index < 0) {
            seen.add(dst);
            stack.push(graph.outgoingIterator(dst));
            path.push(dst);
            subtreeIsTraversed = false;
            break;
          } else {
            cycles.add(new ArrayList(path.subList(index, path.size())));
          }
        }
        if (subtreeIsTraversed) {
          stack.pop();
          path.pop();
        }
      }
    }
    return cycles;
  }