KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > engines > viewdatasourceid > ViewDataSourceID_Engine


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 //
14
// ViewDataSourceID_Engine
15
// EV 04.12.2000
16
//
17
// getInstance()
18
// authoriseRender()
19
// renderLink()
20
// needsJahiaData()
21
// handleActions()
22
//
23

24 package org.jahia.engines.viewdatasourceid;
25
26 import java.io.IOException JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28
29 import org.jahia.data.JahiaData;
30 import org.jahia.data.fields.JahiaField;
31 import org.jahia.engines.JahiaEngine;
32 import org.jahia.exceptions.JahiaException;
33 import org.jahia.params.ParamBean;
34
35 public class ViewDataSourceID_Engine implements JahiaEngine {
36
37     private static ViewDataSourceID_Engine instance = null;
38     public static final String JavaDoc ENGINE_NAME = "viewdatasourceid";
39
40     /** logging */
41     private static final org.apache.log4j.Logger logger =
42             org.apache.log4j.Logger.getLogger (ViewDataSourceID_Engine.class);
43
44
45     /**
46      * constructor EV 04.12.2000
47      */

48     private ViewDataSourceID_Engine () {
49         logger.debug ("***** Starting " + ViewDataSourceID_Engine.class.getName () +
50                 " engine *****");
51     }
52
53
54     /**
55      * getInstance EV 04.12.2000
56      */

57     public static synchronized ViewDataSourceID_Engine getInstance () {
58         if (instance == null) {
59             instance = new ViewDataSourceID_Engine ();
60         }
61         return instance;
62     }
63
64
65     /**
66      * authoriseRender EV 04.12.2000
67      */

68     public boolean authoriseRender (ParamBean jParams) {
69         return (jParams.getOperationMode () == ParamBean.EDIT);
70     }
71
72
73     /**
74      * renderLink EV 04.12.2000
75      */

76     public String JavaDoc renderLink (ParamBean jParams, Object JavaDoc theObj)
77             throws JahiaException {
78         JahiaField theField = (JahiaField) theObj;
79         String JavaDoc params = "?mode=displayid&fid=" + theField.getID ();
80         return jParams.composeEngineUrl (ENGINE_NAME, params);
81     }
82
83
84     /**
85      * needsJahiaData EV 04.12.2000 it doesn't need JahiaData !!
86      */

87     public boolean needsJahiaData (ParamBean jParams) {
88         return false;
89     }
90
91
92     /**
93      * handleActions EV 04.12.2000
94      */

95     public void handleActions (ParamBean jParams, JahiaData jData)
96             throws JahiaException {
97         String JavaDoc mode = jParams.getRequest ().getParameter ("mode");
98         String JavaDoc ipAddr = jParams.getRequest ().getRemoteAddr ();
99         int fid = jParams.getFieldID ();
100         if (mode != null) {
101             if (mode.equals ("displayid")) {
102                 logger.debug (ipAddr + " is accessing ViewDataSourceID " + fid);
103                 displayID (jParams, fid);
104             }
105         }
106     }
107
108
109     /**
110      * Retrieve the engine name.
111      *
112      * @return the engine name.
113      */

114     public final String JavaDoc getName () {
115         return ENGINE_NAME;
116     }
117
118
119     /**
120      * displayID() EV 04.12.2000
121      */

122     public void displayID (ParamBean jParams, int fieldID)
123             throws JahiaException {
124         try {
125             PrintWriter JavaDoc out = jParams.getResponse ().getWriter ();
126             jParams.getResponse ().setContentType ("text/html");
127             String JavaDoc dsUrl = jParams.composeEngineUrl ("datasourcefield",
128                     "&mode=displaydata&fid=" + fieldID);
129             StringBuffer JavaDoc html =
130                     new StringBuffer JavaDoc ("<html><head><title>Data Source ID</title></head>\n");
131             html.append (
132                     "<body bgcolor=\"black\" onLoad=\"document.ds.dsid.focus();document.ds.dsid.select()\">\n");
133             html.append ("<font color=\"white\" size=\"2\"><b>Data Source ID :</b><br>\n");
134             html.append (
135                     "<form name=\"ds\"><input type=\"text\" name=\"dsid\" size=\"60\" value=\"");
136             html.append (dsUrl);
137             html.append ("\"><br>\n");
138             html.append (
139                     "<input type=\"button\" value=\"Close\" onClick=\"window.close()\">\n");
140             html.append ("</form></body></html>");
141             out.println (html.toString ());
142
143         } catch (IOException JavaDoc ie) {
144             String JavaDoc errorMsg = "Error while returning a datasource field : " + ie.getMessage () +
145                     " -> BAILING OUT";
146             logger.error (errorMsg);
147             throw new JahiaException ("Cannot retrieve remote data",
148                     errorMsg, JahiaException.DATA_ERROR, JahiaException.CRITICAL_SEVERITY);
149         }
150
151     }
152
153 }
154
Popular Tags