Tabnine Logo
StreamedHtmlScriptInjector
Code IndexAdd Tabnine to your IDE (free)

How to use
StreamedHtmlScriptInjector
in
rocks.inspectit.agent.java.eum.html

Best Java code snippets using rocks.inspectit.agent.java.eum.html.StreamedHtmlScriptInjector (Showing top 20 results out of 315)

origin: inspectIT/inspectIT

/**
 * Creates a new print writer which performs the tag injection.
 *
 * @param originalWriter
 *            The writer which is wrapped.
 * @param tagToInject
 *            The tag(s) to insert.
 */
public TagInjectionPrintWriter(PrintWriter originalWriter, String tagToInject) {
  super(originalWriter);
  this.originalWriter = originalWriter;
  injector = new StreamedHtmlScriptInjector(tagToInject);
}
origin: inspectIT/inspectIT

@Override
public PrintWriter append(CharSequence csq) {
  String newValue = injector.performInjection(csq);
  if (newValue == null) {
    originalWriter.append(csq);
  } else {
    originalWriter.write(newValue);
  }
  return this;
}
origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
protected void abortInjectionPointSearch() {
  super.abortInjectionPointSearch();
  leftOver = NO_LEFTOVER_CHARACTER_BYTES;
  encodeBuffer = null; // NOPMD
  decodeBuffer = null; // NOPMD
}
origin: inspectIT/inspectIT

  scanXmlDeclaration();
  break;
case SCAN_REQUIRED_XHTML_PREAMBLE:
  scanRequiredXHtmlPreamble();
  break;
case SCAN_HTML_PREAMBLE:
  scanHtmlPreamble();
  break;
case SCAN_FOR_HTML_TAG:
  scanForHtmlTag();
  break;
case SCAN_FOR_HEAD_TAG:
  scanForHeadTag();
  break;
case SCAN_FOR_BODY_TAG:
  scanForBodyTag();
  break;
default:
origin: inspectIT/inspectIT

@Test
public void testPreventDoubleInejection() {
  String src = loadHtmlSource("/html/testCase-HeadInjection.html");
  String modifiedA = runInjector(src);
  String modified = new StreamedHtmlScriptInjector(TAG_TO_INJECT).performInjection(modifiedA);
  assertThat(modified, equalTo(null));
}
origin: inspectIT/inspectIT

/**
 * Tries to find an opening html tag.
 */
private void scanForHtmlTag() {
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "html")) {
    if (tokenParser.getParsedTokenType() != Token.START_TAG) {
      abortInjectionPointSearch();
      return;
    }
    status = Status.SCAN_FOR_HEAD_TAG;
  } else {
    // current token is not the html tag, we assume the document starts immediately with the
    // head
    status = Status.SCAN_FOR_HEAD_TAG;
    processToken();
  }
}
origin: inspectIT/inspectIT

if (hasTerminated()) {
  return null;
while (!hasTerminated()) {
  Result tokenParsingResult = tokenParser.parseToken();
  switch (tokenParsingResult) {
  case FAILURE:
    abortInjectionPointSearch();
    return null;
  case INCOMPLETE:
    return null;
  case SUCCESS:
    processToken();
    if (status == Status.INJECTION_POINT_FOUND) {
      String returnValue;
      abortInjectionPointSearch();
      return returnValue;
    } else if (status != Status.TERMINATED) {
origin: inspectIT/inspectIT

/**
 * Tries to find an opening head tag. Omitting both the head and the body tag is currently not
 * supported.
 */
private void scanForHeadTag() {
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "head")) {
    if (tokenParser.getParsedTokenType() != Token.START_TAG) {
      abortInjectionPointSearch();
      return;
    }
    // Perform injection after start of the head tag
    status = Status.INJECTION_POINT_FOUND;
  } else {
    // current token is not the head tag, we assume it must be the body tag (head is empty)
    status = Status.SCAN_FOR_BODY_TAG;
    processToken();
  }
}
origin: inspectIT/inspectIT

@Override
public void println(float x) {
  String newValue = injector.performInjection(x + NL);
  if (newValue == null) {
    originalWriter.println(x);
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

/**
 * Scans for an opening <?xml .. ?> declaration in case the html is delivered as XML.
 */
private void scanXmlDeclaration() {
  // Preamble checking based on the information on this page
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "?xml")) {
    // ?> is treated by the parser as a stand-alone tag
    if (tokenParser.getParsedTokenType() != Token.STANDALONE_TAG) {
      abortInjectionPointSearch();
      return;
    }
    // Xml header detected, now we require an html doctype to continue
    status = Status.SCAN_REQUIRED_XHTML_PREAMBLE;
  } else {
    // no xml tag found, therefore we are non-strict in requiring a doctype declaration
    status = Status.SCAN_HTML_PREAMBLE;
    processToken();
  }
}
origin: inspectIT/inspectIT

@BeforeMethod
public void init() {
  injector = new StreamedHtmlScriptInjector(TAG_TO_INJECT);
}
origin: inspectIT/inspectIT

/**
 * Tries to find an opening body tag. Omitting both the head and the body tag is currently not
 * supported.
 */
private void scanForBodyTag() {
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "body")) {
    if (tokenParser.getParsedTokenType() != Token.START_TAG) {
      abortInjectionPointSearch();
      return;
    }
    // Perform injection after start of the head tag
    status = Status.INJECTION_POINT_FOUND;
  } else {
    // current token is not the head tag, we assume it must be the body tag (head is empty)
    abortInjectionPointSearch();
  }
}
origin: inspectIT/inspectIT

@Override
public void println(double x) {
  String newValue = injector.performInjection(x + NL);
  if (newValue == null) {
    originalWriter.println(x);
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

/**
 * Scans for an opening html tag, skipping preamble tags like or !DOCTYPE.
 */
private void scanHtmlPreamble() {
  // Preamble checking based on the information on this page
  // http://wiki.selfhtml.org/wiki/HTML/Dokumentstruktur_und_Aufbau#HTML5
  // we also allow html without preamble, directly starting with the <html> tag
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "!DOCTYPE")) {
    // Doctypes are formated as opening tags
    if (tokenParser.getParsedTokenType() != Token.START_TAG) {
      abortInjectionPointSearch();
      return;
    }
    // we accept any doctype starting with "html"
    if (!CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagArguments(), 0, 4, "html", 0, 4)) {
      abortInjectionPointSearch();
      return;
    }
    // DOCTYPE okay, proceed with the next tag scanning for the html tag
    status = Status.SCAN_FOR_HTML_TAG;
  } else {
    // no preamble tag found, we assume the html is starting immediately
    status = Status.SCAN_FOR_HTML_TAG;
    processToken();
  }
}
origin: inspectIT/inspectIT

/**
 * Same as {@link #scanHtmlPreamble()}, however does not allow to ommit the preamble.
 */
private void scanRequiredXHtmlPreamble() {
  // Preamble checking based on the information on this page
  // http://wiki.selfhtml.org/wiki/HTML/Dokumentstruktur_und_Aufbau#HTML5
  // we also allow html without preamble, directly starting with the <html> tag
  if (CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagType(), "!DOCTYPE")) {
    // Doctypes are formated as opening tags
    if (tokenParser.getParsedTokenType() != Token.START_TAG) {
      abortInjectionPointSearch();
      return;
    }
    // we accept any doctype starting with "html"
    if (!CharSequenceUtils.checkEqualIgnoreCase(tokenParser.getTagArguments(), 0, 4, "html", 0, 4)) {
      abortInjectionPointSearch();
      return;
    }
    // DOCTYPE okay, proceed with the next tag scanning for the html tag
    status = Status.SCAN_FOR_HTML_TAG;
  } else {
    // no preamble tag found, it however is required for xhtml
    abortInjectionPointSearch();
    return;
  }
}
origin: inspectIT/inspectIT

@Override
public void println(Object x) {
  String newValue = injector.performInjection(x + NL);
  if (newValue == null) {
    originalWriter.println(x);
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

@Override
public void write(String s) {
  String newValue = injector.performInjection(s);
  if (newValue == null) {
    originalWriter.write(s);
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

@Override
public void println(String x) {
  String newValue = injector.performInjection(x + NL);
  if (newValue == null) {
    originalWriter.println(x);
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

@Override
public void println() {
  String newValue = injector.performInjection(NL);
  if (newValue == null) {
    originalWriter.println();
  } else {
    originalWriter.write(newValue);
  }
}
origin: inspectIT/inspectIT

@Override
public void println(long x) {
  String newValue = injector.performInjection(x + NL);
  if (newValue == null) {
    originalWriter.println(x);
  } else {
    originalWriter.write(newValue);
  }
}
rocks.inspectit.agent.java.eum.htmlStreamedHtmlScriptInjector

Javadoc

A lightweight html parser for injecting a script into a streamed html file on the fly. Features:
  • early out as soon as the file is detected to be non-html (e.g. the data is image data or a xml-file)
  • detects and ignores comments in the file
  • tries to place the tag in the head tag, if it is not present the tag will be placed in the body tag
  • avoid double-injection by checking if the string starting at the injection point matches exactly the tag to inject

Most used methods

  • <init>
    Creates and initializes a new injector.
  • performInjection
    Tries to perform an injection on the given source code. The html file may be split arbitrarily by c
  • abortInjectionPointSearch
    Aborts the search for an injection point.
  • hasTerminated
  • processToken
    Processes the last token parsed by the #tokenParser. This method is called recursively by the token
  • scanForBodyTag
    Tries to find an opening body tag. Omitting both the head and the body tag is currently not supporte
  • scanForHeadTag
    Tries to find an opening head tag. Omitting both the head and the body tag is currently not supporte
  • scanForHtmlTag
    Tries to find an opening html tag.
  • scanHtmlPreamble
    Scans for an opening html tag, skipping preamble tags like or !DOCTYPE.
  • scanRequiredXHtmlPreamble
    Same as #scanHtmlPreamble(), however does not allow to ommit the preamble.
  • scanXmlDeclaration
    Scans for an opening declaration in case the html is delivered as XML.
  • scanXmlDeclaration

Popular in Java

  • Finding current android device location
  • setContentView (Activity)
  • setScale (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Notification (javax.management)
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now