List of usage examples for com.google.gwt.dom.client Document getURL
public String getURL()
From source file:ch.unifr.pai.twice.widgets.mpbrowser.client.MPBrowser.java
License:Apache License
@Override public void onModuleLoad() { multiCursor.start();//from ww w .j a v a 2s .c om scrollBar.getElement().getStyle().setBackgroundColor("lightgrey"); scrollBar.addNorth(scrollUp, 30); scrollBar.addSouth(scrollDown, 30); scrollBar.add(new HTML()); textBox.setWidth("100%"); navig.add(backward); navig.add(forward); navig.setCellWidth(backward, "50px"); navig.setCellWidth(forward, "50px"); navig.add(textBox); navig.setWidth("100%"); Storage s = Storage.getSessionStorageIfSupported(); if (s != null) { String type = s.getItem("ch.unifr.pai.mice.deviceType"); if (type == null || !type.equals("multicursor")) { s.setItem("ch.unifr.pai.mice.deviceType", "multicursor"); } } frame.setUrl(GWT.getHostPageBaseURL() + "http://www.google.ch"); frame.setHeight("100%"); frame.setWidth("100%"); frame.getElement().setAttribute("scrolling", "no"); frame.addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { if (frame.getUrl() != null && !frame.getUrl().startsWith(GWT.getHostPageBaseURL())) { frame.setUrl(GWT.getHostPageBaseURL() + frame.getUrl()); updateScrollBar(); } Document d = IFrameElement.as(frame.getElement()).getContentDocument(); textBox.setValue(d.getURL()); } }); scrollBar2.getElement().getStyle().setBackgroundColor("lightgrey"); scrollBar2.addNorth(scrollUp2, 30); scrollBar2.addSouth(scrollDown2, 30); scrollBar2.add(new HTML()); textBox2.setWidth("100%"); navig2.add(backward2); navig2.add(forward2); navig2.setCellWidth(backward2, "50px"); navig2.setCellWidth(forward2, "50px"); navig2.add(textBox2); navig2.setWidth("100%"); frame2.setUrl(GWT.getHostPageBaseURL() + "http://www.google.ch"); frame2.setHeight("100%"); frame2.setWidth("100%"); frame2.getElement().setAttribute("scrolling", "no"); frame2.addLoadHandler(new LoadHandler() { @Override public void onLoad(LoadEvent event) { if (frame2.getUrl() != null && !frame2.getUrl().startsWith(GWT.getHostPageBaseURL())) { frame2.setUrl(GWT.getHostPageBaseURL() + frame2.getUrl()); updateScrollBar2(); } Document d = IFrameElement.as(frame2.getElement()).getContentDocument(); textBox2.setValue(d.getURL()); } }); DockLayoutPanel p = new DockLayoutPanel(Unit.PX); p.addNorth(navig, 25); p.addEast(scrollBar, 30); p.add(frame); browserSplit.addNorth(p, 500); DockLayoutPanel p2 = new DockLayoutPanel(Unit.PX); p2.addNorth(navig2, 25); p2.addEast(scrollBar2, 30); p2.add(frame2); browserSplit.add(p2); RootLayoutPanel.get().add(browserSplit); }
From source file:client.net.sf.saxon.ce.Configuration.java
License:Mozilla Public License
public DocumentInfo getHostPage() { // attempt to initialise this only once - in the Configuration constructor led // to NamePool exception Document page = Document.get(); return new HTMLDocumentWrapper(page, page.getURL(), this, DocType.UNKNOWN); }
From source file:client.net.sf.saxon.ce.expr.instruct.ResultDocument.java
License:Mozilla Public License
public TailCall processLeavingTail(XPathContext context) throws XPathException { final Controller controller = context.getController(); final APIcommand command = controller.getApiCommand(); XPathContext c2 = context.newMinorContext(); int action = APPEND_CONTENT; if (methodExpression != null) { String method = methodExpression.evaluateAsString(context).toString(); StructuredQName methodQ;// w w w. j ava2 s. c o m if (method.indexOf(':') >= 0) { methodQ = StructuredQName.fromLexicalQName(method, false, nsResolver); } else { methodQ = new StructuredQName("", "", method); } if ("replace-content".equals(methodQ.getLocalName())) { // TODO: check the namespace URI is NamespaceConstant.IXSL action = REPLACE_CONTENT; } } String hrefValue = null; if (href != null) { hrefValue = href.evaluateAsString(context).toString(); } else if (command == APIcommand.UPDATE_HTML) { throw new XPathException("html update - no href value for result-document instruction"); } else { hrefValue = "result" + (controller.getResultDocumentCount() + 1); } NodeInfo target = null; Node targetNode = null; String contextNodeName = ""; String absURI = ""; if (command == APIcommand.TRANSFORM_TO_DOCUMENT) { absURI = getValidAbsoluteURI(controller, hrefValue); targetNode = XMLDOM.createDocument(absURI); } else if (command == APIcommand.TRANSFORM_TO_FRAGMENT || command == APIcommand.TRANSFORM_TO_HTML_FRAGMENT) { absURI = getValidAbsoluteURI(controller, hrefValue); targetNode = HTMLDocumentWrapper.createDocumentFragment((Document) controller.getTargetNode()); } else if (hrefValue.startsWith("#")) { hrefValue = hrefValue.substring(1); targetNode = ((Document) controller.getTargetNode()).getElementById(hrefValue); // com.google.gwt.dom.client.Document.get().getElementById(hrefValue); } else if (hrefValue.startsWith("?select=")) { String select = hrefValue.substring(8); AbstractStaticContext env = new AbstractStaticContext() { public String getURIForPrefix(String prefix) throws XPathException { return null; } public Expression bindVariable(StructuredQName qName) throws XPathException { return null; } public NamespaceResolver getNamespaceResolver() { return null; } //override getFunctionLibrary to return that loaded for the prepared stylesheet public FunctionLibrary getFunctionLibrary() { return controller.getPreparedStylesheet().getFunctionLibrary(); } }; ExpressionVisitor visitor = new ExpressionVisitor(); visitor.setConfiguration(context.getConfiguration()); visitor.setExecutable(new Executable(context.getConfiguration())); visitor.setStaticContext(env); env.setConfiguration(context.getConfiguration()); Container container = (StyleElement) getSourceLocator(); Expression expr = null; try { expr = ExpressionTool.make(select, env, container, 0, Token.EOF, getSourceLocator()); } catch (Exception e) { // occurs if expression contains references to variables etc. within the dynamic context throw new XPathException( "Error on evaluating (in static context) result-document href: " + hrefValue); } expr = visitor.typeCheck(expr, NodeKindTest.DOCUMENT); XPathContext c3 = context.newCleanContext(); //context for ?select expression is the html page if an external node is the context Document page = (Document) controller.getTargetNode(); //com.google.gwt.dom.client.Document.get(); Item cItem = context.getContextItem(); NodeInfo currentContextItem; if (cItem instanceof JSObjectValue) { currentContextItem = null; } else { currentContextItem = (NodeInfo) cItem; } boolean useCurrentContext; if (currentContextItem == null) { useCurrentContext = false; } else { useCurrentContext = (currentContextItem.getBaseURI().equals(page.getURL())); } NodeInfo contextItem; if (useCurrentContext) { contextItem = currentContextItem; if (LogConfiguration.loggingIsEnabled() && contextItem.getNodeKind() == Type.ELEMENT) { contextNodeName = controller.getNamePool().getLocalName(contextItem.getNameCode()); } } else { contextItem = new HTMLDocumentWrapper(page, page.getURL(), context.getConfiguration(), DocType.UNKNOWN); } if (LogConfiguration.loggingIsEnabled()) { contextNodeName = (contextNodeName.equals("") ? "" : " context node: " + contextNodeName); } AxisIterator iterator = SingleNodeIterator.makeIterator(contextItem); iterator.next(); // position on the single item c3.setCurrentIterator(iterator); SequenceIterator iter = expr.iterate(c3); Item resultItem = iter.next(); if (resultItem == null) { } // do nothing else if (!(resultItem instanceof NodeInfo)) { throw new XPathException("non-node returned by result-document href: " + hrefValue); } else { target = (NodeInfo) resultItem; targetNode = (com.google.gwt.dom.client.Node) ((HTMLNodeWrapper) target).getUnderlyingNode(); } } else if (command == APIcommand.UPDATE_HTML) { throw new XPathException( "expected '?select=' or '#' at start of result-document href, found: " + hrefValue); } if (targetNode == null) { logger.warning("result-document target not found for href: " + hrefValue + contextNodeName); return null; } else { logger.fine("processing result-document for href: " + hrefValue + contextNodeName); } //checkAcceptableUri(context, absoluteResultURI.toString()); //IFrameElement container = Document.get().createIFrameElement(); Node container = null; if (command == APIcommand.UPDATE_HTML) { container = HTMLDocumentWrapper.createDocumentFragment((Document) controller.getTargetNode()); } else { addResultDocument(context, new DocumentURI(absURI), (Document) targetNode); container = targetNode; } PipelineConfiguration pipe = controller.makePipelineConfiguration(); Receiver out = controller.openResult(pipe, c2, container, action); try { content.process(c2); out.endDocument(); } catch (XPathException err) { err.setXPathContext(context); err.maybeSetLocation(getSourceLocator()); throw err; } controller.closeResult(out, c2); if (command == APIcommand.UPDATE_HTML) { PendingUpdateList list = controller.getPendingUpdateList(); if (action == REPLACE_CONTENT && command == APIcommand.UPDATE_HTML) { int existingChildren = targetNode.getChildCount(); for (int i = 0; i < existingChildren; i++) { Node child = targetNode.getChild(i); list.add(new DeleteAction(child)); } } list.add(new InsertAction(container, targetNode, InsertAction.LAST)); } //controller.setResultTree(absoluteResultURI.toString(), root); return null; }
From source file:client.net.sf.saxon.ce.js.IXSLFunction.java
License:Mozilla Public License
@SuppressWarnings("rawtypes") public static SequenceIterator convertFromJavaScript(Object jsValue, Configuration config) { if (jsValue == null) { return EmptyIterator.getInstance(); } else if (jsValue instanceof String) { return SingletonIterator.makeIterator(new StringValue((String) jsValue)); } else if (jsValue instanceof Double) { return SingletonIterator.makeIterator(new DoubleValue((Double) jsValue)); } else if (jsValue instanceof Boolean) { return SingletonIterator.makeIterator(BooleanValue.get((Boolean) jsValue)); } else if (!(jsValue instanceof JavaScriptObject)) { return EmptyIterator.getInstance(); }/* w w w.j a v a 2 s . com*/ JavaScriptObject jsObj = (JavaScriptObject) jsValue; short nodeType = getNodeType(jsObj); if (nodeType == -1) { if (isJsArray(jsObj) && jsGetArrayLength(jsObj) > 1) { return new JsArrayIterator((JsArray) jsObj, config); } else { return SingletonIterator.makeIterator(new JSObjectValue(jsObj)); } } com.google.gwt.dom.client.Document page = ((Node) jsValue).getOwnerDocument(); if (page == null) { com.google.gwt.dom.client.Document doc = (Document) jsValue; DocType jsDocType = (doc == Document.get()) ? DocType.UNKNOWN : DocType.NONHTML; HTMLDocumentWrapper docWrapper = new HTMLDocumentWrapper(doc, doc.getURL(), config, jsDocType); return SingletonIterator.makeIterator(docWrapper); } else { DocType jsDocType = (page == Document.get()) ? DocType.UNKNOWN : DocType.NONHTML; HTMLDocumentWrapper htmlDoc = new HTMLDocumentWrapper(page, page.getURL(), config, jsDocType); HTMLNodeWrapper htmlNode = htmlDoc.wrap((Node) jsValue); return SingletonIterator.makeIterator(htmlNode); } }
From source file:client.net.sf.saxon.ce.Xslt20ProcessorImpl.java
License:Mozilla Public License
public Node renderXML(JavaScriptObject inSourceDoc, DocumentInfo styleDoc, com.google.gwt.dom.client.Node target) { try {/*from w w w . j av a 2s. co m*/ if (styleDoc == null) { throw new Exception("Stylesheet for transform is null"); } docFetchRequired = inSourceDoc != null; CompilerInfo info = config.getDefaultXsltCompilerInfo(); info.setErrorListener(new StandardErrorListener()); String asyncSourceURI = null; // for now - don't use aync when using the JavaScript API calls that return a result if (docFetchRequired && (localController.getApiCommand() == APIcommand.UPDATE_HTML || (successCallback != null))) { asyncSourceURI = SaxonceApi.getAsyncUri(inSourceDoc); if (asyncSourceURI != null && asyncSourceURI.toLowerCase().startsWith("file:")) { asyncSourceURI = null; // force synchronous fetch if using file-system protocol } } // ----------- Start async code ------------- fetchedSourceDoc = null; transformInvoked = false; if (asyncSourceURI != null) { final String URI = asyncSourceURI; final Node transformTarget = target; logger.log(Level.FINE, "Aynchronous GET for: " + asyncSourceURI); final HTTPHandler hr = new HTTPHandler(); hr.doGet(asyncSourceURI, new RequestCallback() { public void onError(Request request, Throwable exception) { //hr.setErrorMessage(exception.getMessage()); String msg = "HTTP Error " + exception.getMessage() + " for URI " + URI; handleException(new RuntimeException(msg), "onError"); } public void onResponseReceived(Request request, Response response) { int statusCode = response.getStatusCode(); if (statusCode == 200) { Logger.getLogger("ResponseReceived").fine("GET Ok for: " + URI); Node responseNode; try { responseNode = (Node) XMLDOM.parseXML(response.getText()); } catch (Exception e) { handleException(new RuntimeException(e.getMessage()), "onResponseReceived"); return; } DocumentInfo responseDoc = config.wrapXMLDocument(responseNode, URI); // now document is here, we can transform it Node result = invokeTransform(responseDoc, transformTarget); hr.setResultNode(result); // TODO: This isn't used yet // handle OK response from the server } else if (statusCode < 400) { // transient } else { String msg = "HTTP Error " + statusCode + " " + response.getStatusText() + " for URI " + URI; handleException(new RuntimeException(msg), "onResponseReceived"); //hr.setErrorMessage(statusCode + " " + response.getStatusText()); } } // ends inner method }// ends inner class ); // ends doGet method call } // -------------- End async code /// we can compile - even while sourcedoc is being fetched asynchronously if (stylesheet == null) { if (LogConfiguration.loggingIsEnabled()) { LogController.InitializeTraceListener(); } logger.log(Level.FINE, "Compiling Stylesheet..."); PreparedStylesheet sheet = new PreparedStylesheet(config, info); sheet.prepare(styleDoc); stylesheet = sheet; logger.log(Level.FINE, "Stylesheet compiled OK"); } // for async operation - this is called within the callback - so don't call here if (asyncSourceURI == null && inSourceDoc != null) { int nodeType = (Node.is(inSourceDoc)) ? ((Node) inSourceDoc).getNodeType() : 0; if (nodeType > 0 && nodeType != Node.DOCUMENT_NODE) { // add a document node wrapper Node sourceNode = (Node) inSourceDoc; Document sourceDoc = sourceNode.getOwnerDocument(); HTMLDocumentWrapper htmlDoc = new HTMLDocumentWrapper(sourceDoc, sourceDoc.getURL(), config, DocType.UNKNOWN); fetchedSourceDoc = htmlDoc.wrap(sourceNode); } else { fetchedSourceDoc = SaxonceApi.getDocSynchronously(inSourceDoc, config); } } // this method only runs if transformInvoked == false - need to get sourceDoc reference if not invoked return invokeTransform(fetchedSourceDoc, target); //method ends - allowing onResponceReceived handler to call invokeTransform for async operation } catch (Exception e) { handleException(e, "renderXML"); return null; } }
From source file:org.rstudio.core.client.ScrollUtil.java
License:Open Source License
public static void setScrollPositionOnLoad(final RStudioFrame frame, final int scrollPosition) { Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { @Override/*from www . j a va 2 s .c o m*/ public boolean execute() { // don't wait indefinitely for the document to load retries_++; if (retries_ > MAX_SCROLL_RETRIES) return false; // wait for a document to become available in the frame if (frame.getIFrame() == null) return true; if (frame.getIFrame().getContentDocument() == null) return true; // wait for the document to finish loading Document doc = frame.getIFrame().getContentDocument(); String readyState = getDocumentReadyState(doc); if (readyState == null) return true; if (!readyState.equals("complete")) return true; // wait for a real document to load (about:blank may be intermediate) if (doc.getScrollTop() > 0) return true; if (doc.getURL().equals(ViewerPane.ABOUT_BLANK)) return true; // restore scroll position if (scrollPosition > 0) doc.setScrollTop(scrollPosition); return false; } private int retries_ = 0; }, SCROLL_RETRY_MS); }
From source file:org.rstudio.studio.client.workbench.views.help.HelpPane.java
License:Open Source License
private void helpNavigated(Document doc) { NodeList<Element> elements = doc.getElementsByTagName("a"); for (int i = 0; i < elements.getLength(); i++) { ElementEx a = (ElementEx) elements.getItem(i); String href = a.getAttribute("href", 2); if (href == null) continue; if (href.contains(":") || href.endsWith(".pdf")) { // external links AnchorElement aElement = a.cast(); aElement.setTarget("_blank"); } else {/*from www. j a v a 2 s . c om*/ // Internal links need to be handled in JavaScript so that // they can participate in virtual session history. This // won't have any effect for right-click > Show in New Window // but that's a good thing. a.setAttribute("onclick", "window.parent.helpNavigate(this.href, " + (BrowseCap.isLinuxDesktop() || BrowseCap.isWindowsDesktop() ? "true" : "false") + "); return false"); } } String effectiveTitle = getDocTitle(doc); title_.setText(effectiveTitle); this.fireEvent(new HelpNavigateEvent(doc.getURL(), effectiveTitle)); }
From source file:org.rstudio.studio.client.workbench.views.help.HelpPane.java
License:Open Source License
private String getDocTitle(Document doc) { String docUrl = StringUtil.notNull(doc.getURL()); String docTitle = doc.getTitle(); String previewPrefix = new String("/help/preview?file="); int previewLoc = docUrl.indexOf(previewPrefix); if (previewLoc != -1) { String file = docUrl.substring(previewLoc + previewPrefix.length()); file = URL.decodeQueryString(file); FileSystemItem fsi = FileSystemItem.createFile(file); docTitle = fsi.getName();//from w w w . ja v a 2s. c om } else if (StringUtil.isNullOrEmpty(docTitle)) { String url = new String(docUrl); url = url.split("\\?")[0]; url = url.split("#")[0]; String[] chunks = url.split("/"); docTitle = chunks[chunks.length - 1]; } return docTitle; }