9 Replies Latest reply on Feb 1, 2012 9:21 AM by hypnotec

    question - can I script cq:Page creation via Sling?

    kshih@scripps

      Hello!

       

      I was setting up my CQ5 dev environment and trying to figure out some ways to make things a little more convienent to develop for myself and team.

       

      Taking as a starting poing: http://dev.day.com/docs/en/cq/current/developing/developmenttools/developing_with_eclipse. html, my approach was to, instead, try to script some of the interaction by calling sling services, rather than have to jump between various web interfaces.

       

      I'd rather not call bin/wcmcommand, since from what i surmise from the app, so far, that was not a meant to be a service interface made for this purpose (since I can't locate any documentation on it). Please correct me if I am wrong.

       

      But taking this approach, I am having an issue with getting a proper cq:Page by using Sling alone.

       

      When I run this at the command line:

      curl -D - -X POST -u admin:admin -d":operation=import" -d":contentType=jcr.xml" \

      -d":nameHint=sample-app" -d":content@sample-app/design/.content.xml" \

      -d":replace=true" http://localhost:4502/crx/repository/crx.default/etc/designs/sample-app

       

      where my .content.xml looks like this:

      <?xml version="1.0" encoding="UTF-8"?>

      <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"

      jcr:primaryType="cq:Page">

      <jcr:content

      cq:lastModified="{Date}2012-01-18T16:00:13.713-05:00"

      cq:lastModifiedBy="admin"

      cq:template="/libs/wcm/core/templates/designpage"

      jcr:primaryType="cq:PageContent"

      jcr:title="Sample Application Page Design 2"

      sling:resourceType="wcm/core/components/designer"/>

      </jcr:root>

       

      the result it an nt:file node, not a cq:Page node.

       

      I wonder if you could help me with this, and/or discuss whether this is a reasonable approach or not

       

      Many thanks for considering this,

      ken

       

      Message was edited by: kshih@scripps

        • 1. Re: question - can I script cq:Page creation via Sling?
          hypnotec Adobe Employee

          hi

           

          from your description i gather that your intended scripting of CQ page creation is limited to your development environment. nothing speaks against using the wcm command servlet. the documentation is observing what happens when you create a page via siteadmin and the ensuing POST to the wcm command servlet:

           

          Parametersapplication/x-www-form-urlencoded

          :statusbrowser
          _charset_utf-8
          cmdcreatePage
          label
          parentPath/content/geometrixx/en
          template/apps/geometrixx/templates/contentpage
          titletestpage

          Source

          cmd=createPage&_charset_=utf-8&%3Astatus=browser&parentPath=%2Fcontent%2Fgeometrixx%2Fen&title=testpage&label=&template=%2Fapps%2Fgeometrixx%2Ftemplates%2Fcontentpage

           

          (copied from firebug)

           

          as such, no need to fiddle around with XML files, even though that would be workable. but instead of this you could use VLT just as well which properly serializes between the repository and the file system.

           

          greetings

          dom.

          • 2. Re: question - can I script cq:Page creation via Sling?
            kshih@scripps Level 1

            yeah, i already used that "documentation" too and have it in my script as a stop-gap -- since that service doesn't provide more response or options <- to my knowledge though i suppose i could use the java debugger "documentation" and hope there are method signatures that make an iface derive-able
            (e.g. if node already exists, it very sensibly writes a node the same name with an index++ appended, 200, and an html response -- which is why i thought it might not be intended as a service)

             

            but i thought using Sling would be more clean & answering that question would also let me generalize the solution further, including for any nodetypes we introduce (since I've got other steps I'd like to take care of, as well). so, if you know of a way to do it with Sling, that would be super useful.

             

            yup, you are correct, the intention is for use in development

             

            thanks for your response!

            ken

             

            Message was edited by: kshih@scripps

            • 3. Re: question - can I script cq:Page creation via Sling?
              hypnotec Adobe Employee

              just a small comment: http://localhost:4502/crx/repository/crx.default/etc/designs/sample-ap p is a WebDAV URL - no sling post-servlet there (won't work). why not post outside WebDAV?

               

              dom.

              1 person found this helpful
              • 4. Re: question - can I script cq:Page creation via Sling?
                kshih@scripps Level 1

                ah, thanks! i didn't realize that was the webdav url. i'll make a note. interesting... if i post form fields (curl -F) to that url, it _will_ create an nt:file and resource

                 

                i didn't make webdav avail originally because i was having problems with webdav+cq in win7, but i should try that again

                 

                is that to say there isn't a way to do it with Sling?

                are the /etc and/or /app nodes exposed via Sling?

                 

                thanks again, hypnotec

                 

                ken

                 

                Message was edited by: kshih@scripps

                 

                Message was edited by: kshih@scripps

                • 5. Re: question - can I script cq:Page creation via Sling?
                  hypnotec Adobe Employee

                  there is a way to do it in sling - the details i would have to test myself. but i really don't understand why you don't use FileVault (as advertised in http://dev.day.com/docs/en/cq/current/developing/developmenttools/deve loping_with_eclipse.html) - which does exactly what you want: serialize local XML/binary files into the repository. perfectly scriptable. try a checkout with VLT of /content.

                   

                  dom.

                  1 person found this helpful
                  • 6. Re: question - can I script cq:Page creation via Sling?
                    kshih@scripps Level 1

                    ah, another good point. i must have got caught up in following the directions of that link where it asks you to go to Content Explorer, then Tools->add Page, then vlt... but you're right. I could do it with straight vlt. Originally, i was trying to see if i could just do it with "curl -F"s, but thought i'd try the most straight-forward solution first (since type=jcr.xml is in public Sling documentation, if not its use -- so i was trying to figure that out).

                     

                    I'd still love to know the answer about Sling.

                     

                    To answer your question about "why?": knowing the boundaries, uses, generality of Sling will provide utility in the near future for us (e.g. perhaps in the /var space, if not still in /app /etc space), especially if we need to use it with a js front end; say for a useful admin util that goes beyond the scope of /content or CQ itself. Also, we are planning to use CQ rather deeply over the next few years, and I am very interested in knowing as much as I can about this technology that we're licensing, as well as the scope and use of its frameworks, precisely so I can be able to make informed decisions about our implementation and to better evaluate the use of CQ/ADEP/WEM whether it be for our own code, that coming from vendors, Adobe itself, etc. Deciding what layer of the app to engage means deciding what your dependencies are. Deciding to engage the app at the CQ layer is different from engaging with CRX-only or even engaging with CRX only with JCR ifaces. For example, an admin utility app or specific dynamic app, while aware of CQ, may not actually need to have it installed; or, it can determine how portable our code is between versions, so would affect our upgrade strategy/migrations/licensing. So I can see very easily see a desire to use Sling vs. a vlt solution (e.g. why have a whole version control system when you don't need it? there's more places things can go wrong, more things to depend on, etc). Our efficient use of CQ means that we are a better long-term partner for Adobe, as well, including having the ability possibly to make contributions to any open source projects it supports & to provide a successful implementation example for it perhaps to market. Does that makes sense?

                     

                    Anyway, I definitely appreciate your efforts with this. Thanks so much for thinking about this and for checking out the Sling solution.

                     

                    Best,

                    Ken

                     

                    Message was edited by: kshih@scripps

                    • 7. Re: question - can I script cq:Page creation via Sling?
                      hypnotec Adobe Employee

                      if you say you'd like to use *CQ* as efficiently as possible, regarding scripted page creation, i still maintain my recommendation to use /bin/wcmcommand, as it internally uses PageManager#createPage() which makes sure that a page is created as the system expects (black box). The page manager is official API, and thus you should use it (even if implicitly via wcmcommand). if every anything changes in the way a page is created, you'll run into trouble when not using the page manager.

                       

                      nevertheless, i tested it with sling and it works:

                       

                      XML way:

                       

                      Command: curl -D - -X POST -u admin:admin -F ":operation=import" -F ":contentType=jcr.xml" -F ":nameHint=sample-app" -F ":content=@page.xml" -F ":replace=true" http://localhost:4502/etc/designs/

                       

                      XML (file name: page.xml):

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                      <mypage xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"

                        jcr:primaryType="cq:Page">

                        <jcr:content

                                cq:template="/libs/wcm/core/templates/designpage"

                                jcr:primaryType="cq:PageContent"

                                jcr:title="Sample Application Page Design 2"

                                sling:resourceType="wcm/core/components/designer"/>

                      </mypage>

                       

                      JSON Way:

                       

                      Command: curl -D - -X POST -u admin:admin -F ":operation=import" -F ":contentType=json" -F ":nameHint=sample-app" -F ":content=@page.json" -F ":replace=true" http://localhost:4502/etc/designs/

                       

                      JSON (file name: page.json):

                       

                      {

                          "jcr:primaryType": "cq:Page",

                          "jcr:content": {

                              "sling:resourceType": "foundation/components/redirect",

                              "jcr:title": "Geometrixx Demo Site",

                              "cq:lastModifiedBy": "admin",

                              "jcr:primaryType": "nt:unstructured",

                              "redirectTarget": "/content/geometrixx/en",

                              "cq:designPath": "/etc/designs/geometrixx"

                          }

                      }

                       

                      greetings

                      dom.

                      • 8. Re: question - can I script cq:Page creation via Sling?
                        kshih@scripps Level 1

                        Thanks again, Dom,

                         

                        You have answered my original questions:

                        1) Q: whether wcmcommand is an iface user can use A: yes (recommended)

                        2) Q: how do i accomplish with Sling alone A: answer above

                         

                        Additionally, the following very useful information was revealed to me:

                        a) wcmcommand is not documented (will have to construct ourselves via trial/error/inferrence/existing avail code)

                        b) a url like this is a WebDav URL="http://localhost:4502/crx/repository/crx.default/etc/designs/sample-app"

                        c) nodes like "/etc/designs" _may_ (so far) be directly addressable via Sling

                         

                        I will likely follow your recommendation regarding #1 above, but it was key for me to understand some of CQ's relation to Sling, since most of the CQ documentation seems to take a teach by example approach (good), with no layout of more granular design principles, interaction models, etc, that would help the user "get it." Black-box is fine. But then, ideally, the ifaces should be scrupulously documented, including possible return codes and what they mean; rationalizing the system is also necessary in order for it to be used as a framework, CQ it is presented as. Notice above in #b & #c, that even this basic information of what URL is designed for what is not so easily intuited, even though in hindsight they appear more "obvious." If you go back to my original post, you'll notice that was pretty much the only thing I was missing. This is due to a lack of the kind of documentation I mention. And if the code is the documentation, then the code should be open & discoverable. It doesn't seem reasonable to expect it both ways (closed and undocumented), if usability is a goal (?).

                         

                        Just to clarify, by "using CQ" I mean, not just blindly using CQ for any use of content under the sun, but deciding how to use it, including when _not_ to use it. Using CQ for a task it was not designed to do would reflect badly on the product itself, unfairly, not to mention be really bad for our business.

                         

                        Thanks for taking the time to check test this out and by providing very clear examples and information. I can see that my motivations seem obscure to you, but really, _all_ this info is very practical and key for me. I sincerely thank you for your efforts! knowlege is power!

                         

                        Best,

                        Ken

                        • 9. Re: question - can I script cq:Page creation via Sling?
                          hypnotec Adobe Employee

                          you are welcome

                           

                          we're aware of the issues you mention - unfortunately there's only so many hands available.

                           

                          good luck on your CQ-way.

                          dom.