001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/devtools/ManagedBeanUtil.java $
003: * $Id: ManagedBeanUtil.java 15675 2006-10-04 20:31:40Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.devtools;
021:
022: import java.util.StringTokenizer;
023:
024: /**
025: * <p>Title: ManagedBeanUtil</p>
026: * <p>Description: Programmer's utility to make a whole bunch of managed bean
027: * entries for faces-config.xml</p>
028: * @author Ed Smiley
029: * @version $Id: ManagedBeanUtil.java 15675 2006-10-04 20:31:40Z daisyf@stanford.edu $
030: *
031: * Example output:
032: *
033: * <managed-bean>
034: * <description>Template editor backing bean</description>
035: * <managed-bean-name>template</managed-bean-name>
036: * <managed-bean-class>org.sakaiproject.tool.assessment.ui.bean.author.TemplateBean</managed-bean-class>
037: * <managed-bean-scope>session</managed-bean-scope>
038: * </managed-bean>
039: *
040: */
041:
042: public class ManagedBeanUtil {
043: //layout for managed bean entry
044: private static final String MAN_TAG = "<managed-bean>";
045: private static final String MAN_TAG_END = "</managed-bean>";
046: private static final String DESC_TAG = " <description>";
047: private static final String DESC_TAG_END = "</description>";
048: private static final String NAME_TAG = " <managed-bean-name>";
049: private static final String NAME_TAG_END = "</managed-bean-name>";
050: private static final String CLASS_TAG = " <managed-bean-class>";
051: private static final String CLASS_TAG_END = "</managed-bean-class>";
052: private static final String SCOPE = " <managed-bean-scope>session</managed-bean-scope>";
053:
054: // quick & dirty, rewrite to use your bean classes & generate array to std out
055: // hint: use shell/sed/script to get list from directory and paste in here
056: private static String[] beanz = {
057: "org.sakaiproject.tool.assessment.ui.bean.author.AssessmentBean",
058: "org.sakaiproject.tool.assessment.ui.bean.author.DeleteConfirmBean",
059: "org.sakaiproject.tool.assessment.ui.bean.author.FileUploadBean",
060: "org.sakaiproject.tool.assessment.ui.bean.author.IndexBean",
061: "org.sakaiproject.tool.assessment.ui.bean.author.ItemAuthorBean",
062: "org.sakaiproject.tool.assessment.ui.bean.author.PublishedAssessmentBean",
063: "org.sakaiproject.tool.assessment.ui.bean.author.SectionBean",
064: "org.sakaiproject.tool.assessment.ui.bean.delivery.DisplayAssetsBean",
065: "org.sakaiproject.tool.assessment.ui.bean.delivery.XmlDeliveryBean",
066: "org.sakaiproject.tool.assessment.ui.bean.evaluation.EvaluationResultBean",
067: "org.sakaiproject.tool.assessment.ui.bean.evaluation.HistogramQuestionScoresBean",
068: "org.sakaiproject.tool.assessment.ui.bean.evaluation.HistogramScoresBean",
069: "org.sakaiproject.tool.assessment.ui.bean.evaluation.QuestionScoresBean",
070: "org.sakaiproject.tool.assessment.ui.bean.evaluation.TotalScoresBean",
071: "org.sakaiproject.tool.assessment.ui.bean.misc.DefaultLoginBean",
072: "org.sakaiproject.tool.assessment.ui.bean.misc.DisplayMessageBean",
073: "org.sakaiproject.tool.assessment.ui.bean.misc.NavigationBean",
074: "org.sakaiproject.tool.assessment.ui.bean.misc.SimpleFormLoginBean",
075: "org.sakaiproject.tool.assessment.ui.bean.questionpool.QuestionPoolBean",
076: "org.sakaiproject.tool.assessment.ui.bean.questionpool.QuestionPoolData",
077: "org.sakaiproject.tool.assessment.ui.bean.select.SelectAssessmentBean" };
078:
079: /**
080: * main util method
081: * @param args arguments are fully qualified bean class names
082: */
083: public static void main(String[] args) {
084: if (args.length > 0)
085: beanz = args;
086: for (int i = 0; i < beanz.length; i++) {
087: //log.info(makeManagedBeanEntry(beanz[i]));
088: }
089: }
090:
091: /**
092: * create managed bean entry
093: * @param beanClass
094: * @return
095: */
096: public static String makeManagedBeanEntry(String beanClass) {
097: String manBean = " " + MAN_TAG + "\n";
098: manBean += " " + DESC_TAG + makeDescription(beanClass)
099: + DESC_TAG_END + "\n";
100: manBean += " " + NAME_TAG + makeName(beanClass) + NAME_TAG_END
101: + "\n";
102: manBean += " " + CLASS_TAG + beanClass + CLASS_TAG_END + "\n";
103: manBean += " " + SCOPE + "\n";
104: manBean += " " + MAN_TAG_END + "\n";
105:
106: return manBean;
107: }
108:
109: private static String makeName(String beanClass) {
110: StringTokenizer st = new StringTokenizer(beanClass, ".");
111: String name = beanClass;
112:
113: while (st.hasMoreElements()) {
114: name = st.nextToken();
115: }
116:
117: // don't name your bean "Bean"! :)
118: return name.toLowerCase().replaceAll("bean", "");
119: }
120:
121: private static String makeDescription(String beanClass) {
122: StringTokenizer st = new StringTokenizer(beanClass, ".");
123: String info = beanClass;
124: String pack = beanClass;
125: String desc = "";
126:
127: while (st.hasMoreElements()) {
128: pack = info;
129: info = st.nextToken();
130: }
131:
132: info = info.replaceAll("bean", "");
133: info = info.replaceAll("Bean", "");
134:
135: if (pack.equalsIgnoreCase(info)) {
136: pack = "";
137: } else {
138: pack = "For " + pack + ":";
139: }
140:
141: char ca[] = info.toCharArray();
142:
143: for (int i = 0; i < ca.length; i++) {
144: String ch = "" + ca[i];
145: if (i == 0) {
146: ch = ch.toUpperCase();
147: }
148: if (Character.isUpperCase(ca[i])) {
149: desc += " ";
150: }
151:
152: desc += ch;
153: }
154:
155: return pack + desc + " backing bean.";
156: }
157:
158: }
|