KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webapps > portal > components > PortalManagerImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.webapps.portal.components;
17
18 import java.io.IOException JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.avalon.excalibur.pool.Recyclable;
27 import org.apache.avalon.framework.activity.Disposable;
28 import org.apache.avalon.framework.component.Component;
29 import org.apache.avalon.framework.component.ComponentException;
30 import org.apache.avalon.framework.component.ComponentManager;
31 import org.apache.avalon.framework.component.Composable;
32 import org.apache.avalon.framework.component.Recomposable;
33 import org.apache.avalon.framework.configuration.Configuration;
34 import org.apache.avalon.framework.configuration.ConfigurationException;
35 import org.apache.avalon.framework.context.Context;
36 import org.apache.avalon.framework.context.ContextException;
37 import org.apache.avalon.framework.context.Contextualizable;
38 import org.apache.avalon.framework.logger.AbstractLogEnabled;
39 import org.apache.cocoon.ProcessingException;
40 import org.apache.cocoon.components.ContextHelper;
41 import org.apache.cocoon.components.sax.XMLDeserializer;
42 import org.apache.cocoon.components.source.SourceUtil;
43 import org.apache.cocoon.environment.CocoonRunnable;
44 import org.apache.cocoon.environment.Redirector;
45 import org.apache.cocoon.environment.Request;
46 import org.apache.cocoon.environment.Response;
47 import org.apache.cocoon.environment.Session;
48 import org.apache.cocoon.webapps.authentication.AuthenticationManager;
49 import org.apache.cocoon.webapps.authentication.user.RequestState;
50 import org.apache.cocoon.webapps.portal.PortalConstants;
51 import org.apache.cocoon.webapps.session.ContextManager;
52 import org.apache.cocoon.webapps.session.MediaManager;
53 import org.apache.cocoon.webapps.session.SessionManager;
54 import org.apache.cocoon.webapps.session.TransactionManager;
55 import org.apache.cocoon.webapps.session.context.SessionContext;
56 import org.apache.cocoon.webapps.session.xml.XMLUtil;
57 import org.apache.cocoon.xml.IncludeXMLConsumer;
58 import org.apache.cocoon.xml.XMLConsumer;
59 import org.apache.cocoon.xml.XMLUtils;
60 import org.apache.cocoon.xml.dom.DOMUtil;
61 import org.apache.excalibur.source.Source;
62 import org.apache.excalibur.source.SourceException;
63 import org.apache.excalibur.source.SourceParameters;
64 import org.apache.excalibur.source.SourceResolver;
65 import org.apache.excalibur.store.Store;
66 import org.apache.excalibur.xml.xpath.XPathProcessor;
67 import org.w3c.dom.Document JavaDoc;
68 import org.w3c.dom.DocumentFragment JavaDoc;
69 import org.w3c.dom.Element JavaDoc;
70 import org.w3c.dom.NamedNodeMap JavaDoc;
71 import org.w3c.dom.Node JavaDoc;
72 import org.w3c.dom.NodeList JavaDoc;
73 import org.w3c.dom.Text JavaDoc;
74 import org.xml.sax.Attributes JavaDoc;
75 import org.xml.sax.SAXException JavaDoc;
76 import org.xml.sax.helpers.AttributesImpl JavaDoc;
77
78 /**
79  * This is the basis portal component
80  *
81  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
82  * @version CVS $Id: PortalManagerImpl.java 189932 2005-06-10 09:33:14Z sylvain $
83 */

84 public final class PortalManagerImpl
85 extends AbstractLogEnabled
86 implements Disposable, Composable, Recomposable, Recyclable, Contextualizable, Component, PortalManager {
87
88     /** The cache (store) for the profiles */
89     private Store profileStore;
90
91     /** The authenticationManager */
92     private AuthenticationManager authenticationManager;
93
94     /** The media manager */
95     private MediaManager mediaManager;
96
97     /** The XPath Processor */
98     private XPathProcessor xpathProcessor;
99
100     /** The session manager */
101     private SessionManager sessionManager;
102
103     /** The Context manager */
104     private ContextManager contextManager;
105
106     /** The transaction manager */
107     private TransactionManager transactionManager;
108
109     /** The component manager */
110     protected ComponentManager manager;
111
112     /** The current source resolver */
113     protected SourceResolver resolver;
114
115     /** The context */
116     protected Context componentContext;
117
118     /** Are we already setup for this request? */
119     protected boolean initialized = false;
120
121     /* (non-Javadoc)
122      * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
123      */

124     public void recycle() {
125         if (this.manager != null) {
126             this.manager.release(this.profileStore);
127             this.manager.release( (Component)this.authenticationManager);
128             this.manager.release( (Component)this.mediaManager);
129             this.manager.release( (Component)this.sessionManager);
130             this.manager.release( (Component)this.contextManager);
131             this.manager.release( (Component)this.transactionManager);
132             this.profileStore = null;
133             this.authenticationManager = null;
134             this.mediaManager = null;
135             this.transactionManager = null;
136             this.sessionManager = null;
137             this.contextManager = null;
138         }
139         this.initialized = false;
140     }
141
142     /**
143      * Get the current authentication state
144      */

145     protected RequestState getRequestState() {
146         AuthenticationManager authManager = null;
147         try {
148             authManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE);
149             return authManager.getState();
150         } catch (ComponentException ce) {
151             // ignore this here
152
return null;
153         } finally {
154             this.manager.release( (Component)authManager );
155         }
156     }
157
158     /* (non-Javadoc)
159      * @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
160      */

161     public void compose(ComponentManager manager)
162     throws ComponentException {
163         this.manager = manager;
164         this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
165         this.xpathProcessor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
166     }
167
168     /* (non-Javadoc)
169      * @see org.apache.avalon.framework.component.Recomposable#recompose(org.apache.avalon.framework.component.ComponentManager)
170      */

171     public void recompose(ComponentManager manager) throws ComponentException {
172         this.manager = manager;
173     }
174
175     /* (non-Javadoc)
176      * @see org.apache.avalon.framework.activity.Disposable#dispose()
177      */

178     public void dispose() {
179         if ( this.manager != null ) {
180             this.manager.release( (Component)this.xpathProcessor );
181             this.xpathProcessor = null;
182             this.manager.release( this.resolver );
183             this.resolver = null;
184         }
185     }
186
187     /* (non-Javadoc)
188      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
189      */

190     public void contextualize(Context context) throws ContextException {
191         this.componentContext = context;
192     }
193
194     /**
195      * Get the profile store
196      */

197     protected Store getProfileStore()
198     throws ProcessingException {
199         if (this.profileStore == null) {
200             try {
201                 this.profileStore = (Store)this.manager.lookup(Store.ROLE);
202             } catch (ComponentException ce) {
203                 throw new ProcessingException("Error during lookup of store component.", ce);
204             }
205         }
206         return this.profileStore;
207     }
208
209     /**
210      * Get the authentication manager
211      */

212     protected AuthenticationManager getAuthenticationManager()
213     throws ProcessingException {
214         if (this.authenticationManager == null) {
215             try {
216                 this.authenticationManager = (AuthenticationManager)this.manager.lookup(AuthenticationManager.ROLE);
217             } catch (ComponentException ce) {
218                 throw new ProcessingException("Error during lookup of AuthenticationManager.", ce);
219             }
220         }
221         return this.authenticationManager;
222     }
223
224     /**
225      * Get the media manager
226      */

227     protected MediaManager getMediaManager()
228     throws ProcessingException {
229         if (this.mediaManager == null) {
230             try {
231                 this.mediaManager = (MediaManager)this.manager.lookup(MediaManager.ROLE);
232             } catch (ComponentException ce) {
233                 throw new ProcessingException("Error during lookup of MediaManager.", ce);
234             }
235         }
236         return this.mediaManager;
237     }
238
239     /**
240      * Setup this component
241      */

242     protected void setup()
243     throws ProcessingException {
244         if ( !this.initialized ) {
245
246             final Request request = ContextHelper.getRequest(this.componentContext);
247
248             if ( request.getAttribute(PortalManager.ROLE) == null ) {
249
250                 request.setAttribute(PortalManager.ROLE, Boolean.TRUE);
251
252                 // Get and ignore the configuration
253
this.getConfiguration();
254
255                 try {
256                     this.changeProfile();
257                 } catch (SAXException JavaDoc se) {
258                     throw new ProcessingException(se);
259                 } catch (IOException JavaDoc ioe) {
260                     throw new ProcessingException(ioe);
261                 }
262             }
263
264             this.initialized = true;
265         }
266     }
267
268     /* (non-Javadoc)
269      * @see org.apache.cocoon.webapps.portal.components.PortalManager#configurationTest()
270      */

271     public void configurationTest()
272     throws ProcessingException, IOException JavaDoc, SAXException JavaDoc {
273         // no sync required
274
if (this.getLogger().isDebugEnabled()) {
275             this.getLogger().debug("BEGIN configurationTest");
276         }
277
278         this.setup();
279
280         // Ignore result
281
this.getConfiguration();
282
283         if (this.getLogger().isDebugEnabled()) {
284             this.getLogger().debug("END configurationTest");
285         }
286     }
287
288     /* (non-Javadoc)
289      * @see org.apache.cocoon.webapps.portal.components.PortalManager#getContext(boolean)
290      */

291     public SessionContext getContext(boolean create)
292     throws ProcessingException, IOException JavaDoc, SAXException JavaDoc {
293         // synchronized
294
if (this.getLogger().isDebugEnabled()) {
295             this.getLogger().debug("BEGIN getContext create="+create);
296         }
297         this.setup();
298         SessionContext context = null;
299
300         final Session session = this.getSessionManager().getSession(false);
301         if (session != null) {
302             synchronized(session) {
303                 String JavaDoc appName = this.getRequestState().getApplicationName();
304                 String JavaDoc attrName = PortalConstants.PRIVATE_SESSION_CONTEXT_NAME;
305                 if (appName != null) {
306                     attrName = attrName + ':' + appName;
307                 }
308                 context = this.getContextManager().getContext(attrName);
309                 if (context == null && create) {
310
311                     // create new context
312

313                     context = this.getAuthenticationManager().createApplicationContext(attrName, null, null);
314
315                 }
316             } // end synchronized
317
}
318
319         if (this.getLogger().isDebugEnabled()) {
320             this.getLogger().debug("END getContext context="+context);
321         }
322         return context;
323     }
324
325     /* (non-Javadoc)
326      * @see org.apache.cocoon.webapps.portal.components.PortalManager#streamConfiguration(org.apache.cocoon.xml.XMLConsumer, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
327      */

328     public void streamConfiguration(XMLConsumer consumer,
329                                     String JavaDoc requestURI,
330                                     String JavaDoc profileID,
331                                     String JavaDoc media,
332                                     String JavaDoc contextID)
333     throws IOException JavaDoc, SAXException JavaDoc, ProcessingException {
334         // synchronized not req.
335
this.setup();
336         Response response = ContextHelper.getResponse(this.componentContext);
337
338         XMLUtils.startElement(consumer, PortalConstants.ELEMENT_CONFIGURATION);
339
340         // set the portal-page uri:
341
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(requestURI);
342         buffer.append((requestURI.indexOf('?') == -1 ? '?' : '&'))
343             .append(PortalManagerImpl.REQ_PARAMETER_PROFILE)
344             .append('=')
345             .append(profileID);
346         String JavaDoc uri = response.encodeURL(buffer.toString());
347         XMLUtils.startElement(consumer, "uri");
348         XMLUtils.data(consumer, uri);
349         XMLUtils.endElement(consumer, "uri");
350
351         Map JavaDoc config = this.getConfiguration();
352         String JavaDoc portalURI = response.encodeURL((String JavaDoc)config.get(PortalConstants.CONF_PORTAL_URI));
353
354         XMLUtils.startElement(consumer, "portal");
355         XMLUtils.data(consumer, portalURI);
356         XMLUtils.endElement(consumer, "portal");
357
358         XMLUtils.startElement(consumer, PortalConstants.ELEMENT_PROFILE);
359         XMLUtils.data(consumer, profileID);
360         XMLUtils.endElement(consumer, PortalConstants.ELEMENT_PROFILE);
361
362         if (media != null) {
363             XMLUtils.startElement(consumer, "media");
364             XMLUtils.data(consumer, media);
365             XMLUtils.endElement(consumer, "media");
366         }
367
368         if (contextID != null) {
369             XMLUtils.startElement(consumer, "context");
370             XMLUtils.data(consumer, contextID);
371             XMLUtils.endElement(consumer, "context");
372         }
373
374         XMLUtils.endElement(consumer, PortalConstants.ELEMENT_CONFIGURATION);
375     }
376
377     /* (non-Javadoc)
378      * @see org.apache.cocoon.webapps.portal.components.PortalManager#showAdminConf(org.apache.cocoon.xml.XMLConsumer)
379      */

380     public void showAdminConf(XMLConsumer consumer)
381     throws SAXException JavaDoc, ProcessingException, IOException JavaDoc {
382         // synchronized
383
if (this.getLogger().isDebugEnabled()) {
384             this.getLogger().debug("BEGIN showAdminConf consumer=" + consumer);
385         }
386         this.setup();
387         Request request = ContextHelper.getRequest(this.componentContext);
388         try {
389             String JavaDoc profileID = "global";
390             String JavaDoc copletID = request.getParameter(PortalManagerImpl.REQ_PARAMETER_COPLET);
391
392             SessionContext context = this.getContext(true);
393
394             Map JavaDoc configuration = this.getConfiguration();
395
396             DocumentFragment JavaDoc copletsFragment = (DocumentFragment JavaDoc)context.getAttribute(ATTRIBUTE_ADMIN_COPLETS);
397             String JavaDoc command = request.getParameter(PortalManagerImpl.REQ_PARAMETER_ADMIN_COPLETS);
398             if (command != null && copletsFragment != null) {
399                 try {
400                     this.getTransactionManager().startWritingTransaction(context);
401                     // save : save coplets base
402
// new : new coplet
403
// delete : use id to delete coplet
404
// change : change the coplet
405
// cache : cleans the cache
406
if (command.equals("delete") && copletID != null) {
407                         Node JavaDoc coplet = DOMUtil.getSingleNode(copletsFragment, "coplets-profile/coplets/coplet[@id='"+copletID+"']", this.xpathProcessor);
408                         if (coplet != null) {
409                             coplet.getParentNode().removeChild(coplet);
410                         }
411                     } else if (command.equals("change") && copletID != null) {
412                         Node JavaDoc coplet = DOMUtil.getSingleNode(copletsFragment, "coplets-profile/coplets/coplet[@id='"+copletID+"']", this.xpathProcessor);
413                         if (coplet != null) {
414                             // now get the information
415
String JavaDoc value;
416
417                             value = request.getParameter("portaladmin_title");
418                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.getSingleNode(coplet, "title", this.xpathProcessor), value);
419
420                             value = request.getParameter("portaladmin_mand");
421                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.getSingleNode(coplet, "configuration/mandatory", this.xpathProcessor), value);
422
423                             value = request.getParameter("portaladmin_sizable");
424                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.getSingleNode(coplet, "configuration/sizable", this.xpathProcessor), value);
425
426                             value = request.getParameter("portaladmin_active");
427                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.getSingleNode(coplet, "configuration/active", this.xpathProcessor), value);
428
429                             value = request.getParameter("portaladmin_handsize");
430                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/handlesSizable", this.xpathProcessor), value);
431
432                             value = request.getParameter("portaladmin_handpar");
433                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/handlesParameters", this.xpathProcessor), value);
434
435                             value = request.getParameter("portaladmin_timeout");
436                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/timeout", this.xpathProcessor), value);
437
438                             value = request.getParameter("portaladmin_customizable");
439                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/customizable", this.xpathProcessor), value);
440
441                             value = request.getParameter("portaladmin_persistent");
442                             if (value != null) DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/persistent", this.xpathProcessor), value);
443
444                             String JavaDoc resource = request.getParameter("portaladmin_resource");
445                             if (resource != null) {
446                                 Element JavaDoc resourceNode = (Element JavaDoc)DOMUtil.getSingleNode(coplet, "resource", this.xpathProcessor);
447                                 resourceNode.getParentNode().removeChild(resourceNode);
448                                 resourceNode = coplet.getOwnerDocument().createElementNS(null, "resource");
449                                 resourceNode.setAttributeNS(null, "uri", resource);
450                                 coplet.appendChild(resourceNode);
451                             }
452                             resource = request.getParameter("portaladmin_cust");
453                             boolean isCustom = DOMUtil.getValueAsBooleanOf(coplet, "configuration/customizable", false, this.xpathProcessor);
454                             if (resource != null && isCustom ) {
455                                 Element JavaDoc resourceNode = (Element JavaDoc)DOMUtil.getSingleNode(coplet, "customization", this.xpathProcessor);
456                                 if (resourceNode != null) resourceNode.getParentNode().removeChild(resourceNode);
457                                 resourceNode = coplet.getOwnerDocument().createElementNS(null, "customization");
458                                 resourceNode.setAttributeNS(null, "uri", resource);
459                                 coplet.appendChild(resourceNode);
460                             }
461                             if (!isCustom) {
462                                 Element JavaDoc resourceNode = (Element JavaDoc)DOMUtil.getSingleNode(coplet, "customization", this.xpathProcessor);
463                                 if (resourceNode != null) resourceNode.getParentNode().removeChild(resourceNode);
464                             }
465
466                             // transformations
467
value = request.getParameter("portaladmin_newxsl");
468                             if (value != null) {
469                                 Element JavaDoc tNode = (Element JavaDoc)DOMUtil.selectSingleNode(coplet, "transformation", this.xpathProcessor);
470                                 Element JavaDoc sNode = tNode.getOwnerDocument().createElementNS(null, "stylesheet");
471                                 tNode.appendChild(sNode);
472                                 sNode.appendChild(sNode.getOwnerDocument().createTextNode(value));
473                             }
474
475                             // now get all transformation stylesheets, mark
476
// all stylesheets which should be deleted with
477
// an attribute delete
478
Enumeration JavaDoc keys = request.getParameterNames();
479                             Element JavaDoc sNode;
480                             String JavaDoc key;
481                             while (keys.hasMoreElements() ) {
482                                 key = (String JavaDoc)keys.nextElement();
483                                 if (key.startsWith("portaladmin_xsl_") ) {
484                                     value = key.substring(key.lastIndexOf('_')+ 1);
485                                     sNode = (Element JavaDoc)DOMUtil.getSingleNode(coplet, "transformation/stylesheet[position()="+value+"]", this.xpathProcessor);
486                                     if (sNode != null) {
487                                         String JavaDoc xslName = request.getParameter(key);
488                                         if (xslName.equals("true") ) xslName = "**STYLESHEET**";
489                                         DOMUtil.setValueOfNode(sNode, xslName);
490                                     }
491                                 } else if (key.startsWith("portaladmin_delxsl_") ) {
492                                     value = key.substring(key.lastIndexOf('_')+ 1);
493                                     sNode = (Element JavaDoc)DOMUtil.getSingleNode(coplet, "transformation/stylesheet[position()="+value+"]", this.xpathProcessor);
494                                     if (sNode != null) {
495                                         sNode.setAttributeNS(null, "delete", "true");
496                                     }
497                                 }
498                             }
499                             NodeList JavaDoc delete = DOMUtil.selectNodeList(coplet, "transformation/stylesheet[@delete]", this.xpathProcessor);
500                             if (delete != null) {
501                                 for(int i=0; i < delete.getLength(); i++) {
502                                     delete.item(i).getParentNode().removeChild(delete.item(i));
503                                 }
504                             }
505                         }
506                     } else if (command.equals("new") ) {
507                         // first we have to invent a new coplet id!
508
int index = 0;
509                         boolean found = false;
510                         Element JavaDoc coplet;
511                         Element JavaDoc subNode;
512
513                         while (!found) {
514                             copletID = "S"+index;
515                             coplet = (Element JavaDoc)DOMUtil.getSingleNode(copletsFragment, "coplets-profile/coplets/coplet[@id='"+copletID+"']", this.xpathProcessor);
516                             if (coplet == null) {
517                                 found = true;
518                             } else {
519                                 index++;
520                             }
521                         }
522                         coplet = copletsFragment.getOwnerDocument().createElementNS(null, "coplet");
523                         coplet.setAttributeNS(null, "id", copletID);
524                         subNode = coplet.getOwnerDocument().createElementNS(null, "resource");
525                         coplet.appendChild(subNode);
526                         subNode.setAttributeNS(null, "uri", "uri_in_sitemap");
527
528                         String JavaDoc title = request.getParameter("portaladmin_title");
529                         if (title == null || title.trim().length() == 0) title = "**NEW COPLET**";
530                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/mandatory", this.xpathProcessor), "false");
531                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/sizable", this.xpathProcessor), "true");
532                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/active", this.xpathProcessor), "false");
533                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/handlesParameters", this.xpathProcessor), "true");
534                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "configuration/handlesSizable", this.xpathProcessor), "false");
535                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "title", this.xpathProcessor), title);
536                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "status/visible", this.xpathProcessor), "true");
537                         DOMUtil.setValueOfNode(DOMUtil.selectSingleNode(coplet, "status/size", this.xpathProcessor), "max");
538                         DOMUtil.getSingleNode(copletsFragment, "coplets-profile/coplets", this.xpathProcessor).appendChild(coplet);
539                     } else if (command.equals("save") ) {
540
541                         SourceParameters pars = new SourceParameters();
542                         pars.setSingleParameterValue("profile", "coplet-base");
543                         RequestState state = this.getRequestState();
544                         pars.setSingleParameterValue("application", state.getApplicationName());
545                         pars.setSingleParameterValue("handler", state.getHandlerName());
546
547                         String JavaDoc saveResource = (String JavaDoc)configuration.get(PortalConstants.CONF_COPLETBASE_SAVE_RESOURCE);
548
549                         if (saveResource == null) {
550                             throw new ProcessingException("portal: No save resource defined for type coplet-base.");
551                         } else {
552
553                             SourceUtil.writeDOM(saveResource,
554                                                 null,
555                                                 pars,
556                                                 copletsFragment,
557                                                 this.resolver,
558                                                 "xml");
559
560                             // now the hardest part, clean up the whole cache
561
this.cleanUpCache(null, null, configuration);
562                         }
563                     }
564                 } finally {
565                     this.getTransactionManager().stopWritingTransaction(context);
566                 }
567             }
568
569             // general commands
570
if (command != null && command.equals("cleancache") ) {
571                 this.cleanUpCache(null, null, configuration);
572             }
573
574             String JavaDoc state = request.getParameter(PortalManagerImpl.REQ_PARAMETER_STATE);
575             if (state == null) {
576                 state = (String JavaDoc)context.getAttribute(ATTRIBUTE_ADMIN_STATE, PortalConstants.STATE_MAIN);
577             }
578
579             // now start producing xml:
580
consumer.startElement("", PortalConstants.ELEMENT_ADMINCONF, PortalConstants.ELEMENT_ADMINCONF, XMLUtils.EMPTY_ATTRIBUTES);
581
582             context.setAttribute(ATTRIBUTE_ADMIN_STATE, state);
583             consumer.startElement("", PortalConstants.ELEMENT_STATE, PortalConstants.ELEMENT_STATE, XMLUtils.EMPTY_ATTRIBUTES);
584             consumer.characters(state.toCharArray(), 0, state.length());
585             consumer.endElement("", PortalConstants.ELEMENT_STATE, PortalConstants.ELEMENT_STATE);
586
587             if (state.equals(PortalConstants.STATE_MAIN) ) {
588
589                 Document JavaDoc rolesDF = this.getRoles();
590                 Node JavaDoc roles = null;
591                 if (rolesDF != null) roles = DOMUtil.getSingleNode(rolesDF, "roles", this.xpathProcessor);
592                 IncludeXMLConsumer.includeNode(roles, consumer, consumer);
593             }
594
595             if (state.equals(PortalConstants.STATE_MAIN_ROLE) ) {
596
597                 Document JavaDoc rolesDF = this.getRoles();
598                 Node JavaDoc roles = null;
599                 if (rolesDF != null) roles = DOMUtil.getSingleNode(rolesDF, "roles", this.xpathProcessor);
600                 IncludeXMLConsumer.includeNode(roles, consumer, consumer);
601
602