/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
/** * Returns the document type public identifier * specified for this document, or null. */ public static String whichDoctypePublic( Document doc ) { DocumentType doctype; /* DOM Level 2 was introduced into the code base*/ doctype = doc.getDoctype(); if ( doctype != null ) { // Note on catch: DOM Level 1 does not specify this method // and the code will throw a NoSuchMethodError try { return doctype.getPublicId(); } catch ( Error except ) { } } if ( doc instanceof HTMLDocument ) return DTD.XHTMLPublicId; return null; }
/** * Returns the document type system identifier * specified for this document, or null. */ public static String whichDoctypeSystem( Document doc ) { DocumentType doctype; /* DOM Level 2 was introduced into the code base*/ doctype = doc.getDoctype(); if ( doctype != null ) { // Note on catch: DOM Level 1 does not specify this method // and the code will throw a NoSuchMethodError try { return doctype.getSystemId(); } catch ( Error except ) { } } if ( doc instanceof HTMLDocument ) return DTD.XHTMLSystemId; return null; }
public JProxyExampleDocument(ItsNatServletRequest request,ItsNatHTMLDocument itsNatDoc,FalseDB db) { this.itsNatDoc = itsNatDoc; HTMLDocument doc = itsNatDoc.getHTMLDocument(); ItsNatComponentManager compMgr = itsNatDoc.getItsNatComponentManager(); this.textInput = (ItsNatHTMLInputText)compMgr.createItsNatComponentById("inputId"); EventListener listener = new EventListener() { @Override public void handleEvent(Event evt) { String text = textInput.getText(); String comment = " YES I SAID THAT"; // " YES I SAID THAT"; resultsElem.setTextContent(text + comment); } }; Element buttonElem = doc.getElementById("buttonId"); ((EventTarget)buttonElem).addEventListener("click",listener,false); this.resultsElem = doc.getElementById("resultsId"); }
/** * 从指定流解析HTML * * @param in * 输入流 * @param charSet * 字符集,为null时自动检测 * @return 解析后的DocumentFragment对象 * @throws SAXException * XML语法异常时抛出 * @throws IOException * IO操作错误时抛出 */ public static DocumentFragment parseHTML(InputStream in, String charSet) throws SAXException, IOException { if (parser == null) throw new UnsupportedOperationException( "HTML parser module not loaded, to activate this feature, you must add JEF common-ioc.jar to classpath"); InputSource source; if (charSet != null) { source = new InputSource(new XmlFixedReader(new InputStreamReader(in, charSet))); source.setEncoding(charSet); } else { source = new InputSource(in); } synchronized (parser) { HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); parser.parse(source, fragment); return fragment; } }
/** Works around weird linkage problem, SPF-8671, * in some builds, where one plugin can import this * and another can't. * @param title * @return */ public static HTMLDocument createDocument(String title) { // ClassLoader.getSystemClassLoader().loadClass("org.apache.html.dom.HTMLDOMImplementationImpl", true); LogUtil.warn("Static " + PlanDiffOutputAsTreeHTML.DOM + " is class " + PlanDiffOutputAsTreeHTML.DOM.getClass()); LogUtil.warn(DOM + " is class " + DOM.getClass()); // FIXME: It's a complete mystery ?why the simple call below doesn't work. See SPF-8671. return DOM.createHTMLDocument(title); // try { // Class<?> class1 = ClassLoader.getSystemClassLoader().loadClass("org.apache.html.dom.HTMLDOMImplementationImpl"); // Class <? extends HTMLDOMImplementation> class2 = (Class<? extends HTMLDOMImplementation>) class1; // return class2.getMethod(", arg1) // } catch (Exception e) { // LogUtil.error(e); // return null; // } }
/** * The subtree rooted by the specified element is serialized to a string. * * @param root * the root of the subtree to be serialized (this may be any * node, even a document) * @return the serialized string */ public String serializeToString(Node root) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { if (root instanceof Document) { return documentToString((Document) root); } else if (root instanceof DocumentFragment) { if (root.getOwnerDocument() instanceof HTMLDocument) { return ""; } root = root.getFirstChild(); } transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(root), new StreamResult(writer)); return writer.getBuffer().toString().replaceAll("\n|\r", ""); } catch (TransformerException e) { logger.error(e.getMessage()); } return ""; }
/** * parse the given test with the given URL * @param text * @param pageURL * @throws SAXException * @throws IOException */ public void parse( String text, URL pageURL ) throws SAXException, IOException { HTMLParserFactory.getHTMLParser().parse( pageURL, text, new DocumentAdapter() { public void setDocument(HTMLDocument document ) { HTMLPage.this.setRootNode( document ); } public String getIncludedScript( String srcAttribute ) throws IOException { return HTMLPage.this.getIncludedScript( srcAttribute ); } public ScriptingHandler getScriptingHandler() { return getResponse().getScriptingHandler(); } }); }
/** * parse the given URL with the given pageText using the given document adapter * @param pageURL * @param pageText * @param adapter */ public void parse( URL pageURL, String pageText, DocumentAdapter adapter ) throws IOException, SAXException { try { NekoDOMParser parser = NekoDOMParser.newParser( adapter, pageURL ); parser.parse( new InputSource( new StringReader( pageText ) ) ); Document doc=parser.getDocument(); adapter.setDocument( (HTMLDocument)doc ); } catch (NekoDOMParser.ScriptException e) { throw e.getException(); } }
public void parse( URL pageURL, String pageText, DocumentAdapter adapter ) throws IOException, SAXException { try { Document jtidyDocument = getParser( pageURL ).parseDOM( new ByteArrayInputStream( pageText.getBytes( UTF_ENCODING ) ), null ); HTMLDocument htmlDocument = new HTMLDocumentImpl(); NodeList nl = jtidyDocument.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node importedNode = nl.item(i); if (importedNode.getNodeType() != Node.DOCUMENT_TYPE_NODE) htmlDocument.appendChild( htmlDocument.importNode( importedNode, true ) ); } adapter.setDocument( htmlDocument ); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "UTF-8 encoding failed" ); } }
public HtmlContent(final HTMLDocument document, final HtmlPanel panel, final RecordedInputStream ris, final String charset) { super(); this.document = document; this.panel = panel; this.ris = ris; this.charset = charset; this.sourceCode = null; }
public HtmlContent(final HTMLDocument document, final HtmlPanel panel, final String sourceCode) { super(); this.document = document; this.panel = panel; this.ris = null; this.charset = null; this.sourceCode = sourceCode; }
private static ComponentContent getErrorComponent(final NavigatorFrame frame, final ClientletResponse response, final Throwable exception) { final HtmlPanel panel = new HtmlPanel(); final HtmlRendererContext rcontext = HtmlRendererContextImpl.getHtmlRendererContext(frame); panel.setHtml(getErrorHtml(response, exception), "about:error", rcontext); String sourceCode = "[NOT AVAILABLE]"; if (exception instanceof ClientletException) { final ClientletException ce = (ClientletException) exception; final String sc = ce.getSourceCode(); if (sc != null) { sourceCode = sc; } } return new HtmlContent((HTMLDocument) panel.getRootNode(), panel, sourceCode); }
/** * 载入HTML文档 * * @param in * 输入流 * @return DocumentFragment DOM模型 * @throws SAXException * 解析错误 * @throws IOException * 读写错误 */ public static DocumentFragment parseHTML(Reader in) throws SAXException, IOException { if (parser == null) throw new UnsupportedOperationException( "HTML parser module not loaded, to activate this feature, you must add JEF common-ioc.jar to classpath"); InputSource source; source = new InputSource(in); synchronized (parser) { HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); parser.parse(source, fragment); return fragment; } }
@SuppressWarnings("deprecation") // I keep trying to find something to replace HTMLSerializer and OutputFormat. public void writeDocument(Writer writer, HTMLDocument document) throws IOException { format.setIndenting(false); // newlines cause extraneous spaces in INS and DEL text diffs doSerializationCustomizations(); serializer.setOutputCharStream(writer); serializer.serialize(document); writer.close(); }
@SuppressWarnings("deprecation") // FIXME -- better alternative to these methods? public static void writeDocument(Writer writer, HTMLDocument document) throws IOException { format.setIndenting(true); serializer.setOutputCharStream(writer); serializer.serialize(document); writer.close(); }
/** * Create a new HTML document of the specified <TT>TITLE</TT> text. * * @param title The document title text * @return New HTML document */ public final HTMLDocument createHTMLDocument( String title ) throws DOMException { HTMLDocument doc; if ( title == null ) throw new NullPointerException( "HTM014 Argument 'title' is null." ); doc = new HTMLDocumentImpl(); doc.setTitle( title ); return doc; }
public NodeList parse(String html, HTMLDocument document) { JSObject wrapperDiv = (JSObject) engine.executeScript("document.createElement('div')"); wrapperDiv.setMember("innerHTML", html); JSObject childNodes = (JSObject) wrapperDiv.getMember("childNodes"); NodeList list = new DefaultNodeList(childNodes); return list; }
@Override public List<Element> parseHTML(String html) { NodeList childNodes = parser.parse(html, (HTMLDocument) document); List<Element> list = new ArrayList<>(); for (int i = 0; i < childNodes.getLength(); i++) { Node next = childNodes.item(i); Element element = ((WebKitPageContext) context).createElement(next, this, engine); list.add(element); } if (list.isEmpty()) { return Collections.emptyList(); } else { return list; } }
public static Node parse(String content) throws SAXException, IOException { DOMFragmentParser parser = new DOMFragmentParser(); HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); InputSource is = new InputSource(new StringReader(content)); parser.parse(is, fragment); return fragment; }
/** * Creates a new instance of SimpleHtmlDocument. * * @param Document the HTML DOM document to wrap within this SimpleDocument. */ public SimpleHtmlDocument(HTMLDocument dom) { if (dom == null) { throw new NullPointerException("DOM Cannot be null"); } this.dom = dom; }
public static Node parse( String content ) throws SAXException, IOException { DOMFragmentParser parser = new DOMFragmentParser(); HTMLDocument document = new HTMLDocumentImpl(); DocumentFragment fragment = document.createDocumentFragment(); InputSource is = new InputSource( new StringReader( content ) ); parser.parse( is, fragment ); return fragment; }
public HTMLDocument getDocument() { return _document; }
/** * Returns the document associated with this window. Uses the same name as that used by elements in the DOM. */ public HTMLDocument getOwnerDocument() { return _document; }
private ScriptingHandler getScriptingHandler() { _documentAdapter.setDocument( (HTMLDocument) getCurrentElement().getOwnerDocument() ); return _documentAdapter.getScriptingHandler(); }