Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,36 @@ public static Optional<Thing> convert(Schema schema) {
}

private static void setProperties(Thing.Builder builder, Schema schema, Class<?> builderClass)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
throws InvocationTargetException, IllegalAccessException {

// Set all the properties
for (String propertyName : schema.getProperties().keySet()) {
String methodName = String.format("add%s", capitalize(propertyName));
Method method = builderClass.getMethod(methodName, String.class);
method.invoke(builder, schema.getProperties().get(propertyName).get(0));
try {
String methodName = String.format("add%s", capitalize(propertyName));
Method method = builderClass.getMethod(methodName, String.class);
method.invoke(builder, schema.getProperties().get(propertyName).get(0));
}
catch (NoSuchMethodException e){
builder.addProperty(propertyName, schema.getProperties().get(propertyName).get(0));
}
}
}

private static void setChildren(Thing.Builder builder, Schema schema, Class<?> builderClass)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException {
throws InvocationTargetException, IllegalAccessException, ClassNotFoundException {

for (Schema child : schema.getChildren()) {
if (!StringUtils.isEmpty(child.getPropertyName())) {
Optional<Thing> optionalThing = convert(child);
if (optionalThing.isPresent()) {
String methodName = String.format("add%s", capitalize(child.getPropertyName()));
Method method = builderClass.getMethod(methodName, getInterfaceClass(getTypeName(child)));
method.invoke(builder, optionalThing.get());
try {
String methodName = String.format("add%s", capitalize(child.getPropertyName()));
Method method = builderClass.getMethod(methodName, getInterfaceClass(getTypeName(child)));
method.invoke(builder, optionalThing.get());
}
catch (NoSuchMethodException e){
builder.addProperty(child.getPropertyName(), optionalThing.get());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class MicrodataExtractor implements Extractor {

private static final String ITEM_PROP = "itemprop";

private static final String HYPERLINK_TAG = "a";

@Override
public List<Entity> getThings(Document document) {
Elements elements = getElements(document);
Expand Down Expand Up @@ -89,7 +87,7 @@ private Schema getTree(Element parent) {
}

private String getValue(Element element) {
if (HYPERLINK_TAG.equals(element.tagName()) && element.hasAttr("href")) {
if (element.hasAttr("href")) {
return element.attr("href");
}

Expand Down