Package org.apache.lenya.cms.publication

Examples of org.apache.lenya.cms.publication.Document


    protected void initParameters() {
        super.initParameters();

        WorkflowManager resolver = null;
        try {
            Document doc = getSourceDocument();
            if (doc != null) {
                // read parameters from Dublin Core meta-data
                MetaData dc = doc.getMetaData(DublinCore.DC_NAMESPACE);
                setParameter(DublinCore.ELEMENT_TITLE, dc.getFirstValue(DublinCore.ELEMENT_TITLE));
                setParameter(DublinCore.ELEMENT_DESCRIPTION, dc
                        .getFirstValue(DublinCore.ELEMENT_DESCRIPTION));

                // read parameters from document attributes
                setParameter(LANGUAGES, doc.getLanguages());
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
                String lastModified = format
                        .format(new Date(getSourceDocument().getLastModified()));
                setParameter(LASTMODIFIED, lastModified);
                boolean visible = doc.getLink().getNode().isVisible();
                setParameter(VISIBLE_IN_NAVIGATION, Boolean.valueOf(visible));

                Workflowable workflowable = WorkflowUtil.getWorkflowable(this.manager,
                        getSession(), getLogger(), doc);
                resolver = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
View Full Code Here


       
        Publication pub = getPublication("test");
        Area area = pub.getArea("authoring");
        SiteStructure site = area.getSite();
       
        Document source = site.getNode("/index").getLink("en").getDocument();
        Document target = site.getNode("/tutorial").getLink("en").getDocument();
       
        LinkManager linkManager = null;
        LinkResolver resolver = null;
        try {
            linkManager = (LinkManager) getManager().lookup(LinkManager.ROLE);
View Full Code Here

        protected Document[] getLinksToDocument() {
            Set docs = new HashSet();
            LinkManager linkMgr = null;
            try {
                linkMgr = (LinkManager) this.manager.lookup(LinkManager.ROLE);
                Document liveVersion = this.document.getAreaVersion(Publication.LIVE_AREA);
                Document[] referencingDocs = linkMgr.getReferencingDocuments(liveVersion);
                for (int d = 0; d < referencingDocs.length; d++) {
                    Document doc = referencingDocs[d];
                    if (doc.getArea().equals(Publication.LIVE_AREA)) {
                        docs.add(doc);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
View Full Code Here

            if (recipients[i].equals(sender))
                return;
        }

        String url;
        Document authoringVersion = authoringDocument.getAreaVersion(Publication.AUTHORING_AREA);
        Proxy proxy = authoringVersion.getPublication().getProxy(authoringVersion, false);

        if (proxy != null) {
            url = proxy.getURL(authoringVersion);
        } else {
            Request request = ContextHelper.getRequest(this.context);
            final String serverUrl = "http://" + request.getServerName() + ":"
                    + request.getServerPort();
            final String webappUrl = authoringVersion.getCanonicalWebappURL();
            url = serverUrl + request.getContextPath() + webappUrl;
        }

        Text[] subjectParams = { new Text(getEvent(), true) };
        Text[] params = { new Text(url, false) };
View Full Code Here

                try {
                    Link link = getLink(linkUri, pubId, area);
                    LinkTarget target = IconUrlTransformer.this.linkResolver.resolve(
                            IconUrlTransformer.this.factory, link.getUri());
                    if (target.exists()) {
                        Document doc = target.getDocument();
                        ResourceType type = doc.getResourceType();
                        if (Arrays.asList(type.getFormats()).contains("icon")) {
                            name = type.getName();
                        }
                    }
                } catch (Exception e) {
View Full Code Here

            /* sort entries by year -> month -> day -> lastModified */
            Object[] sortedList = filteredDocs.toArray();           
            Arrays.sort(sortedList, new Comparator() {
                public int compare(Object o1, Object o2) {
                    Document d1,d2;
                    int year1,month1,day1;
                    int year2,month2,day2;
                   
                    d1 = (Document)o1;
                    d2 = (Document)o2;
                   
                    String[] patterns;
                    try {
                        patterns = d1.getPath().split("/");
                    } catch (DocumentException e) {
                        throw new RuntimeException(e);
                    }                   
                    year1 = Integer.parseInt(patterns[2]);
                    month1 = Integer.parseInt(patterns[3]);
                    day1 = Integer.parseInt(patterns[4]);
                   
                    try {
                        patterns = d2.getPath().split("/");
                    } catch (DocumentException e) {
                        throw new RuntimeException(e);
                    }                   
                    year2 = Integer.parseInt(patterns[2]);
                    month2 = Integer.parseInt(patterns[3]);
                    day2 = Integer.parseInt(patterns[4]);                   
                                       
                    if (year1 > year2) {
                        return 1;
                    } else if (year1 == year2) {
                        if (month1 > month2) {
                            return 1;
                        } else if (month1 == month2) {
                            if (day1 > day2) {
                                return 1;
                            } else if (day1 == day2) {
                                /* newest first */
                                try {
                                    Date date1 = new Date(d1.getLastModified());
                                    Date date2 = new Date(d2.getLastModified());
                                    return date2.compareTo(date1);
                                } catch (DocumentException e) {
                                    throw new RuntimeException(e);
                                }
                            } else {
                                return -1;
                            }
                        } else {
                            return -1;
                        }
                    } else {
                        return -1;
                    }
                }
            });           
           
            /* group entries by year -> month -> day */
            /* works because the list is sorted =) */
            int currentYear = 0;
            int currentMonth = 0;
            int currentDay = 0;
            boolean yearOpen = false;
            boolean monthOpen = false;
            boolean dayOpen = false;           
            for (int i=0; i<sortedList.length; i++) {
                Document doc = ((Document)sortedList[i]);
                String[] patterns = doc.getPath().split("/");                  
                int year =  Integer.parseInt(patterns[2]);
                int month = Integer.parseInt(patterns[3]);
                int day = Integer.parseInt(patterns[4]);
                if (year != currentYear) {
                    if (dayOpen) {
                        dayOpen = false;
                        this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':'
                                + DAY_NODE_NAME);
                    }
                    if (monthOpen) {
                        monthOpen = false;
                        this.contentHandler.endElement(URI, MONTH_NODE_NAME, PREFIX + ':'
                                + MONTH_NODE_NAME);
                    }
                    if (yearOpen) {
                        this.contentHandler.endElement(URI, YEAR_NODE_NAME, PREFIX + ':'
                                + YEAR_NODE_NAME);
                    }
                    this.attributes.clear();
                    attributes.addAttribute("", ID_ATTR_NAME,
                            ID_ATTR_NAME, "CDATA", String.valueOf(year));
                    this.contentHandler.startElement(URI, YEAR_NODE_NAME, PREFIX + ':'
                            + YEAR_NODE_NAME, attributes);
                    yearOpen = true;
                    currentYear = year;
                    currentMonth = 0;
                    currentDay = 0;                   
                }
                if (month != currentMonth) {
                    if (dayOpen) {
                        dayOpen = false;
                        this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':'
                                + DAY_NODE_NAME);
                    }
                    if (monthOpen) {
                        this.contentHandler.endElement(URI, MONTH_NODE_NAME, PREFIX + ':'
                                + MONTH_NODE_NAME);
                    }
                    this.attributes.clear();
                    attributes.addAttribute("", ID_ATTR_NAME,
                            ID_ATTR_NAME, "CDATA", String.valueOf(month));
                    this.contentHandler.startElement(URI, MONTH_NODE_NAME, PREFIX + ':'
                            + MONTH_NODE_NAME, attributes);
                    monthOpen = true;
                    currentMonth = month;
                    currentDay = 0;
                }
                if (day != currentDay) {
                    if (dayOpen) {
                        this.contentHandler.endElement(URI, DAY_NODE_NAME, PREFIX + ':'
                                + DAY_NODE_NAME);
                    }
                    this.attributes.clear();
                    attributes.addAttribute("", ID_ATTR_NAME,
                            ID_ATTR_NAME, "CDATA", String.valueOf(day));
                    this.contentHandler.startElement(URI, DAY_NODE_NAME, PREFIX + ':'
                            + DAY_NODE_NAME, attributes);
                    dayOpen = true;
                    currentDay = day;
                }               
                if (structure == null) {
                    attributes.clear();
                    attributes.addAttribute("", PATH_ATTR_NAME,
                            PATH_ATTR_NAME, "CDATA", doc.getPath());
                    attributes.addAttribute("", URL_ATTR_NAME,
                            URL_ATTR_NAME, "CDATA", doc.getCanonicalWebappURL());
                    org.w3c.dom.Document docDOM = DocumentHelper.readDocument(doc.getInputStream());
                    Element parent = docDOM.getDocumentElement();
                    Element element = (Element) XPathAPI.selectSingleNode(parent,
                        "/*[local-name() = 'entry']/*[local-name() = 'title']");
                    attributes.addAttribute("", TITLE_ATTR_NAME,
                            TITLE_ATTR_NAME, "CDATA",DocumentHelper.getSimpleElementText(element));
                    attributes.addAttribute("", LASTMOD_ATTR_NAME,
                            LASTMOD_ATTR_NAME, "CDATA", String.valueOf(doc.getLastModified()));
                    DocumentHelper.getSimpleElementText(element);
                    this.contentHandler.startElement(URI, ENTRY_NODE_NAME,
                            PREFIX + ':' + ENTRY_NODE_NAME, attributes);
                    this.contentHandler.endElement(URI, ENTRY_NODE_NAME, PREFIX
                            + ':' + ENTRY_NODE_NAME);
View Full Code Here

     * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
     */
    protected void initParameters() {
        super.initParameters();

        Document parent = getSourceDocument();
        try {
            setParameter(PARENT_ID, parent.getPath());
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

     */
    protected void doExecute() throws Exception {
        super.doExecute();

        // prepare values necessary for blog entry creation
        Document parent = getSourceDocument();
        String language = parent.getPublication().getDefaultLanguage();

        // create new document
        // implementation note: since blog does not have a hierarchy,
        // document id (full path) and document id-name (this leaf's id)
        // are the same
        DocumentManager documentManager = null;
        ServiceSelector selector = null;
        ResourceType resourceType = null;

        try {
            selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
            resourceType = (ResourceType) selector.select(getDocumentTypeName());

            documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);

            DocumentFactory map = getDocumentFactory();

            String documentId = getDocumentID();
           
            String sampleName = resourceType.getSampleNames()[0];
            String sampleUri = resourceType.getSample(sampleName).getUri();

            Document document = documentManager.add(map,
                    resourceType,
                    sampleUri,
                    getSourceDocument().getPublication(),
                    getSourceDocument().getArea(),
                    documentId,
View Full Code Here

    }

    protected void doCheckExecutionConditions() throws Exception {
        String event = getParameterAsString(EVENT);
        if (event != null) {
            Document doc = getSourceDocument();
            UsecaseWorkflowHelper.checkWorkflow(this.manager, this, event, doc,
                    getLogger());
        }
    }
View Full Code Here

        SourceResolver resolver = null;

        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);

            Document doc = getSourceDocument();
            String extension = getSourceExtension();
            // sanity check
            if (doc == null)
                throw new IllegalArgumentException("illegal usage, source document may not be null");

            // create new doc from PUT input
            if (!doc.exists()) {
                DocumentManager documentManager = null;
                ServiceSelector selector = null;
                ResourceType resourceType = null;
                try {
                    selector = (ServiceSelector) this.manager
                            .lookup(ResourceType.ROLE + "Selector");

                    documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);

                    DocumentFactory map = getDocumentFactory();
                    String path = doc.getPath();
                    // lookupResourceType(extension)
                    resourceType = lookUpExtension(extension, selector);
                    ResourceType.Sample sample = resourceType.getSample(resourceType.getSampleNames()[0]);
                    doc = documentManager.add(map, resourceType, sample.getUri(), getPublication(), doc
                            .getArea(), path, doc.getLanguage(), extension, doc.getName(), true);
                    doc.setMimeType(sample.getMimeType());
                    setMetaData(doc);
                } finally {
                    if (documentManager != null) {
                        this.manager.release(documentManager);
                    }
                    if (selector != null) {
                        if (resourceType != null) {
                            selector.release(resourceType);
                        }
                        this.manager.release(selector);
                    }
                }
            }

            String sourceUri = "cocoon:/request/PUT/" + extension;
            org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(sourceUri, manager);

            // validate if a schema is provided and we are not using any fallback
            if (doc.getResourceType().getSchema() != null & fallback == false) {
                validateDoc(resolver, xmlDoc, doc);
            }

            if (!hasErrors()) {
                try {
                    DocumentHelper.writeDocument(xmlDoc, doc.getOutputStream());
                } catch (Exception e) {
                    addErrorMessage("invalid source xml. Full exception: " + e);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.lenya.cms.publication.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.