Search in sources :

Example 1 with WriteXrefArgs

use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.

the class XMLAnalyzerTest method xrefWithSpecialCharsInStringLiterals.

/**
 * XML special chars inside a string were not escaped if single quotes
 * were used around the string. Bug #15859.
 * @throws IOException I/O exception
 */
@Test
public void xrefWithSpecialCharsInStringLiterals() throws IOException {
    StringReader input = new StringReader("<foo xyz='<betweensinglequotes>'> </foo>");
    StringWriter output = new StringWriter();
    XMLAnalyzerFactory fac = new XMLAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    analyzer.writeXref(new WriteXrefArgs(input, output));
    assertTrue(output.toString().contains("&lt;betweensinglequotes&gt;"));
    input = new StringReader("<foo xyz=\"<betweendoublequotes>\"> </foo>");
    output = new StringWriter();
    analyzer.writeXref(new WriteXrefArgs(input, output));
    assertTrue(output.toString().contains("&lt;betweendoublequotes&gt;"));
}
Also used : StringWriter(java.io.StringWriter) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) StringReader(java.io.StringReader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) Test(org.junit.jupiter.api.Test)

Example 2 with WriteXrefArgs

use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.

the class XMLAnalyzerTest method bug2225.

@Test
public void bug2225() throws IOException {
    String xmlText = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n" + "<foo>\n" + "  <bar name=\"com.foo.bar.MyClass\"/>\n" + "  <bar name=\"README.txt\"/>\n" + "</foo>";
    StringReader sr = new StringReader(xmlText);
    StringWriter sw = new StringWriter();
    XMLAnalyzerFactory fac = new XMLAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    analyzer.writeXref(new WriteXrefArgs(sr, sw));
    String[] xref = sw.toString().split("\n");
    // Reference to a Java class should have / instead of . in the path
    assertTrue(xref[2].contains("path=com/foo/bar/MyClass"));
    // Ordinary file names should not have .'s replaced
    assertTrue(xref[3].contains("path=README.txt"));
}
Also used : StringWriter(java.io.StringWriter) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) StringReader(java.io.StringReader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) Test(org.junit.jupiter.api.Test)

Example 3 with WriteXrefArgs

use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.

the class UuencodeAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    // this is to explicitly use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
    JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
    OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
    symbolTokenizer.setReader(getReader(src.getStream()));
    doc.add(full);
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
            args.setProject(project);
            writeXref(args);
        }
    }
}
Also used : JFlexTokenizer(org.opengrok.indexer.analysis.JFlexTokenizer) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) Reader(java.io.Reader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs)

Example 4 with WriteXrefArgs

use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.

the class HaskellXrefTest method writeHaskellXref.

private static int writeHaskellXref(InputStream is, PrintStream os, Definitions defs) throws IOException {
    os.println("<!DOCTYPE html><html lang=\"en\"><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"http://localhost:8080/source/default/style.css\" /><title>Haskell Xref Test</title></head>");
    os.println("<body><div id=\"src\"><pre>");
    Writer w = new StringWriter();
    HaskellAnalyzerFactory fac = new HaskellAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs args = new WriteXrefArgs(new InputStreamReader(is, StandardCharsets.UTF_8), w);
    args.setDefs(defs);
    Xrefer xref = analyzer.writeXref(args);
    os.print(w.toString());
    os.println("</pre></div></body></html>");
    return xref.getLOC();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 5 with WriteXrefArgs

use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.

the class PhpXrefTest method writePhpXref.

public int writePhpXref(InputStream is, PrintStream os) throws IOException {
    os.println("<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"http://localhost:8080/source/default/style.css\" /><title>PHP Xref Test</title></head>");
    os.println("<body><div id=\"src\"><pre>");
    Writer w = new StringWriter();
    PhpAnalyzerFactory fac = new PhpAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs wargs = new WriteXrefArgs(new InputStreamReader(is, StandardCharsets.UTF_8), w);
    wargs.setDefs(getTagsDefinitions());
    analyzer.setScopesEnabled(true);
    analyzer.setFoldingEnabled(true);
    Xrefer xref = analyzer.writeXref(wargs);
    os.print(w.toString());
    os.println("</pre></div></body></html>");
    return xref.getLOC();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

WriteXrefArgs (org.opengrok.indexer.analysis.WriteXrefArgs)13 Xrefer (org.opengrok.indexer.analysis.Xrefer)9 StringWriter (java.io.StringWriter)8 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)8 StringReader (java.io.StringReader)6 Test (org.junit.jupiter.api.Test)6 Reader (java.io.Reader)5 Writer (java.io.Writer)5 OGKTextField (org.opengrok.indexer.analysis.OGKTextField)5 JFlexTokenizer (org.opengrok.indexer.analysis.JFlexTokenizer)4 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)4 InputStreamReader (java.io.InputStreamReader)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 StoredField (org.apache.lucene.document.StoredField)1 Definitions (org.opengrok.indexer.analysis.Definitions)1 ExpandTabsReader (org.opengrok.indexer.analysis.ExpandTabsReader)1 Scopes (org.opengrok.indexer.analysis.Scopes)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 NullWriter (org.opengrok.indexer.util.NullWriter)1