001: /* Copyright 2001, 2002 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;
007:
008: import org.jasig.portal.RDBMServices;
009: import org.jasig.portal.StructureStylesheetDescription;
010: import org.jasig.portal.ThemeStylesheetDescription;
011: import org.jasig.portal.layout.IUserLayoutStore;
012: import org.jasig.portal.layout.UserLayoutStoreFactory;
013:
014: /**
015: * A utility to manage core uPortal stylesheets.
016: *
017: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
018: * @version 1.0
019: */
020: public class RegisterStylesheet {
021:
022: public RegisterStylesheet() {
023: }
024:
025: public static void main(String[] args) {
026: RDBMServices.setGetDatasourceFromJndi(false); /*don't try jndi when not in web app */
027:
028: String stylesheetURI = null;
029: String stylesheetDescriptionURI = null;
030: int stylesheetId = -1;
031: boolean isTheme = true;
032: boolean update = false;
033: boolean delete = false;
034: if (args.length < 3)
035: printHelp();
036: for (int i = 0; i < args.length; i++) {
037: if (!args[i].startsWith("-")) {
038: if (update) {
039: if (i <= 1 || args.length < i + 3) {
040: printHelp();
041: }
042:
043: stylesheetURI = args[i];
044: stylesheetDescriptionURI = args[++i];
045: stylesheetId = Integer.parseInt(args[++i]);
046: } else if (delete) {
047: stylesheetId = Integer.parseInt(args[i]);
048: } else {
049: if (i < 1 || args.length < i + 2) {
050: printHelp();
051: }
052:
053: stylesheetURI = args[i];
054: stylesheetDescriptionURI = args[++i];
055: }
056: } else if (args[i].equals("-s")) {
057: isTheme = false;
058: } else if (args[i].equals("-t")) {
059: isTheme = true;
060: } else if (args[i].equals("-u")) {
061: update = true;
062: } else if (args[i].equals("-d")) {
063: delete = true;
064: } else {
065: printHelp();
066: return;
067: }
068: }
069: if (delete) {
070: if (stylesheetId == -1) {
071: printHelp();
072: return;
073: }
074: } else if (stylesheetURI == null
075: || stylesheetDescriptionURI == null) {
076: printHelp();
077: return;
078: }
079: IUserLayoutStore ulsdb = UserLayoutStoreFactory
080: .getUserLayoutStoreImpl();
081: try {
082: if (update) {
083: if (isTheme) {
084: ulsdb.updateThemeStylesheetDescription(
085: stylesheetDescriptionURI, stylesheetURI,
086: stylesheetId);
087: } else {
088: ulsdb.updateStructureStylesheetDescription(
089: stylesheetDescriptionURI, stylesheetURI,
090: stylesheetId);
091: }
092: // verify
093: if (isTheme) {
094: ThemeStylesheetDescription tsd = UserLayoutStoreFactory
095: .getUserLayoutStoreImpl()
096: .getThemeStylesheetDescription(stylesheetId);
097: } else {
098: StructureStylesheetDescription ssd = UserLayoutStoreFactory
099: .getUserLayoutStoreImpl()
100: .getStructureStylesheetDescription(
101: stylesheetId);
102: }
103: } else if (delete) {
104: if (isTheme) {
105: ulsdb
106: .removeThemeStylesheetDescription(stylesheetId);
107: } else {
108: ulsdb
109: .removeStructureStylesheetDescription(stylesheetId);
110: }
111: } else {
112: Integer id = null;
113: if (isTheme) {
114: id = ulsdb.addThemeStylesheetDescription(
115: stylesheetDescriptionURI, stylesheetURI);
116: } else {
117: id = ulsdb.addStructureStylesheetDescription(
118: stylesheetDescriptionURI, stylesheetURI);
119: }
120:
121: if (id == null) {
122: System.out.println("Save failed!");
123: return;
124: } else {
125: stylesheetId = id.intValue();
126: System.out
127: .println("Save successfull! The new stylehseet was assigned Id="
128: + id);
129: }
130:
131: // verify
132: if (isTheme) {
133: ThemeStylesheetDescription tsd = UserLayoutStoreFactory
134: .getUserLayoutStoreImpl()
135: .getThemeStylesheetDescription(stylesheetId);
136: } else {
137: StructureStylesheetDescription ssd = UserLayoutStoreFactory
138: .getUserLayoutStoreImpl()
139: .getStructureStylesheetDescription(
140: stylesheetId);
141: }
142: }
143:
144: } catch (Exception e) {
145: System.out.println("An error has been encountered:");
146: e.printStackTrace();
147: }
148: }
149:
150: private static void printHelp() {
151: System.out
152: .println("Usage: RegisterStylesheet -(s|t) [-(u|d)] [stylesheetURI] [stylesheetDescriptionURI] [stylesheetId]");
153: System.out
154: .println("The stylesheetId must be specified for update and delete operations.");
155: System.out
156: .println("The URIs must be specified for add and update operations.");
157: System.out
158: .println("The CLASSPATH environment variable should be set up to include\n"
159: + "both \"uPortal/build\" and \"uPortal/build/WEB-INF/classes\" dirs.\n\n"
160: + "For deployment all stylesheets are moved under the \"/stylesheet/\" directory,\n"
161: + "so the URI for a stylesheet will always begin with \"/stylesheet/\", unless\n"
162: + "you're specifying a global URL (which is not recommended).\n"
163: + "Stylesheet description files (.sdf) are moved to the same location, so\n"
164: + "their URI should be specified in the same manner.\n\n"
165: + "For example to specify a URI for a tab-column.xsl (part of the distribution),\n"
166: + "use \"/stylesheets/org/jasig/portal/layout/tab-column/tab-column.xsl\".\n");
167: System.out.println("Flag specification:");
168: System.out
169: .println("\t-s : process structure stylesheet (either \"-t\" or \"-s\" are required on the command line)");
170: System.out
171: .println("\t-t : process theme stylesheet (either \"-t\" or \"-s\" are required on the command line)");
172: System.out.println("\t-u : update stylesheet definition");
173: System.out.println("\t-d : delete stylesheet definition");
174: System.exit(0);
175: }
176: }
|