com.google.gwt.xml.client.Document Java Examples

The following examples show how to use com.google.gwt.xml.client.Document. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BookXmlSerdes.java    From requestor with Apache License 2.0 6 votes vote down vote up
private Book[] parseXmlDocumentAsBook(Document xml) {
    final NodeList idNodes = xml.getElementsByTagName("id");
    final NodeList titleNodes = xml.getElementsByTagName("title");
    final NodeList authorNodes = xml.getElementsByTagName("author");
    final NodeList publicationDateNodes = xml.getElementsByTagName("publicationDate");

    int length = idNodes.getLength();
    Book[] books = new Book[length];

    for (int i = 0; i < length; i++) {
        String id = ((Text) idNodes.item(i).getFirstChild()).getData();
        String title = ((Text) titleNodes.item(i).getFirstChild()).getData();
        String author = ((Text) authorNodes.item(i).getFirstChild()).getData();
        String publicationDate = ((Text) publicationDateNodes.item(i).getFirstChild()).getData();
        books[i] = new Book(Integer.valueOf(id), title, author, new Date(Long.valueOf(publicationDate)));
    }

    return books;
}
 
Example #2
Source File: RepositoryPresenter.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void onSave(String xml) {

    if(null==selectedDialog) return;

    try {
        DialogXML parser = new DialogXML();

        // validation
        Dialog dialog = parser.unmarshall(xml);

        final Document document = parser.marshall(dialog);

        vfs.save(selectedDialog, ModelEditor.formatXml(document.toString()), new SimpleCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
                Console.info("Successfully saved "+selectedDialog.getName());
                getView().updateFile(selectedDialog.getName(), document.toString());
            }
        });
    } catch (Throwable e) {
        e.printStackTrace();
        Console.error("Failed to save dialog", e.getMessage());
    }

}
 
Example #3
Source File: DialogXML.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public Dialog unmarshall(String xml)
{

    try {
        Document document = XMLParser.parse(xml);
        Element root = document.getDocumentElement();

        // model
        Builder builder = new Builder();
        dfsElement(builder, DOMUtils.getFirstChildElement(root));

        // dialog
        Dialog dialog = new Dialog(new QName(root.getNamespaceURI(), root.getAttribute("id")), builder.build());

        return dialog;
    } catch (RuntimeException e) {
        Window.alert("Faile to parse XML: "+e.getMessage());
        throw e;
    }
}
 
Example #4
Source File: PropertiesAdapter.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    if(unit instanceof Container)
    {
        Container container = (Container)unit;
        if(container.getTemporalOperator()!=null) {
            el.setAttribute("operator", container.getTemporalOperator().toString());
        }
    }

    return el;
}
 
Example #5
Source File: YaBlocksEditor.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
public Set<String> getBlockTypeSet() {
  Set<String> blockTypes = new HashSet<String>();
  String xmlString = blocksArea.getBlocksContent();
  Document blockDoc = XMLParser.parse(xmlString);
  NodeList blockElements = blockDoc.getElementsByTagName("block");
  for (int i = 0; i < blockElements.getLength(); ++i) {
    Element blockElem = (Element) blockElements.item(i);
    blockTypes.add(blockElem.getAttribute("type"));
  }
  return blockTypes;
}
 
Example #6
Source File: BookXmlSerdes.java    From requestor with Apache License 2.0 5 votes vote down vote up
@Override
public Book deserialize(String response, DeserializationContext context) {
    Document xml;
    try {
        xml = XMLParser.parse(response);
    } catch (DOMParseException e) {
        throw new UnableToDeserializeException("Could not read response as xml.", e);
    }
    return parseXmlDocumentAsBook(xml)[0];
}
 
Example #7
Source File: BookXmlSerdes.java    From requestor with Apache License 2.0 5 votes vote down vote up
@Override
public <C extends Collection<Book>> C deserialize(Class<C> collectionType, String response,
                                                  DeserializationContext context) {
    C col = context.getInstance(collectionType);

    Document xml;
    try {
        xml = XMLParser.parse(response);
    } catch (DOMParseException e) {
        throw new UnableToDeserializeException("Could not read response as xml.", e);
    }

    Collections.addAll(col, parseXmlDocumentAsBook(xml));
    return col;
}
 
Example #8
Source File: ToolstripAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    return el;
}
 
Example #9
Source File: UsewareAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {

    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), elementName);
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    if(unit instanceof Container)
    {
        Container container = (Container)unit;
        if(container.getTemporalOperator()!=null) {
            el.setAttribute("operator", container.getTemporalOperator().toString());
        }
    }
    else if(unit instanceof Trigger)
    {
        Trigger trigger = (Trigger)unit;
        el.setAttribute("type", trigger.getType().toString());
    }
    else if(unit instanceof Link)
    {
        Link link = (Link)unit;
        el.setAttribute("target", link.getTarget().toString());
    }

    return el;
}
 
Example #10
Source File: PagesAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    return el;
}
 
Example #11
Source File: PulldownAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    return el;
}
 
Example #12
Source File: EditorPanelAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    return el;
}
 
Example #13
Source File: FormAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());
    return el;
}
 
Example #14
Source File: TodoAdapter.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Element toXML(Document document, InteractionUnit unit) {
    Element el = DOMUtils.createElementNS(document, unit.getId().getNamespaceURI(), getElementName());
    el.setAttribute("id", unit.getId().getLocalPart());
    el.setAttribute("label", unit.getLabel());

    return el;
}
 
Example #15
Source File: TestReader.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public TestRun read(String s) {

		Document doc = XMLParser.parse(s);
		TestRun tr = new TestRun();

		Element run = doc.getDocumentElement();

		NodeList runChildren = run.getChildNodes();
		for (int i = 0; i < runChildren.getLength(); i++) {
			Node runChild = runChildren.item(i);
			String name = runChild.getNodeName();

			switch (name) {
			case "desc":
				tr.description = trim(runChild.getChildNodes().item(0)
						.getNodeValue());
				break;
			case "precisionModel":
				tr.precisionModel = trim(((Element) runChild)
						.getAttribute("type"));
				break;
			case "resultMatcher":
				tr.resultMatcher = trim(runChild.getChildNodes().item(0)
						.getNodeValue());
				break;
			case "geometryOperation":
				tr.geometryOperation = trim(runChild.getChildNodes().item(0)
						.getNodeValue());
				break;
			case "case":
				TestCase tc = new TestCase();
				tr.testCases.add(tc);
				parseTestCase(runChild, tc);
				break;
			default:
				// sLogger.severe("-------" + name + "-------");
				break;
			}
		}

		return tr;
	}
 
Example #16
Source File: DOMUtils.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Element createElementNS(Document doc, String ns, String name)
{
    return (Element)NodeImpl.build(_createElementNS(getJSObj(doc), ns, name));
}
 
Example #17
Source File: DialogXML.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
Document getResult() {
    return document;
}
 
Example #18
Source File: DialogXML.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Document marshall(Dialog dialog) {

        DMRMarshallRoutine marshaller = new DMRMarshallRoutine(dialog);
        dialog.getInterfaceModel().accept(marshaller);
        return marshaller.getResult();
    }
 
Example #19
Source File: XmlDebugPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Document getDocument() {
  return document;
}
 
Example #20
Source File: ElementAdapter.java    From core with GNU Lesser General Public License v2.1 votes vote down vote up
Element toXML(Document doc, T unit);