KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > media > urlcomposers > MarkupURLComposer


1 /*
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9  */

10
11 package org.mmbase.applications.media.urlcomposers;
12
13 import org.mmbase.module.core.*;
14 import org.mmbase.applications.media.Format;
15 import java.util.*;
16
17
18 /**
19  * Produces links to (jsp) templates which can present a media
20  * fragment. These templates can e.g. produce pieces of HTML (for use
21  * with object tag), or perhaps a better example are
22  * SMIL-jsp-templates ( with response.setHeader("Content-Type",
23  * "application/smil");)
24  *
25  * Depends on a 'template' to be linked to the fragment, or to one of
26  * its parent fragments.
27  *
28  * @author Michiel Meeuwissen
29  * @author Rob Vermeulen (VPRO)
30  * @since MMBase-1.7
31  */

32 public class MarkupURLComposer extends FragmentURLComposer {
33     
34     /**
35      * Typical for a 'MarkupURLComposer' is that it should have a
36      * 'template'. It could have been called a 'TemplateURLComposer',
37      * but that sounds to general..
38      */

39     protected MMObjectNode getTemplate() {
40         return (MMObjectNode) getInfo().get("template");
41     }
42     
43     /**
44      * This composer can only do something if it has a template. The
45      * URLComposerFactory arranges this, but if somewhy it doesn't, it still works.
46      *
47      * More importantly, it could also do checks to link 'markup
48      * language type' to source format type. Currently is checked
49      * that the source-format must be Real, if the templates language
50      * is SMIL (this is perhaps too limited).
51      */

52     
53     public boolean canCompose() {
54         MMObjectNode template = getTemplate();
55         if (template == null) return false;
56         Format sourceFormat = Format.get(source.getIntValue("format"));
57         if (getFormat() == Format.SMIL && !( sourceFormat == Format.RM || sourceFormat == Format.RA)) return false;
58         return true;
59     }
60     
61     protected StringBuffer JavaDoc getURLBuffer() {
62         MMObjectNode template = getTemplate();
63         if (template != null) {
64             String JavaDoc url = template.getStringValue("url");
65             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(url + "fragment=" + fragment.getNumber() + "&format=" + Format.get(source.getIntValue("format")) + "&source=" + source.getNumber());
66             if (url.indexOf("://") < 0) {
67                 if (! url.startsWith("/")) {
68                     buf.insert(0, Config.templatesDir);
69                 }
70                 buf.insert(0, "http://" + Config.host);
71             }
72             return buf;
73         } else {
74             return new StringBuffer JavaDoc("[Could not compose]"); // should not happen
75
}
76         
77     }
78     public String JavaDoc getGUIIndicator(Map options) {
79         Locale locale = (Locale) options.get("locale");
80         Format sourceFormat = Format.get(source.getIntValue("format"));
81         return super.getGUIIndicator(options) + " (" + sourceFormat.getGUIIndicator(locale) + ")";
82     }
83     
84     
85     public String JavaDoc getDescription(Map options) {
86         Locale locale = (Locale) options.get("locale");
87         ResourceBundle m = ResourceBundle.getBundle("org.mmbase.applications.media.urlcomposers.resources.markupurlcomposer", locale);
88         String JavaDoc url = getURL() + "&amp;language=" + locale.getLanguage();
89         MMObjectNode template = getTemplate();
90         if (template.getStringValue("mimetype").equals("text/html")) {
91             return template.getStringValue("name") + "<br />" + template.getStringValue("description") + "<br />" + m.getString("object") + ":<br /><nobr>&lt;object data='" + url + "' type='text/html'&gt;&lt/object&gt;</nobr>";
92         } else {
93             return template.getStringValue("name") + "<br />" + template.getStringValue("description");
94         }
95     }
96     
97     
98     /**
99      * Depends on mimetype of the template to return the format of this urlcomposer.
100      */

101     
102     public Format getFormat() {
103         MMObjectNode template = getTemplate();
104         if (template == null) return Format.HTML;
105         String JavaDoc mimetype = template.getStringValue("mimetype");
106         if (mimetype.equals("application/smil")) {
107             return Format.SMIL;
108         } else {
109             return Format.HTML;
110         }
111     }
112 }
113
Popular Tags