You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-user@portals.apache.org by Zsofi <zs...@rndsoft.hu> on 2004/03/16 11:44:56 UTC

contenttype

Hello!

I m not really understand the getter and setter method of the content type in the RenderResponseImpl class. Because when I set a contenttype, and I want to get it may give me a different one. I hope that someone can explain me why it is good for me, and what the point is.

public String getContentType() {
 if (!isContentTypeSet) {
  return null;
 }
 return InformationProviderAccess.getDynamicProvider(getHttpServletRequest()).getResponseContentType();
}

public void setContentType(String type) {
 String mimeType = stripCharacterEncoding(type);
 if (!isValidContentType(mimeType)) {
  throw new IllegalArgumentException(mimeType);
 }
 this._getHttpServletResponse().setContentType(mimeType);
 isContentTypeSet = true;
}


In the portlet Api:
setContentType:
Sets the MIME type for the render response. The portlet must set the content type before calling getWriter() or getPortletOutputStream(). 
Calling setContentType after getWriter or getOutputStream does not change the content type.

getContentType:
public java.lang.String getContentType()Returns the MIME type that can be used to contribute markup to the render response. 
If no content type was set previously using the setContentType(java.lang.String) method this method retuns null.

The specification:

A portlet must set the content type of the response using the setContentType method of
the RenderResponse interface. The setContentType method must throw an
IllegalArgumentException if the content type set does not match (including wildcard
matching) any of the content types returned by the getResponseContentType method of 
the PortleRequest objectl. The portlet container should ignore any character
encoding specified as part of the content type.
If the getWriter or getPortletOutputStream methods are called before the
setContentType method, they must throw an IllegalStateException.
The setContentType method must be called before the getWriter or
getPortletOutputStream methods. If called after, it should be ignored.
If the portlet has set a content type, the getContentType method must return it.
Otherwise, the getContentType method must return null.

Do they mean the same?


Thanks: zsofi