Examples of PasteItem


Examples of com.mysticcoders.mysticpaste.model.PasteItem

            }
        });

        historyDataView = new DataView<PasteItem>("history", historyDataProvider, ITEMS_PER_PAGE) {
            protected void populateItem(Item<PasteItem> item) {
                final PasteItem pasteItem = item.getModelObject();

                logger.debug("Client ["+ getClientIpAddress() +"] showing paste with ID: " + pasteItem.getItemId());

                PageParameters params = new PageParameters();
                params.add("0", pasteItem.getItemId());
                item.add(new BookmarkablePageLink<Void>("viewLink", ViewPublicPage.class, params));

                final String[] contentLines = pasteItem.getContent().split("\n");
                item.add(new Label("lineCount", "(" + contentLines.length + " Line" +
                        (contentLines.length > 1 ? "s" : "") + ")"));

                item.add(new Label("posted", PasteItem.getElapsedTimeSincePost(pasteItem)));
                WebMarkupContainer hasImage = new WebMarkupContainer("hasImage") {
                    @Override
                    public boolean isVisible() {
                        return pasteItem.hasImage();

                    }
                };
                item.add(hasImage);
                item.add(new Label("content",
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

                return pasteModel.getObject().getParent() != null;
            }
        };

        if (pasteModel.getObject().getParent() != null) {
            PasteItem parentPaste = pasteService.getItem(pasteModel.getObject().getParent());
            PageParameters pp = new PageParameters();
            pp.add("0", parentPaste.getItemId());
            diffView.add(new BookmarkablePageLink<Void>("originalPasteLink", (parentPaste.isPrivate() ? ViewPrivatePage.class : ViewPublicPage.class), pp));


            Object[] diffOutput = PasteItem.diffPastes(parentPaste.getContent(), pasteModel.getObject().getContent());

            List<Integer> changedLines = (List<Integer>) diffOutput[0];       // TODO horrible horrible hackish thing, where do you get these things
            String diffText = (String) diffOutput[1];

            diffView.add(new HighlighterPanel("highlightedContent",
                    new Model<String>(diffText),
                    parentPaste.getType(),
                    false,
                    highlightLines,
                    changedLines));
        }
        add(diffView);

        final List<PasteItem> pasteChildren = pasteService.hasChildren(pasteModel.getObject());

//        final List<PasteItem> pasteChildren = new ArrayList<PasteItem>();
        WebMarkupContainer hasChildPastes = new WebMarkupContainer("hasChildPastes") {
            @Override
            public boolean isVisible() {
                return pasteChildren != null && pasteChildren.size() > 0;
            }
        };
        add(hasChildPastes);

        hasChildPastes.add(new ListView<PasteItem>("childPastes", pasteChildren) {

            @Override
            protected void populateItem(ListItem<PasteItem> item) {
                PasteItem pasteItem = item.getModelObject();

                PageParameters pp = new PageParameters();
                pp.add("0", pasteItem.getItemId());
                BookmarkablePageLink<Void> viewPaste = new BookmarkablePageLink<Void>("viewChildPaste", (pasteItem.isPrivate() ? ViewPrivatePage.class : ViewPublicPage.class), pp);

                viewPaste.add(new Label("pasteId", new PropertyModel<String>(item.getModel(), "itemId")));

                item.add(viewPaste);

                item.add(new Label("posted", PasteItem.getElapsedTimeSincePost(pasteItem)));
            }
        });

        String language = pasteModel.getObject().getType();
        add(new HighlighterPanel("highlightedContent",
                new PropertyModel<String>(pasteModel, "content"),
                language, false,
                highlightLines));

        add(createRawLink("rawLink", params));
        add(createDownloadLink("downloadLink", params));

        PageParameters repasteParams = new PageParameters();
        repasteParams.add("0", pasteModel.getObject().getItemId());
        add(new BookmarkablePageLink<Void>("repasteLink", ReplyPastePage.class, repasteParams));

        final Label markAbuseLabel = new Label("markAbuseLabel", "Report Abuse");
        markAbuseLabel.setOutputMarkupId(true);
        StatelessLink markAbuseLink = new StatelessLink("markAbuseLink") {

            public void onClick() {
                PasteItem pasteItem = pasteModel.getObject();

                pasteService.increaseAbuseCount(pasteItem);

                markAbuseLabel.setDefaultModel(new Model<String>("Marked As Spam"));
                markAbuseLabel.add(new AttributeModifier("style", "color: red; font-weight: bold;"));
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

        return null;
    }

    public PasteItem get(String id) {
        logger.info("Retrieving paste ID: " + id);
        PasteItem pasteItem =
                ds.find(PasteItem.class).field("itemId").equal(id).get();
        return pasteItem;
    }
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

    private List<PasteItem> getUnpackedHistory(List<byte[]> packedHistory) {
        List<PasteItem> pasteItems = new ArrayList<PasteItem>();
        try {
            for(byte[] packed : packedHistory) {
                PasteItemCache itemCache = msgpack.read(packed, PasteItemCache.class);
                PasteItem item = new PasteItem();
                item.setItemId(itemCache.itemId);
                item.setTimestamp(itemCache.timestamp);
                item.setContent(itemCache.content);
                pasteItems.add(item);
            }

            return pasteItems;
        } catch(IOException e) {
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

    public int incViewCount(PasteItem pasteItem) {
        logger.info("Incrementing view count for pasteId:" + pasteItem.getItemId());
        try {
            Query<PasteItem> query = ds.find(PasteItem.class).field("itemId").equal(pasteItem.getItemId());
            UpdateOperations<PasteItem> updateOp = ds.createUpdateOperations(PasteItem.class).inc("viewCount", 1);
            PasteItem resultItem = ds.findAndModify(query, updateOp);

            return resultItem.getViewCount();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

        try {
            Query<PasteItem> query = ds.find(PasteItem.class).field("itemId").equal(pasteItem.getItemId());
            UpdateOperations<PasteItem> updateOp = ds.createUpdateOperations(PasteItem.class).inc("abuseCount", 1);

            PasteItem modifiedPasteItem = ds.findAndModify(query, updateOp);
            if (modifiedPasteItem.getAbuseCount() > 1) {
                System.out.println("Removing paste [" + modifiedPasteItem.getItemId() + "] because of abuseCount:" + modifiedPasteItem.getAbuseCount());
                jedis.lrem("pasteHistory", 1, "" + modifiedPasteItem.getPasteIndex());
            }
        } catch (JedisConnectionException je) {
            if (null != jedis) {
                jedisPool.returnBrokenResource(jedis);
                jedis = null;
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

        logger.info("Decrementing view count for pasteId:" + pasteItem.getItemId());
        try {
            Query<PasteItem> query = ds.find(PasteItem.class).field("itemId").equal(pasteItem.getItemId());
            UpdateOperations<PasteItem> updateOp = ds.createUpdateOperations(PasteItem.class).dec("abuseCount");

            PasteItem modifiedPasteItem = ds.findAndModify(query, updateOp);
            if (modifiedPasteItem.getAbuseCount() > 1) {
                System.out.println("Restoring paste [" + modifiedPasteItem.getItemId() + "] because of abuseCount:" + modifiedPasteItem.getAbuseCount());
// TODO figure out how we can fix the list and how to include the paste in the proper spot
//                redisTemplate.opsForList().
//                redisTemplate.opsForList().remove("pasteHistory", 1, "" + modifiedPasteItem.getPasteIndex());
            }
        } catch (Exception e) {
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

        final HistoryDataProvider historyDataProvider = new HistoryDataProvider(pasteService);
        final WebMarkupContainer historyDataViewContainer = new WebMarkupContainer("historyContainer");

        historyDataView = new DataView<PasteItem>("history", historyDataProvider, itemsPerPage) {
            protected void populateItem(Item<PasteItem> item) {
                final PasteItem pasteItem = item.getModelObject();

                PageParameters params = new PageParameters();
                params.add("0", pasteItem.getItemId());
                item.add(new BookmarkablePageLink<Void>("viewLink", ViewPublicPage.class, params));

                item.add(new AjaxLink<Void>("increaseAbuseCount") {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        pasteService.increaseAbuseCount(pasteItem);
                        target.add(historyDataViewContainer);
                    }
                });
/*
                item.add(new AjaxLink<Void>("decreaseAbuseCount") {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        pasteService.decreaseAbuseCount(pasteItem);
                        target.add(historyDataView);
                    }
                });
*/
                final String[] contentLines = pasteItem.getContent().split("\n");
                item.add(new Label("lineCount", "(" + contentLines.length + " Line" +
                        (contentLines.length > 1 ? "s" : "") + ")"));

                item.add(new Label("posted", PasteItem.getElapsedTimeSincePost(pasteItem)));
                item.add(new Label("clientIp", new PropertyModel<String>(item.getModel(), "clientIp")));

                WebMarkupContainer hasImage = new WebMarkupContainer("hasImage") {
                    @Override
                    public boolean isVisible() {
                        return pasteItem.hasImage();
                    }
                };
                item.add(hasImage);
                item.add(new Label("content",
                        new PropertyModel<String>(pasteItem, "previewContent")));
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem

        String type = req.getParameter("type");
        String content = req.getParameter("content");
        String fileExtension = req.getParameter("fileExt");
        String redirect = req.getParameter("redirect");

        PasteItem item = new PasteItem();
        item.setContent(content);
        if (Strings.isEmpty(fileExtension)) {
            item.setType(Strings.isEmpty(type) ? DEFAULT_LANG : type);
        } else {
            item.setType(mapFileType(fileExtension));
        }

        getPasteService(getServletContext()).createItem(item);

        StringBuilder sb = new StringBuilder("http://");
        sb.append("mysticpaste.com");
/*
        sb.append(req.getServerName());
        if (req.getServerPort() != 80) {
            sb.append(":").append(req.getServerPort());
        }
*/

        sb.append("/view/").append(item.getItemId());

        if (redirect != null && redirect.equalsIgnoreCase("true")) {
            resp.sendRedirect(sb.toString());

        } else {
            resp.setHeader("X-Paste-Identifier", "" + item.getItemId())// Added to allow pastebin integration with the VIM plugin

            resp.getWriter().print(item.getItemId());
            resp.flushBuffer();
        }

    }
View Full Code Here

Examples of com.mysticcoders.mysticpaste.model.PasteItem


    public String createReplyItem(PasteItem item, String parentId)
            throws ParentNotFoundException {
        String id;
        PasteItem parent = pasteItemDao.get(parentId);
        if (null != parent) {
            item.setParent(parent.getItemId());
            // set created timestamp
            item.setTimestamp(new Date(System.currentTimeMillis()));
            id = pasteItemDao.create(item);
        } else {
            throw new ParentNotFoundException("Parent does not exist");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.