Package org.restlet.ext.xml

Examples of org.restlet.ext.xml.DomRepresentation


    public MailResolver(String identifier, Representation mail) {
        this.identifier = identifier;

        if (mail != null) {
            this.map = new HashMap<String, Object>();
            DomRepresentation rep = null;
            if (mail instanceof DomRepresentation) {
                rep = (DomRepresentation) mail;
            } else {
                rep = new DomRepresentation(mail);
            }

            Node node = rep.getNode("/email/head/from/text()");
            if (node != null) {
                add("from", node.getNodeValue());
            }
            final NodeList nodes = rep.getNodes("/email/head/to/text()");
            if ((nodes != null) && (nodes.getLength() > 0)) {
                final StringBuilder builder = new StringBuilder(nodes.item(0)
                        .getNodeValue());
                for (int i = 1; i < nodes.getLength(); i++) {
                    builder.append(", ").append(nodes.item(i).getNodeValue());
                }
                add("recipients", builder.toString());
            }
            node = rep.getNode("/email/head/subject/text()");
            if (node != null) {
                add("subject", node.getNodeValue());
            }
            node = rep.getNode("/email/body/text()");
            if (node != null) {
                add("message", node.getNodeValue());
            }
        }
    }
View Full Code Here


                        localId.toString());
            }
        }

        MediaType xrds = new MediaType("application/xrds+xml");
        return new DomRepresentation(xrds, response);
    }
View Full Code Here

        }

        if (MediaType.TEXT_HTML.equals(input.getMediaType())
                && input.getSize() != 0) {
            // Check for a form
            DomRepresentation htmlRep = new DomRepresentation(input);

            Node form = htmlRep.getNode("//form");

            if (form != null) { // Check for an on load....
                Node body = htmlRep.getNode("//body");
                NamedNodeMap nnm = body.getAttributes();
                Node onload = nnm.getNamedItem("onload");
                String val = onload.getNodeValue();
                if (val.endsWith(".submit();")) {
                    NamedNodeMap nnm2 = form.getAttributes();
View Full Code Here

     * @throws MessagingException
     */
    public RepresentationMessage(Representation xmlMessage, Session session)
            throws IOException, AddressException, MessagingException {
        super(session);
        DomRepresentation dom = new DomRepresentation(xmlMessage);
        Document email = dom.getDocument();
        Element root = (Element) email.getElementsByTagName("email").item(0);
        Element header = (Element) root.getElementsByTagName("head").item(0);
        String subject = header.getElementsByTagName("subject").item(0)
                .getTextContent();
        String from = header.getElementsByTagName("from").item(0)
View Full Code Here

        if (!response.getStatus().isSuccess()) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
                    "Unable to get the mail from the mailbox");
        }

        return new DomRepresentation(response.getEntity());
    }
View Full Code Here

                    "Cannot get the mail iddentifiers.");
        }

        // 2 - Parse the list of mails
        if (response.isEntityAvailable()) {
            final DomRepresentation rep = new DomRepresentation(response
                    .getEntity());
            for (final Node node : rep.getNodes("/emails/email/@href")) {
                final String href = node.getNodeValue();
                if (href.startsWith("/")) {
                    result.add(href.substring(1));
                } else {
                    result.add(href);
View Full Code Here

     */
    private void getAndCheckJaxb(String subPath) throws Exception {
        Response response = get(subPath);
        assertEquals(Status.SUCCESS_OK, response.getStatus());

        DomRepresentation entity = new DomRepresentation(response.getEntity());
        Node xml = entity.getDocument().getFirstChild();
        System.out.println(subPath + ": " + entity.getText());
        assertEquals("person", xml.getNodeName());

        NodeList nodeList = xml.getChildNodes();
        Node node = nodeList.item(0);
        assertEquals("firstname", node.getNodeName());
View Full Code Here

    /**
     * @param subPath
     * @throws IOException
     */
    private void postAndCheckXml(String subPath) throws Exception {
        final Representation send = new DomRepresentation(
                new StringRepresentation(
                        "<person><firstname>Helmut</firstname><lastname>Kohl</lastname></person>",
                        MediaType.TEXT_XML));
        final Response response = post(subPath, send);
        assertEquals(Status.SUCCESS_OK, response.getStatus());
View Full Code Here

     * @throws IOException
     * @see ProviderTestService#jaxbPostNamespace(javax.xml.bind.JAXBElement)
     */
    public void testJaxbElementPostRootElement() throws Exception {
        if (!LATER) {
            final Representation send = new DomRepresentation(
                    new StringRepresentation(
                            "<person><firstname>Helmut</firstname><lastname>Kohl</lastname></person>\n",
                            MediaType.TEXT_XML));
            final Response response = post("jaxbElement/rootElement", send);
            assertEquals(Status.SUCCESS_OK, response.getStatus());
View Full Code Here

        } else {
            // Fetch a resource: an XML document full of search results
            String term = Reference.encode(args[0]);
            String uri = BASE_URI + "?appid=restbook&query=" + term;
            Representation entity = new ClientResource(uri).get();
            DomRepresentation document = new DomRepresentation(entity);

            // Use XPath to find the interesting parts of the data structure
            String expr = "/ResultSet/Result/Title";
            for (Node node : document.getNodes(expr)) {
                System.out.println(node.getTextContent());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.restlet.ext.xml.DomRepresentation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.