001: /**
002: * $Id: DPHelper.java,v 1.25 2007/01/26 03:48:20 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.desktop.admin.mbeans.tasks;
014:
015: import java.util.Set;
016: import java.util.Map;
017: import java.util.HashMap;
018: import java.util.HashSet;
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.Iterator;
022: import java.util.Properties;
023: import java.util.StringTokenizer;
024:
025: import java.util.logging.Level;
026: import java.util.logging.Logger;
027:
028: import java.io.FileInputStream;
029: import java.io.File;
030: import java.io.IOException;
031: import java.io.FileNotFoundException;
032:
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Comment;
036: import org.w3c.dom.Text;
037: import org.w3c.dom.Node;
038: import org.w3c.dom.NodeList;
039: import org.w3c.dom.NamedNodeMap;
040: import org.w3c.dom.Attr;
041:
042: import javax.management.MBeanServer;
043: import javax.management.ObjectName;
044:
045: import com.iplanet.sso.SSOToken;
046:
047: import com.sun.portal.desktop.encode.Encoder;
048:
049: import com.sun.portal.desktop.dp.xml.XMLDPFactory;
050: import com.sun.portal.desktop.dp.xml.XMLDPRoot;
051: import com.sun.portal.desktop.dp.xml.XMLDPTags;
052:
053: import com.sun.portal.desktop.dp.DPRoot;
054: import com.sun.portal.desktop.dp.DPError;
055:
056: import com.sun.portal.desktop.context.AdminDPContext;
057: import com.sun.portal.desktop.context.DPContext;
058: import com.sun.portal.desktop.context.DSAMEConstants;
059: import com.sun.portal.desktop.context.DSAMEMultiPortalConstants;
060:
061: import com.sun.portal.admin.server.PASModule;
062:
063: import com.sun.portal.admin.common.BackupVersion;
064: import com.sun.portal.admin.common.PSConfigConstants;
065: import com.sun.portal.admin.common.Tags;
066: import com.sun.portal.admin.common.AttrOptionConstants;
067:
068: import com.sun.portal.admin.common.context.PSConfigContext;
069:
070: import com.sun.portal.admin.common.util.AdminUtil;
071:
072: import com.sun.portal.util.Platform;
073:
074: import com.sun.portal.util.ResourceLoader;
075:
076: /**
077: * This class gets hold of the AdminDPContext object, and provide
078: * methods to allow callers to get the dp document(s) and/or other
079: * objects from the backend store.
080: *
081: * The caller needs to provide a SSOToken in the constructor. This
082: * class is called by PortalMBean where the amadmin user and password
083: * is not directly available but a SSOToken is.
084: */
085: public class DPHelper {
086:
087: // File separator.
088: public static final String FS = Platform.fs;
089: public static String DESKTOP = "desktop";
090: public static String SUBSCRIPTIONS = "subscriptions";
091:
092: // local member variables
093: private AdminDPContext m_ADPContext;
094: private XMLDPFactory m_Factory;
095: private String m_Portal;
096: private DSAMEMultiPortalConstants m_Conts;
097: private PSConfigContext m_PCC = null;
098: private static Logger m_Logger = null;
099:
100: public static void setLogger(Logger logger) {
101: m_Logger = logger;
102: }
103:
104: /*
105: * Constructor for the class. Client should use the static
106: * getDPHelper() method to get hold of the DPHelper object.
107: *
108: * @param ssoToken The <code>SSOToken</code> to allow execute on
109: * the underling Identity API.
110: * @param prop The desktopconfig properties file name, which is
111: * required to get the <code>DSAMEAdminDPContext</code> object.
112: * @param portal the portal id.
113: */
114: private DPHelper(PSConfigContext pcc, SSOToken ssoToken,
115: String portal) throws DesktopDataException {
116: m_Portal = portal;
117: m_ADPContext = (AdminDPContext) getAdminDPContext(m_Portal);
118: m_ADPContext.init(ssoToken, null, portal);
119: m_Factory = XMLDPFactory.getInstance();
120: m_PCC = pcc;
121:
122: }
123:
124: /**
125: * Static method to get hold of the Java class.
126: *
127: * @param ssoToken The <code>SSOToken</code> to allow execute on
128: * the underling Identity API.
129: * @param prop The desktopconfig properties file name, which is
130: * required to get the <code>DSAMEAdminDPContext</code> object.
131: * @param portal the portal id.
132: * @return The DPHelper class object.
133: */
134: public static DPHelper getDPHelper(PSConfigContext pcc,
135: SSOToken ssoToken, String portal)
136: throws DesktopDataException {
137: return new DPHelper(pcc, ssoToken, portal);
138: }
139:
140: //--------------------------------------------------------------
141: // The following methods are used by the import/export operation
142: // from the PortalMBean. Specifically, they deal with desktop dp
143: // documents, service attributes specified in the
144: // ExportServiceAttrMap.properties.
145: //--------------------------------------------------------------
146: public static final String DELIM = "@@@!!!";
147:
148: /**
149: * Gets the dp document by given base.
150: *
151: * @param base The base where the dp document is stored. For
152: * example, if the dp document is store in the LDAP, the base is
153: * the dn of the LDAP node.
154: * @return The dp document based on the given location.
155: */
156: public Document getDocument(String base) {
157:
158: Document doc = null;
159: try {
160: String buf = m_ADPContext.getDPDocument(base);
161: // create a dom document for the display profile
162: if (buf != null) {
163: XMLDPRoot dpRoot = (XMLDPRoot) m_Factory.createRoot(
164: (DPContext) m_ADPContext, buf);
165: doc = dpRoot.getDocument();
166: }
167: } catch (Throwable t) {
168: //do nothing, return null
169: }
170:
171: return doc;
172: }
173:
174: /**
175: * Gets the dp document as String.
176: *
177: * @param base The base where the dp document is stored. For
178: * example, if the dp document is store in the LDAP, the base is
179: * the dn of the LDAP node.
180: * @return The dp document based on the given location.
181: */
182: public String getDPDocument(String base) {
183:
184: return m_ADPContext.getDPDocument(base);
185: }
186:
187: /**
188: * Gets all node name for given base.
189: *
190: * @param base The base dn.
191: * @param level The search level.
192: * @param includeParent True if the client also wants search all
193: * the parent nodes.
194: * @return A <code>Set</code> of node names.getAllNamesFromBase()
195: * @see com.sun.portal.desktop.context.AdminDPContext#getAllNamesFromBase
196: */
197: public Set getAllNamesFromBase(String base, int level,
198: boolean includeParent) {
199: return m_ADPContext.getAllNamesFromBase(base, level,
200: includeParent);
201: }
202:
203: /**
204: * Gets all node name from the root node.
205: *
206: * @param level The search level.
207: * @return A <code>Set</code> of node names.
208: * @see com.sun.portal.desktop.context.AdminDPContext#getAllNames
209: */
210: public Set getAllNames(int level) {
211: return m_ADPContext.getAllNames(level);
212: }
213:
214: /**
215: * Gets all the documents associated with the given set of nodes.
216: * The documents list includes all the dp documents that
217: * are the children of the given base.
218: *
219: * @param nodes The set of nodes that the documents are associated
220: * with.
221: * @param level Specifies the scope of the search level.
222: * @return A <code>Map</code> of key, document pair.
223: *
224: */
225: public Map getDocuments(Set nodes, int level) {
226: Map docs = new HashMap();
227:
228: for (Iterator i = nodes.iterator(); i.hasNext();) {
229: String key = (String) i.next();
230: Document doc = getDocument(key);
231:
232: if (doc != null) {
233: docs.put(key, doc);
234: }
235: }
236:
237: return docs;
238: }
239:
240: /**
241: * Gets all the document names associated with the given
242: * base. This method performs the same function as the
243: * <code>getDocuments()</code> method, except that it will
244: * just get the list of the keys and returns a <code>Set</code> of
245: * the document keys.
246: *
247: * @param base The base target where the search begins. For
248: * example, if the dp document is stored in the LDAP, the base
249: * will be the dn of the LDAP node, and the search will be based
250: * on this dn.
251: * @param level Specifies the scope of the search level.
252: * @return A <code>Set</code> of keys.
253: *
254: */
255: public Set getDocumentNames(String base, int level) {
256: Set dns = m_ADPContext.getAllNamesFromBase(base, level, false);
257: Set docs = new HashSet();
258:
259: for (Iterator i = dns.iterator(); i.hasNext();) {
260: String key = (String) i.next();
261: if (m_Logger.isLoggable(Level.FINEST)) {
262: Object tokens[] = { key };
263: m_Logger.log(Level.FINEST, "PSDT_CSPDAMT0092", tokens);
264: }
265:
266: Document doc = getDocument(key);
267:
268: if (doc != null) {
269: docs.add(key);
270: }
271: }
272:
273: return docs;
274: }
275:
276: /**
277: * Gets all the document names from the top most node. This method
278: * performs the same function as the <code>getDocuments()</code> method,
279: * except that it will just get the list of the keys and returns
280: * a <code>Set</code> of the document keys.
281: *
282: * @param level
283: * @return A <code>Set</code> of keys.
284: */
285: public Set getDocumentNames(int level) {
286: Set dns = m_ADPContext.getAllNames(level);
287: Set docs = new HashSet();
288:
289: for (Iterator i = dns.iterator(); i.hasNext();) {
290: String key = (String) i.next();
291: if (m_Logger.isLoggable(Level.FINEST)) {
292: Object tokens[] = { key };
293: m_Logger.log(Level.FINEST, "PSDT_CSPDAMT0092", tokens);
294: }
295: Document doc = getDocument(key);
296: if (doc != null) {
297: docs.add(key);
298: }
299: }
300:
301: return docs;
302: }
303:
304: /**
305: * Sets the attribute value.
306: *
307: * @param dn The distinguish name.
308: * @param key The attribute name.
309: * @param val The attribute value.
310: */
311: public void setServiceAttribute(String base, String key,
312: String val, boolean isGlobal) throws DesktopDataException {
313:
314: List tokList = new ArrayList();
315: List realNameList = new ArrayList();
316: Properties attrConf = getConfProp(PSConfigConstants.PS_EXPORT_SVC_ATTR_MAP_FILE);
317:
318: getExportServices(tokList, realNameList);
319:
320: for (int i = 0; i < tokList.size(); i++) {
321: String service = (String) realNameList.get(i);
322: String attrNameStr = (String) attrConf.get(tokList.get(i));
323: Map attrMap = new HashMap();
324:
325: attrMap.put("operation", "set");
326: if (!isGlobal) {
327: attrMap.put(AttrOptionConstants.OPT_DN, base);
328: }
329: if (service.toLowerCase().indexOf(DESKTOP) != -1) {
330: attrMap.put(AttrOptionConstants.OPT_COMPONENT, DESKTOP);
331: } else if (service.toLowerCase().indexOf(SUBSCRIPTIONS) != -1) {
332: attrMap.put(AttrOptionConstants.OPT_COMPONENT,
333: SUBSCRIPTIONS);
334: }
335:
336: //find out if the key belongs to this service
337: //if found, set the attibute value
338: if (attrNameStr.indexOf(key) != -1) {
339: attrMap.put(AttrOptionConstants.OPT_ATTR_NAME, key);
340: List vals = stringToList(val);
341: if (m_Logger.isLoggable(Level.FINEST)) {
342: Object tokens[] = { base, service, key,
343: vals.toString() };
344: m_Logger.log(Level.FINEST, "PSDT_CSPDAMT0093",
345: tokens);
346: }
347:
348: if (!vals.isEmpty()) {
349: invokeSetAttribute(vals, attrMap);
350: break;
351: }
352: }
353: }
354:
355: }
356:
357: /**
358: * Sets the global desktop attribute value.
359: *
360: * @param key The attribute name.
361: * @param val The attribute value.
362: *
363: public void setGlobalServiceAttribute(String key, String val) throws
364: DesktopDataException {
365: List tokList = new ArrayList();
366: List realNameList = new ArrayList();
367: Properties attrConf =
368: getConfProp(PSConfigConstants.PS_EXPORT_SVC_ATTR_MAP_FILE);
369:
370: getExportServices(tokList,realNameList);
371:
372: for (int i = 0; i < tokList.size(); i++) {
373:
374: String service = (String)realNameList.get(i);
375: String attrNameStr = (String)attrConf.get(tokList.get(i));
376:
377: //if found, set the attibute value
378: if (attrNameStr.indexOf(key) != -1) {
379: List vals = stringToList(val);
380:
381: //replace %PORTAL_ID% in key for the real portal id
382: key = key.replaceAll(Tags.PORTAL_ID,m_Portal);
383:
384: if (!vals.isEmpty()) {
385: //m_ADPContext.setGlobalAttributeMultiVal(service,
386: // key, vals);
387:
388: Object tokens[] = {service, key, vals.toString()};
389: //AUDIT TRAIL
390: if (m_Logger.isLoggable(Level.INFO)) {
391: m_Logger.log(Level.INFO,
392: "PSDT_CSPDAMT0093",tokens);
393: }
394: break;
395: }
396: }
397: }
398:
399: }
400: */
401: /**
402: * Check if the given base is the global key.
403: *
404: * @param base The base
405: * @return true if the base is the global key; fase otherwise
406: */
407: public boolean isGlobal(String base) {
408: return m_ADPContext.isGlobal(base);
409: }
410:
411: /**
412: * Get service attribute value from the dp admin context, and store
413: * the service attribute name and value pairs into the passed in
414: * <code>Properties</code> object.
415: *
416: * @param dn Node where the dp attributes are stored
417: * @param prop Properties object that will store the attribute
418: * values
419: * @return boolean <code>true<code> if there is attribute found
420: * in this node, <code>false</code> otherwise.
421: */
422: public boolean getServiceAttributes(String dn, Properties prop)
423: throws DesktopDataException {
424:
425: boolean hasProperty = false;
426: List tokList = new ArrayList();
427: List realNameList = new ArrayList();
428: Properties attrConf = getConfProp(PSConfigConstants.PS_EXPORT_SVC_ATTR_MAP_FILE);
429:
430: getExportServices(tokList, realNameList);
431:
432: //Loop through the services
433:
434: for (int ind = 0; ind < tokList.size(); ind++) {
435: String key = (String) tokList.get(ind);
436: String service = (String) realNameList.get(ind);
437: List attrNames = new ArrayList();
438: Map attrMap = new HashMap();
439:
440: getServiceAttributeNames((String) attrConf.get(key),
441: attrNames);
442:
443: if (m_Logger.isLoggable(Level.FINEST)) {
444: Object tokens[] = { dn, service, attrNames.toString() };
445: m_Logger.log(Level.FINEST, "PSDT_CSPDAMT0094", tokens);
446: }
447:
448: attrMap.put("operation", "get");
449: if (!isGlobal(dn)) {
450: attrMap.put(AttrOptionConstants.OPT_DN, dn);
451: }
452: if (service.toLowerCase().indexOf(DESKTOP) != -1) {
453: attrMap.put(AttrOptionConstants.OPT_COMPONENT, DESKTOP);
454: } else if (service.toLowerCase().indexOf(SUBSCRIPTIONS) != -1) {
455: attrMap.put(AttrOptionConstants.OPT_COMPONENT,
456: SUBSCRIPTIONS);
457: }
458:
459: //Loop through the attribute names
460: for (int k = 0; k < attrNames.size(); k++) {
461: String attrName = (String) attrNames.get(k);
462: if (m_Logger.isLoggable(Level.INFO)) {
463: Object tokens[] = { attrName };
464: m_Logger
465: .log(Level.INFO, "PSDT_CSPDAMT0095", tokens);
466: }
467:
468: attrMap
469: .put(AttrOptionConstants.OPT_ATTR_NAME,
470: attrName);
471: List vals = invokeGetAttribute(attrMap);
472: if (vals != null && !vals.isEmpty()) {
473: hasProperty = true;
474: String val = listToString(vals);
475: //AUDIT TRAIL
476: if (m_Logger.isLoggable(Level.INFO)) {
477: Object tokens[] = { val };
478: m_Logger.log(Level.INFO, "PSDT_CSPDAMT0096",
479: tokens);
480: }
481: prop.setProperty(attrName, val);
482: }
483: }
484: }
485:
486: return hasProperty;
487: }
488:
489: private void getExportServices(List tokList, List realNameList)
490: throws DesktopDataException {
491:
492: // Load the property file that defines the set portal
493: // Services
494: Properties svcConf = getConfProp(PSConfigConstants.PS_SERVICE_CONFIG_FILE);
495:
496: // Get the value of the property that defines the list of
497: // services that are portal specific
498: String exportSvcList = svcConf
499: .getProperty("ExportServices", "");
500: // The value of the export services property is a space
501: // separated string of service names. Create a tokenizer to
502: // tokenize the string into individual service names
503: StringTokenizer exportSvcTokens = new StringTokenizer(
504: exportSvcList);
505: // Initialize a Set that will contain the portal specific service names
506: while (exportSvcTokens.hasMoreTokens()) {
507:
508: String exportService = exportSvcTokens.nextToken();
509:
510: tokList.add(exportService);
511: exportService = exportService.replaceFirst(Tags.PORTAL_ID,
512: m_Portal);
513: realNameList.add(exportService);
514: if (m_Logger.isLoggable(Level.FINEST)) {
515: Object tokens[] = { exportService };
516: m_Logger.log(Level.FINEST, "PSDT_CSPDAMT0097", tokens);
517: }
518: }
519: }
520:
521: private Properties getConfProp(String config)
522: throws DesktopDataException {
523:
524: Properties svcConf = new Properties();
525: String svcConfLocation = null;
526:
527: try {
528: // Load the property file that defines the set portal
529: // Services
530: String psLibLocation = m_PCC.getPSBaseDir() + FS + "lib";
531: svcConfLocation = psLibLocation + FS + config;
532: // Load the property file
533: svcConf.load(new FileInputStream(svcConfLocation));
534: } catch (FileNotFoundException fe) {
535: throw new DesktopDataException(fe.getMessage(), fe);
536: } catch (IOException ioe) {
537: throw new DesktopDataException("DPHelper.getConfProp() ",
538: ioe);
539: }
540: return svcConf;
541: }
542:
543: private void getServiceAttributeNames(String value, List attrNames) {
544:
545: if (value != null) {
546: // The value of the service attribute names is a space
547: // separated string of attribute names. Create a tokenizer to
548: // tokenize the string into individual attribute name.
549: StringTokenizer attrNameTokens = new StringTokenizer(value);
550:
551: int i = 0;
552: while (attrNameTokens.hasMoreTokens()) {
553: String attrName = attrNameTokens.nextToken();
554: attrNames.add(i, attrName);
555: i++;
556: }
557: }
558:
559: }
560:
561: private List invokeGetAttribute(Map attrMap) {
562:
563: List vals = null;
564: String[] signature = { "java.util.Map" };
565: Object[] params = { attrMap };
566: try {
567: ObjectName on = AdminUtil.getPortalMBeanObjectName(
568: AdminUtil.DEFAULT_DOMAIN, m_Portal);
569: MBeanServer mbs = PASModule.getMBeanServer();
570: vals = (List) mbs.invoke(on, "getAttribute", params,
571: signature);
572: } catch (Exception e) {
573: //do nothing, returns the empty list
574: }
575: return vals;
576:
577: }
578:
579: private void invokeSetAttribute(List vals, Map attrMap) {
580:
581: String[] signature = { "java.util.List", "java.util.Map" };
582: Object[] params = { vals, attrMap };
583: try {
584: ObjectName on = AdminUtil.getPortalMBeanObjectName(
585: AdminUtil.DEFAULT_DOMAIN, m_Portal);
586: MBeanServer mbs = PASModule.getMBeanServer();
587: mbs.invoke(on, "setAttribute", params, signature);
588: } catch (Exception e) {
589: //do nothing, returns the empty list
590: }
591:
592: }
593:
594: /**
595: * Convert a dom document to string.
596: *
597: * @param doc The dom document.
598: * @return A String contains the dp document.
599: */
600: static public String generateDPDocument(Document doc) {
601: StringBuffer st = XMLDPRoot.getXMLHeader();
602: Element e = (Element) ((doc
603: .getElementsByTagName(XMLDPTags.DISPLAYPROFILE_TAG))
604: .item(0));
605:
606: if (e == null) {
607: return null;
608: }
609:
610: toStringBuffer(e, st, 1);
611: return st.toString();
612: }
613:
614: /*
615: * Merge the given dp into the specified base node.
616: *
617: * @param isGlobal is the base global.
618: * @param base the base dn where the merged dp to be stored.
619: * @param dp the dp to be merged
620: */
621: public void storeCombinedDPDocument(boolean isGlobal, String base,
622: String dp) throws DesktopDataException {
623: DPRoot baseRoot = null;
624: String baseDoc = null;
625: String mergedDp = null;
626: Set docs = new HashSet();
627:
628: if (isGlobal) {
629: baseDoc = m_ADPContext.getGlobalDPDocument();
630: } else {
631: baseDoc = m_ADPContext.getDPDocument(base);
632: }
633: if (baseDoc != null && baseDoc.length() > 0) {
634: baseRoot = m_Factory.createRoot(m_ADPContext, baseDoc);
635: } else {
636: //
637: // if doc is empty, create an empty dproot
638: //
639: baseRoot = m_Factory.createRoot(m_ADPContext);
640: }
641:
642: DPRoot dpRoot = m_Factory.createRoot(m_ADPContext, dp);
643: StringBuffer b = new StringBuffer(256);
644:
645: try {
646: DPAUtil.combineRoots(dpRoot, baseRoot);
647: } catch (DPAException dpe) {
648: throw new DesktopDataException(
649: "DPHelper.storeCombinedDpDocument", dpe);
650: }
651:
652: dpRoot.toXML(b, 0);
653: String combinedDp = b.toString();
654:
655: if (isGlobal) {
656: storeGlobalDPDocument(combinedDp);
657: } else {
658: storeDPDocument(base, combinedDp);
659: }
660:
661: }
662:
663: /**
664: * Stores the global dp document.
665: *
666: * @param dp The dp document.
667: * @see
668: * com.sun.portal.desktop.context.AdminDPContext#storeGlobalDPDocument
669: */
670: public void storeGlobalDPDocument(String dp)
671: throws DesktopDataException {
672: try {
673: DPRoot dpRoot = m_Factory.createRoot(m_ADPContext, dp);
674: } catch (DPError de) {
675: m_Logger.log(Level.SEVERE, "PSDT_CSPDAMT0117", de);
676: throw new DesktopDataException(
677: "DPHelper.storeGlobalDPDocument, invalid dp format",
678: de);
679: }
680:
681: m_ADPContext.storeGlobalDPDocument(dp);
682: //AUDIT TRAIL
683: if (m_Logger.isLoggable(Level.INFO)) {
684: Object tokens[] = { "global" };
685: m_Logger.log(Level.INFO, "PSDT_CSPDAMT0115", tokens);
686: }
687: }
688:
689: public void storeDPDocument(String base, String dp)
690: throws DesktopDataException {
691: try {
692: DPRoot dpRoot = m_Factory.createRoot(m_ADPContext, dp);
693: } catch (DPError de) {
694: m_Logger.log(Level.SEVERE, "PSDT_CSPDAMT0117", de);
695: throw new DesktopDataException(
696: "DPHelper.storeDpDocument, invalid dp format", de);
697: }
698:
699: m_ADPContext.storeDPDocument(base, dp);
700: //AUDIT TRAIL
701: if (m_Logger.isLoggable(Level.INFO)) {
702: Object tokens[] = { base };
703: m_Logger.log(Level.INFO, "PSDT_CSPDAMT0115", tokens);
704: }
705: }
706:
707: public void removeDPDocument(String base) {
708:
709: m_ADPContext.removeDPDocument(base);
710: //AUDIT TRAIL
711: if (m_Logger.isLoggable(Level.INFO)) {
712: Object tokens[] = { base };
713: m_Logger.log(Level.INFO, "PSDT_CSPDAMT0118", tokens);
714: }
715: }
716:
717: private String listToString(List vals) {
718:
719: StringBuffer st = new StringBuffer(800);
720: for (Iterator i = vals.iterator(); i.hasNext();) {
721: String val = (String) i.next();
722: st.append(val);
723: st.append(DELIM);
724: }
725:
726: return st.toString();
727: }
728:
729: private List stringToList(String vals) {
730: String[] arr = vals.split(DELIM);
731: List valList = new ArrayList();
732:
733: for (int i = 0; i < arr.length; i++) {
734: valList.add(arr[i]);
735: }
736:
737: return valList;
738: }
739:
740: public static Object getAdminDPContext(String portal)
741: throws DesktopDataException {
742: String adminDPContextClassName = null;
743: try {
744: Properties contextProps = ResourceLoader
745: .getInstance(portal).getProperties(
746: "contextconfig.properties");
747: adminDPContextClassName = contextProps
748: .getProperty(AdminDPContext.ADMINDPCONTEXTCLASSNAME_KEY);
749: } catch (FileNotFoundException fnfe) {
750: throw new DesktopDataException(
751: "DPHelper.getAdminDPContext()", fnfe);
752: } catch (IOException ioe) {
753: throw new DesktopDataException(
754: "DPHelper.getAdminDPContext()", ioe);
755: }
756: if (adminDPContextClassName == null) {
757: throw new DesktopDataException(
758: "DPHelper.getAdminDPContext():admindpcontext classname is null");
759: }
760: Object adcObj = null;
761:
762: try {
763: adcObj = (Class.forName(adminDPContextClassName)
764: .newInstance());
765: } catch (ClassNotFoundException cnfe) {
766: throw new DesktopDataException(
767: "DPHelper.getAdminDPContext()", cnfe);
768: } catch (NoClassDefFoundError ncdfe) {
769: throw new DesktopDataException(
770: "DPHelper.getAdminDPContext()", ncdfe);
771: } catch (IllegalAccessException iae) {
772: throw new DesktopDataException(
773: "DPHelper.getAdminDPContext()", iae);
774: } catch (ClassCastException cce) {
775: throw new DesktopDataException(
776: "DPHelper.getAdminDPContext()", cce);
777: } catch (InstantiationException ie) {
778: throw new DesktopDataException(
779: "DPHelper.getAdminDPContext()", ie);
780: } catch (SecurityException se) {
781: throw new DesktopDataException(
782: "DPHelper.getAdminDPContext()", se);
783: }
784:
785: return adcObj;
786: }
787:
788: // The following code is copied from XMLDPObject
789: static final int INDENT_SPACES = 4;
790:
791: static void appendBuffer(String a, StringBuffer b, int indent) {
792: if (b.length() != 0) {
793: if (b.charAt(b.length() - 1) == '\n') {
794: for (int i = 0; i < indent * INDENT_SPACES; i++) {
795: b.append(" ");
796: }
797: }
798: }
799:
800: b.append(a);
801: }
802:
803: static void toStringBuffer(Node n, StringBuffer b, int indent) {
804:
805: //
806: // note: we only handle ELEMENT and TEXT node types
807: //
808:
809: switch (n.getNodeType()) {
810: case Node.ELEMENT_NODE:
811: Element e = (Element) n;
812:
813: appendBuffer("<", b, indent);
814: appendBuffer(e.getTagName(), b, indent);
815: NamedNodeMap attrs = e.getAttributes();
816: if (attrs != null) {
817: int numAttrs = attrs.getLength();
818: for (int i = 0; i < numAttrs; i++) {
819: Node na = attrs.item(i);
820: if (na.getNodeType() != Node.ATTRIBUTE_NODE) {
821: continue;
822: }
823: Attr a = (Attr) na;
824: appendBuffer(" ", b, indent);
825: appendBuffer(Encoder.XML_ENCODER
826: .encode(a.getName()), b, indent);
827: appendBuffer("=\"", b, indent);
828: appendBuffer(Encoder.XML_ENCODER.encode(a
829: .getValue()), b, indent);
830: appendBuffer("\"", b, indent);
831: }
832: }
833:
834: Node s = e.getNextSibling();
835: boolean appendNewline = !(s != null && s.getNodeType() == Node.TEXT_NODE);
836:
837: NodeList nodes = e.getChildNodes();
838:
839: if (nodes.getLength() == 0) {
840: if (appendNewline) {
841: appendBuffer("/>\n", b, indent);
842: } else {
843: appendBuffer("/>", b, indent);
844: }
845: } else {
846:
847: if (nodes.item(0).getNodeType() == Node.TEXT_NODE) {
848: appendBuffer(">", b, indent);
849: } else {
850: appendBuffer(">\n", b, indent);
851: }
852:
853: for (int j = 0; j < nodes.getLength(); j++) {
854: toStringBuffer(nodes.item(j), b, indent + 1);
855: }
856:
857: appendBuffer("</", b, indent);
858: appendBuffer(e.getTagName(), b, indent);
859: if (appendNewline) {
860: appendBuffer(">\n", b, indent);
861: } else {
862: appendBuffer(">", b, indent);
863: }
864: }
865:
866: break;
867:
868: case Node.COMMENT_NODE:
869: Comment c = (Comment) n;
870: appendBuffer("<!--", b, indent);
871: appendBuffer(c.getData(), b, indent);
872: appendBuffer("-->\n", b, indent);
873:
874: break;
875:
876: case Node.TEXT_NODE:
877: Text t = (Text) n;
878: String text = t.getData();
879: if (text.length() > 0) {
880: appendBuffer(Encoder.XML_ENCODER.encode(text), b, 0);
881: }
882:
883: break;
884:
885: default:
886: // throw new DPError(
887: // "XMLDPObject.toStringBuffer(): unknown node type encountered"
888: // );
889: }
890: }
891:
892: }
|