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 高田 督人 <ma...@exa-corp.co.jp> on 2004/02/04 07:37:33 UTC
How can I marshall "portlet.xml"?
Hi,
I am trying to edit the "portlet.xml" by creating an instance of
"PortletDefinitionImpl" and adding it to the
"PortletApplicationDefinitionImpl" object,
and marshalling the PortletApplicationDefinitionImpl object.
And I have encountered some problems.
When I marshall the "portlet.xml" after unmarshalling the
"portlet.xml"without doing anything to the object,
the Marshallized "portlet.xml" is not same as the original "portlet.xml".
ie: <portlet-info> is lost...
What should I do to not lose <portlet-info>?
masato takada
masato-takada-v@exa-corp.co.jp
----------- original portlet.xml ---------------
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description>HelloWorld Test</description>
<portlet-name>HelloWorldSamplePortlet</portlet-name>
<display-name>Hello World Sample Portlet</display-name>
<portlet-class>portlet.HelloWorldPortlet</portlet-class>
<init-param>
<name>servletName</name>
<value>/HelloWorld</value>
</init-param>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>jp</supported-locale>
<portlet-info>
<title>hello world</title>
<short-title>hello</short-title>
<keywords>hello</keywords>
</portlet-info>
<portlet-preferences>
<preference>
<name>servletName</name>
<value>/HelloWorld</value>
<read-only>false</read-only>
</preference>
<preferences-validator>org.apache.pluto.core.impl.PreferencesValidatorImpl</
preferences-validator>
</portlet-preferences>
</portlet>
</portlet-app>
---------- marshallized "portlet.xml" ------
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0"
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<portlet id="">
<description>HelloWorld Test</description>
<portlet-name>HelloWorldSamplePortlet</portlet-name>
<display-name>Hello World Sample Portlet</display-name>
<portlet-class>portlet.HelloWorldPortlet</portlet-class>
<init-param>
<name>servletName</name>
<value>/HelloWorld</value>
</init-param>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>jp</supported-locale>
<portlet-preferences xsi:type="preference-impl">
<name>servletName</name>
<value>/HelloWorld</value>
<read-only>false</read-only>
</portlet-preferences>
</portlet>
</portlet-app>
----------- test program --------------------------
org.w3c.dom.Document portletDocument =
XmlParser.parsePortletXml(new FileInputStream(portletXml));
Unmarshaller unmarshaller = new Unmarshaller(mappingPortletXml);
PortletApplicationDefinitionImpl portletApp =
(PortletApplicationDefinitionImpl) unmarshaller.unmarshal(
portletDocument);
if (portletXml != null) {
OutputFormat of = new OutputFormat();
of.setIndenting(true);
of.setIndent(4); // 2-space indention
of.setLineWidth(16384);
// As large as needed to prevent linebreaks in text nodes
FileWriter writer = new FileWriter(portletXml);
XMLSerializer serializer = new XMLSerializer(writer, of);
try {
Marshaller marshaller =
new Marshaller(serializer.asDocumentHandler());
marshaller.setSchemaLocation("http://java.sun.com/xml/ns/portlet/portlet-app
_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd");
marshaller.setMapping(mappingPortletXml);
marshaller.marshal(portletApp);
} catch (Exception e) {
writer.close();
e.printStackTrace(System.out);
throw new Exception();
}
}
------------------------------------------------------------------