You should introduce a new semantically meaningful exception type rather
than recycling GadgetException here. We really need to get rid of as much
usage of that as possible.

On Thu, Aug 14, 2008 at 6:33 PM, <[EMAIL PROTECTED]> wrote:

> Author: johnh
> Date: Thu Aug 14 18:33:55 2008
> New Revision: 686103
>
> URL: http://svn.apache.org/viewvc?rev=686103&view=rev
> Log:
> Second try.
>
> Resolution to SHINDIG-501.
>
> Framework for generating a parse tree of HTML and CSS content.
>
> These interfaces are defined in order to cleanly separate parsing logic
> from classes that manipulate a given parse tree (HTML or CSS). The parse
> tree objects are intended to be only as complex as is needed for the vast
> majority of content rewriting manipulation. They provide structure but
> no more semantics (validation, CSS resolution, etc.) than that.
>
> This code is new, and does not affect existing functionality.
>
>
> Added:
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetCssParser.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetHtmlParser.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssDeclaration.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssRule.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlAttribute.java
>
>  
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlNode.java
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetCssParser.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetCssParser.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetCssParser.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetCssParser.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,34 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +import org.apache.shindig.gadgets.GadgetException;
> +
> +import java.util.List;
> +
> +/**
> + * Parser for CSS content. Parsing may be done on a fully-formed
> + * CSS block, such as the contents of a CSS file or &lt;style&gt; block.
> + *
> + * [EMAIL PROTECTED] ParsedCssRule} and [EMAIL PROTECTED] 
> ParsedCssDeclaration} for additional
> + * parsing requirements and semantics.
> + */
> +public interface GadgetCssParser {
> +  public List<ParsedCssRule> parse(String css) throws GadgetException;
> +  public List<ParsedCssDeclaration> parseInline(String style) throws
> GadgetException;
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetHtmlParser.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetHtmlParser.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetHtmlParser.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/GadgetHtmlParser.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,34 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +import org.apache.shindig.gadgets.GadgetException;
> +
> +import java.util.List;
> +
> +/**
> + * Parser for arbitrary HTML content. The content may simply be a
> + * fragment or snippet of HTML rather than a fully-structured Document,
> + * so the interface returns a list of [EMAIL PROTECTED] ParsedHtmlNode} 
> objects
> + * rather than a single top-level item.
> + *
> + * [EMAIL PROTECTED] ParsedHtmlNode} for parsing details
> + */
> +public interface GadgetHtmlParser {
> +  public List<ParsedHtmlNode> parse(String source) throws GadgetException;
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssDeclaration.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssDeclaration.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssDeclaration.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssDeclaration.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,36 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +/**
> + * Interface for a single CSS declaration, eg. color: blue; in:
> + * #id {
> + *   color: blue;
> + * }
> + */
> +public interface ParsedCssDeclaration {
> +  /**
> +   * @return Name of the declaration
> +   */
> +  public String getName();
> +
> +  /**
> +   * @return Value of the declaration
> +   */
> +  public String getValue();
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssRule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssRule.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssRule.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedCssRule.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,37 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +import java.util.List;
> +
> +/**
> + * Simplified interface for a parsed CSS rule.
> + *
> + * For rule:
> + * #id1, .class1 {
> + *   color: blue;
> + *   font-size: 10 em;
> + * }
> + *
> + * Selectors are "#id1" and ".class1", and ParsedCssDeclarations
> + * are name/value "color"/"blue" and "font-size"/"10 em".
> + */
> +public interface ParsedCssRule {
> +  public List<String> getSelectors();
> +  public List<ParsedCssDeclaration> getDeclarations();
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlAttribute.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlAttribute.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlAttribute.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlAttribute.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,33 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +/**
> + * Simple name/value representation of a parsed HTML attribute.
> + */
> +public interface ParsedHtmlAttribute {
> +  /**
> +   * @return HTML attribute name.
> +   */
> +  public String getName();
> +
> +  /**
> +   * @return HTML attribute value.
> +   */
> +  public String getValue();
> +}
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlNode.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlNode.java?rev=686103&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlNode.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/parse/ParsedHtmlNode.java
> Thu Aug 14 18:33:55 2008
> @@ -0,0 +1,56 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.parse;
> +
> +import java.util.List;
> +
> +/**
> + * Simplified interface wrapping a unit of parsed HTML.
> + * Each [EMAIL PROTECTED] ParsedHtmlNode} is either text-type or
> + * tag-type. The following snippet of HTML provides an example of both
> types:
> + *
> + * &lt;div id="foo"&gt;content&lt;div&gt;
> + *
> + * This corresponds to a single top-level [EMAIL PROTECTED] ParsedHtmlNode}
> + * where [EMAIL PROTECTED] getTagName()} returns "div" and has one
> + * [EMAIL PROTECTED] ParsedHtmlAttribute} with N/V "id"/"foo", [EMAIL 
> PROTECTED] getText()}
> + * is [EMAIL PROTECTED] null}, and has one [EMAIL PROTECTED] ParsedHtmlNode} 
> child. That
> + * child in turn has [EMAIL PROTECTED] getText()} equal to "content", with
> + * all other methods returning [EMAIL PROTECTED] null}.
> + */
> +public interface ParsedHtmlNode {
> +  /**
> +   * @return Tag name for an HTML element, or null if text-type.
> +   */
> +  public String getTagName();
> +
> +  /**
> +   * @return List of HTML attributes on an element, or null if text-type
> +   */
> +  public List<ParsedHtmlAttribute> getAttributes();
> +
> +  /**
> +   * @return List of child nodes of the HTML element, or null if text-type
> +   */
> +  public List<ParsedHtmlNode> getChildren();
> +
> +  /**
> +   * @return Unescaped text as contained in an HTML string; null if
> tag-type
> +   */
> +  public String getText();
> +}
>
>
>

Reply via email to