use of de.java2html.options.JavaSourceConversionOptions 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.options.JavaSourceConversionOptions 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