1 12 package org.eclipse.ant.internal.core.contentDescriber; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.Reader ; 17 18 import javax.xml.parsers.ParserConfigurationException ; 19 20 import org.eclipse.core.internal.content.XMLContentDescriber; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.IExecutableExtension; 24 import org.eclipse.core.runtime.content.IContentDescription; 25 import org.xml.sax.InputSource ; 26 import org.xml.sax.SAXException ; 27 28 44 public final class AntBuildfileContentDescriber extends XMLContentDescriber implements IExecutableExtension { 45 46 57 private int checkCriteria(InputSource contents) throws IOException { 58 AntHandler antHandler = new AntHandler(); 59 try { 60 if (!antHandler.parseContents(contents)) { 61 return INDETERMINATE; 62 } 63 } catch (SAXException e) { 64 return INDETERMINATE; 66 } catch (ParserConfigurationException e) { 67 String message = "Internal Error: XML parser configuration error during content description for Ant buildfiles"; throw new RuntimeException (message); 70 } 71 if (antHandler.hasRootProjectElement()) { 73 if (antHandler.hasProjectDefaultAttribute() || antHandler.hasTargetElement() || antHandler.hasAntElement()) { 74 return VALID; 77 } 78 return INDETERMINATE; 80 } 81 82 return INDETERMINATE; 83 } 84 85 88 public int describe(InputStream contents, IContentDescription description) throws IOException { 89 if (super.describe(contents, description) == INVALID) { 91 return INVALID; 92 } 93 contents.reset(); 95 return checkCriteria(new InputSource (contents)); 97 } 98 99 102 public int describe(Reader contents, IContentDescription description) throws IOException { 103 if (super.describe(contents, description) == INVALID) { 105 return INVALID; 106 } 107 contents.reset(); 109 return checkCriteria(new InputSource (contents)); 111 } 112 113 116 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { 117 } 118 } | Popular Tags |