[opencms-dev] creating a file

Christoph P. Kukulies kuku at physik.rwth-aachen.de
Fri Aug 29 15:28:14 CEST 2008


Sorry, again, it doesn't work with your suggestion.
Here is the code:

<%@ page session="false" %>
<%@ page
import="java.util.*,org.opencms.jsp.*,org.opencms.file.*,java.text.DateFormat,
java.text.SimpleDateFormat,org.opencms.main.*" %>
<%@ page import="org.opencms.lock.CmsLockType" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<%!
protected String BASE_URL="";
public static SimpleDateFormat ISO8601FORMAT = new
SimpleDateFormat("yyyy-MM-dd");
private String recurseTree(CmsObject cmso,CmsJspActionElement jsp,
String path)  {
	StringBuffer sb = new StringBuffer();
        
	try {
		ArrayList files = (ArrayList)
cmso.getFilesInFolder(path);
		Iterator i = files.iterator();
		while (i.hasNext()) {
			CmsFile f = (CmsFile) i.next();	
			String thispath = jsp.link(cmso.getSitePath(f));
			CmsProperty secret =
cmso.readPropertyObject(f,"sitemap_hidden",true);
			CmsProperty changeFreqProperty =
cmso.readPropertyObject(f,"sitemap_change_frequency",true);
			CmsProperty priorityProperty =
cmso.readPropertyObject(f,"sitemap_priority",true);
			String changeFrequency =
changeFreqProperty.getValue("weekly");
			String priority =
priorityProperty.getValue("1");
			if ((secret.getValue("false") == "false") 
				&&
(thispath.endsWith("html")||thispath.endsWith("jsp")||thispath.endsWith("pdf")||thispath.endsWith("htm")))
{		
				sb.append("<url>\n");			
				sb.append("<loc>"+BASE_URL+thispath+"</loc>\n");
				//DateFormat df =
				//DateFormat.getDateInstance();
				String niceDate =
ISO8601FORMAT.format(new Date(f.getDateLastModified()));
				sb.append("<lastmod>"+niceDate+"</lastmod>\n");
				sb.append("<changefreq>"+changeFrequency+"</changefreq>\n");
				sb.append("<priority>"+priority+"</priority>\n");
				sb.append("</url>\n");
			}
		}
		ArrayList folders = (ArrayList)
cmso.getSubFolders(path);
		Iterator j = folders.iterator();	
		while (j.hasNext()) {
			CmsFolder f = (CmsFolder) j.next();
			sb.append( recurseTree(cmso,jsp,
cmso.getSitePath(f) ) );
		}
	}
	catch (CmsException cmsException) {
		sb.append("A CMS exception occurred:
"+cmsException.toString());
	
	}
	return sb.toString();

}
%>
<%

 CmsJspActionElement cms = new
org.opencms.jsp.CmsJspActionElement(pageContext, request, response);
 CmsObject cmso = cms.getCmsObject();
 String filename="sitemap.xml";
 String s_filecontent;
 cmso.getRequestContext().setCurrentProject(cmso.readProject("Offline"));
if (cmso.existsResource(filename)) {
       cmso.lockResource(filename,CmsLock.TEMPORARY);
        cmso.deleteResource(filename,
CmsResource.DELETE_PRESERVE_SIBLINGS);
        if (cmso.existsResource(filename)) {
                cmso.unlockResource(filename);
                cmso.publishResource(filename);
        }
}


String url = cms.info("opencms.url");
int lastSlash = url.indexOf("/",8);
BASE_URL = url.substring(0,lastSlash);
s_filecontent=recurseTree(cmso,cms, "/");
cmso.createResource(
        filename,
        OpenCms.getResourceManager().getResourceType("plain").getTypeId(),
        s_filecontent.getBytes(),
        new ArrayList()
);
cmso.unlockResource(filename);
cmso.publishResource(filename);

%> 
</urlset>

On Fri, Aug 29, 2008 at 12:49:30PM +0200, Dirk Hinderks wrote:
> On Fri, Aug 29, 2008 at 09:32:18AM +0200, Christoph P. Kukulies wrote:
> > Thanks. I just thought that the package imports in the header of the
> > jsp,
> > 
> > [...]
> > <%@ page
> > import="java.util.*,org.opencms.jsp.*,org.opencms.file.*,java.text.DateFormat,
> > java.text.SimpleDateFormat,org.opencms.main.*" %>
> > [...]
> > 
> > were for just this purpose.
> 
> You're mostly right.  But you import types/classes, not packages.  If
> I've understood you right, you've used something equivalent to:
> 
>   <%@ page import="org.opencms.lock" %>
> 
> In order to use »org.opencms.lock.CmsLockType.TEMPORARY« without
> qualification as »CmsLockType.TEMPORARY«, add the following to your JSP
> (note that the right class name is »CmsLockType« instead of »CmsLock«):
> 
>   <%@ page import="org.opencms.lock.CmsLockType" %>
> 
> The servlet container (i.e. Tomcat) translates this to the import
> declaration »import org.opencms.lock.CmsLockType;« before compilation.
> 
> -- 
> Dirk Hinderks, Cologne, Germany
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list