Exemplo n.º 1
0
    /*
     * Appends the given tag, including its body, to the XML view,
     * and optionally reset default namespace to "", if none specified.
     */
    private void appendTag(Node n, boolean addDefaultNS) throws JasperException {

      Node.Nodes body = n.getBody();
      String text = n.getText();

      buf.append("<").append(n.getQName());
      buf.append("\n");

      printAttributes(n, addDefaultNS);
      buf.append("  ").append(jspIdPrefix).append(":id").append("=\"");
      buf.append(jspId++).append("\"\n");

      if (ROOT_ACTION.equals(n.getLocalName()) || body != null || text != null) {
        buf.append(">\n");
        if (ROOT_ACTION.equals(n.getLocalName())) {
          if (compiler.getCompilationContext().isTagFile()) {
            appendTagDirective();
          } else {
            appendPageDirective();
          }
        }
        if (body != null) {
          body.visit(this);
        } else {
          appendText(text, false);
        }
        buf.append("</" + n.getQName() + ">\n");
      } else {
        buf.append("/>\n");
      }
    }
Exemplo n.º 2
0
  /**
   * @param page the page nodes from which to generate the XML view
   * @param compiler The compiler for this page
   * @throws JasperException If an error occurs
   */
  public PageDataImpl(Node.Nodes page, Compiler compiler) throws JasperException {

    // First pass
    FirstPassVisitor firstPass = new FirstPassVisitor(page.getRoot(), compiler.getPageInfo());
    page.visit(firstPass);

    // Second pass
    buf = new StringBuilder();
    SecondPassVisitor secondPass =
        new SecondPassVisitor(page.getRoot(), buf, compiler, firstPass.getJspIdPrefix());
    page.visit(secondPass);
  }
Exemplo n.º 3
0
  @Test
  public void testBug54240() throws Exception {
    Tomcat tomcat = getTomcatInstanceTestWebapp(false, true);

    ServletContext context = ((Context) tomcat.getHost().findChildren()[0]).getServletContext();

    TagPluginManager manager = new TagPluginManager(context);

    Node.Nodes nodes = new Node.Nodes();
    Node.CustomTag c =
        new Node.CustomTag(
            "test:ATag",
            "test",
            "ATag",
            "http://tomcat.apache.org/jasper",
            null,
            null,
            null,
            null,
            null,
            new TagFileInfo("ATag", "http://tomcat.apache.org/jasper", tagInfo));
    c.setTagHandlerClass(TesterTag.class);
    nodes.add(c);
    manager.apply(nodes, null, null);

    Node n = nodes.getNode(0);
    Assert.assertNotNull(n);
    Assert.assertTrue(n instanceof Node.CustomTag);

    Node.CustomTag t = (Node.CustomTag) n;
    Assert.assertNotNull(t.getAtSTag());

    Node.Nodes sTag = c.getAtSTag();
    Node scriptlet = sTag.getNode(0);
    Assert.assertNotNull(scriptlet);
    Assert.assertTrue(scriptlet instanceof Node.Scriptlet);
    Node.Scriptlet s = (Node.Scriptlet) scriptlet;
    Assert.assertEquals("//Just a comment", s.getText());
  }
Exemplo n.º 4
0
  public void apply(Node.Nodes page, ErrorDispatcher err, PageInfo pageInfo)
      throws JasperException {

    init(err);
    if (tagPlugins == null || tagPlugins.size() == 0) {
      return;
    }

    this.pageInfo = pageInfo;

    page.visit(
        new Node.Visitor() {
          public void visit(Node.CustomTag n) throws JasperException {
            invokePlugin(n);
            visitBody(n);
          }
        });
  }
Exemplo n.º 5
0
 public static void set(Node.Nodes page, ErrorDispatcher err) throws JasperException {
   page.visit(new CustomTagCounter());
   page.visit(new ScriptingVariableVisitor(err));
 }
Exemplo n.º 6
0
 public void generateAttribute(String attributeName) {
   curNodes.add(new Node.AttributeGenerator(node.getStart(), attributeName, node));
 }
Exemplo n.º 7
0
 public void generateJavaSource(String sourceCode) {
   curNodes.add(new Node.Scriptlet(sourceCode, node.getStart(), null));
 }
Exemplo n.º 8
0
 public void generateDeclaration(String id, String text) {
   if (pageInfo.isPluginDeclared(id)) {
     return;
   }
   curNodes.add(new Node.Declaration(text, node.getStart(), null));
 }