/** * Makes a deep copy of the HTMLPage object * * @return a copy of the HTMLPage object */ public synchronized Object clone() throws CloneNotSupportedException { HTMLPage page = (HTMLPage) super.clone(); page.list = new LinkedList<HTMLElement>(); for (HTMLElement elem : list) page.list.addLast((HTMLElement) elem.clone()); return page; }
// Once collected, you get only one visit from the root tag block (hopefully HTML) public void visit(TagBlock tb) { // We are not going to parse attribute information in pages that don't have an HTML tag block if (tb.startTag.tagName.equalsIgnoreCase("HTML")) { HTMLElement he; TagBlock tbe; // Let's go looking for the head tag for (Enumeration be = tb.body.elements(); be.hasMoreElements(); ) { he = (HTMLElement) be.nextElement(); if (he.getClass() == TagBlock.class) { tbe = (TagBlock) he; if (tbe.startTag.tagName.equalsIgnoreCase("HEAD")) { // Found the head tag block, now let's look for the page title and any meta tags for (Enumeration hbe = tbe.body.elements(); hbe.hasMoreElements(); ) { he = (HTMLElement) hbe.nextElement(); if (he.getClass() == TagBlock.class) { tbe = (TagBlock) he; if (tbe.startTag.tagName.equalsIgnoreCase("TITLE")) { // Should only be one item in title body, hopefully it's a text element for (Enumeration e = tbe.body.elements(); e.hasMoreElements(); ) { he = (HTMLElement) e.nextElement(); if (he.getClass() == Text.class) { pageTitle = HttpUtility.HtmlDecode(((Text) he).text).Trim(); break; } } } } else if (he.getClass() == Tag.class) { Tag tg = (Tag) he; // See if this is a META tag if (tg.tagName.equalsIgnoreCase("META")) { // Convert this tag and it's attributes into a more .NET // friendly collection MetaTag metaTag = new MetaTag(tg); // Copy attributes in Java vector into .NET ArrayList... for (Enumeration ae = tg.attributeList.attributes.elements(); ae.hasMoreElements(); ) metaTag.get_Attributes().Add((Attribute) ae.nextElement()); tagList.Add(metaTag); } } } // Once we've found the head element, we can leave... break; } } } } }
/** {@inheritDoc} */ @Override public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); if (domNode.getPage().getWebClient().getOptions().isAppletEnabled()) { try { createAppletMethodAndProperties(); } catch (final Exception e) { throw new RuntimeException(e); } } }
@Override public void setValue(String value) { super.setValue(value); setContent(value); }
@Override public void onModuleLoad() { final Document doc = getDocument(); final HTMLBodyElement body = bodyElement(); HTMLElement div = doc.createElement("DIV"); HTMLElement p = doc.createElement("P"); HTMLElement input = doc.createElement("input"); HTMLElement button = doc.createElement("button"); final Person person = new Person(); person.setName("Cristian"); TemplatePerson templatePerson = (TemplatePerson) getDocument().getElementById("auto-bind-demo"); templatePerson.setPerson(person); final PathObserver<Person, String> observer = PathObserverFactory.createPathObserver(person, "name"); input.bind("value", observer); final PathObserver<Person, String> observer1 = PathObserverFactory.createPathObserver(person, "name"); final String original = observer1.open( PathObserverFactory.createOpenPathObserverListener( new OpenPathObserverListener<Person>() { @Override public void onOpen(String newValue, String oldValue) { HTMLElement p = doc.createElement("P"); p.setInnerText("The new Value is: " + newValue); body.appendChild(p); } }), person); button.setInnerText("Clear changes"); button.addEventListener( "click", EventListenerFactory.createEventListener( new EventListener<JsObject>() { @Override public void onEvent(JsObject event) { String actualValue = observer.discardChanges(); window().getConsole().log(original); observer.close(); observer1.close(); HTMLElement p = doc.createElement("P"); p.setInnerText( "The Actual Value of Observation is: " + actualValue + " and the Original Value if property name is: " + original); body.appendChild(p); } })); window() .getConsole() .log( "%cWelcome to JSInterop!%c", "font-size:1.5em;color:#4558c9;", "color:#d61a7f;font-size:1em;"); div.appendChild(p); div.appendChild(input); body.appendChild(div); body.appendChild(button); final Employee employee = new Employee("Cristian", "202223232"); final ObjectObserver<Employee> objectObserver = PathObserverFactory.createObjectObserver(employee); objectObserver.open( PathObserverFactory.createOpenObjectObserverListener( new OpenObjectObserverListener<Employee>() { @Override public void onOpen(JsArray added, JsArray removed, JsArray changed) { window().getConsole().log("Added +++ "); window().getConsole().log(added); window().getConsole().log("Added --- "); window().getConsole().log("Removed +++ "); window().getConsole().log(removed); window().getConsole().log("Removed --- "); window().getConsole().log("Changed +++ "); window().getConsole().log(changed); window().getConsole().log("Changed --- "); } }), employee); employee.setCuit("nnnnn"); employee.setName("Vamos"); window().getConsole().log(objectObserver.discardChanges()); }