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

Olli Aro olli_aro at yahoo.co.uk
Mon Feb 23 08:59:01 CET 2004


Alex,

You cannot use CmsXmlControlFile to write a plain file because it does not
have a control file. Please try cms.writeFile (or was it cms.writeResource
cannot remember without reading the API) method instead.

Regards,

Olli

-----Original Message-----
From: opencms-dev-admin at opencms.org [mailto:opencms-dev-admin at opencms.org]
On Behalf Of Alex !
Sent: 23 February 2004 03:57
To: opencms-dev at opencms.org
Subject: [opencms-dev] "Wrong XML content type, ErrorCode: 20" when trying
to add plain/text file

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/templat
es/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

_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 06/02/2004
 




More information about the opencms-dev mailing list