use of de.java2html.javasource.JavaSourceParser in project OpenOLAT by OpenOLAT.
the class SourceViewController method showjavaSource.
/**
* provide a class name with path and you will get an string media resource you can display
* @param cl
* @return
* @throws IOException
*/
public static MediaResource showjavaSource(String cl) throws IOException {
JavaSource jsource = null;
cl = cl.replace('.', '/');
String javaSourcePath = WebappHelper.getSourcePath() + "/" + cl + ".java";
File file = new File(javaSourcePath);
StringWriter writer = new StringWriter();
writer.append(HTML_START);
if (file.exists()) {
jsource = new JavaSourceParser().parse(file);
// Create a converter and write the JavaSource object as Html
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
converter.convert(jsource, JavaSourceConversionOptions.getDefault(), writer);
} else {
writer.append("<html><body><h3>The source file could not be found in the following path:<br>" + javaSourcePath + "<br>Check if configured source path in brasatoconfig.xml is correct.</h3></body></html>");
}
StringMediaResource mr = new StringMediaResource();
mr.setContentType(TEXT_HTML_CHARSET_UTF_8);
writer.append(HTML_STOP);
mr.setData(writer.toString());
return mr;
}
use of de.java2html.javasource.JavaSourceParser in project openolat by klemens.
the class SourceViewController method showjavaSource.
/**
* provide a class name with path and you will get an string media resource you can display
* @param cl
* @return
* @throws IOException
*/
public static MediaResource showjavaSource(String cl) throws IOException {
cl = cl.replace('.', '/');
String javaSourcePath = WebappHelper.getSourcePath() + "/" + cl + ".java";
File file = new File(javaSourcePath);
StringWriter writer = new StringWriter();
writer.append(HTML_START);
if (file.exists()) {
JavaSource jsource = new JavaSourceParser().parse(file);
// Create a converter and write the JavaSource object as Html
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
converter.convert(jsource, JavaSourceConversionOptions.getDefault(), writer);
} else {
appendError(writer, javaSourcePath);
}
writer.append(HTML_STOP);
StringMediaResource mr = new StringMediaResource();
mr.setContentType(TEXT_HTML_CHARSET_UTF_8);
mr.setData(writer.toString());
return mr;
}
use of de.java2html.javasource.JavaSourceParser in project OpenOLAT by OpenOLAT.
the class SourceViewController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == viewVeloctiySource) {
String velocityTemplatePath = WebappHelper.getSourcePath() + "/" + vc.getPage();
String vcContent = FileUtils.load(new File(velocityTemplatePath), "utf-8");
sourceview.contextPut("content", vcContent);
sourceview.contextPut("vcname", vc.getPage());
view = new CloseableModalController(getWindowControl(), "close...", sourceview);
listenTo(view);
view.activate();
} else if (source == viewJSource) {
// Parse the raw text to a JavaSource object
JavaSource jsource = null;
try {
String className = clazz.getCanonicalName();
className = className.replace('.', '/');
String sourcePath = WebappHelper.getSourcePath() + "/" + className + ".java";
jsource = new JavaSourceParser().parse(new File(sourcePath));
} catch (IOException e) {
showInfo("todo");
}
// Create a converter and write the JavaSource object as Html
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
StringWriter writer = new StringWriter();
writer.append(HTML_START);
try {
JavaSourceConversionOptions options = JavaSourceConversionOptions.getDefault();
options.setShowLineNumbers(true);
converter.convert(jsource, options, writer);
} catch (IOException e) {
//
}
StringMediaResource mr = new StringMediaResource();
mr.setContentType(TEXT_HTML_CHARSET_UTF_8);
writer.append(HTML_STOP);
mr.setData(writer.toString());
ureq.getDispatchResult().setResultingMediaResource(mr);
}
}
use of de.java2html.javasource.JavaSourceParser in project evosuite by EvoSuite.
the class ClassAction method highlightSource.
public void highlightSource(VirtualChannel channel, BuildListener listener) throws InterruptedException {
Generation latestGeneration = CUTUtil.getLatestGeneration(this.cut);
if (latestGeneration.isFailed()) {
StringBuilder str = new StringBuilder();
str.append("<h3>std_err_CLIENT</h3>");
str.append("<p>" + this.getLog(channel, latestGeneration.getStdErrCLIENT()) + "</p>");
str.append("<h3>std_out_CLIENT</h3>");
str.append("<p>" + this.getLog(channel, latestGeneration.getStdOutCLIENT()) + "</p>");
str.append("<h3>std_err_MASTER</h3>");
str.append("<p>" + this.getLog(channel, latestGeneration.getStdErrMASTER()) + "</p>");
str.append("<h3>std_out_MASTER</h3>");
str.append("<p>" + this.getLog(channel, latestGeneration.getStdOutMASTER()) + "</p>");
this.testSourceCode = str.toString();
return;
}
Generation latestSuccessfulGeneration = CUTUtil.getLatestSuccessfulGeneration(this.cut);
if (latestSuccessfulGeneration == null) {
this.testSourceCode = "<p>There was not a single successful generation " + "for this class. Likely this is an EvoSuite bug.</p>";
return;
}
TestSuite suite = latestSuccessfulGeneration.getSuite();
if (suite == null) {
this.testSourceCode = "<p>Test suite of the latest successful generation " + "is null. Likely this is an EvoSuite bug.</p>";
return;
}
try {
String javaFile = suite.getFullPathOfTestSuite();
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "JavaFile: " + javaFile);
ByteArrayOutputStream out = new ByteArrayOutputStream();
new FilePath(channel, javaFile).copyTo(out);
InputStream file = new ByteArrayInputStream(out.toByteArray());
JavaSource source = new JavaSourceParser().parse(new InputStreamReader(file, Charset.forName("UTF-8")));
JavaSourceConversionOptions options = JavaSourceConversionOptions.getDefault();
options.setShowLineNumbers(true);
options.setAddLineAnchors(true);
JavaSource2HTMLConverter converter = new JavaSource2HTMLConverter();
StringWriter writer = new StringWriter();
converter.convert(source, options, writer);
this.testSourceCode = writer.toString();
} catch (IOException e) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + e.getMessage());
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Returning a empty source-code");
this.testSourceCode = e.getMessage();
}
}
Aggregations