use of javax.swing.text.html.parser.DTD in project camel by apache.
the class JavadocParserTest method testGetMethods.
@Test
public void testGetMethods() throws Exception {
final DTD dtd = DTD.getDTD("html.dtd");
final String javaDocPath = String.class.getName().replaceAll("\\.", "/") + ".html";
final JavadocParser htmlParser = new JavadocParser(dtd, javaDocPath);
htmlParser.parse(new InputStreamReader(new URL(JAVA6_STRING).openStream(), "UTF-8"));
assertNull("Java6 getErrorMessage", htmlParser.getErrorMessage());
assertEquals("Java6 getMethods", 65, htmlParser.getMethods().size());
htmlParser.reset();
htmlParser.parse(new InputStreamReader(new URL(JAVA7_STRING).openStream(), "UTF-8"));
assertNull("Java7 getErrorMessage", htmlParser.getErrorMessage());
assertEquals("Java7 getMethods", 65, htmlParser.getMethods().size());
htmlParser.reset();
htmlParser.parse(new InputStreamReader(new URL(JAVA8_STRING).openStream(), "UTF-8"));
assertNull("Java8 getErrorMessage", htmlParser.getErrorMessage());
assertEquals("Java8 getMethods", 67, htmlParser.getMethods().size());
}
use of javax.swing.text.html.parser.DTD in project jdk8u_jdk by JetBrains.
the class Test8017492 method main.
public static void main(String[] args) throws Exception {
Runnable task = new Runnable() {
@Override
public void run() {
try {
SunToolkit.createNewAppContext();
DTD dtd = DTD.getDTD("dtd");
dtd.elements = new Vector<Element>() {
@Override
public synchronized int size() {
return Integer.MAX_VALUE;
}
};
dtd.getElement("element");
} catch (Exception exception) {
throw new Error("unexpected", exception);
}
}
};
// run task with different AppContext
Thread thread = new Thread(new ThreadGroup("$$$"), task);
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
}
});
thread.start();
thread.join();
// add error handling
HTMLDocument document = new HTMLDocument() {
@Override
public HTMLEditorKit.ParserCallback getReader(int pos) {
return getReader(pos, 0, 0, null);
}
@Override
public HTMLEditorKit.ParserCallback getReader(int pos, int popDepth, int pushDepth, HTML.Tag insertTag) {
return new HTMLDocument.HTMLReader(pos, popDepth, pushDepth, insertTag) {
@Override
public void handleError(String error, int pos) {
throw new Error(error);
}
};
}
};
// run parser
new HTMLEditorKit().insertHTML(document, 0, "<html><body>text", 0, 0, null);
}
use of javax.swing.text.html.parser.DTD in project camel by apache.
the class JavadocApiMethodGeneratorMojo method getSignatureList.
@Override
public List<String> getSignatureList() throws MojoExecutionException {
// signatures as map from signature with no arg names to arg names from JavadocParser
Map<String, String> result = new HashMap<String, String>();
final Pattern packagePatterns = Pattern.compile(excludePackages);
final Pattern classPatterns = (excludeClasses != null) ? Pattern.compile(excludeClasses) : null;
final Pattern includeMethodPatterns = (includeMethods != null) ? Pattern.compile(includeMethods) : null;
final Pattern excludeMethodPatterns = (excludeMethods != null) ? Pattern.compile(excludeMethods) : null;
// for proxy class and super classes not matching excluded packages or classes
for (Class<?> aClass = getProxyType(); aClass != null && !packagePatterns.matcher(aClass.getPackage().getName()).matches() && (classPatterns == null || !classPatterns.matcher(aClass.getSimpleName()).matches()); aClass = aClass.getSuperclass()) {
log.debug("Processing " + aClass.getName());
final String javaDocPath = aClass.getName().replaceAll("\\.", "/").replace('$', '.') + ".html";
// read javadoc html text for class
InputStream inputStream = null;
try {
inputStream = getProjectClassLoader().getResourceAsStream(javaDocPath);
if (inputStream == null) {
log.debug("JavaDoc not found on classpath for " + aClass.getName());
break;
}
// transform the HTML to get method summary as text
// dummy DTD
final DTD dtd = DTD.getDTD("html.dtd");
final JavadocParser htmlParser = new JavadocParser(dtd, javaDocPath);
htmlParser.parse(new InputStreamReader(inputStream, "UTF-8"));
// look for parse errors
final String parseError = htmlParser.getErrorMessage();
if (parseError != null) {
throw new MojoExecutionException(parseError);
}
// get public method signature
final Map<String, String> methodMap = htmlParser.getMethodText();
for (String method : htmlParser.getMethods()) {
if (!result.containsKey(method) && (includeMethodPatterns == null || includeMethodPatterns.matcher(method).find()) && (excludeMethodPatterns == null || !excludeMethodPatterns.matcher(method).find())) {
final int leftBracket = method.indexOf('(');
final String name = method.substring(0, leftBracket);
final String args = method.substring(leftBracket + 1, method.length() - 1);
String[] types;
if (args.isEmpty()) {
types = new String[0];
} else {
// get raw types from args
final List<String> rawTypes = new ArrayList<String>();
final Matcher argTypesMatcher = RAW_ARGTYPES_PATTERN.matcher(args);
while (argTypesMatcher.find()) {
rawTypes.add(argTypesMatcher.group(1));
}
types = rawTypes.toArray(new String[rawTypes.size()]);
}
final String resultType = getResultType(aClass, name, types);
if (resultType != null) {
result.put(method, resultType + " " + name + methodMap.get(method));
}
}
}
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
IOUtil.close(inputStream);
}
}
if (result.isEmpty()) {
throw new MojoExecutionException("No public non-static methods found, " + "make sure Javadoc is available as project test dependency");
}
return new ArrayList<String>(result.values());
}
use of javax.swing.text.html.parser.DTD in project jdk8u_jdk by JetBrains.
the class bug8074956 method main.
public static void main(String[] args) throws Exception {
final DTD html32 = DTD.getDTD("html32");
ContentModel contentModel = new ContentModel('&', new ContentModel());
Element elem1 = html32.getElement("html-element");
contentModel.first(elem1);
Element elem2 = html32.getElement("test-element");
// Shouldn't throw ArrayIndexOutOfBoundsException
contentModel.first(elem2);
}
use of javax.swing.text.html.parser.DTD in project jdk8u_jdk by JetBrains.
the class bug6938813 method validate.
private static void validate() throws Exception {
AppContext appContext = AppContext.getAppContext();
assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");
// Spoil hash value
DTD invalidDtd = DTD.getDTD("invalid DTD");
DTD.putDTDHash(DTD_KEY, invalidDtd);
assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");
Object dtdKey = getParserDelegator_DTD_KEY();
assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");
// Init default DTD
new ParserDelegator();
Object dtdValue = appContext.get(dtdKey);
assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");
// Try reinit default DTD
new ParserDelegator();
assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
if (styleSheet == null) {
// First AppContext
styleSheet = htmlEditorKit.getStyleSheet();
assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
} else {
assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
}
}
Aggregations