Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2006-12-13 17:36:00 +0000
committerCurtis D'Entremont2006-12-13 17:36:00 +0000
commit2e57613f8140e9184b0fca6126c4a54e727904a2 (patch)
tree4c6d5dc9e52a9fd325af7835044d49017cdf7ea7
parent2b9117ef6862e48f3529d3be43aad7886cc77201 (diff)
downloadeclipse.platform.ua-2e57613f8140e9184b0fca6126c4a54e727904a2.tar.gz
eclipse.platform.ua-2e57613f8140e9184b0fca6126c4a54e727904a2.tar.xz
eclipse.platform.ua-2e57613f8140e9184b0fca6126c4a54e727904a2.zip
160969 [Help] Exception occurred while adding document xxx.xhtml to index.
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java93
1 files changed, 18 insertions, 75 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java
index b8d16197f..5ef12465f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java
@@ -10,89 +10,47 @@
*******************************************************************************/
package org.eclipse.help.internal.xhtml;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Hashtable;
+import java.io.Reader;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.content.IContentDescriber;
import org.eclipse.core.runtime.content.IContentDescription;
-import org.eclipse.core.runtime.content.XMLRootElementContentDescriber;
/**
* A content describer for XHTML.
*/
public class XHTMLContentDescriber implements IContentDescriber {
- private static final String PROPERTY_DTD = "dtd"; //$NON-NLS-1$
+ private static final String XHTML_DTD_PREFIX = "http://www.w3.org/TR/xhtml"; //$NON-NLS-1$
- // XHTML has 3 DTDs, so we have to try each one.
- private static final String DTD_STRICT = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; //$NON-NLS-1$
- private static final String DTD_TRANSITIONAL = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; //$NON-NLS-1$
- private static final String DTD_FRAMESET = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"; //$NON-NLS-1$
-
- private static final int BUFFER_SIZE = 8192;
+ private static final int BUFFER_SIZE = 4096;
- private XMLRootElementContentDescriber describerStrict = new XMLRootElementContentDescriber();
- private XMLRootElementContentDescriber describerTransitional = new XMLRootElementContentDescriber();
- private XMLRootElementContentDescriber describerFrameset = new XMLRootElementContentDescriber();
-
- /**
- * Constructs a new XHTMLContentDescriber. Initializes the three
- * delegates with their respective DTDs.
- */
- public XHTMLContentDescriber() {
- try {
- describerStrict.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_STRICT));
- }
- catch (CoreException e) {
- // not much we can do here
- }
-
- try {
- describerTransitional.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_TRANSITIONAL));
- }
- catch (CoreException e) {
- // not much we can do here
- }
-
- try {
- describerFrameset.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_FRAMESET));
- }
- catch (CoreException e) {
- // not much we can do here
- }
- }
-
/* (non-Javadoc)
* @see org.eclipse.core.runtime.content.IContentDescriber#describe(java.io.InputStream, org.eclipse.core.runtime.content.IContentDescription)
*/
public int describe(InputStream contents, IContentDescription description) throws IOException {
- /*
- * Load the first BUFFER_SIZE bytes, then pass that to each delegate.
- * If any one recognizes their DTD, return VALID.
- */
+ Reader reader = null;
try {
- byte[] buffer = new byte[BUFFER_SIZE];
- contents.read(buffer);
- contents.close();
-
- ByteArrayInputStream in = new ByteArrayInputStream(buffer);
- if (describerTransitional.describe(in, description) == VALID) {
- return VALID;
- }
- in = new ByteArrayInputStream(buffer);
- if (describerStrict.describe(in, description) == VALID) {
- return VALID;
- }
- in = new ByteArrayInputStream(buffer);
- return describerFrameset.describe(in, description);
+ reader = new ASCIIReader(contents, BUFFER_SIZE);
+ char[] chars = new char[BUFFER_SIZE];
+ reader.read(chars);
+ String str = new String(chars);
+ return (str.indexOf(XHTML_DTD_PREFIX) != -1) ? VALID : INVALID;
}
catch (Exception e) {
return INDETERMINATE;
}
+ finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ }
+ catch (IOException e) {
+ }
+ }
+ }
}
/* (non-Javadoc)
@@ -101,19 +59,4 @@ public class XHTMLContentDescriber implements IContentDescriber {
public QualifiedName[] getSupportedOptions() {
return new QualifiedName[0];
}
-
- /**
- * Creates a new parameter suitable for passing into the
- * XMLRootElementContentDescriber. The parameters have to be
- * in the form of a Hashtable.
- *
- * @param name parameter name
- * @param value parameter value
- * @return the parameter, in Hashtable form
- */
- private static Hashtable getParameter(String name, String value) {
- Hashtable hash = new Hashtable();
- hash.put(name, value);
- return hash;
- }
}

Back to the top