Package org.apache.lenya.cms.publication

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


     */
    protected Document getAuthoringDocument()
        throws ParameterException, DocumentBuildException, ExecutionException {
        String id = getParameters().getParameter(PARAMETER_DOCUMENT_ID);
        String language = getParameters().getParameter(PARAMETER_DOCUMENT_LANGUAGE);
        DocumentBuilder builder = getPublication().getDocumentBuilder();
        String url =
            builder.buildCanonicalUrl(getPublication(), Publication.AUTHORING_AREA, id, language);
        Document document = builder.buildDocument(getPublication(), url);
        return document;
    }
View Full Code Here


     */
    protected Document getLiveDocument()
        throws ParameterException, DocumentBuildException, ExecutionException {
        String id = getParameters().getParameter(PARAMETER_DOCUMENT_ID);
        String language = getParameters().getParameter(PARAMETER_DOCUMENT_LANGUAGE);
        DocumentBuilder builder = getPublication().getDocumentBuilder();
        String url =
            builder.buildCanonicalUrl(getPublication(), Publication.LIVE_AREA, id, language);
        Document document = builder.buildDocument(getPublication(), url);
        return document;
    }
View Full Code Here

            String href = attrs.getValue(ATTRIBUTE_HREF);
            if (href != null) {

                Publication publication = getCurrentDocument().getPublication();
                DocumentBuilder builder = publication.getDocumentBuilder();

                try {

                    newAttrs = new AttributesImpl(attrs);

                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug(this.indent + "href URL: [" + href + "]");
                    }

                    String context = this.request.getContextPath();

                    if (href.startsWith(context + "/" + publication.getId())) {
                       
                        final String webappUrlWithAnchor = href.substring(context.length());
                       
                        String anchor = null;
                        String webappUrl = null;
                       
                        int anchorIndex = webappUrlWithAnchor.indexOf("#");
                        if (anchorIndex > -1) {
                            webappUrl = webappUrlWithAnchor.substring(0, anchorIndex);
                            anchor = webappUrlWithAnchor.substring(anchorIndex + 1);
                        }
                        else {
                            webappUrl = webappUrlWithAnchor;
                        }
                       
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug(this.indent + "webapp URL: [" + webappUrl + "]");
                            getLogger().debug(this.indent + "anchor:     [" + anchor + "]");
                        }
                        if (builder.isDocument(publication, webappUrl)) {

                            Document targetDocument = builder.buildDocument(publication, webappUrl);

                            if (getLogger().isDebugEnabled()) {
                                getLogger().debug(this.indent + "Resolved target document: ["
                                        + targetDocument + "]");
                            }

                            String currentAreaUrl = builder.buildCanonicalUrl(publication,
                                    getCurrentDocument().getArea(),
                                    targetDocument.getId(),
                                    targetDocument.getLanguage());
                            targetDocument = builder.buildDocument(publication, currentAreaUrl);

                            if (targetDocument.exists()) {
                                rewriteLink(newAttrs, targetDocument, anchor);
                            } else {
                                this.ignoreAElement = true;
View Full Code Here

        TransformerFactory tFactory = TransformerFactory.newInstance();

        Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet));

        Publication publication = getPublication();
        DocumentBuilder builder = publication.getDocumentBuilder();

        // replace all internal links
        String oldURL =
            getContextPrefix() + builder.buildCanonicalUrl(publication, area, oldDcoumentId);
        String newURL =
            getContextPrefix() + builder.buildCanonicalUrl(publication, area, newDocumentId);

        log("Replace '" + oldURL + "' by '" + newURL + "'");
        transformer.setParameter("idbefore", oldURL);
        transformer.setParameter("idafter", newURL);

        replace_internal(rootDir, transformer);

        // now also do the replacement for all language versions
        String[] languages = publication.getLanguages();
        for (int i = 0; i < languages.length; i++) {
            String language = languages[i];

            oldURL =
                getContextPrefix()
                    + builder.buildCanonicalUrl(publication, area, oldDcoumentId, language);
            newURL =
                getContextPrefix()
                    + builder.buildCanonicalUrl(publication, area, newDocumentId, language);

            log("Replace '" + oldURL + "' by '" + newURL + "'");
            transformer.setParameter("idbefore", oldURL);
            transformer.setParameter("idafter", newURL);
View Full Code Here

                        documentid.substring(0, lang)
                            + documentid.substring(lang + langLength, l - bxLength);
                }
            }

            DocumentBuilder builder = publication.getDocumentBuilder();

            String srcUrl =
                builder.buildCanonicalUrl(publication, document.getArea(), documentid, language);
            Document srcDoc = builder.buildDocument(publication, srcUrl);
            File newFile = srcDoc.getFile();
            filename = newFile.getCanonicalPath();

        } else {
            filename = document.getFile().getCanonicalPath();
View Full Code Here

     */
    protected Document getAuthoringDocument()
        throws ParameterException, DocumentBuildException, ExecutionException {
        String id = getParameters().getParameter(PARAMETER_DOCUMENT_ID);
        String language = getParameters().getParameter(PARAMETER_DOCUMENT_LANGUAGE);
        DocumentBuilder builder = getPublication().getDocumentBuilder();
        String url =
            builder.buildCanonicalUrl(getPublication(), Publication.AUTHORING_AREA, id, language);
        Document document = builder.buildDocument(getPublication(), url);
        return document;
    }
View Full Code Here

    public Document[] getInternalReferences() throws ProcessingException {
        ArrayList unpublishedReferences = new ArrayList();
        SiteTree sitetree;
        Pattern internalLinkPattern = getInternalLinkPattern();
        Publication publication = pageEnvelope.getPublication();
        DocumentBuilder builder = publication.getDocumentBuilder();
        try {
            sitetree = publication.getTree(Publication.LIVE_AREA);
            String[] internalLinks =
                Grep.findPattern(
                    pageEnvelope.getDocument().getFile(),
                    internalLinkPattern,
                    1);
            String[] internalLinksLanguages =
                Grep.findPattern(
                    pageEnvelope.getDocument().getFile(),
                    internalLinkPattern,
                    2);

            for (int i = 0; i < internalLinks.length; i++) {
                String docId = internalLinks[i];
                String language = null;

                log.debug("docId: " + docId);
                if (internalLinksLanguages[i] != null) {
                    // trim the leading '_'
                    language = internalLinksLanguages[i].substring(1);
                }

                log.debug("language: " + language);
                SiteTreeNode documentNode = sitetree.getNode(docId);

                if (language == null) {
                    String url =
                        "/"
                            + publication.getId()
                            + "/"
                            + pageEnvelope.getDocument().getArea()
                            + docId
                            + ".html";
                    language =
                        builder.buildDocument(publication, url).getLanguage();
                }
                log.debug("language: " + language);
                if (documentNode == null
                    || documentNode.getLabel(language) == null) {
                    // the docId has not been published for the given language
                    String url = null;
                    if (language != null) {
                        url =
                            builder.buildCanonicalUrl(
                                publication,
                                Publication.AUTHORING_AREA,
                                docId,
                                language);
                        log.debug("url: " + url);
                    } else {
                        url =
                            builder.buildCanonicalUrl(
                                publication,
                                Publication.AUTHORING_AREA,
                                docId);
                        log.debug("url: " + url);
                    }
                    unpublishedReferences.add(
                        builder.buildDocument(publication, url));
                }
            }
        } catch (SiteTreeException e) {
            throw new ProcessingException(e);
        } catch (IOException e) {
View Full Code Here

        DocumentIdToPathMapper mapper = publication.getPathMapper();
        if (mapper instanceof PathToDocumentIdMapper) {
            PathToDocumentIdMapper fileMapper = (PathToDocumentIdMapper)mapper;
            String documentId = null;
            String language = null;
            DocumentBuilder builder = publication.getDocumentBuilder();
            File[] inconsistentFiles;
            try {
                inconsistentFiles =
                    Grep.find(
                        publication.getContentDirectory(area),
                        getReferencesSearchString());
                for (int i = 0; i < inconsistentFiles.length; i++) {
                    // for performance reasons the getReferencesSearchString() is
                    // constructed in a way such that it will catch all files which
                    // have a link to any language version of the current document.
                    // That's why we need to do some additional tests for each hit.
                    String languageOfCurrentDocument =
                        pageEnvelope.getDocument().getLanguage();
                    String defaultLanguage =
                        pageEnvelope.getPublication().getDefaultLanguage();
                    Pattern referencesSearchStringWithLanguage =
                        Pattern.compile(
                            getReferencesSearchString()
                                + "_"
                                + languageOfCurrentDocument);
                    Pattern referencesSearchStringWithOutLanguage =
                        Pattern.compile(
                            getReferencesSearchString() + "\\.html");
                    log.debug(
                        "languageOfCurrentDocument: "
                            + languageOfCurrentDocument);
                    log.debug("defaultLanguage: " + defaultLanguage);
                    log.debug(
                        "referencesSearchStringWithOutLanguage: "
                            + referencesSearchStringWithOutLanguage.pattern());
                    log.debug(
                        "referencesSearchStringWithLanguage: "
                            + referencesSearchStringWithLanguage.pattern());
                    // a link is indeed to the current document if the following conditions
                    // are met:
                    // 1. the link is to foo_xx and the language of the current
                    //    document is xx.
                    // 2. or the link is to foo.html and the language of the current
                    //    document is the default language.
                    // Now negate the expression because we continue if above (1) and (2) are
                    // false, and you'll get the following if statement
                    if (!Grep
                        .containsPattern(
                            inconsistentFiles[i],
                            referencesSearchStringWithLanguage)
                        && !(Grep
                            .containsPattern(
                                inconsistentFiles[i],
                                referencesSearchStringWithOutLanguage)
                            && languageOfCurrentDocument.equals(
                                defaultLanguage))) {
                        // the reference foo_xx is neither to the language of the current
                        // document.
                        // nor is the reference foo.html and the current document is in the
                        // default language.
                        // So the reference is of no importance to us, skip
                        continue;
                    }

                    documentId =
                        fileMapper.getDocumentId(
                            publication,
                            area,
                            inconsistentFiles[i]);
                    log.debug("documentId: " + documentId);
                    language = fileMapper.getLanguage(inconsistentFiles[i]);
                    log.debug("language: " + language);

                    String url = null;
                    if (language != null) {
                        url =
                            builder.buildCanonicalUrl(
                                publication,
                                area,
                                documentId,
                                language);
                        log.debug("url: " + url);
                    } else {
                        url =
                            builder.buildCanonicalUrl(
                                publication,
                                area,
                                documentId);
                        log.debug("url: " + url);
                    }
                    documents.add(builder.buildDocument(publication, url));
                }
            } catch (IOException e) {
                throw new ProcessingException(e);
            } catch (DocumentDoesNotExistException e) {
                throw new ProcessingException(e);
View Full Code Here

        Label[] labels = node.getLabels();
        for (int i = 0; i < labels.length; i++) {

            String language = labels[i].getLanguage();
            DocumentBuilder builder = publication.getDocumentBuilder();

            try {
                String url = builder.buildCanonicalUrl(publication, area, documentId, language);
                Document document = builder.buildDocument(publication, url);

                String servletContext = new File(servletContextPath).getCanonicalPath();
                log("Deleting scheduler entry for document [" + document + "]");
                log("Resolving servlet [" + servletContext + "]");
View Full Code Here

      throw new BuildException(e);
    }
    SiteTreeNode node = tree.getNode(documentid);
    Label[] labels = node.getLabels();

    DocumentBuilder builder = publication.getDocumentBuilder();

    try {
      if (labels.length < 1) {
        log("no languages found for the node with id : " + node.getId());
        url = builder.buildCanonicalUrl(publication, area, documentid);
        writeDCIdentifier(publication, url);
      } else {
        for (int i = 0; i < labels.length; i++) {
          language = labels[i].getLanguage();
          url = builder.buildCanonicalUrl(publication, area, documentid, language);
          writeDCIdentifier(publication, url);
        }
      }
    } catch (DocumentException e1) {
      throw new BuildException(e1);
View Full Code Here

TOP

Related Classes of org.apache.lenya.cms.publication.DocumentBuilder

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.