[ 
https://issues.apache.org/jira/browse/TIKA-1373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14071697#comment-14071697
 ] 

Nick Burch commented on TIKA-1373:
----------------------------------

I've just tried it with svn trunk, and I think I see the issue there. The 
problem looks to be that we're getting back html when we ask for text

{code}$ tika --text tika-core/src/main/java/org/apache/tika/Tika.java | head
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
    <meta name="generator" content="JHighlight v1.0 
(http://jhighlight.dev.java.net)" />
    <title>Tika.java</title>
    <link rel="Help" href="http://jhighlight.dev.java.net"; />
    <style type="text/css">
.java_type {
{code}

Note that I've asked for Text, but got HTML!

> AutoDetectParser extracts no text when SourceCodeParser is selected
> -------------------------------------------------------------------
>
>                 Key: TIKA-1373
>                 URL: https://issues.apache.org/jira/browse/TIKA-1373
>             Project: Tika
>          Issue Type: Bug
>    Affects Versions: 1.5
>            Reporter: Andrés Aguilar-Umaña
>
> When using the AutoDetectParser in java code, and the SourceCodeParser is 
> selected (i.e. java files), the handler gets no text:
> I have this test program:
>     String data = "public class HelloWorld {}";
>     ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes());
>     Parser autoDetectParser = new AutoDetectParser();
>     autoDetectParser = new SourceCodeParser();
>     BodyContentHandler bch = new BodyContentHandler(50);
>     ParseContext parseContext = new ParseContext();
>     Metadata metadata = new Metadata();
>     metadata.set(Metadata.CONTENT_TYPE, "text/x-java-source");
>     try {
>        autoDetectParser.parse(bais, bch, metadata, parseContext);
>     } catch (Exception e) {
>        e.printStackTrace();
>     }
>     System.out.println("Text extracted: "+bch.toString())
> It returns (using the SourceCodeParser): 
>     > Text extracted: 
> But when I use this code:
>     String data = "public class HelloWorld {}";
>     ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes());
>     Parser autoDetectParser = new AutoDetectParser();
>     autoDetectParser = new SourceCodeParser();
>     BodyContentHandler bch = new BodyContentHandler(50);
>     ParseContext parseContext = new ParseContext();
>     Metadata metadata = new Metadata();
>     metadata.set(Metadata.CONTENT_TYPE, "text/plain");
>     try {  autoDetectParser.parse(bais, bch, metadata, parseContext);  } 
> catch (Exception e) {  e.printStackTrace();  }
>     System.out.println("Text extracted: "+bch.toString())
> The Text Parser is used and I get:
> > Text extracted: public class HelloWorld {}
> I have also tested this command: 
> > java -jar tika-app-1.5.jar -t D:\text.java
>   (no text)
> > 



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to