4.4.3.3. The complete editor class

Following the complete listing of the content handler class:
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
package myexample;
 
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Properties;
import org.docma.plugin.CharEntity;
import org.docma.plugin.PluginUtil;
import org.docma.plugin.StoreConnection;
import org.docma.plugin.web.ContentAppHandler;
import org.docma.plugin.web.WebUserSession;
 
public class MyTextEditor implements ContentAppHandler
{
private File relativePath;
private String relativeURL;
private String applicationId;
 
@Override
public void initialize(File webBasePath,
String relativeAppPath,
Properties props) throws Exception
{
relativePath = new File(relativeAppPath);
relativeURL = relativeAppPath.replace(File.separatorChar, '/');
applicationId = relativePath.getName().trim();
}
 
@Override
public String getApplicationId()
{
return applicationId;
}
 
@Override
public String getApplicationName(String languageCode)
{
// return "My Text Viewer";
String key = getApplicationId() + ".application_name";
return PluginUtil.getLabel(languageCode, key, null);
}
 
@Override
public String[] getSupportedViewExtensions()
{
return new String[] { "content", "txt" };
}
@Override
public String[] getSupportedEditExtensions()
{
return new String[] { "content", "txt" };
}
 
@Override
public String getPreviewURL(WebUserSession webSess, String nodeId)
{
String viewJSP = relativeURL + "/view.jsp?docsess=" +
encode(webSess.getSessionId()) +
"&nodeid=" + encode(nodeId);
return webSess.encodeURL(viewJSP);
}
 
@Override
public void openViewer(WebUserSession webSess, String nodeId)
throws Exception
{
String url = getPreviewURL(webSess, nodeId);
String js = "window.open('" + url +
"', '_blank', 'width=420,height=480,location=no,menubar=no')";
webSess.evalJavaScript(js);
}
 
@Override
public void openEditor(WebUserSession webSess, String nodeId)
throws Exception
{
StoreConnection conn = webSess.getOpenedStore();
String url = relativeURL + "/edit.jsp" +
"?docsess=" + encode(webSess.getSessionId()) +
"&nodeid=" + encode(nodeId) +
"&store=" + encode(conn.getStoreId()) +
"&version=" + encode(conn.getVersionId().toString()) +
"&lang=" + encode(conn.getCurrentLanguage().getCode());
url = webSess.encodeURL(url);
String js = "window.open('" + url +
"', '_blank', 'width=420,height=480,location=no,menubar=no')";
webSess.evalJavaScript(js);
}
 
@Override
public void setCharEntities(CharEntity[] entities)
{
}
 
private String encode(String value)
{
try {
return URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException ex) {
return value;
}
}
}

Listing 4.4.9. MyTextEditor.java