List of usage examples for org.w3c.dom Element getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:kenh.xscript.ScriptUtils.java
/** * Get xScript instance./* w w w. j a v a 2s. co m*/ * @param node * @param env * @return */ public static final Element getInstance(Node node, Environment env) throws UnsupportedScriptException { if (node.getNodeType() != Node.ELEMENT_NODE) return null; if (env == null) env = new Environment(); Element element = getElement(node, env); if (!(element instanceof Script)) throw new UnsupportedScriptException(element, "The root element should be <script>. [" + element.getClass().getCanonicalName() + "]"); return element; }
From source file:kenh.xscript.ScriptUtils.java
/** * Debug method for <code>Element</code> * @param element/*from w w w. j a v a 2s . c om*/ * @param level * @param stream */ private static final void debug_(Element element, int level, PrintStream stream) { String repeatStr = " "; String prefix = StringUtils.repeat(repeatStr, level); stream.print(prefix + "<" + element.getClass().getCanonicalName()); // Attribute output Map<String, String> attributes = element.getAttributes(); if (attributes != null && attributes.size() > 0) { Set<String> keys = attributes.keySet(); for (String key : keys) { stream.print(" " + key + "=\"" + attributes.get(key) + "\""); } } Vector<Element> children = element.getChildren(); String text = element.getText(); if ((children == null || children.size() == 0) && StringUtils.isBlank(text)) { stream.println("/>"); return; } else { stream.println(">"); // child elements if (children != null && children.size() > 0) { for (Element child : children) { debug_(child, level + 1, stream); } } // text/context if (StringUtils.isNotBlank(text)) { stream.println(prefix + repeatStr + "<![CDATA[" + text + "]]>"); } stream.println(prefix + "</" + element.getClass().getCanonicalName() + ">"); } }
From source file:eu.esdihumboldt.hale.common.core.io.HaleIO.java
/** * Get the value of a complex property represented as a DOM element. * /*from ww w. ja v a 2s.c o m*/ * @param element the DOM element * @param expectedType the expected parameter type, this must be either * {@link String}, DOM {@link Element} or a complex value type * defined in the {@link ComplexValueExtension} * @param context the context object, may be <code>null</code> * @return the complex value or <code>null</code> if it could not be created * from the element */ @SuppressWarnings("unchecked") public static <T> T getComplexValue(Element element, Class<T> expectedType, Object context) { if (element == null) { return null; } QName name; if (element.getNamespaceURI() != null && !element.getNamespaceURI().isEmpty()) { name = new QName(element.getNamespaceURI(), element.getLocalName()); } else { String ln = element.getTagName(); // .getLocalName(); name = new QName(ln); } ComplexValueDefinition cvt = ComplexValueExtension.getInstance().getDefinition(name); Object value = null; if (cvt != null) { try { value = cvt.fromDOM(element, context); } catch (Exception e) { throw new IllegalStateException("Failed to load complex value from DOM", e); } } if (value != null && expectedType.isAssignableFrom(value.getClass())) { return (T) value; } // maybe the element itself is OK if (expectedType.isAssignableFrom(element.getClass())) { return (T) element; } if (expectedType.isAssignableFrom(String.class)) { // FIXME use legacy complex value if possible } return null; }
From source file:io.github.bonigarcia.wdm.BrowserManager.java
public List<URL> getDriversFromXml(URL driverUrl, List<String> driverBinary) throws Exception { log.info("Reading {} to seek {}", driverUrl, getDriverName()); List<URL> urls = new ArrayList<URL>(); int retries = 1; int maxRetries = WdmConfig.getInt("wdm.seekErrorRetries"); do {/* w ww . j av a2 s . c o m*/ try { Proxy proxy = createProxy(); URLConnection conn = proxy != null ? driverUrl.openConnection(proxy) : driverUrl.openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); Document xml = loadXML(reader); XPath xPath = XPathFactory.newInstance().newXPath(); NodeList nodes = (NodeList) xPath.evaluate("//Contents/Key", xml.getDocumentElement(), XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); ++i) { Element e = (Element) nodes.item(i); String version = e.getChildNodes().item(0).getNodeValue(); urls.add(new URL(driverUrl + version)); } reader.close(); break; } catch (Throwable e) { log.warn("[{}/{}] Exception reading {} to seek {}: {} {}", retries, maxRetries, driverUrl, getDriverName(), e.getClass().getName(), e.getMessage(), e); retries++; if (retries > maxRetries) { throw e; } } } while (true); return urls; }
From source file:com.bluexml.side.clazz.alfresco.reverse.reverser.ReverseModel.java
protected void createDataType(Model model, com.bluexml.side.alfresco.binding.Model.DataTypes.DataType dataType) { CustomDataType createCustomDataType = CommonFactory.eINSTANCE.createCustomDataType(); // extract data from dataType Element analyserClass = (Element) dataType.getAnalyserClass(); if (analyserClass == null) { // model from alfresco 4.0+ analyserClass = (Element) dataType.getDefaultAnalyserClass(); }//from w w w. ja v a 2s.c o m System.out.println("ReverseModel.addDataTypes() " + analyserClass.getClass().getName()); String description = dataType.getDescription(); Element javaClass = (Element) dataType.getJavaClass(); System.out.println("ReverseModel.addDataTypes() " + javaClass.getClass().getName()); String qname = dataType.getName(); String title = dataType.getTitle(); // set customDataType setNameAndNS(createCustomDataType, qname); createCustomDataType.setDescription(description); createCustomDataType.setDataTypeImp(javaClass.getTextContent()); MetaInfo createMetaInfo = ReverseHelper.createMetaInfo("analyser", null, analyserClass.getTextContent()); createCustomDataType.getMetainfo().add(createMetaInfo); model.getCustomDataTypeSet().add(createCustomDataType); register.recordNewEObject(createCustomDataType, qname); System.out.println("ReverseModel.addDataTypes() reccord :" + qname); ReverseHelper.addSimpleNameTag(createCustomDataType); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Document.java
/** * Create a new HTML element with the given tag name. * * @param tagName the tag name//from ww w . j a va 2s. co m * @return the new HTML element, or NOT_FOUND if the tag is not supported */ @JsxFunction public Object createElement(String tagName) { Object result = NOT_FOUND; try { final BrowserVersion browserVersion = getBrowserVersion(); // FF supports document.createElement('div') or supports document.createElement('<div>') // but not document.createElement('<div name="test">') // IE supports also document.createElement('<div name="test">') if (!browserVersion.hasFeature(JS_DOCUMENT_CREATE_ELEMENT_EXTENDED_SYNTAX) && tagName.startsWith("<") && tagName.endsWith(">")) { tagName = tagName.substring(1, tagName.length() - 1); final Matcher matcher = TAG_NAME_PATTERN.matcher(tagName); if (!matcher.matches()) { LOG.info("createElement: String contains an invalid character: "); throw Context.reportRuntimeError("String contains an invalid character"); } } final SgmlPage page = getPage(); final org.w3c.dom.Element element = page.createElement(tagName); if (element instanceof BaseFrameElement) { ((BaseFrameElement) element).markAsCreatedByJavascript(); } final Object jsElement = getScriptableFor(element); if (jsElement == NOT_FOUND) { if (LOG.isDebugEnabled()) { LOG.debug("createElement(" + tagName + ") cannot return a result as there isn't a JavaScript object for the element " + element.getClass().getName()); } } else { result = jsElement; } } catch (final ElementNotFoundException e) { // Just fall through - result is already set to NOT_FOUND } return result; }
From source file:com.amalto.workbench.providers.datamodel.util.SchemaItemLabelCreator.java
protected String getLableForElement(Element element) { try {//from w w w. ja va 2s. co m if (element.getLocalName().equals("documentation")) {//$NON-NLS-1$ return "Documentation: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (element.getLocalName().equals("appinfo")) {//$NON-NLS-1$ String source = element.getAttribute("source");//$NON-NLS-1$ if (source != null) { if (source.startsWith("X_Label_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(8).toLowerCase()) + " Label: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$ return "Foreign Key: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$ return "Foreign Key Info: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$ return "Source System: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$ return "Target System(s): " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(14).toLowerCase()) + " Description: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_Write")) {//$NON-NLS-1$ return "Writable By : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$ return "Look Field : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Workflow")) {//$NON-NLS-1$ return "Workflow access : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Hide")) {//$NON-NLS-1$ return "No Access to : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Facet")) {//$NON-NLS-1$ return source.substring(2, 7) + "_Msg_" + source.substring(8) + ": "//$NON-NLS-1$//$NON-NLS-2$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$ return source + ": " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Schematron")) {//$NON-NLS-1$ String pattern = (String) element.getFirstChild().getUserData("pattern_name");//$NON-NLS-1$ if (pattern == null) { Element el = Util.parse(element.getChildNodes().item(0).getNodeValue()) .getDocumentElement(); if (el.getAttributes().getNamedItem("name") != null)//$NON-NLS-1$ pattern = el.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$ } return "Validation Rule: " + (pattern == null ? "" : pattern);//$NON-NLS-1$//$NON-NLS-2$ } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$ return "Foreign Key resolution: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$ return "Foreign Key integrity: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$ return "Foreign Key integrity override: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$ return "Foreign Key Filter: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else { return source + ": " + Util.nodeToString(element);//$NON-NLS-1$ } } else { return Util.nodeToString(element); } } else { return Util.nodeToString(element); } } catch (Exception e) { log.error(e.getMessage(), e); } return "?? " + element.getClass().getName() + " : " + element.toString();//$NON-NLS-1$//$NON-NLS-2$ }
From source file:org.apache.axis2.wsdl.util.WSDLWrapperReloadImpl.java
public org.w3c.dom.Element getDocumentationElement() { if (isDebugEnabled) { log.trace(myClassName + ".getDocumentationElement() call stack =" + JavaUtils.callStackToString()); }// w ww .j av a 2 s.c o m // See if we have a soft reference to the DocumentElement if (hasCachedDocElement()) { Element e = getCachedDocElement(); if (log.isDebugEnabled()) { log.debug(myClassName + ".getDocumentationElement() from soft reference "); } return e; } // reload the wsdl definition object // TODO: what about any online changes that have been made to the definition? if (isDebugEnabled) { log.debug(myClassName + ".getDocumentationElement() from reloaded wsdl Definition"); } Definition def = null; try { def = loadDefinition(); } catch (Exception e) { if (isDebugEnabled) { log.debug(myClassName + ".getDocumentationElement(): error trying to load Definition [" + e.getClass().getName() + "] error [" + e.getMessage() + "] ", e); } } if (def != null) { org.w3c.dom.Element docElement = def.getDocumentationElement(); setCachedDocElement(docElement); setCachedTypes(def.getTypes()); if (isDebugEnabled) { if (docElement != null) { log.debug(myClassName + ".getDocumentationElement() from reloaded wsdl Definition returning NON-NULL org.w3c.dom.Element"); } else { log.debug(myClassName + ".getDocumentationElement() from reloaded wsdl Definition returning NULL org.w3c.dom.Element"); } } return docElement; } else { if (isDebugEnabled) { log.debug(myClassName + ".getDocumentationElement() returning NULL"); } return null; } }
From source file:org.jboss.jsfunit.test.richfaces.RichInplaceInputTest.java
/** * This method mirrors the implementation of RichFacesClient.setInplaceInput() * but adds a great many assertions to verify both htmlunit and richfaces * are behaving as they should. ( used by testInplaceInput_Raw() ) * * @param controlId// w w w. jav a2s . c o m * @param value * @param customSaveId * * @throws IOException */ private void setInplaceInput_CImpl(String controlId, String value, String customSaveId) throws IOException { // Find outside control Element e = client.getElement(controlId); assertNotNull("Control not found: " + controlId, e); assertTrue("Control not expected type (HtmlSpan): " + e.getClass(), e instanceof HtmlSpan); HtmlSpan span = (HtmlSpan) e; // Find text control e = client.getElement(controlId + "tempValue"); assertNotNull("Control not found: " + controlId + "tempValue", e); assertTrue("Control not expected type (HtmlTextInput): " + e.getClass(), e instanceof HtmlTextInput); HtmlTextInput nameInput = (HtmlTextInput) e; // Make sure input control is hidden String hiddenStyle = nameInput.getAttribute("style"); assertTrue("Input control not hidden as expected: [" + hiddenStyle + "]", hiddenStyle.contains("display:none") || hiddenStyle.contains("display: none")); // Activate control - click on outside table control span.click(); // Make sure input control is now visible String visibleStyle = nameInput.getAttribute("style"); assertFalse("Input control not visible as expected: [" + visibleStyle + "]", visibleStyle.contains("display:none") || visibleStyle.contains("display: none")); // Type value into input control nameInput.type(value); // Type #3 - CUSTOM save button if (customSaveId != null) { // Find and Click save button e = client.getElement(customSaveId); assertNotNull("Control not found: " + customSaveId, e); assertTrue("Control not expected type (HtmlButton): " + e.getClass(), e instanceof HtmlButton); HtmlButton saveButton = (HtmlButton) e; saveButton.click(); } else { // Check to see if buttons are visible e = client.getElement(controlId + "bar"); assertNotNull("Control not found: " + controlId + "bar", e); assertTrue("Control not expected type (HtmlDivision): " + e.getClass(), e instanceof HtmlDivision); HtmlDivision buttons = (HtmlDivision) e; String buttonStyle = buttons.getAttribute("style"); // Type #1 - NO BUTTONS if (buttonStyle.contains("display:none") || buttonStyle.contains("display: none")) { // Remove focus from name input control nameInput.blur(); // Type #2 - built-in buttons } else { // Find and "mousedown" the standard "ok" button e = client.getElement(controlId + "ok"); assertNotNull("Control not found: " + controlId + "ok", e); assertTrue("Control not expected type (HtmlImageInput): " + e.getClass(), e instanceof HtmlImageInput); HtmlImageInput okButton = (HtmlImageInput) e; okButton.fireEvent("mousedown"); } } // Make sure name input is no longer visible hiddenStyle = nameInput.getAttribute("style"); assertTrue("Input control not hidden as expected: [" + hiddenStyle + "]", hiddenStyle.contains("display:none") || hiddenStyle.contains("display: none")); String inputValue = nameInput.getValueAttribute(); assertEquals("Input control value is not set as expected", _TEST_NAME_VALUE, inputValue); // Find the hidden input control e = client.getElement(controlId + "value"); assertNotNull("Control not found: " + controlId + "value", e); assertTrue("Control not expected type (HtmlHiddenInput): " + e.getClass(), e instanceof HtmlHiddenInput); HtmlHiddenInput hiddenInput = (HtmlHiddenInput) e; // Make sure the hidden value is set String hiddenValue = hiddenInput.getValueAttribute(); assertEquals("Hidden control value is not set as expected", value, hiddenValue); }
From source file:org.jboss.jsfunit.test.richfaces.RichInplaceInputTest.java
/** * This helper function will make sure the hidden value of the * inplace input control is set properly. * * @param componentID//www . ja va2 s . c o m * @param value */ private void assertInplaceInputValue(String componentID, String value) { // Find the hidden input control Element e = client.getElement(componentID + "value"); assertNotNull("Control not found: " + componentID + "value", e); assertTrue("Control not expected type (HtmlHiddenInput): " + e.getClass(), e instanceof HtmlHiddenInput); HtmlHiddenInput hiddenInput = (HtmlHiddenInput) e; // Make sure the hidden value is set String hiddenValue = hiddenInput.getValueAttribute(); assertEquals("Hidden control value is not set as expected", value, hiddenValue); }