Package org.archive.wayback.replay.html

Examples of org.archive.wayback.replay.html.ReplayParseContext


    // To make sure we get the length, we have to buffer it all up...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // set up the context:
        ReplayParseContext context = new ReplayParseContext(fact, url,
                timestamp);
    context.setOutputCharset(outputCharset);
    context.setOutputStream(baos);
    // jspExec is null for attribute rewrite tests.
    context.setJspExec(jspExec);
   
    // and finally, parse, using the special lexer that knows how to
    // handle javascript blocks containing unescaped HTML entities:
    Page lexPage = new Page(bais,charSet);
    Lexer lexer = new Lexer(lexPage);
View Full Code Here


        // NOTE: this compares output of Node.toHtml() with the original input.
        // there's a good chance of Node.toHtml() producing different text than original HTML.
        String out = servletOutput.getString();
        assertEquals("servlet output", payload, out);
       
        ReplayParseContext context = parseContextCapture.getValue();
        // testing indirectly because ReplayParseContext has no method returning baseUrl.
        assertEquals("baseUrl is correctly set up", "http://www.example.com/a.html", context.resolve("a.html"));
    }
View Full Code Here

        // NOTE: this compares output of Node.toHtml() with the original input.
        // there's a good chance of Node.toHtml() producing different text than original HTML.
        String out = servletOutput.getString();
        assertEquals("servlet output", payload, out);
       
        ReplayParseContext context = parseContextCapture.getValue();
        // testing indirectly because ReplayParseContext has no method returning baseUrl.
        assertEquals("baseUrl is correctly set up", "http://www.example.com/a.html", context.resolve("a.html"));
    }
View Full Code Here

        cut.renderResource(null, response, wbRequest, result, payloadResource, payloadResource, uriConverter, null);
       
        EasyMock.verify(nodeHandler, response, uriConverter);
       
        ReplayParseContext context = parseContextCapture.getValue();
        assertNotNull(context);
        // it's a kind of odd to use this constant defined in FastArchivalUrlReplayParseEventHandler.
        // ArchivalUrlSAXRewriteReplayRenderer is supposed not to be tied with particular ParseEventHandler
        // implementation.
        assertNotNull("FERRET_DONE flag is set",
                context.getData(FastArchivalUrlReplayParseEventHandler.FERRET_DONE_KEY));
    }
View Full Code Here

       
        cut.renderResource(null, response, wbRequest, result, payloadResource, payloadResource, uriConverter, null);
       
        EasyMock.verify(nodeHandler, response, uriConverter);
       
        ReplayParseContext context = parseContextCapture.getValue();
        assertNotNull(context);
        // it's kind of odd to use this constant defined in FastArchivalUrlReplayParseEventHandler.
        // ArchivalUrlSAXRewriteReplayRenderer is supposed not to be tied with particular ParseEventHandler
        // implementation.
        assertNull("FERRET_DONE flag is NOT set",
                context.getData(FastArchivalUrlReplayParseEventHandler.FERRET_DONE_KEY));
    }
View Full Code Here

    } else {
      fact = new IdentityResultURIConverterFactory(uriConverter);     
    }   
   
    // set up the context:
    ReplayParseContext context =
      new ReplayParseContext(fact,url,result.getCaptureTimestamp());
   
    context.setRewriteHttpsOnly(rewriteHttpsOnly);
   
    JSPExecutor jspExec = new JSPExecutor(uriConverter, httpRequest,
        httpResponse, wbRequest, results, result, resource);
   

    // To make sure we get the length, we have to buffer it all up...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    context.setOutputCharset("utf-8");
    context.setOutputStream(baos);
    context.setJspExec(jspExec);
    context.setInJS(true); //for https://webarchive.jira.com/browse/ARI-3762
   
    String policy = result.getOraclePolicy();
   
    if (policy != null) {
      context.putData(CaptureSearchResult.CAPTURE_ORACLE_POLICY, policy);
    }
   
    //RewriteReplayParseEventHandler.addRewriteParseContext(context);
   
   
View Full Code Here

         * @param node
         * @throws IOException
         */
        @Override
  public void handleNode(ParseContext pContext, Node node) throws IOException {
    ReplayParseContext context = (ReplayParseContext)pContext;
    if (NodeUtils.isRemarkNode(node)) {
      RemarkNode remarkNode = (RemarkNode)node;
      remarkNode.setText(jsBlockTrans.transform(context,
        remarkNode.getText()));
      emit(context, null, node, null);

    } else if (NodeUtils.isTextNode(node)) {
      TextNode textNode = (TextNode)node;
      if (context.isInCSS()) {
        handleCSSTextNode(context, textNode);
      } else if (context.isInScriptText()) {
        handleJSTextNode(context, textNode);
      }
      emit(context, null, textNode, null);
//        handleContentTextNode(context,textNode);
    } else if (NodeUtils.isTagNode(node)) {
      TagNode tagNode = (TagNode)node;

      if (tagNode.isEndTag()) {
        if (tagNode.getTagName().equals("HEAD")) {
          context.putData(FERRET_IN_HEAD, null);
        }

        if (checkAllowTag(pContext, tagNode)) {
          emit(context, null, tagNode, null);
        }

//        handleCloseTagNode(context,tagNode);
      } else if (tagNode.getTagName().startsWith("![CDATA[")) {
        // CDATA section is delivered as TagNode, and it
        // appears there's no ordinary way of replacing its
        // body content. Also CSS/JS handling method wants
        // TextNode. Create a temporary TextNode for them,
        // and write "<![CDATA["..."]]>" around it.
        String text = tagNode.getText();
        int s = "![CDATA[".length();
        // text is supposed to end with "]]", but just in case.
        int e = text.endsWith("]]") ? text.length() - 2 : text.length();
        if (context.isInCSS()) {
          TextNode textNode = new TextNode(text.substring(s, e));
          handleCSSTextNode(context, textNode);
          emit(context, "<![CDATA[", textNode, "]]>");
        } else if (context.isInScriptText()) {
          TextNode textNode = new TextNode(text.substring(s, e));
          handleJSTextNode(context, textNode);
          emit(context, "<![CDATA[", textNode, "]]>");
        } else {
          emit(context, null, tagNode, null);
        }
      } else {
        context.setInHTML(true);
        // assume start, possibly empty:
        handleOpenTagNode(context, tagNode);
      }
    } else {
      throw new IllegalArgumentException("Unknown node type..");
View Full Code Here

         */
        @Override
  public void handleParseComplete(ParseContext pContext) throws IOException {
    // if no HTML element was found (inHTML==false), don't insert EndJsp.
    if (endJsp != null && pContext.isInHTML()) {
      ReplayParseContext context = (ReplayParseContext) pContext;
      OutputStream out = context.getOutputStream();
      String tmp = null;
      try {
        tmp = context.getJspExec().jspToString(endJsp);
      } catch (ServletException e) {
        e.printStackTrace();
      }
      if (tmp != null) {
//        Charset charset = Charset.forName(context.getOutputCharset());
        String charset = context.getOutputCharset();
        out.write(tmp.getBytes(charset));
      }
    }
  }
View Full Code Here

         * @throws IOException
         */
        @Override
  public void handleParseStart(ParseContext pContext) throws IOException {
   
    ReplayParseContext context = (ReplayParseContext) pContext;
   
    String policy = context.getJspExec().getUiResults().getResult().getOraclePolicy();
   
    if (policy != null) {
      context.setOraclePolicy(policy);
    }
   
    if (startJsp != null) {
      OutputStream out = context.getOutputStream();
      String tmp = null;
      try {
        tmp = context.getJspExec().jspToString(startJsp);
      } catch (ServletException e) {
        e.printStackTrace();
      }
      if (tmp != null) {
//        Charset charset = Charset.forName(context.getOutputCharset());
        String charset = context.getOutputCharset();
        out.write(tmp.getBytes(charset));
      }
    }
  }
View Full Code Here

    String charSet = charsetDetector.getCharset(httpHeadersResource, decodedResource, wbRequest);

    ContextResultURIConverterFactory fact = createConverterFactory(uriConverter, httpRequest, wbRequest);
   
    // set up the context:
    ReplayParseContext context =
        new ReplayParseContext(fact,url,result.getCaptureTimestamp());
   
    context.setRewriteHttpsOnly(rewriteHttpsOnly);

    if(!wbRequest.isFrameWrapperContext()) {
      // in case this is an HTML page with FRAMEs, peek ahead an look:
      // TODO: make ThreadLocal:
      byte buffer[] = new byte[FRAMESET_SCAN_BUFFER_SIZE];

      decodedResource.mark(FRAMESET_SCAN_BUFFER_SIZE);
      int amtRead = decodedResource.read(buffer);
      decodedResource.reset();

      if(amtRead > 0) {
        StringBuilder foo = new StringBuilder(new String(buffer,charSet));
        int frameIdx = TagMagix.getEndOfFirstTag(foo, "FRAMESET");
        if(frameIdx != -1) {
          // insert flag so we don't add FRAMESET:
          context.putData(FastArchivalUrlReplayParseEventHandler.FERRET_DONE_KEY,"");

//          // top-level Frameset: Draw the frame wrapper thingy:
//          frameWrappingRenderer.renderResource(httpRequest,
//              httpResponse, wbRequest, result, resource,
//              uriConverter, results);
//          return;
        }
      }
    }


    // copy the HTTP response code:
    HttpHeaderOperation.copyHTTPMessageHeader(httpHeadersResource, httpResponse);

    // transform the original headers according to our headerProcessor:
    Map<String,String> headers = HttpHeaderOperation.processHeaders(
        httpHeadersResource, result, uriConverter, httpHeaderProcessor);

    // prepare several objects for the parse:

    // a JSPExecutor:
    JSPExecutor jspExec = new JSPExecutor(uriConverter, httpRequest,
        httpResponse, wbRequest, results, result, decodedResource);


    // To make sure we get the length, we have to buffer it all up...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    context.setOutputCharset(OUTPUT_CHARSET);
    context.setOutputStream(baos);
    context.setJspExec(jspExec);


    // and finally, parse, using the special lexer that knows how to
    // handle javascript blocks containing unescaped HTML entities:
    Page lexPage = new Page(decodedResource,charSet);
View Full Code Here

TOP

Related Classes of org.archive.wayback.replay.html.ReplayParseContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.