Examples of ExplicitStateHighlighter


Examples of com.uwyn.jhighlight.highlighter.ExplicitStateHighlighter

    styles.clear();
    tokens.clear();
   
    InputStream in = new StringBufferInputStream(text);
   
    ExplicitStateHighlighter highlighter = null;
   
    if (role.equals("JAVA")) {
        highlighter = new JavaHighlighter();
      ((JavaHighlighter) highlighter).ASSERT_IS_KEYWORD = true;     
    } else if (role.equals("XML")) {
      highlighter = new XmlHighlighter();
    } else {
      return 0;
    }
   
    Reader isr;
    if (encoding == null) {
      isr = new InputStreamReader(in);
    }
    else {
      isr = new InputStreamReader(in, encoding);
    }
   
    BufferedReader r = new BufferedReader(isr);
   
    // Read all the text into a buffer so that we capture newline characters
    StringBuffer buf = new StringBuffer();
    int c = 0;  
    while ((c = r.read()) != -1) {
      buf.append((char) c);
    }
    
    // Split the text into separate lines incase it includes newline characters
    String allLines = buf.toString();
    String[] lines = allLines.split("\n");
//    for (int jj=0; jj < lines.length; jj++) {
//      System.out.println("Line: " + lines[jj]);
//    }
   
    for (int i=0; i < lines.length; i ++) {
      String line = lines[i];
      if ((i != lines.length -1) || (i == lines.length - 1 && allLines.endsWith("\n"))) {
        line += "\n";      // Put back the newline if needed
      }

      line = StringUtils.convertTabsToSpaces(line, 4);
     
      // should be optimized by reusing a custom LineReader class
      Reader lineReader = new StringReader(line);
      highlighter.setReader(lineReader);
      int index = 0;
      while (index < line.length())
      {
        int style = highlighter.getNextToken();       
        int length = highlighter.getTokenLength();
        String token = line.substring(index, index + length);
       
        styles.add(getCssClass(role, style));
        tokens.add(token);
View Full Code Here

Examples of com.uwyn.jhighlight.highlighter.ExplicitStateHighlighter

   * @since 1.0
   */
  public void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment)
  throws IOException
  {
    ExplicitStateHighlighter highlighter = getHighlighter();
   
    Reader isr;
    Writer osw;
    if (null == encoding)
    {
      isr = new InputStreamReader(in);
      osw = new OutputStreamWriter(out);
    }
    else
    {
      isr = new InputStreamReader(in, encoding);
      osw = new OutputStreamWriter(out, encoding);
    }
   
    BufferedReader r = new BufferedReader(isr);
    BufferedWriter w = new BufferedWriter(osw);
   
    if (fragment)
    {
//      w.write(getXhtmlHeaderFragment(name));
    }
    else
    {
      w.write(getXhtmlHeader(name));
    }
   
    String line;
    String token;
    int length;
    int style;
    String css_class;
    int previous_style = 0;
    boolean newline = false;
   
    StringBuffer buf = new StringBuffer();
    int c = 0;  
    while ((c = r.read()) != -1) {
      buf.append((char) c);
    }
    
    String allLines = buf.toString();
    String[] lines = allLines.split("\n");
//    for (int jj=0; jj < lines.length; jj++) {
//      System.out.println("Line: " + lines[jj]);
//    }
   
    // We get a new instance of this class each time we parse a programlisting so we can
    // can use an instance variable to detect if it's the first time we've been called.
    // This will allow us to put <br/> before each line so that the callout extension will work correctly.
   
    for (int i=0; i < lines.length; i ++) {
      line = lines[i];
      lineNo++;

      line = StringUtils.convertTabsToSpaces(line, 4);
     
      // should be optimized by reusing a custom LineReader class
      Reader lineReader = new StringReader(line);
      highlighter.setReader(lineReader);
      int index = 0;
      while (index < line.length())
      {
        style = highlighter.getNextToken();
        length = highlighter.getTokenLength();
        token = line.substring(index, index + length);
       
        if (style != previous_style || newline)      // assume we have a new style if there is a newline
        {
          css_class = getCssClass(style);
View Full Code Here

Examples of com.uwyn.jhighlight.highlighter.ExplicitStateHighlighter

   * @since 1.0
   */
  public void highlight(String name, InputStream in, OutputStream out, String encoding, boolean fragment)
  throws IOException
  {
    ExplicitStateHighlighter highlighter = getHighlighter();
   
    Reader isr;
    Writer osw;
    if (null == encoding)
    {
      isr = new InputStreamReader(in);
      osw = new OutputStreamWriter(out);
    }
    else
    {
      isr = new InputStreamReader(in, encoding);
      osw = new OutputStreamWriter(out, encoding);
    }
   
    BufferedReader r = new BufferedReader(isr);
    BufferedWriter w = new BufferedWriter(osw);
   
    if (fragment)
    {
      w.write(getXhtmlHeaderFragment(name));
    }
    else
    {
      w.write(getXhtmlHeader(name));
    }
   
    String line;
    String token;
    int length;
    int style;
    String css_class;
    int previous_style = 0;
    boolean newline = false;
    while ((line = r.readLine()) != null)
    {
      line += "\n";
      line = StringUtils.convertTabsToSpaces(line, 4);
     
      // should be optimized by reusing a custom LineReader class
      Reader lineReader = new StringReader(line);
      highlighter.setReader(lineReader);
      int index = 0;
      while (index < line.length())
      {
        style = highlighter.getNextToken();
        length = highlighter.getTokenLength();
        token = line.substring(index, index + length);
       
        if (style != previous_style ||
          newline)
        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.