Re: Removing meta tags from source

Joe Walnes <[email protected]>
Newsgroups gmane.comp.web.sitemesh.general
Message-ID <[email protected]>
On Apr 12, 2005 4:00 PM, Jeff Faulkner <[email protected]> wrote:
> Is there a way to have the meta tags used to pass information to the decorator be hidden
> when viewing the source?    

In the very latest snapshot there is - I've just added a small change
that allows you to override the behavior of the tag processing rules
in the HTML parser. Here's what you need to do:

1. Grab the latest snapshot: http://www.codehaus.org/~joe/sitemesh-SNAPSHOT.jar

2. Create a new parser class.

----
package com.blah;

public class MyPageParser extends HTMLPageParser {

  protected void addUserDefinedRules(State html, PageBuilder page) {
    super.addUserDefinedRules(html, page);
    html.addRule(new InvisibleMetaTagRule(page));
  }

  class InvisibleMetaTagRule extends BasicRule {

    private final PageBuilder page;

    public MetaTagRule(PageBuilder page) {
      super("meta");
      this.page = page;
    }
  
    public void process(Tag tag) {
      // Extracts meta tag information, but does NOT write the tag
back to the page.
      if (tag.hasAttribute("name", false)) {
        page.addProperty("meta."
        + tag.getAttributeValue("name", false), 
        tag.getAttributeValue("content", false));
      } else if (tag.hasAttribute("http-equiv", false)) {
        page.addProperty("meta.http-equiv." 
          + tag.getAttributeValue("http-equiv", false), 
          tag.getAttributeValue("content", false));
      }
    }
  }
}
----

3. Register the parser, in sitemesh.xml, by replacing the line:

  <parser content-type="text/html" 
    class="com.opensymphony.module.sitemesh.parser.FastPageParser" />

with:
  <parser content-type="text/html" 
    class="com.blah.MyPageParser" />

> The way I have things set up now they are being displayed in the
> content source of the page. It might be marginally better to have them placed at least
> in the head tag of the completed page.

This is bizarre. Assuming the meta tags are in the head tag of your
content page, and the decorator:head tag also appears in the head of
your decorator, then they should be in the final page. If you are not
doing this, then you may run into other weird problems.


cheers
-Joe

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.