Package org.internna.iwebmvc.model.core

Examples of org.internna.iwebmvc.model.core.Document


    public void setAsText() throws Exception {
        DES3CiphererDecipherer crypto = new DES3CiphererDecipherer();
        crypto.init();
        DocumentBinder binder = new DocumentBinder(crypto);
        binder.setAsText("mimeType=image/gif\nsizeInBytes=200\nuri=" + crypto.encrypt("/xx/yy.gif") + "\ncreated=2008-03-18\nidentifier=coverdata\n");
        Document doc = (Document) binder.getValue();
        assertEquals("coverdata", doc.getIdentifier());
        assertTrue(200 == doc.getSizeInBytes());
        Calendar c = Calendar.getInstance();
        assertTrue(doc.getCreated().compareTo(c.getTime()) < 0);
    }
View Full Code Here


    }

    @Override
    @SuppressWarnings("unchecked")
    public void setAsText(String text) throws IllegalArgumentException {
        Document doc = (Document) getValue();
        Properties properties = new Properties();
        try {
            properties.load(IOUtils.toInputStream(text));
            String uri = properties.getProperty("uri");
            Assert.isEncrypted(decipherer, uri);
            if (doc == null) doc = new Document();
            doc.setUri(decipherer.decrypt(uri));
            doc.setMimeType(properties.getProperty("mimeType"));
            doc.setIdentifier(properties.getProperty("identifier"));
            doc.setCreated(dateFormat.parse(properties.getProperty("created")));
            doc.setSizeInBytes(Long.parseLong(properties.getProperty("sizeInBytes")));
        } catch (Exception ex) {
            if (log.isDebugEnabled()) log.debug("Could not completely bind [" + text + "] as a Document: " + ex.getMessage());
        }
        setValue(doc);
    }
View Full Code Here

        this.decipherer = decipherer;
    }

    @SuppressWarnings("unchecked")
    public Document getDocument(String text) throws IllegalArgumentException {
        Document doc = new Document();
        Properties properties = new Properties();
        try {
            properties.load(IOUtils.toInputStream(text));
            String uri = properties.getProperty("uri");
            Assert.isEncrypted(decipherer, uri);
            doc.setUri(decipherer.decrypt(uri));
            doc.setMimeType(properties.getProperty("mimeType"));
            doc.setIdentifier(properties.getProperty("identifier"));
            doc.setCreated(dateFormat.parse(properties.getProperty("created")));
            doc.setSizeInBytes(Long.parseLong(properties.getProperty("sizeInBytes")));
            return doc;
        } catch (Exception ex) {
            if (log.isDebugEnabled()) log.debug("Could not completely bind [" + text + "] as a Document: " + ex.getMessage());
        }
        return null;
View Full Code Here

        for (String doc : text.split("##")) {
            if (StringUtils.hasText(doc)) {
                if (doc.startsWith("-")) {
                    Iterator<Document> it = docs.getDocuments().iterator();
                    while (it.hasNext()) {
                        Document d = it.next();
                        if (doc.substring(1).equals(d.getUri())) it.remove();
                    }
                } else {
                    Document document = getDocument(doc);
                    if (document != null) docs.addDocument(document);
                }
            }
        }
        setValue(docs);
View Full Code Here

        entityManager.getTransaction().begin();
    }

    @Test
    public void upload() throws Exception {
        Document doc = monitor.upload(transfer);
        assertTrue("Size set", doc.getSizeInBytes() > 1000);
        assertTrue("Uri set", doc.getUri().indexOf("globe") > 0);
        assertEquals("Mime set", "image/gif", doc.getMimeType());
    }
View Full Code Here

TOP

Related Classes of org.internna.iwebmvc.model.core.Document

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.