6051801b419b4b89dbdc08fa11fb162d.ppt
- Количество слайдов: 34
WME Math. Edit (Status Report) by K. Cem Karadeniz 03/15/2006 Kent State University Computer Science March 15 th, 2006
Overview • New implementation platform: JAVA – Why Applet? – Advantages & Disadvantages – Security, Applet Signature, Policy – The Box Model and Animation – Current Package and Class Hierarchy – Serializer, Parser and SAX 03/15/2006 2
Overview (cont. ) • Interface Design – Old Interface vs. New Interface • Application Programming Interface (API) – Interaction with Other WME Components • Enabling Web Pages for Math. ML (brief) – Use XHML template package (cancelled) • Demo of the Current Tool 03/15/2006 3
Refreshing the Requirements The WME Math. Edit tool, • • • requires animation and very intensive input control (keyboard, mouse) êêêêê has to work online on client side êêêêê has to be able to communicate two ways within the web page êêêêê should have access to clients’ local hard drives to read/write files (for also debugging) êêêóó may store formulas as image files êóóóó 03/15/2006 4
Communication Scenario • Considering those requirements, we have the following communication scenario diagram: 03/15/2006 5
Why JAVA? • All the requirements can be implemented by using JAVA and its Applet technology. • Applets are full JAVA programs and they, – allow to create the highly needed symbol animation, – are capable to work online, – can interact with web page, – may access the client hard drive (!) 03/15/2006 6
JAVA Applet: Pros[Cons • Applets provide ways to fulfill all five requirements that I just mentioned; they are full featured programs! <x 5 • Object-oriented code has tremendous advantages (i. e. plug n play parsers, code reuse and easy maintenance) < • Platform independent coding & execution on platform dependent JVM 03/15/2006 7
JAVA Applet: Pros[Cons • Applet comes with following constraints as far as the WME is concerned: – Extra action needed for security (next) – Requires a heavy weight plug-in (JRE) ~16 MB! • Like every other tool to implement Math. Edit! – Relatively slow initialization due to Java nature (interpreted language) and large bytecode size • Researching open-source optimizers and tools to convert to native code (!) – if larger than 300 k I will try • 1. 5. 0 (or 5. 0) is beyond other older versions 03/15/2006 8
Applet Security • • • Applets used to have a bad fame about security First choice of malicious hackers to hack MS Windows remotely JDK’s goal is to enable browsers to run untrusted applets in a trusted environment 1. Local policy files (suitable for development) 2. Signed applets (WME will possibly use this) 03/15/2006 9
Applet Security: Local Policy • • • Plain text files on client machines Default: . java. policy in the user home directory Not very practical for WME (why? ) You can use policytool program in SDK For now WME Math. Edit needs the following permissions: grant code. Base "file: /javaworld/-" { It is also possible to grant all permissions: permission java. io. File. Permission "<<ALL FILES>>", "read, write"; grant code. Base "file: /javaworld/-" { permission java. util. Property. Permission "user. dir", "read"; permission java. security. All. Permission; permission java. lang. Runtime. Permission "modify. Thread"; }; 03/15/2006 10
Applet Security: Signed Classes • This does not require any file on client < • Program has to be in a JAR package • Only the main class must still be present together with the signed JAR file • Tools to use in J 2 SE SDK: – jar – keytool – jarsigner 03/15/2006 11
Applet Security: Signed Classes (cont. ) • Signing an applet is almost like writing a small program! It needs some effort K. My five-step minimal process below: 1. 2. # jar cvf mathedit_unsigned. jar mathedit # keytool –genkey -alias mymathedit -keypass keymathedit -keystore matheditkey. bin (can have multiple keys -alias) -storepass pubmathedit 3. Answer questions (next slide) 4. # jarsigner -keystore matheditkey. bin -signedjar mathedit_signed. jar mathedit_unsigned. jar mymathedit 5. Answer questions (next-next slide) 03/15/2006 12
Applet Security: Signed Classes (cont. ) • You have to answer seven questions when you issue the keytool command on previous slide. User will grant access depending on them. • Answers should be explanatory otherwise people will deny access What is your first and last name? [Unknown]: The WME Research Team What is the name of your organizational unit? [Unknown]: Web-based Mathematics Education What is the name of your organization? [Unknown]: Kent State University Computer Science What is the name of your City or Locality? [Unknown]: Kent What is the name of your State or Province? [Unknown]: OH What is the two-letter country code for this unit? [Unknown]: US Is CN=The WME Research Team, OU=Web-based Mathematics Education, O=Kent State University Computer Science, L=Kent, ST=OH, C=US correct? [no]: yes 03/15/2006 13
Applet Security: Signed Classes (cont. ) • You have to answer two more questions when you issue the jarsigner command (step 4) • Answers are from the keytool command (from step 2) # jarsigner -keystore matheditkey. bin -signedjar mathedit_signed. jar mathedit_unsigned. jar mymathedit Enter Passphrase for keystore: pubmathedit Enter key password for mymathedit: keymathedit 03/15/2006 14
Applet Security: Signed Classes (cont. ) • If you successfully complete the process you will get the following message: Warning: The signer certificate will expire within six months. • You can always buy a permanent certificate that will allow your applet to run automatically without any warning message (next) • From Veri. Sign or some similar company… 03/15/2006 15
Running the Applet • If you are a developer you will use a policy file like I showed together with the appletviewer tool • You don’t need to sign your applet until you publish it • To run the applet on your local machine: # appletviewer -J-Djava. security. policy=myappletpolicy deploy. html 03/15/2006 16
03/15/2006 17
03/15/2006 18
Applet Security: Signed Classes (cont. ) 03/15/2006 19
JAVA and the Box Model • Currently I implemented square root and fraction using what I refer as “box model” • Box is from javax. swing. Box • private Component ra = Box. create. Rigid. Area(new Dimension(my. D+5, 0)); • Creates an invisible Component 03/15/2006 20
Fraction Model Box • Same idea but now starts with two rigid areas at the same time • private Component ra = Box. create. Rigid. Area(new Dimension(my. Dim 1+5, 0)); • private Component dxra = Box. create. Rigid. Area(new Dimension(0, my. Dim 2)); 03/15/2006 21
Package & Class Hierarchy • I have currently 10 (img and mmlex are different) packages and 28 classes & interfaces • Main package is mathedit. cem. appmain – – 03/15/2006 My. Editor. App. html My. Editor. App. java My. Editor. Panel. java My. Editor. Renderer. j ava 22
Parser and SAX • I have a 750 lines Math. ML parser class, I wrote it converting from a C++ parser, not easy even to convert! • As I mentioned before plug & play, can allow to change the parser since each parser is a class obeying some rules (OOP interface concept) • public interface Parser { //. . . • public class MMLParser implements Parser { //. . . } 03/15/2006 } 23
Parser and SAX • Simple API for XML • Comes as part of JAVA core: import org. xml. sax. Input. Source; public My. Box parse(Input. Source source) throws Exception { Document. Builder. Factory f = Document. Builder. Factory. new. Instance(); f. set. Validating(true); f. set. Namespace. Aware(true); f. set. Ignoring. Element. Content. Whitespace(true); Document. Builder builder = f. new. Document. Builder(); return parse. Dom(builder. parse(source)); // XML + Math. ML Parse } • Visit http: //www. saxproject. org/ for more information 03/15/2006 24
Math. ML Serializers (MMLSerializer. java) • In Java a Serializer converts a Java object to an XML representation using a specific XML processing mechanism • In WME Math. Edit: convert what is visually on the swing panel (on the tool’s typing area) to XML • XML is Math. ML in this case • I have two serializers for now (one for square root and one for fraction) • Each added feature will require a new serializer 03/15/2006 25
private String serialize. Fraction(Frac. My. Box box) { String result = ""; if (attrs. length()>0) { result += ind()+"<"+tag("mstyle")+attrs+">"; indcnt++; } result += ind()+"<"+tag("mfrac"); if (box. get. Line. Thickness()!=1) result += " linethickness=""+box. get. Line. Thickness()+"""; result += ">"; indcnt++; result += serialize. Box(box. get. Numerator()) + serialize. Box(box. get. Denominator()); indcnt--; result += ind()+"</"+tag("mfrac")+">"; if (attrs. length()>0) { indcnt--; result += ind()+"</"+tag("mstyle")+">"; } return result; } 03/15/2006 26
private String serialize. Sqrt(Sqrt. My. Box box) { String result = ""; String attrs = check. For. Style(box); if (attrs. length()>0) { result += ind()+"<"+tag("mstyle")+attrs+">"; indcnt++; } result += ind()+"<"+tag("msqrt")+">"; indcnt++; if ( box. get. Childs(). size()==1 && (box. get. Base(). get. Type()==My. Box. row. BBox) ) result += serialize. Box(box. get. Base()); else { result += ind()+"<"+tag("mrow")+">"; indcnt++; for (int i=0; i<box. get. Childs(). size(); i++) result += serialize. Box((My. Box)box. get. Childs(). element. At(i )); indcnt--; result += ind()+"</"+tag("mrow")+">"; } indcnt--; result += ind()+"</"+tag("msqrt")+">"; if (attrs. length()>0) { indcnt--; result += ind()+"</"+tag("mstyle")+">"; } return result; } 03/15/2006 27
API for WME Components • Other WME components like DMAD, Glossary Service, Bulletin Board need output of my program, which brings a need for API • API is also needed for ordinary WME pages • I don’t have any Java. Script API yet because the program is not even half way implemented • Two APIs are available through <param … /> • Output is simply a string containing full of Math. ML tags, attributes, and user input (see the demo) 03/15/2006 28
How to Embed the Tool • Two files under mathedit directory which is in the root directory of the web page/site • File 1: mathedit_signed. jar • File 2: My. Editor. App. class <applet code="mathedit/cem/appmain/My. Editor. App. class“ archive="mathedit/mathedit_signed. jar" type="application/x-java-applet; version=1. 5. 0" width="430" height="300"> <param name="type" value="application/x-java-applet" /> (next slide covers HERE, the param API) </applet> 03/15/2006 29
Two Applet Parameters <param name="open. MMLfile" value="ex 02. mml" /> <param name="open. MMLstr" value="<math><mrow><mfrac><mrow><mn>1</mn></mro w>…” /> • But there is a problem in the second param (why? ) <param name="open. MMLstr" value="< math> < mrow> < mfrac> < ; mrow> < mn> …” /> • Java. Script API should handle the problem 03/15/2006 30
Interface Design 03/15/2006 31
Interface Design (cont. ) 03/15/2006 32
Demo 03/15/2006 33
Thank you • Questions? • Comments? • Suggestions? 03/15/2006 34
6051801b419b4b89dbdc08fa11fb162d.ppt