Package org.apache.lenya.cms.publication

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


            setIgnoreAElement(false);

            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 webappUrlWithQueryString = href.substring(context.length());
                        String webappUrlWithAnchor;
                       
                        String queryString = null;
View Full Code Here


        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Resolving policy for webapp URL [" + webappUrl + "]");
        }

        Publication publication = getPublication(webappUrl);
        DocumentBuilder builder = publication.getDocumentBuilder();
        String url = null;
        try {
            if (builder.isDocument(publication, webappUrl)) {
                Document document = builder.buildDocument(publication, webappUrl);
                if (document.existsInAnyLanguage()) {
                    url = "/" + document.getArea() + document.getId();
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("    Document exists");
                        getLogger().debug("    Document ID: [" + document.getId() + "]");
                    }
                }
            }
        } catch (Exception e) {
            throw new AccessControlException(e);
        }

        if (url == null) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("    Document does not exist.");
            }
            url = webappUrl.substring(("/" + publication.getId()).length());
        }

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("    Using URL: [" + url + "]");
        }
View Full Code Here

   * @throws AccessControlException when the publication could not be created.
   */
    protected Publication getPublication(String url) throws AccessControlException {
        getLogger().debug("Building publication");

        Publication publication;
        Source source = null;
        SourceResolver resolver = null;

        try {
            resolver = (SourceResolver) serviceManager.lookup(SourceResolver.ROLE);
View Full Code Here

     *
     * @throws Exception DOCUMENT ME!
     */
    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src,
        Parameters parameters) throws Exception {
        Publication publication = PublicationFactory.getPublication(objectModel);

        // Get request object
        Request request = ObjectModelHelper.getRequest(objectModel);

        if (request == null) {
            getLogger().error("No request object");

            return null;
        }

        // Get parameters
        //String parentid = request.getParameter("parentid");
        String parentid = request.getParameter("properties.create.parent-id");
        log.debug("properties.create.parent-id = " + parentid);

        //String childid = request.getParameter("childid");
        String childid = request.getParameter("properties.create.child-id");
        log.debug("properties.create.child-id = " + childid);

        //String childname = request.getParameter("childname");
        String childname = request.getParameter("properties.create.child-name");
        log.debug("properties.create.child-name = " + childname);

        //String childtype = request.getParameter("childtype");
        String childtype = request.getParameter("properties.create.child-type");
        log.debug("properties.create.childtype = " + childtype);
       
        //String visibleInNav = request.getParameter("visible");
        String visible = request.getParameter("properties.create.visible");

        boolean visibleInNav = true;
        if (visible.equals("no")){
          visibleInNav = false;
        }
       
        short childType;
        if (childtype.equals("branch")) {
            childType = ParentChildCreatorInterface.BRANCH_NODE;
        } else if (childtype.equals("leaf")) {
            childType = ParentChildCreatorInterface.LEAF_NODE;
        } else {
            log.error("No such child type: " + childtype);
            return null;
        }



        //String doctype = request.getParameter("doctype");
        String doctype = request.getParameter("properties.create.doctype");
        log.debug("poperties.create.doctype = " + doctype);

        //String language = request.getParameter("language");
        String language = request.getParameter("properties.create.language");
        log.debug("poperties.create.language = " + language);
   



        if (!validate(parentid, childid, childname, childtype, doctype)) {
            getLogger().error("Exception: Validation of parameters failed");

            return null;
        }

        // Get session
        Session session = request.getSession(true);

        if (session == null) {
            getLogger().error("No session object");

            return null;
        }

        // Get creator
        ParentChildCreatorInterface creator = null;
        String absoluteDoctypesPath = publication.getDirectory() + File.separator + doctypesPath;
        Document doctypesDoc = new SAXReader().read("file:" + absoluteDoctypesPath +
                "doctypes.xconf");
        Attribute creator_src = (Attribute) doctypesDoc.selectSingleNode("/doctypes/doc[@type='" +
                doctype + "']/creator/@src");

        if (creator_src != null) {
            log.info("Creator found for \"" + doctype + "\": " + creator_src.getName() + " " + creator_src.getPath() + " " + creator_src.getValue());

            // now get the constructor that accepts the configuration
            Class creatorClass = Class.forName(creator_src.getValue());
            creator = (ParentChildCreatorInterface) creatorClass.newInstance();
        } else {
            log.warn("No creator found for \"" + doctype + "\". DefaultBranchCreator will be taken.");
            creator = new org.apache.lenya.cms.authoring.DefaultBranchCreator();
        }

        getLogger().debug(".act(): Creator : " + creator.getClass().getName());

        // Init creator
        // "Read" the configuration from the DOM node
        DefaultConfigurationBuilder defaultConfigBuilder = new DefaultConfigurationBuilder();
        Configuration[] docTypeConfigs = defaultConfigBuilder.buildFromFile(absoluteDoctypesPath +
                "doctypes.xconf").getChildren();

        Configuration doctypeConf = null;

        for (int i = 0; i < docTypeConfigs.length; i++) {
            String typeName = docTypeConfigs[i].getAttribute("type");

            if (typeName.equals(doctype)) {
                doctypeConf = docTypeConfigs[i].getChild("creator", false);
            }
        }

        creator.init(doctypeConf);

        // add a node to the tree
        SiteTree siteTree = publication.getTree(Publication.AUTHORING_AREA);
        Label[] labels = new Label[1];
        labels[0] = new Label(childname, language);
        siteTree.addNode(parentid, creator.generateTreeId(childid, childType), labels, visibleInNav);

        // Transaction should actually be finished here!
        // Create actual document
        // grab all the parameters from session, request params and
        // sitemap params
        HashMap allParameters = new HashMap();
        String[] names = parameters.getNames();

        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            String value = null;

            try {
                value = parameters.getParameter(name);
            } catch (ParameterException pe) {
                value = null;
            }

            allParameters.put(name, value);
        }

        Enumeration requestParameters = request.getParameterNames();

        while (requestParameters.hasMoreElements()) {
            String requestParameterName = (String) requestParameters.nextElement();

            if (allParameters.containsKey(requestParameterName)) {
                // we do not allow name clashes
                throw new ProcessingException("Name clash in request parameter " +
                    "and sitemap parameter: " + requestParameterName);
            }

            allParameters.put(requestParameterName, request.getParameter(requestParameterName));
        }

        Enumeration sessionAttributeNames = session.getAttributeNames();

        while (sessionAttributeNames.hasMoreElements()) {
            String sessionAttributeName = (String) sessionAttributeNames.nextElement();

            if (allParameters.containsKey(sessionAttributeName)) {
                // we do not allow name clashes
                throw new ProcessingException("Name clash in session attribute " +
                    "and request parameter or sitemap parameter: " + sessionAttributeName);
            }

            allParameters.put(sessionAttributeName, session.getAttribute(sessionAttributeName));
        }

        try {
            creator.create(publication, new File(absoluteDoctypesPath + "samples"),
                new File(publication.getDirectory(), docsPath + parentid), parentid, childid, childType,
                childname, language, allParameters);
        } catch (Exception e) {
            log.error("Creator threw exception: " + e);
            return null;
        }
View Full Code Here

     * Returns the publication.
     * @return A publication.
     * @throws ExecutionException when something went wrong.
     */
    public Publication getPublication() throws ExecutionException {
        Publication publication;
        try {
            publication =
                PublicationFactory.getPublication(
                    get(Task.PARAMETER_PUBLICATION_ID),
                    get(Task.PARAMETER_SERVLET_CONTEXT));
View Full Code Here

                if (getLogger().isDebugEnabled()) {
                    getLogger().debug(
                            "Convert links: No XPaths for resource type [" + type.getName() + "]");
                }
            } else {
                Publication pub = examinedDocument.getPublication();
                ChainLinkRewriter incomingRewriter = new ChainLinkRewriter();
                incomingRewriter.add(new RelativeToAbsoluteLinkRewriter(examinedDocument
                        .getCanonicalWebappURL()));
                incomingRewriter.add(new IncomingLinkRewriter(pub));

                // Workaround:
                // We create a new session because the sitetree of the transaction doesn't yet
                // contain
                // references to any new documents that were uploaded during the transaction.
                // See https://issues.apache.org/bugzilla/show_bug.cgi?id=47621
                Session readOnlySession = RepositoryUtil.createSession(this.manager,
                        examinedDocument.getSession().getIdentity(), false);
                DocumentFactory newFactory = DocumentUtil.createDocumentFactory(this.manager,
                        readOnlySession);
                final LinkRewriter[] rewriters = { new UrlToUuidRewriter(pub.getFactory()),
                        new UrlToUuidRewriter(newFactory) };

                org.w3c.dom.Document xml = DocumentHelper.readDocument(examinedDocument
                        .getInputStream());

                for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger()
                                .debug("Convert links: Check XPath [" + xPaths[xPathIndex] + "]");
                    }
                    NodeList nodes = XPathAPI.selectNodeList(xml, xPaths[xPathIndex]);
                    for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
                        Node node = nodes.item(nodeIndex);
                        if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
                            throw new RuntimeException("The XPath [" + xPaths[xPathIndex]
                                    + "] may only match attribute nodes!");
                        }
                        Attr attribute = (Attr) node;
                        final String url = attribute.getValue();
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("Convert links: Check URL [" + url + "]");
                        }
                        final String originalUrl = url.startsWith(prefix) ? url.substring(prefix
                                .length()) : url;
                        final String srcPubUrl;
                        if (incomingRewriter.matches(originalUrl)) {
                            srcPubUrl = incomingRewriter.rewrite(originalUrl);
                        } else {
                            srcPubUrl = originalUrl;
                        }
                        final String srcPubPrefix = "/" + srcPub.getId() + "/";
                        if (srcPubUrl.startsWith(srcPubPrefix)) {
                            final String destPubUrl = "/" + pub.getId() + "/"
                                    + srcPubUrl.substring(srcPubPrefix.length());
                            boolean rewritten = false;
                            for (int i=0; i<rewriters.length; i++) {
                                final LinkRewriter rewriter = rewriters[i];
                                if (!rewritten && rewriter.matches(destPubUrl)) {
View Full Code Here

  DocumentManager docMgr = null;
  try {
      docMgr = (DocumentManager) getManager().lookup(DocumentManager.ROLE);

      Publication pub = getPublication("test");
      Area area = pub.getArea(Publication.AUTHORING_AREA);
      Area trashArea = pub.getArea("trash");
      SiteStructure site = area.getSite();
      SiteNode node = site.getNode(PATH);
      Document doc_en = node.getLink("en").getDocument();
      Document doc_de = node.getLink("de").getDocument();

      DocumentLocator loc = DocumentLocator.getLocator(pub.getId(), "trash", PATH, doc_en.getLanguage());

      docMgr.copyAll(area, PATH, trashArea, PATH);

      SiteStructure trashSite = trashArea.getSite();
      assertTrue(trashSite.contains(PATH));
View Full Code Here

    }

    protected void checkPostconditions() throws Exception {
        super.checkPostconditions();
       
        Publication pub = getPublication("test");
        SiteStructure trashSite = pub.getArea("trash").getSite();
  assertFalse(trashSite.contains(PATH));
    }
View Full Code Here

        if (!getParameterAsBoolean(PARAM_CHECK_MISSING_ANCESTORS, true)) {
            return;
        }
       
        Document document = getSourceDocument();
        Publication publication = document.getPublication();
        DocumentFactory map = document.getFactory();
        SiteStructure liveSite = publication.getArea(Publication.LIVE_AREA).getSite();

        List missingDocuments = new ArrayList();

        ServiceSelector selector = null;
        SiteManager siteManager = null;
        try {
            selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
            siteManager = (SiteManager) selector.select(publication.getSiteManagerHint());

            if (!liveSite.contains(document.getPath())) {
                DocumentLocator liveLoc = document.getLocator().getAreaVersion(
                        Publication.LIVE_AREA);
                DocumentLocator[] requiredNodes = siteManager
View Full Code Here

     */
    public void testImport() throws Exception {

        Session session = login("lenya");

        Publication pub = getPublication(session, "test");
        Area area = pub.getArea("authoring");

        if (area.getDocuments().length == 0) {
            Publication defaultPub = getPublication(session, "default");
            Area defaultArea = defaultPub.getArea("authoring");
            String pubPath = defaultArea.getPublication().getDirectory().getAbsolutePath();
            String path = pubPath.replace(File.separatorChar, '/') + "/example-content";
            Importer importer = new Importer(getManager(), getLogger());
            importer.importContent(defaultPub, area, path);

            assertTrue(area.getSite().contains("/tutorial"));

            session.commit();
        }

        Session aliceSession = login("alice");
        Publication alicePub = getPublication(aliceSession, "test");
        final SiteStructure authSite = alicePub.getArea("authoring").getSite();
        assertTrue(authSite.contains("/tutorial"));
        final Document index = authSite.getNode("/index").getLink("en").getDocument();
        final org.w3c.dom.Document indexDoc = DocumentHelper.readDocument(index.getRepositoryNode()
                .getInputStream());

View Full Code Here

TOP

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

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.