[opencms-dev] "Wrong XML content type, ErrorCode: 20" when trying to add plain/text file

Alex ! kingofkingston at hotmail.com
Mon Feb 23 04:58:01 CET 2004


Hi,

I am trying to add a plain type file via jsp, (code below), containing xml, 
but get the following error code + message:

CMSErrorCode: 20
CMSError: Wrong XML content type

I cannot find any documentation for error codes anywhere, nor can I figure 
out what the problem is, i've tried a few things but nothing is working.

The file is added to the vfs, but the exception is still thrown (the xml 
content is added correctly too).

I'm sure it is a simple mistake.

Your help is much appreciated.

Alex.



(note: seems to make no difference if setMasterTemplate() is called or not, 
therefore I have left it commented since I assume text/plain type files dont 
have a master template?)

<%@ page import = "java.util.*, com.opencms.flex.jsp.*, com.opencms.file.*, 
com.opencms.template.*, com.opencms.core.CmsException" %>
<%

	CmsJspActionElement cmsJspAE = new CmsJspActionElement(pageContext, 
request, response);
	CmsObject cmsObj = cmsJspAE.getCmsObject();

	String contents = new String();
	contents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
	contents += "<advert>\n";
	contents += " <element1>\n";
	contents += "  content for element1\n";
	contents += " </element1>\n";
	contents += " <element2>\n";
	contents += "  content for element2\n";
	contents += " </element2>\n";
	contents += "</advert>\n";

	//byte[] resContents = new byte[0];
	byte[] resContents = contents.getBytes();

	Hashtable resProperties = new Hashtable();
	resProperties.put("Title", "This is the title");
/*	resProperties.put("Description", "This is the description");
	resProperties.put("Keywords", "keyword1, keyword2, keyword3");
	resProperties.put("NavText", "test add html page");
	resProperties.put("NavPos", "10");
   resProperties.put("content-encoding", "ISO-8859-1");
*/
	try
	{
		//CmsResource newfile = cmsObj.createResource("/test/", "test_page.html", 
"page", resProperties, resContents);
		CmsResource newfile = cmsObj.createResource("/test/", "test_plain.xml", 
"plain", resProperties, resContents);
		CmsXmlControlFile controlFile = new CmsXmlControlFile(cmsObj, 
(CmsFile)newfile);
		//controlFile.setMasterTemplate("/system/modules/com.opencms.default/templates/empty");
		controlFile.write();
	}

	catch(CmsException e)
	{
		out.println("<p>Exception whilst trying to create a new CMS resource!</p>"
						+ "<p>CMSErrorCode: " + e.getType() + "</p>"
						+ "<p>CMSError: " + e.C_EXTXT[e.getType()] + "</p>" );
	}

%>

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! 
http://www.msn.co.uk/messenger




More information about the opencms-dev mailing list