Jackrabbit Content Repository
  1. Jackrabbit Content Repository
  2. JCR-1787

XmlHandler export functions don't work in XML repository mode - causes XML with XSLT dependencies to show up with jcr:content XML element.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: jackrabbit-jcr-server
    • Labels:
      None

      Description

      I can't view XML files with XSLT dependencies because the XML returned from XML requests will come back as the "jcr:content" XML representation.

      <?xml version="1.0" encoding="UTF-8" ?>
      <jcr:content xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:xrc="http://www.xerceo.com/learn/jcr-1.0" xmlns:rep="internal" jcr:primaryType="nt:resource" jcr:uuid="33951e14-7a9a-4746-b848-4f931f4c01be" jcr:data="" jcr:encoding="UTF-8" jcr:lastModified="2008-10-06T14:46:43.965-05:00" jcr:mimeType="text/xml" />

      I suggest changes to package org.apache.jackrabbit.server.io.XmlHandler:

      1) Create new method:

      /**

      • @see DefaultHandler#exportData(ExportContext, boolean, Node)
        */
        protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
        // first child of content is XML document root
        if (contentNode.getNodes().hasNext()) { contentNode = contentNode.getNodes().nextNode(); }

      OutputStream out = context.getOutputStream();
      out.write(ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false).getBytes());
      }

      Change canExport method:

      /**

      • @see IOHandler#canExport(ExportContext, boolean)
        */
        public boolean canExport(ExportContext context, boolean isCollection) {
        if (super.canExport(context, isCollection)) {
        String mimeType = null;
        try
        Unknown macro: { Node contentNode = getContentNode(context, isCollection); if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) { mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString(); } else { mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName()); } }

        catch (RepositoryException e)

        { // ignore and return false }

        return XML_MIMETYPE.equals(mimeType);
        }
        return false;
        }

      This causes my server to return the correct XML then

      1. XmlHandler.java
        9 kB
        Nicholas DiPiazza

        Activity

        Jukka Zitting made changes -
        Workflow jira [ 12443577 ] no-reopen-closed, patch-avail [ 12467806 ]
        Jukka Zitting made changes -
        Component/s jackrabbit-jcr-server [ 12312058 ]
        Hide
        Nicholas DiPiazza added a comment -

        Simple.

        <servlet>
        <servlet-name>Webdav</servlet-name>
        <description>The webdav servlet that connects HTTP request to the repository.</description>
        <servlet-class>org.apache.jackrabbit.j2ee.SimpleWebdavServlet</servlet-class>
        <init-param>
        <param-name>resource-path-prefix</param-name>
        <param-value>/repository</param-value>
        <description>defines the prefix for spooling resources out of the repository.</description>
        </init-param>

        <init-param>
        <param-name>resource-config</param-name>
        <param-value>/WEB-INF/jackrabbit-webdav-config.xml</param-value>
        <description>Defines various dav-resource configuration parameters.</description>
        </init-param>
        <init-param>
        <param-name>missing-auth-mapping</param-name>
        <param-value>anonymous:anonymous</param-value>
        <description>
        Defines how a missing authorization header should be handled.
        1) If this init-param is missing, a 401 response is generated.
        This is suiteable for clients (eg. webdav clients) for which
        sending a proper authorization header is not possible if the
        server never sent a 401.
        2) If this init-param is present with an empty value,
        null-credentials are returned, thus forcing an null login
        on the repository.
        3) If this init-param has a 'user:password' value, the respective
        simple credentials are generated.
        </description>
        </init-param>
        <load-on-startup>4</load-on-startup>
        </servlet>

        Show
        Nicholas DiPiazza added a comment - Simple. <servlet> <servlet-name>Webdav</servlet-name> <description>The webdav servlet that connects HTTP request to the repository.</description> <servlet-class>org.apache.jackrabbit.j2ee.SimpleWebdavServlet</servlet-class> <init-param> <param-name>resource-path-prefix</param-name> <param-value>/repository</param-value> <description>defines the prefix for spooling resources out of the repository.</description> </init-param> <init-param> <param-name>resource-config</param-name> <param-value>/WEB-INF/jackrabbit-webdav-config.xml</param-value> <description>Defines various dav-resource configuration parameters.</description> </init-param> <init-param> <param-name>missing-auth-mapping</param-name> <param-value>anonymous:anonymous</param-value> <description> Defines how a missing authorization header should be handled. 1) If this init-param is missing, a 401 response is generated. This is suiteable for clients (eg. webdav clients) for which sending a proper authorization header is not possible if the server never sent a 401. 2) If this init-param is present with an empty value, null-credentials are returned, thus forcing an null login on the repository. 3) If this init-param has a 'user:password' value, the respective simple credentials are generated. </description> </init-param> <load-on-startup>4</load-on-startup> </servlet>
        Hide
        Julian Reschke added a comment -

        Which of the two WebDAV servers are you using? JCR webdav or simple webdav?

        Show
        Julian Reschke added a comment - Which of the two WebDAV servers are you using? JCR webdav or simple webdav?
        Hide
        Nicholas DiPiazza added a comment -

        1) Here is the situation. I have XML files that are linked with XSLT files in the repository.

        I need to be able to use read-only webdav and serve these XML pages from the repository and have them launch in the browser.

        The problem was when my XML configuration was turned on, the result of the webdav path would return the actual XML from the Node... not the XML contained within the jcr:data.

        2) Webdav config:

        I am using the out of the box webdav config.

        <propertymanager>
        <!-- class element defines the manager to be used. The specified class
        must implement the PropertyManager interface.
        Note, that the handlers are being added and called in the order
        they appear in the configuration.
        -->
        <class name="org.apache.jackrabbit.server.io.PropertyManagerImpl" />
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.VersionHandler" />
        </propertyhandler>
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.VersionHistoryHandler" />
        </propertyhandler>
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.ZipHandler" />
        </propertyhandler>
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.XmlHandler" />
        </propertyhandler>
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
        </propertyhandler>
        <propertyhandler>
        <class name="org.apache.jackrabbit.server.io.DefaultHandler" />
        </propertyhandler>
        </propertymanager>

        Show
        Nicholas DiPiazza added a comment - 1) Here is the situation. I have XML files that are linked with XSLT files in the repository. I need to be able to use read-only webdav and serve these XML pages from the repository and have them launch in the browser. The problem was when my XML configuration was turned on, the result of the webdav path would return the actual XML from the Node... not the XML contained within the jcr:data. 2) Webdav config: I am using the out of the box webdav config. <propertymanager> <!-- class element defines the manager to be used. The specified class must implement the PropertyManager interface. Note, that the handlers are being added and called in the order they appear in the configuration. --> <class name="org.apache.jackrabbit.server.io.PropertyManagerImpl" /> <propertyhandler> <class name="org.apache.jackrabbit.server.io.VersionHandler" /> </propertyhandler> <propertyhandler> <class name="org.apache.jackrabbit.server.io.VersionHistoryHandler" /> </propertyhandler> <propertyhandler> <class name="org.apache.jackrabbit.server.io.ZipHandler" /> </propertyhandler> <propertyhandler> <class name="org.apache.jackrabbit.server.io.XmlHandler" /> </propertyhandler> <propertyhandler> <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" /> </propertyhandler> <propertyhandler> <class name="org.apache.jackrabbit.server.io.DefaultHandler" /> </propertyhandler> </propertymanager>
        Hide
        Julian Reschke added a comment -

        I think it would be helpful if you would be more specific about what you're doing.

        That would include a description of the WebDAV servlet config, and the sequence of HTTP calls you make (do you have a trace?)

        Show
        Julian Reschke added a comment - I think it would be helpful if you would be more specific about what you're doing. That would include a description of the WebDAV servlet config, and the sequence of HTTP calls you make (do you have a trace?)
        Nicholas DiPiazza made changes -
        Attachment XmlHandler.java [ 12391741 ]
        Hide
        Nicholas DiPiazza added a comment -

        Here is the XmlHandler.java file that I am using with no issues.

        Once again, this is for people who need to server XML pages from the Jackrabbit repository with XML Persistance turned on.

        Show
        Nicholas DiPiazza added a comment - Here is the XmlHandler.java file that I am using with no issues. Once again, this is for people who need to server XML pages from the Jackrabbit repository with XML Persistance turned on.
        Nicholas DiPiazza made changes -
        Description I can't view XML files with XSLT dependencies because the XML returned from XML requests will come back as the "jcr:content" XML representation.

        <?xml version="1.0" encoding="UTF-8" ?>
          <jcr:content xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:xrc="http://www.xerceo.com/learn/jcr-1.0" xmlns:rep="internal" jcr:primaryType="nt:resource" jcr:uuid="33951e14-7a9a-4746-b848-4f931f4c01be" jcr:data="PD94bWwtc3R5bGVzaGVldCB0eXBlPSJ0ZXh0L3hzbCIgaHJlZj0iaHR0cDovLzE5Mi4xNjguMi41Ojg3ODcvL3hsZWFybi9pbmZ1c2UveHNsdC9sYXlvdXRfMV8xXzEueHNsIj8+PGFjdGl2aXR5IGxvb2tuZmVlbD0iYmx1ZV9zdHJlYW0iIHdlYmFwcEN0eHQ9Ii94bGVhcm4iIGFjdGl2aXR5VGVtcGxhdGVJZD0ibGF5b3V0XzFfMV8xIiBmb290ZXI9InRydWUiIGhlYWRlcj0idHJ1ZSIgaWQ9ImFjdGl2aXR5MC43Mjc3NDIyODAzMzgxNTQwLjM2OTkyNzcxOTE3MTczMjEiIG5hcnJhdGlvbkF1dG9TdGFydD0iIiBuYXJyYXRpb25QYXRoPSIiIG5hcnJhdGlvblNob3dQbGF5ZXI9IiIgbmFycmF0aW9uVXVpZD0iIiB0aXRsZT0iQWN0aXZpdHkgMSI+PGNlbGxzLz48L2FjdGl2aXR5Pg==" jcr:encoding="UTF-8" jcr:lastModified="2008-10-06T14:46:43.965-05:00" jcr:mimeType="text/xml" />


        I suggest changes to package org.apache.jackrabbit.server.io.XmlHandler:

        1) Create new method:

        /**
             * @see DefaultHandler#exportData(ExportContext, boolean, Node)
             */
            protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
                // first child of content is XML document root
                if (contentNode.getNodes().hasNext()) {
                    contentNode = contentNode.getNodes().nextNode();
                }
                
                OutputStream out = context.getOutputStream();
                out.write(ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false).getBytes());
            }


        Change canExport method:

        /**
             * @see IOHandler#canExport(ExportContext, boolean)
             */
            public boolean canExport(ExportContext context, boolean isCollection) {
                if (super.canExport(context, isCollection)) {
                    String mimeType = null;
                    try {
                        Node contentNode = getContentNode(context, isCollection);
                        if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                            mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                        } else {
                            mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                        }
                    } catch (RepositoryException e) {
                        // ignore and return false
                    }
                    return XML_MIMETYPE.equals(mimeType);
                }
                return false;
            }


        This causes my server to return the correct XML then

        I can't view XML files with XSLT dependencies because the XML returned from XML requests will come back as the "jcr:content" XML representation.

        <?xml version="1.0" encoding="UTF-8" ?>
          <jcr:content xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:xrc="http://www.xerceo.com/learn/jcr-1.0" xmlns:rep="internal" jcr:primaryType="nt:resource" jcr:uuid="33951e14-7a9a-4746-b848-4f931f4c01be" jcr:data="" jcr:encoding="UTF-8" jcr:lastModified="2008-10-06T14:46:43.965-05:00" jcr:mimeType="text/xml" />


        I suggest changes to package org.apache.jackrabbit.server.io.XmlHandler:

        1) Create new method:

        /**
             * @see DefaultHandler#exportData(ExportContext, boolean, Node)
             */
            protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
                // first child of content is XML document root
                if (contentNode.getNodes().hasNext()) {
                    contentNode = contentNode.getNodes().nextNode();
                }
                
                OutputStream out = context.getOutputStream();
                out.write(ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false).getBytes());
            }


        Change canExport method:

        /**
             * @see IOHandler#canExport(ExportContext, boolean)
             */
            public boolean canExport(ExportContext context, boolean isCollection) {
                if (super.canExport(context, isCollection)) {
                    String mimeType = null;
                    try {
                        Node contentNode = getContentNode(context, isCollection);
                        if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                            mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                        } else {
                            mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                        }
                    } catch (RepositoryException e) {
                        // ignore and return false
                    }
                    return XML_MIMETYPE.equals(mimeType);
                }
                return false;
            }


        This causes my server to return the correct XML then

        Hide
        Nicholas DiPiazza added a comment -

        Then i had to change exportData further to get my XML back in Base 32:

        if (contentNode.getNodes().hasNext())

        { contentNode = contentNode.getNodes().nextNode(); }

        OutputStream out = context.getOutputStream();
        String res = ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false);
        Base64.decode(res.toCharArray(), out);

        Show
        Nicholas DiPiazza added a comment - Then i had to change exportData further to get my XML back in Base 32: if (contentNode.getNodes().hasNext()) { contentNode = contentNode.getNodes().nextNode(); } OutputStream out = context.getOutputStream(); String res = ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false); Base64.decode(res.toCharArray(), out);
        Nicholas DiPiazza made changes -
        Field Original Value New Value
        Description I can't view XML files with XSLT dependencies because the XML returned from XML requests will come back as the "jcr:content" XML representation.

        <?xml version="1.0" encoding="UTF-8" ?>
          <jcr:content xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:xrc="http://www.xerceo.com/learn/jcr-1.0" xmlns:rep="internal" jcr:primaryType="nt:resource" jcr:uuid="33951e14-7a9a-4746-b848-4f931f4c01be" jcr:data="PD94bWwtc3R5bGVzaGVldCB0eXBlPSJ0ZXh0L3hzbCIgaHJlZj0iaHR0cDovLzE5Mi4xNjguMi41Ojg3ODcvL3hsZWFybi9pbmZ1c2UveHNsdC9sYXlvdXRfMV8xXzEueHNsIj8+PGFjdGl2aXR5IGxvb2tuZmVlbD0iYmx1ZV9zdHJlYW0iIHdlYmFwcEN0eHQ9Ii94bGVhcm4iIGFjdGl2aXR5VGVtcGxhdGVJZD0ibGF5b3V0XzFfMV8xIiBmb290ZXI9InRydWUiIGhlYWRlcj0idHJ1ZSIgaWQ9ImFjdGl2aXR5MC43Mjc3NDIyODAzMzgxNTQwLjM2OTkyNzcxOTE3MTczMjEiIG5hcnJhdGlvbkF1dG9TdGFydD0iIiBuYXJyYXRpb25QYXRoPSIiIG5hcnJhdGlvblNob3dQbGF5ZXI9IiIgbmFycmF0aW9uVXVpZD0iIiB0aXRsZT0iQWN0aXZpdHkgMSI+PGNlbGxzLz48L2FjdGl2aXR5Pg==" jcr:encoding="UTF-8" jcr:lastModified="2008-10-06T14:46:43.965-05:00" jcr:mimeType="text/xml" />


        I suggest changes to package org.apache.jackrabbit.server.io.XmlHandler:

        1) Create new method:

        /**
             * @see DefaultHandler#exportData(ExportContext, boolean, Node)
             */
            protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
                // first child of content is XML document root
                if (contentNode.getNodes().hasNext()) {
                    contentNode = contentNode.getNodes().nextNode();
                }
                
                OutputStream out = context.getOutputStream();
                out.write(ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false).getBytes());
            }


        Change canExport method:

        /**
             * @see IOHandler#canExport(ExportContext, boolean)
             */
            public boolean canExport(ExportContext context, boolean isCollection) {
                if (super.canExport(context, isCollection)) {
                    String mimeType = null;
                    try {
                        Node contentNode = getContentNode(context, isCollection);
                        if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                            mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                        } else {
                            mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                        }
                    } catch (RepositoryException e) {
                        // ignore and return false
                    }
                    return XML_MIMETYPE.equals(mimeType);
                }
                return false;
            }


        This causes my server to return the correct XML then:

        I can't view XML files with XSLT dependencies because the XML returned from XML requests will come back as the "jcr:content" XML representation.

        <?xml version="1.0" encoding="UTF-8" ?>
          <jcr:content xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:xrc="http://www.xerceo.com/learn/jcr-1.0" xmlns:rep="internal" jcr:primaryType="nt:resource" jcr:uuid="33951e14-7a9a-4746-b848-4f931f4c01be" jcr:data="PD94bWwtc3R5bGVzaGVldCB0eXBlPSJ0ZXh0L3hzbCIgaHJlZj0iaHR0cDovLzE5Mi4xNjguMi41Ojg3ODcvL3hsZWFybi9pbmZ1c2UveHNsdC9sYXlvdXRfMV8xXzEueHNsIj8+PGFjdGl2aXR5IGxvb2tuZmVlbD0iYmx1ZV9zdHJlYW0iIHdlYmFwcEN0eHQ9Ii94bGVhcm4iIGFjdGl2aXR5VGVtcGxhdGVJZD0ibGF5b3V0XzFfMV8xIiBmb290ZXI9InRydWUiIGhlYWRlcj0idHJ1ZSIgaWQ9ImFjdGl2aXR5MC43Mjc3NDIyODAzMzgxNTQwLjM2OTkyNzcxOTE3MTczMjEiIG5hcnJhdGlvbkF1dG9TdGFydD0iIiBuYXJyYXRpb25QYXRoPSIiIG5hcnJhdGlvblNob3dQbGF5ZXI9IiIgbmFycmF0aW9uVXVpZD0iIiB0aXRsZT0iQWN0aXZpdHkgMSI+PGNlbGxzLz48L2FjdGl2aXR5Pg==" jcr:encoding="UTF-8" jcr:lastModified="2008-10-06T14:46:43.965-05:00" jcr:mimeType="text/xml" />


        I suggest changes to package org.apache.jackrabbit.server.io.XmlHandler:

        1) Create new method:

        /**
             * @see DefaultHandler#exportData(ExportContext, boolean, Node)
             */
            protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException {
                // first child of content is XML document root
                if (contentNode.getNodes().hasNext()) {
                    contentNode = contentNode.getNodes().nextNode();
                }
                
                OutputStream out = context.getOutputStream();
                out.write(ValueHelper.serialize(contentNode.getProperty("jcr:data").getValue(), false).getBytes());
            }


        Change canExport method:

        /**
             * @see IOHandler#canExport(ExportContext, boolean)
             */
            public boolean canExport(ExportContext context, boolean isCollection) {
                if (super.canExport(context, isCollection)) {
                    String mimeType = null;
                    try {
                        Node contentNode = getContentNode(context, isCollection);
                        if (contentNode.hasProperty(JcrConstants.JCR_MIMETYPE)) {
                            mimeType = contentNode.getProperty(JcrConstants.JCR_MIMETYPE).getString();
                        } else {
                            mimeType = context.getMimeResolver().getMimeType(context.getExportRoot().getName());
                        }
                    } catch (RepositoryException e) {
                        // ignore and return false
                    }
                    return XML_MIMETYPE.equals(mimeType);
                }
                return false;
            }


        This causes my server to return the correct XML then

        Nicholas DiPiazza created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Nicholas DiPiazza
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development