private void parse() { String name = fEditor.getEditorInput().getName(); Reader reader = new StringReader(fEditor.getDocument().get()); Template template = null; try { parseHtml(); if (fEditor.getEditorInput() instanceof IFileEditorInput) ((IFileEditorInput) fEditor.getEditorInput()) .getFile() .deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); RuntimeInstance runtime = VelocityEditorEnvironment.getParser(); SimpleNode root = runtime.parse(reader, name); // Create tree model NodeVisitor visitor = new NodeVisitor(name); root.jjtAccept(visitor, null); template = visitor.getTemplate(); fError = ""; } catch (ParseException e) { if (!name.matches(".*?\\.jsp.*")) { if (e.getMessage() != null) { fError = e.getMessage(); Token token = e.currentToken; if (token != null) { fEditor.addProblemMarker(e.getMessage(), token.next.beginLine, IMarker.SEVERITY_ERROR); } } else { fError = ""; } } } catch (Exception e) { fError = ""; VelocityPlugin.log(e); } finally { try { reader.close(); } catch (IOException e) { VelocityPlugin.log(e); } } // Replace saved template with the new parsed one synchronized (this) { if (template != null) { fTemplate = template; // Save last successful parse tree fLastTemplate = template; } else { fTemplate = null; } } // Update outline view and display error message in status line Display.getDefault() .syncExec( new Runnable() { public void run() { fEditor.updateOutlinePage(); fEditor.displayErrorMessage(fError); } }); reconcile(); }
private SimpleNode parse(String template) { SimpleNode nodeTree = null; try { nodeTree = velocityRuntime.parse(new StringReader(template), template); } catch (ParseException pex) { throw new CayenneRuntimeException( "Error parsing template '" + template + "' : " + pex.getMessage()); } if (nodeTree == null) { throw new CayenneRuntimeException("Error parsing template " + template); } return nodeTree; }