Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
T E C H
T I P S
TIPS, TECHNIQUES, AND SAMPLE CODE
A digit ([0-9])
A non-digit ([^0-9])
A whitespace character [ \t\n\x0B\f\r]
non-whitespace character: [^\s]
\w
\W
The final set of character classes listed here are the boundary
matchers. These are meant to match the beginning or end of
a sequence of characters, specifically a line, word, or pattern.
^
$
\b
\B
\A
\G
\Z
\z
}
}
}
For example, if you compile the program, and then run it like
this:
java MyMatch "I want to be in lectures" "lect" "pict"
It returns:
I want to be in pictures
Notice that when you run the program, it is unnecessary to
escape the \ character from the command line. That's because
the javac compiler does not process that information. For
example, if the search string is:
"I want to be in lectures\I want to be a star"
and you run the program with the same pattern ("lect") and
replacement string ("pict"), it returns:
I want to be in pictures\I want to be a star
For more information about pattern matching and regular
expressions, see the technical article Regular Expressions and
the Java Programming Language
(http://java.sun.com/jdc/technicalArticles/releases/1.4regex/).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CREATING A HELPSET WITH JAVAHELP SOFTWARE
JavaHelp software allows you to add online help to any system
that has a Java Runtime Environment (JRE). With JavaHelp
software, you can embed online documentation inside your
client-side programs. This includes the obvious applets and
applications, but you can also use JavaHelp software with
JavaBeans(tm) technology components or as standalone help
for third-party systems.
Getting started with the JavaHelp software is easy. Just go to
http://java.sun.com/products/javahelp/download_binary.html. You
can download either the user-version, with a JRE, or a
developer-centric version (as a Zip or self-extracting
executable). There is also a JavaHelp User Guide that comes with
the software downloads. If you view the JavaHelp User Guide,
you'll see the JavaHelp system in action.
Once started, the Swing-based help viewer for JavaHelp presents
information in a series of views. You'll find a Table of
Contents, index of topics, and search. These three features
combined are called the HelpSet and may include multiple help
topic files. Essentially, it is your job to create the help topic
files and the navigation files, mapping the help topic to the file
with the necessary information. The topic files are basic HTML,
and the navigation files are formatted in XML. You can however use
a third-party tool to automatically produce the necessary files.
For example, a tool such as RoboHELP generates the necessary
files in the JavaHelp format. See the list of tools supporting
For the map file, you need to create a mapping from map ID to
files, similar to the following:
<mapID target="one" url="Hello/First/one.htm" />
Be sure the help files are specified as relative locations from
the HelpSet. You could hard code complete paths, but then as soon
as you JAR up the HelpSet, all paths would be wrong. Of course,
these could be complete URLs to resources on the Web. If you want
to have one "overview" help file at the top, and two help files
in each of the First and Last directories, your XML mapping might
appear as follows. Create this Map.jhm file in the help directory.
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE map
PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN"
"http://java.sun.com/products/javahelp/map_1_0.dtd">
<map version="1.0">
<mapID target="overview" url="Hello/overview.htm" />
<mapID target="one" url="Hello/First/one.htm" />
<mapID target="two" url="Hello/First/two.htm" />
<mapID target="three" url="Hello/Last/three.htm" />
<mapID target="four" url="Hello/Last/four.htm" />
</map>
The table of contents and index files are next. These provide
alternate means of working through the various help files. Again,
these are described in XML files.
For the table of contents, each target from the map is mapped to
text to appear in the table of contents. Create this toc.xml file
in the help directory.
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE toc
PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN"
"http://java.sun.com/products/javahelp/toc_1_0.dtd">
<toc version="1.0">
<tocitem image="toplevelfolder" target="overview" text="Hello, JavaHelp">
<tocitem text="First Stuff">
<tocitem target="one" text="The One"/>
<tocitem target="two" text="The Second"/>
</tocitem>
<tocitem text="Last Stuff">
<tocitem target="three" text="What's Third?"/>
<tocitem target="four" text="The End"/>
</tocitem>
</tocitem>
</toc>
The index is just another way of presenting the data. As you
create the index.xml file, you must alphabetize/list terms in the
order you want them presented. Simply create the XML file with
a set of hierarchical <indexitem> entries. In each <indexitem>
entry, provide a value for the text attribute and a value for the
target attribute. The value for the text attribute specifies what
to display to the user in the index. The value for the target
attribute specifies what help to display. Create this index.xml
You can also add a search tab. To do this, run the jhindexer
program and add another <view> to the HelpSet. Enter the
jhindexer command as follows in the directory that contains the
hello.hs file.
jhindexer Hello
If the command isn't in your path, you'll need to prefix the
command with its full path. You can find the command in the
javahelp/bin (Unix) or javahelp\bin (Windows) subdirectory of
your JavaHelp installation directory.
Here's the <view> tag you need to add to hello.hs. JavaHelpSearch
is the name of the directory used for the help index support
files to be saved.
<view>
<name>Search</name>
<label>Word Search</label>
<type>javax.help.SearchView</type>
<data engine="com.sun.java.help.search.DefaultSearchEngine">
JavaHelpSearch
</data>
</view>
For more information about JavaHelp software, see the JavaHelp
software page (http://java.sun.com/products/javahelp/).
. . . . . . . . . . . . . . . . . . . . . . .
IMPORTANT: Please read our Terms of Use, Privacy, and Licensing
policies:
http://www.sun.com/share/text/termsofuse.html
http://www.sun.com/privacy/
http://developer.java.sun.com/berkeley_license.html
* FEEDBACK
Comments? Send your feedback on the JDC Tech Tips to:
jdc-webmaster@sun.com
* SUBSCRIBE/UNSUBSCRIBE
- To subscribe, go to the subscriptions page,
(http://developer.java.sun.com/subscription/), choose
the newsletters you want to subscribe to and click "Update".
- To unsubscribe, go to the subscriptions page,
(http://developer.java.sun.com/subscription/), uncheck the
appropriate checkbox, and click "Update".
- To use our one-click unsubscribe facility, see the link at
the end of this email:
- ARCHIVES
You'll find the JDC Tech Tips archives at:
http://java.sun.com/jdc/TechTips/index.html
- COPYRIGHT
Copyright 2002 Sun Microsystems, Inc. All rights reserved.
901 San Antonio Road, Palo Alto, California 94303 USA.
This document is protected by copyright. For more information, see:
http://java.sun.com/jdc/copyright.html
JDC Tech Tips
April 23, 2002
Sun, Sun Microsystems, Java, Java Developer Connection, JavaHelp,
and JavaBeans are trademarks or registered trademarks of
Sun Microsystems, Inc. in the United States and other countries.