source: trunk/gsdl3/docs/manual/hints.tex@ 10880

Last change on this file since 10880 was 3785, checked in by kjdon, 21 years ago

added some hints :-)

  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1\documentclass[a4paper,11pt]{article}
2\usepackage{times,epsfig}
3
4\newenvironment{bulletedlist}%
5{\begin{list}{$\bullet$}{\setlength{\itemsep}{0pt}\setlength{\parsep}{0pt}}}%
6{\end{list}}
7
8
9\begin{document}
10
11\title{Some hints for developers}
12
13\maketitle
14
15\section{Java code}
16
17the java code is found in gsdl3/src/java/org/greenstone/gsdl3
18util has various utility classes, service has the services, action has the actions, build has the building code, etc.
19
20\section{Working with XML}
21
22We use the DOM model for handling XML. This involves Documents, Nodes, Elements etc. Node is the basic thing in the tree, all others inherit from this. A Document represents a whole document, and is a kind of container for all the nodes. Elements and Nodes are not supposed to exist outside of the context of a document, so you have to have a document to create them. The document is not the top level node in the tree, to get this, use Document.getDocumentElement(). If you create nodes etc but dont append them to something already in the document tree, they will be separate - but they still know who their owner document is.
23
24There is a utility class called XMLConverter - this creates new Documents, and converts Strings or files to Documents.
25eg:
26XMLConverter converter = new XMLConverter();
27Document doc = converter.newDOM();
28
29File stylesheet = new File(``query.xsl'');
30Document style = converter.getDOM(stylesheet);
31
32String message = ``<message><request type='cgi'/></message>'';
33Document m = converter.getDOM(message);
34
35To output a document as a String, use converter.getString(doc);
36
37
38To add nodes and stuff to an empty document - create them, then append to the tree
39
40Document doc = converter.newDOM();
41Element e = doc.createElement(``message'');
42doc.appendChild(e);
43
44Note, you can only append one node to a document - this will become the toplevel node. After that, you can append nodes to child nodes as you like, but a document is only allowed one top level node.
45
46DOM006 Hierarchy request error: happens if you have more than one root node in your document
47
48\section{Working with XSLT}
49
50* adding html to an xml doc:
51
52eg I have a text node with html inside it inside a resource element
53to add that to a new XML doc, I use
54{\em <xsl:value-of select='resource'>\/}
55
56if the output mode is xml or html, this will escape any special characters
57ie $<$ and $>$ etc
58
59use
60{\em <xsl:value-of disable-output-escaping="yes" select='resource'>\/}
61instead.
62
63* including an xml doc into a stylesheet:
64
65{\em <xsl:variable name='import' select='document(``newdoc.xml'')'/>\/}
66
67then can use the info:
68
69{\em <xsl:value-of select='\$import/element'/>\/}
70
71* selecting an ancestor:
72
73 the ancestor axis contains the parent of the context node, and its
74 parent and so on. to pick one node among these:
75 ancestor::elem-name. I dont know how this works if there are two
76 nodes with the same name in the axis.
77
78* basic XSLT elements
79\begin{quote}\begin{footnotesize}\begin{verbatim}
80<xsl:template match='xxx' name='yyy'/>
81
82<xsl:apply-templates select='xxx'/>
83<xsl:call-templates name='yyy'/>
84
85<xsl:variable name='doc' select='document("layout.xml")'/>
86
87<xsl:value-of select='$doc/chapter1'/> $
88\end{verbatim}\end{footnotesize}\end{quote}
89
90* using namespaces
91If you are using the same namespace in more than one file, eg in the source xml and in the stylesheet, make sure that the URI for the xmlns:xxx thingy is the same in both cases---otherwise the names dont match. This includes http:// on the front.
92
93\subsection{What can I do to speed up XSL transformations?}
94
95This information taken from the Xalan FAQS page.
96
97\begin{bulletedlist}
98
99\item Use a Templates object (with a different Transformers for each
100transformation) to perform multiple transformations with the same set
101of stylesheet instructions (see Multithreading).
102
103\item Set up your stylesheets to function efficiently.
104
105\item Don't use "//" (descendant axes) patterns near the root of a
106large document.
107
108\item Use xsl:key elements and the key() function as an efficient way
109to retrieve node sets.
110
111\item Where possible, use pattern matching rather than xsl:if or
112xsl:when statements.
113
114\item xsl:for-each is fast because it does not require pattern matching.
115
116\item Keep in mind that xsl:sort prevents incremental processing.
117
118\item When you create variables,
119{\em <xsl:variable name="fooElem" select="foo"/>\/} is usually faster
120than \\
121{\em <xsl:variable name="fooElem"><xsl:value-of-select="foo"/></xsl:variable>\/}.
122
123\item Be careful using the last() function.
124
125\item The use of index predicates within match patterns can be expensive.
126
127\item Decoding and encoding is expensive.
128
129\item For the ultimate in server-side scalability, perform transform
130operations on the client. For examples, see appletXMLtoHTML and
131get-todo-list.
132
133\end{bulletedlist}
134
135\section{Java gdbm}
136
137To talk to gdbm, a jni wrapper called java-gdbm is used. It was
138obtained from:\\ {\tt
139http://aurora.rg.iupui.edu/~schadow/dbm-java/pip/gdbm/}
140
141It uses packing objects to convert to and from an array of bytes (in
142gdbm file) from and to java objects. In my GDBMWrapper class I use
143StringPacking - uese UTF-8 encoding. but some stuff came out funny. so
144I had to changes the from\_bytes method in StringPacking.java to use
145new String(raw, "UTF-8") instead of new String(raw). this seems to
146work.
147
148Note---if we use this gdbm stuff to create the file too, may need to
149alter the to-bytes method.
150
151The makefile in j-gdbm is crap---it tries to get stuff from its
152original CVS tree. I have created a new Makefile---in my-j-gdbm
153directory. this stuff needs to go into cvs probably.
154
155* I dont think {\em <xsl:with-param name='xxx' select='true'/>\/} is
156the same as {\em <xsl:with-param name='xxx'>true</xsl:with-param>\/}
157use the second one.
158
159
160\section{Resources}
161
162Contents for 'The Java Native Interface Programmer's Guide and
163Specification' on-line\\ {\tt
164http://java.sun.com/docs/books/jni/html/jniTOC.html}
165
166Java Native Interface Specification\\
167{\tt http://java.sun.com/j2se/1.4/docs/guide/jni/spec/jniTOC.doc.html}
168
169JNI Documentation Contents\\
170{\tt http://java.sun.com/j2se/1.4/docs/guide/jni/index.html}
171
172another JNI page\\
173{\tt http://mindprod.com/jni.html}
174
175Java 1.4 api index\\
176{\tt http://java.sun.com/j2se/1.4/docs/api/index.html}
177
178Java tutorial index\\
179{\tt http://java.sun.com/docs/books/tutorial/index.html}
180
181Safari books online - has java, XML, XSLT, etc books\\
182{\tt http://proquest.safaribooksonline.com/mainhom.asp?home}
183
184Java 1.4 i18n FAQ\\
185{\tt http://www.sun.com/developers/gadc/faq/java/java1.4.html}
186
187Java and XSLT page\\
188{\tt http://www.javaolympus.com/java/Java\%20and\%20XSLT.html}
189
190Xalan-Java overview\\
191{\tt http://xml.apache.org/xalan-j/overview.html}
192
193Tomcat documentation index\\
194{\tt http://jakarta.apache.org/tomcat/tomcat-4.0-doc/index.html}
195
196Servlet and JSP tutorial\\
197{\em http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/\/}
198
199Core Servlets and JavaServer Pages, book by Marty Hall. download the
200pdf from here (try before you buy link)\\ {\tt
201http://www.coreservlets.com/}
202
203J-gdbm page\\
204{\em http://aurora.rg.iupui.edu/~schadow/dbm-java/pip/gdbm/\/}
205
206Stuarts page of links\\
207{\em http://www.cs.waikato.ac.nz/~nzdl/gsdl3/\/}
208
209a good basic xslt tutorial\\
210{\tt http://www.zvon.org/xxl/XSLTutorial/Books/Output/contents.html}
211
212JAXP (java api for xml processing) package overview\\
213{\tt http://java.sun.com/xml/jaxp/dist/1.1/docs/api/overview-summary.html}
214
215DeveloperWorks, xml zone\\
216{\tt http://www-106.ibm.com/developerworks/xml/}
217
218xslt.com\\
219{\tt http://www.xslt.com/}
220
221jeni tennison's xslt pages\\
222{\tt http://www.jenitennison.com/xslt/}
223
224apaches xml tools\\
225{\tt http://xml.apache.org/}
226
227
228\end{document}
Note: See TracBrowser for help on using the repository browser.