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();
 }
Пример #2
0
 static SimpleNode parsedTemplateForResource(String templateStr, String resourceName) {
   try {
     return velocityRuntimeInstance.parse(templateStr, resourceName);
   } catch (ParseException e) {
     throw new AssertionError(e);
   }
 }
Пример #3
0
 static SimpleNode parsedTemplateForResource(String resourceName) {
   InputStream in = RetrofitTemplateVars.class.getResourceAsStream(resourceName);
   if (in == null) {
     throw new IllegalArgumentException("Could not find resource: " + resourceName);
   }
   try {
     Reader reader = new InputStreamReader(in, "UTF-8");
     return velocityRuntimeInstance.parse(reader, resourceName);
   } catch (UnsupportedEncodingException e) {
     throw new AssertionError(e);
   } catch (ParseException e) {
     throw new AssertionError(e);
   }
 }
  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;
  }