001: /* Copyright 2003 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.tools.chanpub;
007:
008: import java.io.File;
009: import java.io.FileFilter;
010: import java.io.InputStream;
011: import java.io.PrintWriter;
012: import java.io.StringWriter;
013: import java.util.Date;
014: import java.util.HashMap;
015: import java.util.Iterator;
016: import java.util.Map;
017: import javax.xml.parsers.DocumentBuilder;
018: import javax.xml.parsers.DocumentBuilderFactory;
019:
020: import org.jasig.portal.ChannelCategory;
021: import org.jasig.portal.ChannelDefinition;
022: import org.jasig.portal.ChannelParameter;
023: import org.jasig.portal.ChannelRegistryStoreFactory;
024: import org.jasig.portal.ChannelType;
025: import org.jasig.portal.Constants;
026: import org.jasig.portal.EntityIdentifier;
027: import org.jasig.portal.IChannelRegistryStore;
028: import org.jasig.portal.RDBMServices;
029: import org.jasig.portal.groups.IEntity;
030: import org.jasig.portal.groups.IEntityGroup;
031: import org.jasig.portal.groups.IGroupConstants;
032: import org.jasig.portal.security.IAuthorizationPrincipal;
033: import org.jasig.portal.security.IPermission;
034: import org.jasig.portal.security.IPerson;
035: import org.jasig.portal.security.IUpdatingPermissionManager;
036: import org.jasig.portal.security.PersonFactory;
037: import org.jasig.portal.services.AuthorizationService;
038: import org.jasig.portal.services.GroupService;
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041: import org.jasig.portal.utils.ResourceLoader;
042: import org.jasig.portal.utils.XML;
043: import org.w3c.dom.Document;
044: import org.w3c.dom.Element;
045: import org.w3c.dom.Node;
046: import org.w3c.dom.NodeList;
047: import org.xml.sax.ErrorHandler;
048: import org.xml.sax.SAXException;
049: import org.xml.sax.SAXParseException;
050:
051: /**
052: * This is a Channel Publisher tool to install uPortal channels from outside of
053: * the portal or from within a channel archive.
054: * Currently configured to be executed via Jakarta Ant or via a
055: * channel-definition block within a CAR deployment descriptor.
056: *
057: * Sample of command line arguments:
058: * ant publish -Dchannel=all (this will publish all channels that have a corresponding xml file)
059: * ant publish -Dchannel=webmail.xml (this will publish the specified channels)
060: *
061: * @author Freddy Lopez, flopez@unicon.net
062: * @author Ken Weiner, kweiner@unicon.net
063: * @author Mark Boyd, mboyd@sct.com
064: * @version $Revision: 36740 $
065: */
066: public class ChannelPublisher implements ErrorHandler {
067: private static final Log log = LogFactory
068: .getLog(ChannelPublisher.class);
069:
070: private static final String FRAMEWORK_OWNER = IPermission.PORTAL_FRAMEWORK;
071: private static final String SUBSCRIBER_ACTIVITY = IPermission.CHANNEL_SUBSCRIBER_ACTIVITY;
072: private static final String GRANT_PERMISSION_TYPE = IPermission.PERMISSION_TYPE_GRANT;
073:
074: private static final int LOAD_ALL_FILES = 0;
075: private static final int LOAD_ONE_FILE = 1;
076:
077: private IPerson systemUser;
078: private DocumentBuilder domParser;
079: private IChannelRegistryStore crs;
080: private Map chanTypesNamesToIds;
081: private boolean mOnCommandLine = false;
082: private boolean mOverrideExisting = false;
083:
084: private static final String chanDefsLocation = "/properties/chanpub";
085:
086: /**
087: * @param args
088: * @throws Exception We let Exceptions bubble up so that ant will know
089: * that the publishing failed and can report the error message and stack
090: * trace to the user.
091: */
092: public static void main(String[] args) throws Exception {
093: try {
094: RDBMServices.setGetDatasourceFromJndi(false); /*don't try jndi when not in web app */
095: /*
096:
097: Channel Publisher Tool Workflow.
098: 1) read all or specified channel.xml file
099:
100: ant publish -Dchannel=all or -Dchannel=webmail.xml
101:
102: 2) validate each against the channelDefinition.dtd file
103:
104: 3) publish one channel at a time
105:
106: */
107:
108: // determine whether user wants to publish one or all of the channels in current directory
109: int mode = LOAD_ALL_FILES;
110:
111: if (args[1] != null && args[1].length() > 0) {
112: // MODE = 0 for all channels in directory
113: // MODE = 1 for individual channel
114: if (args[1].equals("all"))
115: mode = LOAD_ALL_FILES;
116: else
117: mode = LOAD_ONE_FILE;
118:
119: }
120:
121: ChannelPublisher publisher = getCommandLineInstance();
122:
123: // determine what mode we are in
124: if (mode == LOAD_ONE_FILE) {
125: System.out
126: .println("You have chosen to publish one channel.....");
127: System.out.print("Publishing channel " + args[1]
128: + ".....");
129: // lets publish one channel only
130: publisher.publishChannel(args[1]);
131: System.out.println("Done");
132: } else {
133: // lets publish all channels in directory
134: System.out
135: .println("You have chosen to publish all channels.....");
136:
137: // user has selected to publish all channel in the /channels directory
138: // lets publish all channel one by one that is
139: // create InputStream object to pass to next method
140: File f = ResourceLoader.getResourceAsFile(
141: ChannelPublisher.class, chanDefsLocation + "/");
142: if (f.isDirectory()) {
143:
144: // Consider only files that end in .xml
145: class ChannelDefFileFilter implements FileFilter {
146: public boolean accept(File file) {
147: return file.getName().endsWith(".xml");
148: }
149: }
150: File[] files = f
151: .listFiles(new ChannelDefFileFilter());
152:
153: for (int j = 0; j < files.length; j++) {
154: String name = files[j].getName();
155: // lets publish one at a time
156: try {
157: publisher.publishChannel(name);
158: } catch (Exception e) {
159: // Add file name into exception so we will know which
160: // file has the problem.
161: throw new Exception(
162: "Unable to publish file: " + name,
163: e);
164: }
165: System.out.println("Published channel " + name);
166: }
167: }
168: }
169: System.out.println("Publishing finished.");
170: System.exit(0);
171: } catch (Exception e) {
172: // signal failure to ant and log
173: log.error(e, e);
174: throw e;
175: }
176: }
177:
178: /**
179: * Sets up the system user for use during publishing.
180: *
181: */
182: private void setupSystemUser() {
183: systemUser = PersonFactory.createSystemPerson();
184: }
185:
186: /**
187: * Publishes the channel represented by the XML located in the file
188: * represented by the passed in filename and returns the resultant
189: * ChannelDefinition object.
190: *
191: * @param filename the name of a file containing the channel XML definition
192: * @return org.jasig.portal.ChannelDefinition the published channel definition
193: * @throws Exception
194: */
195: public ChannelDefinition publishChannel(String filename)
196: throws Exception {
197: ChannelInfo ci = getChannelInfo(filename);
198: return publishChannel(ci);
199: }
200:
201: /**
202: * Publishes the channel represented by the XML accessed via the passed in
203: * InputStream object and returns the resultant ChannelDefinition object.
204: *
205: * @param is and InputStream containing the channel XML definition
206: * @return org.jasig.portal.ChannelDefinition the published channel definition
207: * @throws Exception
208: */
209: public ChannelDefinition publishChannel(InputStream is)
210: throws Exception {
211: ChannelInfo ci = getChannelInfo(is);
212: return publishChannel(ci);
213: }
214:
215: /**
216: * Publishes the channel represented by the passed in ChannelDefinition
217: * object and returns the resultant ChannelDefinition object.
218: *
219: * @param ci
220: * @return
221: * @throws Exception
222: */
223: private ChannelDefinition publishChannel(ChannelInfo ci)
224: throws Exception {
225:
226: if (ci == null)
227: return null;
228:
229: try {
230: if (ci.chanDef.getTypeId() != -1) {
231: ChannelType type = crs.getChannelType(ci.chanDef
232: .getTypeId());
233: ci.chanDef.setJavaClass(type.getJavaClass());
234: }
235: crs.saveChannelDefinition(ci.chanDef);
236:
237: // Permission for everyone to subscribe to channel
238: AuthorizationService authService = AuthorizationService
239: .instance();
240: String target = "CHAN_ID." + ci.chanDef.getId();
241: IUpdatingPermissionManager upm = authService
242: .newUpdatingPermissionManager(FRAMEWORK_OWNER);
243:
244: // Remove old permissions
245: IPermission[] oldPermissions = upm.getPermissions(
246: SUBSCRIBER_ACTIVITY, target);
247: upm.removePermissions(oldPermissions);
248:
249: // Add new permissions for this channel based on both groups and users
250: if (ci.groups != null) {
251: IPermission[] newGroupPermissions = new IPermission[ci.groups.length];
252: for (int j = 0; j < ci.groups.length; j++) {
253: IAuthorizationPrincipal authPrincipal = authService
254: .newPrincipal(ci.groups[j]);
255: newGroupPermissions[j] = upm
256: .newPermission(authPrincipal);
257: newGroupPermissions[j]
258: .setType(GRANT_PERMISSION_TYPE);
259: newGroupPermissions[j]
260: .setActivity(SUBSCRIBER_ACTIVITY);
261: newGroupPermissions[j].setTarget(target);
262: }
263: upm.addPermissions(newGroupPermissions);
264: }
265: if (ci.users != null) {
266: IPermission[] newUserPermissions = new IPermission[ci.users.length];
267: for (int j = 0; j < ci.users.length; j++) {
268: IAuthorizationPrincipal authPrincipal = authService
269: .newPrincipal(ci.users[j]);
270: newUserPermissions[j] = upm
271: .newPermission(authPrincipal);
272: newUserPermissions[j]
273: .setType(GRANT_PERMISSION_TYPE);
274: newUserPermissions[j]
275: .setActivity(SUBSCRIBER_ACTIVITY);
276: newUserPermissions[j].setTarget(target);
277: }
278: upm.addPermissions(newUserPermissions);
279: }
280:
281: // Categories
282: // First, remove channel from its categories
283: ChannelCategory[] categories = crs
284: .getParentCategories(ci.chanDef);
285: for (int i = 0; i < categories.length; i++) {
286: crs
287: .removeChannelFromCategory(ci.chanDef,
288: categories[i]);
289: }
290: // Now add channel to assigned categories
291: if (ci.categories != null) {
292: for (int k = 0; k < ci.categories.length; k++) {
293: crs.addChannelToCategory(ci.chanDef,
294: ci.categories[k]);
295: }
296: }
297:
298: // Need to approve channel
299: crs.approveChannelDefinition(ci.chanDef, systemUser,
300: new Date());
301:
302: } catch (Exception e) {
303: log
304: .error("publishChannel() :: Exception while attempting to publish channel to database. Channel name = "
305: + ci.chanDef.getName());
306: throw e;
307: }
308: return ci.chanDef;
309: }
310:
311: /**
312: * Set up a DOM parser for handling the XML channel-definition data.
313: *
314: * @throws Exception
315: */
316: private void setupDomParser() throws Exception {
317: try {
318: DocumentBuilderFactory dbf = DocumentBuilderFactory
319: .newInstance();
320: dbf.setValidating(true);
321: domParser = dbf.newDocumentBuilder();
322: domParser.setEntityResolver(new ChannelDefDtdResolver());
323: domParser.setErrorHandler(this );
324: } catch (Exception e) {
325: log.error("setupDomParser() :: creating Dom Parser. ", e);
326: throw e;
327: }
328: }
329:
330: /**
331: * Populates and returns a ChannelInfo object based on the passed in
332: * file name containing XML data structured according to the
333: * channel-definition dtd.
334: *
335: * @param chanDefFile
336: * @return
337: * @throws Exception
338: */
339: private ChannelInfo getChannelInfo(String chanDefFile)
340: throws Exception {
341: InputStream is = ResourceLoader.getResourceAsStream(
342: ChannelPublisher.class, chanDefsLocation + "/"
343: + chanDefFile);
344: return getChannelInfo(is);
345: }
346:
347: /**
348: * Populates and returns a ChannelInfo object based on the input stream
349: * containing XML data structured according to the channel-definition dtd.
350: *
351: * @param is
352: * @return
353: * @throws Exception
354: */
355: private ChannelInfo getChannelInfo(InputStream is) throws Exception {
356: ChannelInfo ci = new ChannelInfo();
357: Document doc = null;
358:
359: // Build a DOM tree out of Channel_To_Publish.xml
360: doc = domParser.parse(is);
361:
362: Element chanDefE = doc.getDocumentElement();
363: final String id = getId(chanDefE);
364: if (id != null) {
365: ci.chanDef = crs.newChannelDefinition(Integer.parseInt(id));
366: } else {
367: String fname = getFname(chanDefE);
368:
369: // Use existing channel definition if it exists,
370: // otherwise make a new one with a new ID
371: ci.chanDef = crs.getChannelDefinition(fname);
372:
373: if (ci.chanDef != null && !mOverrideExisting) {
374: log
375: .error("chanDef with fname "
376: + fname
377: + " already exists "
378: + "and override is false. Terminating publication.");
379: return null;
380: }
381:
382: if (ci.chanDef == null) {
383: ci.chanDef = crs.newChannelDefinition();
384: }
385: }
386:
387: for (Node param = chanDefE.getFirstChild(); param != null; param = param
388: .getNextSibling()) {
389: if (!(param instanceof Element))
390: continue; // whitespace (typically \n) between tags
391: Element pele = (Element) param;
392: String tagname = pele.getTagName();
393: String value = XML.getElementText(pele).trim();
394:
395: // each tagname corresponds to an object data field
396: if (tagname.equals("title"))
397: ci.chanDef.setTitle(value);
398: else if (tagname.equals("name"))
399: ci.chanDef.setName(value);
400: else if (tagname.equals("makeFNameAccessibleOnly"))
401: ci.fNameAccessibleOnly = true;
402: else if (tagname.equals("fname"))
403: ci.chanDef.setFName(value);
404: else if (tagname.equals("desc"))
405: ci.chanDef.setDescription(value);
406: else if (tagname.equals("type"))
407: getType(ci, value);
408: else if (tagname.equals("class"))
409: ci.chanDef.setJavaClass(value);
410: else if (tagname.equals("timeout"))
411: ci.chanDef.setTimeout(Integer.parseInt(value));
412: else if (tagname.equals("hasedit"))
413: ci.chanDef.setEditable((value != null && value
414: .equals("Y")) ? true : false);
415: else if (tagname.equals("hashelp"))
416: ci.chanDef.setHasHelp((value != null && value
417: .equals("Y")) ? true : false);
418: else if (tagname.equals("hasabout"))
419: ci.chanDef.setHasAbout((value != null && value
420: .equals("Y")) ? true : false);
421: else if (tagname.equals("secure"))
422: ci.chanDef.setIsSecure((value != null && value
423: .equals("Y")) ? true : false);
424: else if (mOnCommandLine && tagname.equals("categories"))
425: getCategories(ci, pele);
426: else if (mOnCommandLine && tagname.equals("groups"))
427: getGroups(ci, pele);
428: else if (mOnCommandLine && tagname.equals("users"))
429: getUsers(ci, pele);
430: else if (tagname.equals("parameters"))
431: getParameters(ci, pele);
432:
433: ci.chanDef.setPublisherId(0); // system user
434: ci.chanDef.setPublishDate(new Date());
435: }
436: if (ci.groups == null && !mOnCommandLine)
437: ci.groups = getAdminGroup();
438: if (ci.categories == null && !mOnCommandLine)
439: ci.categories = getDefaultCategory(ci.fNameAccessibleOnly);
440: return ci;
441: }
442:
443: /**
444: * Determines the functional name of the channel.
445: *
446: * @param chanDefE
447: * @return
448: * @throws Exception
449: */
450: private String getFname(Element chanDefE) throws Exception {
451: String fname = null;
452: for (Node n = chanDefE.getFirstChild(); n != null; n = n
453: .getNextSibling()) {
454: if (n.getNodeType() == Node.ELEMENT_NODE) {
455: if (n.getNodeName().equals("fname")) {
456: fname = XML.getElementText((Element) n).trim();
457: }
458: }
459: }
460:
461: // Complain if we don't find an fname
462: if (fname == null)
463: throw new Exception("Missing required fname element");
464: return fname;
465: }
466:
467: /**
468: * Find the channel id.
469: *
470: * @param chanDefE
471: * @return possible channel id
472: * @throws Exception
473: */
474: private String getId(Element chanDefE) throws Exception {
475: String id = null;
476: for (Node n = chanDefE.getFirstChild(); n != null; n = n
477: .getNextSibling()) {
478: if (n.getNodeType() == Node.ELEMENT_NODE) {
479: if (n.getNodeName().equals("channelId")) {
480: id = XML.getElementText((Element) n).trim();
481: }
482: }
483: }
484: return id;
485: }
486:
487: /**
488: * Translate the declared channel type name into a channel type id.
489: *
490: * @param ci
491: * @param value
492: * @throws Exception
493: */
494: private void getType(ChannelInfo ci, String value) throws Exception {
495: Integer typeId = (Integer) chanTypesNamesToIds.get(value);
496: if (typeId != null) {
497: ci.chanDef.setTypeId(typeId.intValue());
498: } else {
499: StringWriter sw = new StringWriter();
500: PrintWriter pw = null;
501: for (Iterator itr = chanTypesNamesToIds.keySet().iterator(); itr
502: .hasNext();) {
503: if (pw == null) {
504: pw = new PrintWriter(sw);
505: pw.print("['");
506: pw.print((String) itr.next());
507: pw.print("'");
508: } else {
509: pw.print(" | '");
510: pw.print((String) itr.next());
511: pw.print("'");
512: }
513: }
514: pw.print("]");
515: pw.flush();
516: throw new Exception("Invalid entry '" + value
517: + "' for Channel Type. Must be one of "
518: + sw.toString());
519: }
520: }
521:
522: /**
523: * Translate channel category names into category ids.
524: *
525: * @param ci The ChannelInfo object being populated.
526: * @param pele The Element containing the category elements.
527: * @throws Exception
528: */
529: private void getCategories(ChannelInfo ci, Element pele)
530: throws Exception {
531: NodeList anodes = pele.getElementsByTagName("category");
532: if (anodes.getLength() != 0) {
533: ci.categories = new ChannelCategory[anodes.getLength()];
534: for (int j = 0; j < anodes.getLength(); j++) {
535: Element anode = (Element) anodes.item(j);
536: String catString = XML.getElementText(anode).trim();
537: // need to look up corresponding category id
538: // ie: Applications = local.50
539: // Entertainment = local.51
540: IEntityGroup cat = getGroup(catString,
541: ChannelDefinition.class);
542:
543: if (cat != null)
544: ci.categories[j] = crs.getChannelCategory(cat
545: .getKey());
546: else
547: throw new Exception("Invalid entry '" + catString
548: + "' for category.");
549: }
550: }
551: }
552:
553: /**
554: * Load the declared parameters.
555: *
556: * @param ci The ChannelInfo object being populated.
557: * @param pele The Element containing the parameter elements.
558: */
559: private void getParameters(ChannelInfo ci, Element pele) {
560: NodeList anodes = pele.getElementsByTagName("parameter");
561: if (anodes.getLength() > 0) {
562: for (int j = 0; j < anodes.getLength(); j++) {
563: String pname = null;
564: String pvalue = null;
565: String povrd = null;
566: String pdescr = null;
567: Element anode = (Element) anodes.item(j);
568: NodeList namenodes = anode.getElementsByTagName("name");
569: if (namenodes.getLength() > 0) {
570: pname = XML.getElementText(
571: (Element) namenodes.item(0)).trim();
572: }
573: NodeList valuenodes = anode
574: .getElementsByTagName("value");
575: if (valuenodes.getLength() > 0) {
576: pvalue = XML.getElementText(
577: (Element) valuenodes.item(0)).trim();
578: }
579: NodeList descnodes = anode
580: .getElementsByTagName("description");
581: if (descnodes.getLength() > 0) {
582: pdescr = XML.getElementText(
583: (Element) descnodes.item(0)).trim();
584: }
585: NodeList ovrdnodes = anode.getElementsByTagName("ovrd");
586: if (ovrdnodes.getLength() > 0) {
587: povrd = XML.getElementText(
588: (Element) ovrdnodes.item(0)).trim();
589: }
590: ChannelParameter chanParam = new ChannelParameter(
591: pname, pvalue, RDBMServices.dbFlag(povrd));
592: chanParam.setDescription(pdescr);
593: ci.chanDef.addParameter(chanParam);
594: }
595: }
596: }
597:
598: /**
599: * Translate access group names into group ids.
600: *
601: * @param ci The ChannelInfo object being populated.
602: * @param pele The Element containing the group elements.
603: * @throws Exception
604: */
605: private void getGroups(ChannelInfo ci, Element pele)
606: throws Exception {
607: NodeList anodes = pele.getElementsByTagName("group");
608: if (anodes.getLength() != 0) {
609: ci.groups = new IEntityGroup[anodes.getLength()];
610: for (int j = 0; j < anodes.getLength(); j++) {
611: Element anode = (Element) anodes.item(j);
612: String groupStr = XML.getElementText(anode).trim();
613: // need to look up corresponding group id
614: // ie: Everyone = local.0
615: // Developers = local.4
616: IEntityGroup group = getGroup(groupStr, IPerson.class);
617:
618: if (group != null)
619: ci.groups[j] = group;
620: else
621: throw new Exception("Invalid entry '" + groupStr
622: + "' for group.");
623: }
624: }
625: }
626:
627: /**
628: * Translate access user ids into the user entity objects.
629: *
630: * @param ci The ChannelInfo object being populated.
631: * @param pele The Element containing the user elements.
632: * @throws Exception
633: */
634: private void getUsers(ChannelInfo ci, Element pele)
635: throws Exception {
636: NodeList anodes = pele.getElementsByTagName("user");
637: if (anodes.getLength() != 0) {
638: ci.users = new IEntity[anodes.getLength()];
639: for (int j = 0; j < anodes.getLength(); j++) {
640: Element anode = (Element) anodes.item(j);
641: String userStr = XML.getElementText(anode).trim();
642: // need to look up corresponding user
643: IEntity user = GroupService.getEntity(userStr,
644: IPerson.class);
645:
646: if (user != null)
647: ci.users[j] = user;
648: else
649: throw new Exception("Invalid entry '" + userStr
650: + "' for user.");
651: }
652: }
653: }
654:
655: /**
656: * Gets the portal administrators group.
657: */
658: private IEntityGroup[] getAdminGroup() throws Exception {
659: String dg = GroupService.PORTAL_ADMINISTRATORS;
660: IEntityGroup e = GroupService.getDistinguishedGroup(dg);
661: return new IEntityGroup[] { e };
662: }
663:
664: /**
665: * Obtains an auto-publish category located in the root category or creates
666: * if not found.
667: */
668: private ChannelCategory[] getDefaultCategory(
669: boolean fNameAccessibleOnly) throws Exception {
670: ChannelCategory rootCat = crs.getTopLevelChannelCategory();
671:
672: if (fNameAccessibleOnly)
673: return new ChannelCategory[] { rootCat };
674:
675: ChannelCategory[] topCats = crs.getChildCategories(rootCat);
676: ChannelCategory autoCat = null;
677:
678: for (int i = 0; i < topCats.length; i++) {
679: if (topCats[i].getName().equals(
680: Constants.AUTO_PUBLISH_CATEGORY)) {
681: autoCat = topCats[i];
682: break;
683: }
684: }
685: if (autoCat == null) // target category not created. create.
686: {
687: autoCat = crs.newChannelCategory(
688: Constants.AUTO_PUBLISH_CATEGORY,
689: "Holds Auto-published " + "Channels.", "system");
690: crs.addCategoryToCategory(autoCat, rootCat);
691: }
692: return new ChannelCategory[] { autoCat };
693: }
694:
695: /**
696: * Attempts to determine group key based on a group name or fully qualifed
697: * group key.
698: * @param groupName a <code>String</code> value
699: * @param entityType the kind of entity the group contains
700: * @return a group key
701: */
702: private static IEntityGroup getGroup(String groupName,
703: Class entityType) throws Exception {
704: IEntityGroup group = null;
705: EntityIdentifier[] groups = GroupService.searchForGroups(
706: groupName, IGroupConstants.IS, entityType);
707: if (groups != null && groups.length > 0) {
708: group = GroupService.findGroup(groups[0].getKey());
709: } else {
710: // An actual group key might be specified, so try looking up group directly
711: group = GroupService.findGroup(groupName);
712: }
713: return group;
714: }
715:
716: /**
717: * Load the lookup table to translate channel type names into ids.
718: *
719: * @throws Exception
720: */
721: private void initChanTypeMap() throws Exception {
722: if (chanTypesNamesToIds == null) {
723: chanTypesNamesToIds = new HashMap();
724: chanTypesNamesToIds.put("Custom", new Integer(-1));
725:
726: ChannelType[] types = crs.getChannelTypes();
727: for (int i = 0; i < types.length; i++)
728: chanTypesNamesToIds.put(types[i].getName(),
729: new Integer(types[i].getId()));
730: }
731: }
732:
733: private static class ChannelInfo {
734: ChannelDefinition chanDef;
735: IEntityGroup[] groups;
736: ChannelCategory[] categories;
737: boolean fNameAccessibleOnly = false;
738: IEntity[] users;
739: }
740:
741: private ChannelPublisher(boolean onCommandLine) throws Exception {
742: mOnCommandLine = onCommandLine;
743: // initialize channel registry store
744: crs = ChannelRegistryStoreFactory.getChannelRegistryStoreImpl();
745: // read in channel types
746: initChanTypeMap();
747:
748: // create IPerson object for the portal's system user
749: setupSystemUser();
750: // setup DOM Parser with dtd validation
751: setupDomParser();
752: }
753:
754: public void setOverride(boolean b) {
755: mOverrideExisting = b;
756: }
757:
758: public static ChannelPublisher getCommandLineInstance()
759: throws Exception {
760: ChannelPublisher publisher = new ChannelPublisher(true);
761: publisher.setOverride(true);
762: return publisher;
763: }
764:
765: public static ChannelPublisher getChannelArchiveInstance()
766: throws Exception {
767: return new ChannelPublisher(false);
768: }
769:
770: /*
771: * (non-Javadoc)
772: *
773: * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
774: */
775: public void warning(SAXParseException arg0) throws SAXException {
776: if (log.isInfoEnabled())
777: log
778: .info(
779: "Warning occurred while parsing channel definition.",
780: arg0);
781: }
782:
783: /*
784: * (non-Javadoc)
785: *
786: * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
787: */
788: public void error(SAXParseException arg0) throws SAXException {
789: throw new SAXException(
790: "Error occurred while parsing channel definition.",
791: arg0);
792: }
793:
794: /*
795: * (non-Javadoc)
796: *
797: * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
798: */
799: public void fatalError(SAXParseException arg0) throws SAXException {
800: throw new SAXException(
801: "Fatal Error occurred while parsing channel definition.",
802: arg0);
803: }
804: }
|