Chromium Code Reviews| Index: java/org/chromium/distiller/SchemaOrgParserAccessor.java |
| diff --git a/java/org/chromium/distiller/SchemaOrgParserAccessor.java b/java/org/chromium/distiller/SchemaOrgParserAccessor.java |
| index e789a41121c21eff406aa6650f58d9bc7e32170b..3359689448da9810cb6f609bfb09adb90b4a914b 100644 |
| --- a/java/org/chromium/distiller/SchemaOrgParserAccessor.java |
| +++ b/java/org/chromium/distiller/SchemaOrgParserAccessor.java |
| @@ -9,13 +9,17 @@ import org.chromium.distiller.proto.DomDistillerProtos.TimingInfo; |
| import com.google.gwt.dom.client.Element; |
| import java.util.ArrayList; |
| +import java.util.HashSet; |
| import java.util.List; |
| +import java.util.Set; |
| /** |
| * This class instantiates SchemaOrgParser and implements MarkupParser.Accessor interface to provide |
| * access to properties that SchemaOrgParser has parsed. |
| */ |
| public class SchemaOrgParserAccessor implements MarkupParser.Accessor { |
| + |
| + private static Set<SchemaOrgParser.Type> supportedTypes; |
| private final SchemaOrgParser parser; |
| /** |
| @@ -30,6 +34,11 @@ public class SchemaOrgParserAccessor implements MarkupParser.Accessor { |
| parser = new SchemaOrgParser(root, timingInfo); |
| } |
| + static { |
|
wychen
2016/03/14 22:58:42
static sections tend to have performance issues in
|
| + supportedTypes = new HashSet<>(); |
| + supportedTypes.add(SchemaOrgParser.Type.RECIPE); |
| + } |
| + |
| @Override |
| public String getTitle() { |
| String title = ""; |
| @@ -162,4 +171,27 @@ public class SchemaOrgParserAccessor implements MarkupParser.Accessor { |
| public boolean optOut() { |
| return false; |
| } |
| + |
| + /** |
| + * Get schema.org parsed content. |
| + * |
| + * Content is generated when a main entity is identified or |
| + * has only one entity item parsed and it is supported |
| + * |
| + * @return HTML output from the supported item. |
| + */ |
| + @Override |
| + public String getStructuredData() { |
| + String output = ""; |
| + SchemaOrgParser.ThingItem entity = parser.getMainEntity(); |
| + List<SchemaOrgParser.ThingItem> topLevelEntities = |
| + parser.getTopLevelEntities(); |
| + if (entity == null && topLevelEntities.size() == 1) { |
| + entity = topLevelEntities.get(0); |
| + } |
| + if (entity != null && supportedTypes.contains(entity.getType())) { |
| + output = entity.generateOutput(); |
| + } |
| + return output; |
| + } |
| } |