@Override protected GadgetSpec parse(String content, Query query) throws XmlException, GadgetException { // Allow BOM entity as first item on stream and ignore it: if (content.length() >= BOM_ENTITY.length() && content.substring(0, BOM_ENTITY.length()).equalsIgnoreCase(BOM_ENTITY)) { content = content.substring(BOM_ENTITY.length()); } Element element = XmlUtil.parse(content); return new GadgetSpec(query.getSpecUri(), element, content); } }
public LinkSpec(Element element, Uri base) throws SpecParserException { this.base = base; rel = XmlUtil.getAttribute(element, "rel"); if (rel == null) { throw new SpecParserException("Link/@rel is required!"); } href = XmlUtil.getUriAttribute(element, "href"); if (href == null) { throw new SpecParserException("Link/@href is required!"); } }
/** * @param node * @param attr * @return True if the attribute exists and is not equal to "false" * false otherwise. */ public static boolean getBoolAttribute(Node node, String attr) { return getBoolAttribute(node, attr, false); }
/** * Retrieves an attribute as a URI, and verifies that the URI is an http or https URI. * @param node * @param attr * @param base * @return the parsed uri, or null if the attribute is not a valid http or * https URI. */ public static Uri getHttpUriAttribute(Node node, String attr, Uri base) { return getHttpUriAttribute(node, attr, base, null); }
/** * @param node * @param attr * @return The value of the given attribute, or null if not present. */ public static String getAttribute(Node node, String attr) { return getAttribute(node, attr, null); }
/** * Retrieves an attribute as a URI. * @param node * @param attr * @return The parsed uri, or null. */ public static Uri getUriAttribute(Node node, String attr) { return getUriAttribute(node, attr, null); }
/** * @return An attribute coerced to an integer. */ public static int getIntAttribute(Node node, String attr) { return getIntAttribute(node, attr, 0); }
/** * Use for testing. */ public GadgetSpec(Uri url, String xml) throws SpecParserException { this(url, XmlUtil.parseSilent(xml), xml); }
/** * Retrieves an attribute as a URI, and verifies that the URI is an http or https URI. * @param node * @param attr * @param base * @return the parsed uri, or null if the attribute is not a valid http or * https URI. */ public static Uri getHttpUriAttribute(Node node, String attr, Uri base) { return getHttpUriAttribute(node, attr, base, null); }
/** * @param node * @param attr * @return The value of the given attribute, or null if not present. */ public static String getAttribute(Node node, String attr) { return getAttribute(node, attr, null); }
/** * Retrieves an attribute as a URI. * @param node * @param attr * @return The parsed uri, or null. */ public static Uri getUriAttribute(Node node, String attr) { return getUriAttribute(node, attr, null); }
/** * @return An attribute coerced to an integer. */ public static int getIntAttribute(Node node, String attr) { return getIntAttribute(node, attr, 0); }
/** * Use for testing. */ public GadgetSpec(Uri url, String xml) throws SpecParserException { this(url, XmlUtil.parseSilent(xml), xml); }
@Test(expected=XmlException.class) public void parseBadXmlThrows() throws XmlException { XmlUtil.parse("malformed xml"); } }
/** * Retrieves an attribute as a URI, and verifies that the URI is an http or https URI. * @param node * @param attr * @param base * @return the parsed uri, or null if the attribute is not a valid http or * https URI. */ public static Uri getHttpUriAttribute(Node node, String attr, Uri base) { return getHttpUriAttribute(node, attr, base, null); }
public LinkSpec(Element element, Uri base) throws SpecParserException { this.base = base; rel = XmlUtil.getAttribute(element, "rel"); if (rel == null) { throw new SpecParserException("Link/@rel is required!"); } href = XmlUtil.getUriAttribute(element, "href"); if (href == null) { throw new SpecParserException("Link/@href is required!"); } }
/** * @param node * @param attr * @return The value of the given attribute, or null if not present. */ public static String getAttribute(Node node, String attr) { return getAttribute(node, attr, null); }
/** * @param node * @param attr * @return True if the attribute exists and is not equal to "false" * false otherwise. */ public static boolean getBoolAttribute(Node node, String attr) { return getBoolAttribute(node, attr, false); }
/** * Retrieves an attribute as a URI. * @param node * @param attr * @return The parsed uri, or null. */ public static Uri getUriAttribute(Node node, String attr) { return getUriAttribute(node, attr, null); }
/** * @return An attribute coerced to an integer. */ public static int getIntAttribute(Node node, String attr) { return getIntAttribute(node, attr, 0); }