1 11 package org.eclipse.help.internal.xhtml; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.io.Reader ; 16 17 import org.eclipse.core.runtime.QualifiedName; 18 import org.eclipse.core.runtime.content.IContentDescriber; 19 import org.eclipse.core.runtime.content.IContentDescription; 20 import org.eclipse.help.internal.search.ASCIIReader; 21 22 25 public class XHTMLContentDescriber implements IContentDescriber { 26 27 private static final String XHTML_DTD_PREFIX = "http://www.w3.org/TR/xhtml"; 29 public static final int BUFFER_SIZE = 4096; 30 31 34 public int describe(InputStream contents, IContentDescription description) throws IOException { 35 Reader reader = null; 36 try { 37 reader = new ASCIIReader(contents, BUFFER_SIZE); 38 char[] chars = new char[BUFFER_SIZE]; 39 reader.read(chars); 40 String str = new String (chars); 41 return (str.indexOf(XHTML_DTD_PREFIX) != -1) ? VALID : INVALID; 42 } 43 catch (Exception e) { 44 return INDETERMINATE; 45 } 46 finally { 47 if (reader != null) { 48 try { 49 reader.close(); 50 } 51 catch (IOException e) { 52 } 53 } 54 } 55 } 56 57 60 public QualifiedName[] getSupportedOptions() { 61 return new QualifiedName[0]; 62 } 63 } 64 | Popular Tags |