[opencms-dev] Problem with read deleted files, work online/offline, but not work logout...

Schliemann, Kai K.Schliemann at comundus.com
Tue Nov 25 16:20:12 CET 2014


Hi Deiverson,
I did not check what your code does.
But if you need a non-standard list of resources, you can use the class CmsResourceFilter (http://files.opencms.org/javadoc/core/org/opencms/file/CmsResourceFilter.html).
HTH
Best regards
Kai

Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Deiverson Silveira
Gesendet: Dienstag, 25. November 2014 13:40
An: The OpenCms mailing list
Betreff: Re: [opencms-dev] Problem with read deleted files, work online/offline, but not work logout...

Hi,
My solution, is not elegance solution, but don´t have time for correcty solution, used cmspermissionset, dont work change permission instance  my cmsobject, sorry because poor code:

<%@page import="org.opencms.file.
CmsResource"%>
<%@page import="java.util.Iterator"%<mailto:%25 at page%20import=%22java.util.Iterator%22%25>>
<%@page import="java.util.List"%<mailto:%25 at page%20import=%22java.util.List%22%25>>
<%@page import="java.util.Date"%<mailto:%25 at page%20import=%22java.util.Date%22%25>>
<%@page import="org.opencms.file.history.I_CmsHistoryResource"%<mailto:%25 at page%20import=%22org.opencms.file.history.I_CmsHistoryResource%22%25>>
<%@page import="org.opencms.jsp.CmsJspLoginBean"%<mailto:%25 at page%20import=%22org.opencms.jsp.CmsJspLoginBean%22%25>>
<%@page import="java.text.SimpleDateFormat"%<mailto:%25 at page%20import=%22java.text.SimpleDateFormat%22%25>>
<%@page import="org.opencms.file.CmsObject"%<mailto:%25 at page%20import=%22org.opencms.file.CmsObject%22%25>>
<%@page import="org.opencms.jsp.CmsJspActionElement"%<mailto:%25 at page%20import=%22org.opencms.jsp.CmsJspActionElement%22%25>>
<%@ page import="org.opencms.workplace.*" %><%

CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);

boolean testLogin = false;
CmsObject cmso = cms.getCmsObject();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
CmsJspLoginBean loginBean= new CmsJspLoginBean(pageContext, request, response);

try {

    if(loginBean.getUser().isGuestUser()){
        cmso.loginUser("Admin", "admin");
        testLogin = true;
    }

    Date dt = null;
    String dataConvertida = null;
    String dataPesquisada = "01/01/2014 00:01";
    I_CmsHistoryResource res = null;
    Long dataCurrentLong = null;
    Date dataSearchLong = null;
    List list = cmso.readDeletedResources("/", true);
    String arquivo;
    Iterator iter = list.iterator();
    out.println("Lista: "+ list.size()+"<br>");

        dataPesquisada = request.getParameter("data").toLowerCase();
        dataSearchLong = sdf.parse(dataPesquisada);
        out.println("Data a ser pesquisada maior que: <b>" + dataPesquisada + "</b><br><br>");

        while (iter.hasNext()) {
            res = (I_CmsHistoryResource)iter.next();
            //dataConvertida = String.valueOf(res.getDateLastModified());
            dataCurrentLong = res.getDateLastModified();
            arquivo = cmso.getSitePath((CmsResource)res);
            dt = new Date(dataCurrentLong);
            dataConvertida = sdf.format(dt);
            if(dataCurrentLong > dataSearchLong.getTime()){
                //cmso.readResource(arquivo).getStructureId().toString()
                out.println(" <b>Nome do recurso excluido: </b>" + arquivo +" - <b>UUID:</b> " + res.getResourceId().toString() + "  <b>Data da exclusão:</b> " +  dataConvertida + "<br><br>");
            }
        }

    } catch (Exception e) {
        out.println("<br><b>O formato da data deve ser dd/mm/yyyy HH:mm </b>" +e.getMessage());
    } finally{
        out.println("<br>Operação realizada com sucesso.");
        if(testLogin){
            session.invalidate();
        }
    }

    %>

2014-11-24 18:46 GMT-02:00 Deiverson Silveira <deiverson at solutioncms.com<mailto:deiverson at solutioncms.com>>:
I again...

I see the problem:

in classe CmsObject.java, I have this:

    public List<I_CmsHistoryResource> readDeletedResources(String resourcename, boolean readTree) throws CmsException {

        CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL);
        return m_securityManager.readDeletedResources(m_context, resource, readTree);
    }

This is a problem >>> return m_securityManager.readDeletedResources(m_context, resource, readTree);

How can set permission in my object?


2014-11-24 16:59 GMT-02:00 Deiverson Silveira <deiverson at solutioncms.com<mailto:deiverson at solutioncms.com>>:

ahhhh, it is test:
cmso.getRequestContext().setSiteRoot(OpenCms.getSiteManager().getDefaultSite().getSiteRoot()); cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));

But dont work, for work online/offline, remove this.

2014-11-24 16:58 GMT-02:00 Deiverson Silveira <deiverson at solutioncms.com<mailto:deiverson at solutioncms.com>>:
Hi List,

I'm building a code that need to return the list of deleted files and the uuid from a past date by parameter , however my code works only when I am logged in, if I force the login on the object with admin, works , however it would inject a security breach , this code works online logged in / offline , the problem is when this offline , the file list is reset , someone what should I do to set the permissions of my object so that even offline return my list of deleted resources?

My Code (but work logged online and offline, but I need work logout :~( :
<%@page import="org.opencms.file.CmsProject"%<mailto:%25 at page%20import=%22org.opencms.file.CmsProject%22%25>>
<%@page import="org.opencms.util.CmsUUID"%<mailto:%25 at page%20import=%22org.opencms.util.CmsUUID%22%25>>
<%@page import="java.io.File"%<mailto:%25 at page%20import=%22java.io.File%22%25>>
<%@page import="java.util.Collections"%<mailto:%25 at page%20import=%22java.util.Collections%22%25>>
<%@page import="org.apache.commons.io.comparator.LastModifiedFileComparator"%<mailto:%25 at page%20import=%22org.apache.commons.io.comparator.LastModifiedFileComparator%22%25>>
<%@page import="java.util.Date"%<mailto:%25 at page%20import=%22java.util.Date%22%25>>
<%@page import="org.opencms.jsp.CmsJspActionElement"%<mailto:%25 at page%20import=%22org.opencms.jsp.CmsJspActionElement%22%25>>
<%@page import="java.text.SimpleDateFormat"%<mailto:%25 at page%20import=%22java.text.SimpleDateFormat%22%25>>
<%@page import="org.opencms.file.CmsObject"%<mailto:%25 at page%20import=%22org.opencms.file.CmsObject%22%25>>
<%@page import="org.opencms.file.CmsResource"%<mailto:%25 at page%20import=%22org.opencms.file.CmsResource%22%25>>
<%@page import="org.opencms.workplace.list.CmsListItem"%<mailto:%25 at page%20import=%22org.opencms.workplace.list.CmsListItem%22%25>>
<%@page import="org.opencms.file.history.I_CmsHistoryResource"%<mailto:%25 at page%20import=%22org.opencms.file.history.I_CmsHistoryResource%22%25>>
<%@page import="org.opencms.main.OpenCms"%<mailto:%25 at page%20import=%22org.opencms.main.OpenCms%22%25>>
<%@page import="org.opencms.workplace.list.CmsHtmlList"%<mailto:%25 at page%20import=%22org.opencms.workplace.list.CmsHtmlList%22%25>>
<%@page import="java.util.List"%<mailto:%25 at page%20import=%22java.util.List%22%25>>
<%@page import="org.opencms.workplace.commons.CmsDeletedResourcesList"%<mailto:%25 at page%20import=%22org.opencms.workplace.commons.CmsDeletedResourcesList%22%25>>
<%@page import="java.util.Iterator"%<mailto:%25 at page%20import=%22java.util.Iterator%22%25>>
<%@page import="java.util.Set"%<mailto:%25 at page%20import=%22java.util.Set%22%25>>
<%@page import="java.util.Map"%<mailto:%25 at page%20import=%22java.util.Map%22%25>>
<%@ page import="org.opencms.workplace.*" %><%
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
CmsObject cmso = cms.getCmsObject();

cmso.getRequestContext().setSiteRoot(OpenCms.getSiteManager().getDefaultSite().getSiteRoot());
cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
Date dt = null;
String dataConvertida = null;
String dataPesquisada = "01/01/2014 00:01";
I_CmsHistoryResource res = null;
Long dataCurrentLong = null;
Date dataSearchLong = null;
List list = cmso.readDeletedResources("/", true);
String arquivo;
Iterator iter = list.iterator();
out.println("Lista: "+ list.size()+"<br>");
try {
dataPesquisada = request.getParameter("data").toLowerCase();
dataSearchLong = sdf.parse(dataPesquisada);
out.println("Data a ser pesquisada maior que: <b>" + dataPesquisada + "</b><br><br>");
while (iter.hasNext()) {
   res = (I_CmsHistoryResource)iter.next();
   //dataConvertida = String.valueOf(res.getDateLastModified());
dataCurrentLong = res.getDateLastModified();
arquivo = cmso.getSitePath((CmsResource)res);
   dt = new Date(dataCurrentLong);
dataConvertida = sdf.format(dt);
if(dataCurrentLong > dataSearchLong.getTime()){
//cmso.readResource(arquivo).getStructureId().toString()
    out.println(" <b>Nome do recurso excluido: </b>" + arquivo +" - <b>UUID:</b> " + res.getResourceId().toString() + "  <b>Data da exclusão:</b> " +  dataConvertida + "<br><br>");
}
}
} catch (Exception e) {
out.println("<br><b>O formato da data deve ser dd/mm/yyyy HH:mm </b>" +e.getMessage());
}
%>


Help, please experts!

Regards,

Deiverson


--
www.solutioncms.com<http://www.solutioncms.com>
The Brazilian
Official Provider OpenCms



--
www.solutioncms.com<http://www.solutioncms.com>
The Brazilian
Official Provider OpenCms



--
www.solutioncms.com<http://www.solutioncms.com>
The Brazilian
Official Provider OpenCms



--
www.solutioncms.com<http://www.solutioncms.com>
The Brazilian
Official Provider OpenCms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20141125/c8c9db45/attachment.htm>


More information about the opencms-dev mailing list