List of usage examples for com.google.gwt.dom.client Element hasAttribute
@Override
public boolean hasAttribute(String name)
From source file:client.net.sf.saxon.ce.dom.HTMLWriter.java
License:Mozilla Public License
public static void setAttribute(Document doc, Element element, String name, String URI, String value, WriteMode wMode) {// w w w.ja va 2 s .c o m // fix for IE issue with colspan etc #1570 name = tableAttributeFix(name, wMode); if (attNSSupported(doc)) { setAttributeJs(doc, element, name, URI, value); } else { String prefix = name.substring(0, name.indexOf(":")); String x = "xmlns"; String nsDeclaraction = (prefix.length() == 0) ? x : x + ":" + prefix; if (!element.hasAttribute(nsDeclaraction)) { addNamespace(element, prefix, URI); } element.setAttribute(name, value); setAttributeProps(element, name, value); } }
From source file:com.ciplogic.web.codeeditor.render.geshi.GeshiCodeRenderer.java
License:Open Source License
@Override public boolean isShowLines(Element codeElement) { return codeElement.hasAttribute(linesAttribute) && linesAttributeValue.equalsIgnoreCase(codeElement.getAttribute(linesAttribute)); }
From source file:com.dom_distiller.client.ContentExtractor.java
License:Open Source License
/** * Strips all "id" attributes from nodes in the tree rooted at |clonedSubtree| *///from ww w .j av a 2 s . c o m private static void stripIds(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element e = Element.as(node); if (e.hasAttribute("id")) { e.setAttribute("id", ""); } // Intentional fall-through. case Node.DOCUMENT_NODE: for (int i = 0; i < node.getChildCount(); i++) { stripIds(node.getChild(i)); } } }
From source file:com.dom_distiller.client.SchemaOrgParser.java
License:Open Source License
private void getElementsWithItemAttribute(Element e, List<Element> allProp) { if (e.hasAttribute("ITEMPROP") || e.hasAttribute("ITEMSCOPE")) { allProp.add(e);/* w w w.ja v a 2s. c o m*/ } NodeList<Node> children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.getItem(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; getElementsWithItemAttribute(Element.as(child), allProp); } }
From source file:com.dom_distiller.client.SchemaOrgParser.java
License:Open Source License
private static boolean isItemScope(Element e) { return e.hasAttribute("ITEMSCOPE") && e.hasAttribute("ITEMTYPE"); }
From source file:com.dom_distiller.client.TableClassifier.java
License:Open Source License
public static Type table(TableElement t) { sReason = Reason.UNKNOWN;//from w ww . ja v a 2 s . co m // The following heuristics are dropped from said url: // - table created by CSS display style is layout table, because we only handle actual // <table> elements. // 1) Table inside editable area is layout table, different from said url because we ignore // editable areas during distillation. Element parent = t.getParentElement(); while (parent != null) { if (parent.hasTagName("INPUT") || parent.getAttribute("contenteditable").equalsIgnoreCase("true")) { return logAndReturn(Reason.INSIDE_EDITABLE_AREA, "", Type.LAYOUT); } parent = parent.getParentElement(); } // 2) Table having role="presentation" is layout table. String tableRole = t.getAttribute("role").toLowerCase(); if (tableRole.equals("presentation")) { return logAndReturn(Reason.ROLE_TABLE, "_" + tableRole, Type.LAYOUT); } // 3) Table having ARIA table-related roles is data table. if (sARIATableRoles.contains(tableRole) || sARIARoles.contains(tableRole)) { return logAndReturn(Reason.ROLE_TABLE, "_" + tableRole, Type.DATA); } // 4) Table having ARIA table-related roles in its descendants is data table. // This may have deviated from said url if it only checks for <table> element but not its // descendants. List<Element> directDescendants = getDirectDescendants(t); for (Element e : directDescendants) { String role = e.getAttribute("role").toLowerCase(); if (sARIATableDescendantRoles.contains(role) || sARIARoles.contains(role)) { return logAndReturn(Reason.ROLE_DESCENDANT, "_" + role, Type.DATA); } } // 5) Table having datatable="0" attribute is layout table. if (t.getAttribute("datatable").equals("0")) { return logAndReturn(Reason.DATATABLE_0, "", Type.LAYOUT); } // 6) Table having nested table(s) is layout table. // The order here and #7 (table having <=1 row/col is layout table) is different from said // url: the latter has these heuristics after #10 (table having "summary" attribute is // data table), but our eval sets indicate the need to bump these way up to here, because // many (old) pages have layout tables that are nested or with <TH>/<CAPTION>s but only 1 // row or col. if (hasNestedTables(t)) return logAndReturn(Reason.NESTED_TABLE, "", Type.LAYOUT); // 7) Table having only one row or column is layout table. // See comments for #6 about deviation from said url. NodeList<TableRowElement> rows = t.getRows(); if (rows.getLength() <= 1) return logAndReturn(Reason.LESS_EQ_1_ROW, "", Type.LAYOUT); NodeList<TableCellElement> cols = getMaxColsAmongRows(rows); if (cols == null || cols.getLength() <= 1) { return logAndReturn(Reason.LESS_EQ_1_COL, "", Type.LAYOUT); } // 8) Table having legitimate data table structures is data table: // a) table has <caption>, <thead>, <tfoot>, <colgroup>, <col>, or <th> elements Element caption = t.getCaption(); if ((caption != null && hasValidText(caption)) || t.getTHead() != null || t.getTFoot() != null || hasOneOfElements(directDescendants, sHeaderTags)) { return logAndReturn(Reason.CAPTION_THEAD_TFOOT_COLGROUP_COL_TH, "", Type.DATA); } // Extract all <td> elements from direct descendants, for easier/faster multiple access. List<Element> directTDs = new ArrayList<Element>(); for (Element e : directDescendants) { if (e.hasTagName("TD")) directTDs.add(e); } for (Element e : directTDs) { // b) table cell has abbr, headers, or scope attributes if (e.hasAttribute("abbr") || e.hasAttribute("headers") || e.hasAttribute("scope")) { return logAndReturn(Reason.ABBR_HEADERS_SCOPE, "", Type.DATA); } // c) table cell has <abbr> element as a single child element. NodeList<Element> children = e.getElementsByTagName("*"); if (children.getLength() == 1 && children.getItem(0).hasTagName("ABBR")) { return logAndReturn(Reason.ONLY_HAS_ABBR, "", Type.DATA); } } // 9) Table occupying > 95% of document width without viewport meta is layout table; // viewport condition is not in said url, added here for typical mobile-optimized sites. // The order here is different from said url: the latter has it after #14 (>=20 rows is // data table), but our eval sets indicate the need to bump this way up to here, because // many (old) pages have layout tables with the "summary" attribute (#10). Element docElement = t.getOwnerDocument().getDocumentElement(); int docWidth = docElement.getOffsetWidth(); if (docWidth > 0 && (double) t.getOffsetWidth() > 0.95 * (double) docWidth) { boolean viewportFound = false; NodeList<Element> allMeta = docElement.getElementsByTagName("META"); for (int i = 0; i < allMeta.getLength() && !viewportFound; i++) { MetaElement meta = MetaElement.as(allMeta.getItem(i)); viewportFound = meta.getName().equalsIgnoreCase("viewport"); } if (!viewportFound) { return logAndReturn(Reason.MORE_95_PERCENT_DOC_WIDTH, "", Type.LAYOUT); } } // 10) Table having summary attribute is data table. // This is different from said url: the latter lumps "summary" attribute with #8, but we // split it so as to insert #9 in between. Many (old) pages have tables that are clearly // layout: their "summary" attributes say they're for layout. They also occupy > 95% of // document width, so #9 coming before #10 will correctly classify them as layout. if (t.hasAttribute("summary")) return logAndReturn(Reason.SUMMARY, "", Type.DATA); // 11) Table having >=5 columns is data table. if (cols.getLength() >= 5) return logAndReturn(Reason.MORE_EQ_5_COLS, "", Type.DATA); // 12) Table having borders around cells is data table. for (Element e : directTDs) { String border = DomUtil.getComputedStyle(e).getBorderStyle(); if (!border.isEmpty() && !border.equals("none") && !border.equals("hidden")) { return logAndReturn(Reason.CELLS_HAVE_BORDER, "_" + border, Type.DATA); } } // 13) Table having differently-colored rows is data table. String prevBackgroundColor = null; for (int i = 0; i < rows.getLength(); i++) { String color = DomUtil.getComputedStyle(rows.getItem(i)).getBackgroundColor(); if (prevBackgroundColor == null) { prevBackgroundColor = color; continue; } if (!prevBackgroundColor.equalsIgnoreCase(color)) { return logAndReturn(Reason.DIFFERENTLY_COLORED_ROWS, "", Type.DATA); } } // 14) Table having >=20 rows is data table. if (rows.getLength() >= 20) return logAndReturn(Reason.MORE_EQ_20_ROWS, "", Type.DATA); // 15) Table having <=10 cells is layout table. if (directTDs.size() <= 10) return logAndReturn(Reason.LESS_EQ_10_CELLS, "", Type.LAYOUT); // 16) Table containing <embed>, <object>, <applet> or <iframe> elements (typical // advertisement elements) is layout table. if (hasOneOfElements(directDescendants, sObjectTags)) { return logAndReturn(Reason.EMBED_OBJECT_APPLET_IFRAME, "", Type.LAYOUT); } // 17) Table occupying > 90% of document height is layout table. // This is not in said url, added here because many (old) pages have tables that don't fall // into any of the above heuristics but are for layout, and hence shouldn't default to data // by #18. int docHeight = docElement.getOffsetHeight(); if (docHeight > 0 && (double) t.getOffsetHeight() > 0.9 * (double) docHeight) { return logAndReturn(Reason.MORE_90_PERCENT_DOC_HEIGHT, "", Type.LAYOUT); } // 18) Otherwise, it's data table. return logAndReturn(Reason.DEFAULT, "", Type.DATA); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.JQueryFileUploadOverlay.java
License:Apache License
protected void addPendingUpload(JavaScriptObject jqXHR) { Element fileInput = fileUploadWidget.getFileInputElement(); if (!fileUploadWidget.isEnabled()) { for (JavaScriptObject currentXHR : currentXHRs) { cancelXHR(currentXHR);/*w w w . j av a 2 s . c o m*/ } return; } boolean multiple = fileInput.hasAttribute("multiple"); if (!multiple) { if (!currentXHRs.isEmpty()) return; currentXHRs.add(jqXHR); skipLastFiles(jqXHR); } else { currentXHRs.add(jqXHR); } if (currentXHRs.size() == getOriginalFilesCount(jqXHR)) { for (JavaScriptObject xhr : currentXHRs) { if (!isValidFile(getFileName(xhr), getFileSize(xhr))) { currentXHRs.clear(); return; } } queueUploadStart(); // all files added to pending queue, start uploading submitXHR(currentXHRs.get(0)); } }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
private Element findLoadMoreRecordsElement() { if (_ul != null) { final NodeList<Node> children = _ul.getChildNodes(); for (int ri = children.getLength(); ri > 0; --ri) { final Node child = children.getItem(ri - 1); if (child.getNodeType() != Node.ELEMENT_NODE) continue; final Element childElem = (Element) child; if (childElem.hasAttribute(IS_LOAD_MORE_RECORDS_ATTRIBUTE_NAME)) { return childElem; }//from w w w. j a v a2 s . c o m } } return null; }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@Override public Object _getInnerAttributeFromSplitLocator(List<String> locatorArray, GetAttributeConfiguration configuration) { switch (configuration.getAttribute()) { case ELEMENT: if (locatorArray.size() == 1 || locatorArray.size() == 2) { String substring = locatorArray.get(0); if (substring.startsWith("row[")) { final Pair<String, Map<String, String>> p = AutoTest.parseLocatorFallbackPath(substring); if (p != null) { assert "row".equals(p.getFirst()); final Element rowElem = findElementByRowFieldConfigObj(p.getSecond()); if (locatorArray.size() == 1) return rowElem; else if (locatorArray.size() == 2) { substring = locatorArray.get(1); if ("title".equals(substring)) { return getChildElementHavingClass(rowElem, RECORD_TITLE_CLASS_NAME); }/*from w ww .j av a 2 s.c o m*/ } } } else if ("loadMoreRecordsRow".equals(substring) && locatorArray.size() == 1) { return findLoadMoreRecordsElement(); } } break; case VALUE: if (locatorArray.size() == 2) { String substring = locatorArray.get(0); if (substring.startsWith("row[")) { final Pair<String, Map<String, String>> p = AutoTest.parseLocatorFallbackPath(substring); if (p != null) { assert "row".equals(p.getFirst()); final Element rowElem = findElementByRowFieldConfigObj(p.getSecond()); if (rowElem != null && rowElem.hasAttribute(RECORD_INDEX_ATTRIBUTE_NAME)) { int i = Integer.parseInt(rowElem.getAttribute(RECORD_INDEX_ATTRIBUTE_NAME), 10); final RecordList data = _getData(); if (data != null && i >= 0 && i < data.size()) { final Record record = data.get(i); substring = locatorArray.get(1); if ("isSelected".equals(substring)) return isSelected(record); else if ("title".equals(substring)) { return record.getAttributeAsObject(getTitleField()); } } } } } } break; default: break; } return super._getInnerAttributeFromSplitLocator(locatorArray, configuration); }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@SGWTInternal protected Integer _findRecordIndex(Element element) { if (element == null) { return null; }//from w w w . jav a 2 s. co m while (!element.hasAttribute(RECORD_INDEX_ATTRIBUTE_NAME)) { element = element.getParentElement(); if (element == null) { break; } } boolean found = false; if (element != null) { if (element.getTagName().equalsIgnoreCase("li")) { Element parent = element.getParentElement(); Element thisElement = this.getElement(); while (parent != null) { if (parent == thisElement) { found = true; break; } parent = parent.getParentElement(); } } else { NodeList<Node> nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.getItem(i); if (element == node) { found = true; break; } } } } if (found) { assert element != null; return Integer.valueOf(element.getAttribute(RECORD_INDEX_ATTRIBUTE_NAME)); } return null; }