001: /* Copyright 2001 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;
007:
008: import java.util.Hashtable;
009: import java.util.StringTokenizer;
010:
011: import org.w3c.dom.ProcessingInstruction;
012:
013: /**
014: * Combines all of the information required to describe
015: * an XSLT stylesheet.
016: * @author Peter Kharchenko, pkharchenko@interactivebusiness.com
017: * @version $Revision: 34820 $
018: */
019: public class StylesheetDescription {
020: public String s_href;
021: public String s_type;
022: public String s_title;
023: public String s_media;
024: public String s_charset;
025: public boolean b_alternate;
026:
027: public StylesheetDescription() {
028: }
029:
030: public StylesheetDescription(String uri, String type) {
031: s_href = uri;
032: s_type = type;
033: s_media = new String("");
034: s_charset = null;
035: b_alternate = false;
036: s_title = new String("");
037: }
038:
039: public StylesheetDescription(String uri, String type, String title,
040: String media, String charset, boolean alternate) {
041: s_href = uri;
042: s_type = type;
043: s_media = media;
044: s_charset = charset;
045: b_alternate = alternate;
046: s_title = title;
047: }
048:
049: public StylesheetDescription(ProcessingInstruction pi) {
050: // determine parameters from the ProcessingInstruction
051: if (pi.getNodeName().equals("xml-stylesheet")) {
052: PIAttributes pia = new PIAttributes(pi);
053: s_href = pia.getAttribute("href");
054: s_type = pia.getAttribute("type");
055: s_title = pia.getAttribute("title");
056: s_media = pia.getAttribute("media");
057: s_charset = pia.getAttribute("charset");
058:
059: if ("yes".equals(pia.getAttribute("alternate")))
060: b_alternate = true;
061: else
062: b_alternate = false;
063:
064: if (s_media == null)
065: s_media = new String("");
066:
067: if (s_title == null)
068: s_title = new String("");
069: }
070: }
071:
072: public StylesheetDescription(String data) {
073: PIAttributes pia = new PIAttributes(data);
074: s_href = pia.getAttribute("href");
075: s_type = pia.getAttribute("type");
076: s_title = pia.getAttribute("title");
077: s_media = pia.getAttribute("media");
078: s_charset = pia.getAttribute("charset");
079:
080: if ("yes".equals(pia.getAttribute("alternate")))
081: b_alternate = true;
082: else
083: b_alternate = false;
084:
085: if (s_media == null)
086: s_media = new String("");
087:
088: if (s_title == null)
089: s_title = new String("");
090: }
091:
092: public String getTitle() {
093: return s_title;
094: }
095:
096: public String getURI() {
097: return s_href;
098: }
099:
100: public String getType() {
101: return s_type;
102: }
103:
104: public String getMedia() {
105: return s_media;
106: }
107:
108: public boolean getAlternate() {
109: return b_alternate;
110: }
111:
112: public String getCharset() {
113: return s_charset;
114: }
115:
116: public void setTitle(String title) {
117: s_title = title;
118: }
119:
120: public void setType(String type) {
121: s_type = type;
122: }
123:
124: public void setMedia(String media) {
125: s_media = media;
126: }
127:
128: public void setURI(String uri) {
129: s_href = uri;
130: }
131:
132: public void setCharset(String charset) {
133: s_charset = charset;
134: }
135:
136: public void setAlternate(boolean alternate) {
137: b_alternate = alternate;
138: }
139:
140: /**
141: * Parses a processing instruction's (PI) attributes for easy retrieval.
142: */
143: class PIAttributes {
144: private Hashtable piAttributes = null;
145:
146: PIAttributes(String data) {
147: piAttributes = new Hashtable();
148: StringTokenizer tokenizer = new StringTokenizer(data, "=\"");
149: while (tokenizer.hasMoreTokens()) {
150: piAttributes.put(tokenizer.nextToken().trim(),
151: tokenizer.nextToken().trim());
152: }
153: }
154:
155: /**
156: * Constructor.
157: * @param pi The processing instruction whose attributes are to be parsed
158: */
159: PIAttributes(ProcessingInstruction pi) {
160: this (pi.getNodeValue());
161: }
162:
163: /**
164: * Returns value of specified attribute.
165: * @param name Attribute name
166: * @return Attribute value, or null if the attribute name does not exist
167: */
168: String getAttribute(String name) {
169: return (String) piAttributes.get(name);
170: }
171: }
172:
173: }
|