Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 77 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
77
Dung lượng
8,03 MB
Nội dung
A public identifier (or publicId) provides no hint as to the actual location of a schema or DTD but instead provides a unique identifier for the artifact that you can use to determine the location by some other means (such as the XML catalog). A schema’s public identifier is its namespace, such as http://java.sun.com/xml/ns/j2ee and is typically specified by declaring a namespace in an XML document (see line 4 in Example 15.1 earlier). A DTD’s public identifier, typically specified in a comment in the DTD, is specified in an XML file by using the PUBLIC keyword in a DOCTYPE statement (see Example 15.2). Example 15.2 J2EE 1.3 PUBLIC DOCTYPE <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> A system identifier (or systemId) provides a hint as to the actual location of a schema or DTD. A schema system identifier, typically a URL, is specified in an XML file using the xsi:schemaLocation attribute. This attribute contains a list of paired items, where the first item is the schema namespace and the second item is the system identifier (see lines 6 and 7 in Example 15.1 earlier). A DTD system identifier, also typically a URL, is specified in an XML file using the SYSTEM keyword in a DOCTYPE statement (see Example 15.3). Example 15.3 J2EE 1.3 SYSTEM DOCTYPE <!DOCTYPE web-app SYSTEM "http://java.sun.com/dtd/web-app_2_3.dtd"> Every J2EE Web application contains the XML file web.xml, known as the deployment descriptor (see Example 15.1), which holds configuration details for the application, such as servlet mappings. The deployment descriptor is located in the web-inf folder in each application. The deployment descriptor specifies the specific J2EE grammar it requires by declaring a system identifier. For J2EE 1.4 the system identifier is http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd (There are different grammars for the different parts and versions of the J2EE specification.) As mentioned earlier, having access to the file containing the J2EE grammar will allow WTP’s tools to provide enhanced function for validation and content assistance for web.xml. Contributing Resources to the XML Catalog 649 By default, WTP will attempt to retrieve remote schemas and DTDs from the Web and cache them using a cache resource resolution strategy. In the case of J2EE, this allows WTP users to get the enhanced function even though the J2EE schemas and DTDs are not bundled with WTP. Although this solution generally works well, it does have a number of drawbacks for new users. ❍ New users must use WTP while connected to the Internet in order to download these schemas and DTDs. This adds an extra configuration step to the WTP install process and can lead to problems if the servers are not visible (due to server outage, proxy configuration or some other problem) when attempting to download the files. ❍ Creation of the first Web application will take longer than subsequent Web applications as the user has to accept license agreements and download the schemas and DTDs. ❍ Every new user must perform this operation. This reduces the efficiency of your organization by placing a burden on all developers that use WTP, increases bandwidth consumption, and may lead to an increase in support calls if there are any network difficulties. For these reasons you will bundle the J2EE schemas and DTDs with the ver- sion of WTP your organization distributes internally, preventing the need for WTP to retrieve the files remotely. In the following sections you will contribute the J2EE schemas to WTP using WTP’s XML catalog. The XML Catalog WTP’s XML catalog allows you to register schemas and DTDs for use in resource resolution. (The catalog can actually register any resource that can be specified with a URI, such as a WSDL document. See the online documentation on the WTP Web site for more about registering any resource.) Typically the XML catalog is used in the way you are going to make use of it, to specify the location of local schemas and DTDs. To put this function in resource resolution terminology, the XML catalog implements a resource resolution strategy that retrieves a specific resource from a catalog of resources using a key. In fact, the XML catalog is a URI resolver that has been contributed to the URI resolution framework, which you will make direct use of later in this chapter. The XML catalog includes a graphical user interface (see Figure 15.2) that allows you to easily contribute resources to it. Resources can be contributed through the XML catalog preferences page, found under Window ᭤ Preferences ᭤ Web and XML ᭤ XML Catalog. While this preferences page is a good way for users to 650 CHAPTER 15 • Customizing Resource Resolution Contributing Resources to the XML Catalog 651 Figure 15.2 Add XML Catalog Entry Adding a Single Resource to the XML Catalog As you saw earlier in Example 15.1, the J2EE deployment descriptor for a J2EE 1.4 application specifies the following location for its grammar: http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd Open this location in your Web browser. You will see that this location is that of the J2EE schema. It is this file that you want to bundle with WTP. The J2EE schema contains license terms in a documentation block at the top. These are the terms that restrict WTP from bundling this schema. As long as you accept the terms (perhaps schools should start teaching software developers licensing law, as we frequently seem to be in positions that require us to under- stand licensing terms), download the schema and save it in your plug-in in a folder named j2eeschemas. customize their workspace, it still requires user interaction and therefore will not completely solve your problem. To bundle the J2EE schemas with WTP, you will need to contribute them to the XML catalog using the XML catalog’s defined extension point. With the J2EE schema stored locally in your plug-in, you are ready to con- tribute it to the XML catalog. Open your plug-in manifest editor and change to the Dependencies tab. Add a dependency on org.eclipse.wst.xml.core The XML core plug-in contains non-UI XML functionality, including the non-UI components of the XML catalog. Next change to the Extensions tab. The XML catalog defines the following extension point that allows you to add your own entries to the catalog: org.eclipse.wst.xml.core.catalogContributions Add a new catalogContributions extension. Give your new extension the id j2eecatalog and the name J2EE Catalog. This extension will house all of your contributions to the XML catalog. Right click on the XML catalog extension and select New ᭤ catalogContribution. This extension element allows you to specify multiple cata- log contributions, but for now you will only specify one. Right click on the new catalogContribution and select New ᭤ system. This will create a new entry in the XML catalog that specifies system identifier as the key. Set the systemId to the location of the schema specified in the J2EE deployment descriptor: http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd Set the uri, which specifies the location of the schema that you want to use, to the relative location of the schema in your plug-in, namely j2eeschemas/web-app_2_4.xsd (You can also click Browse to select the location.) The effect of adding this entry to the XML catalog is that when the J2EE schema location is requested, it will return the local location of the schema from your plug-in. Save your plug-in manifest. Change to the plugin.xml source view and view the extension declara- tion (see Example 15.4). Example 15.4 Listing of Catalog Extension <extension id="org.eclipsewtp.resourceresolution.j2eecatalog" name="J2EE Catalog" point="org.eclipse.wst.xml.core.catalogContributions"> <catalogContribution> <system systemId="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" uri="j2eeschemas/web-app_2_4.xsd"/> </catalogContribution> </extension> 652 CHAPTER 15 • Customizing Resource Resolution Time to try out your changes. Launch a runtime workspace. When the work- space is open, navigate to the XML catalog preference page. The J2EE schema should now be listed in the catalog (see Figure 15.3). So far, so good. Contributing Resources to the XML Catalog 653 Next create a new dynamic Web project. You can name the project anything you like. Accept all the default settings and click Finish in the New Dynamic Web Project wizard. The license dialog does not appear (good) and your new project shows an error (bad). What went wrong? The error has occurred because the J2EE schema is not a stand-alone schema. It requires other schemas that cannot be resolved by the validator now that the schema is included in the XML catalog. In the next section you will add the rest of the J2EE schemas to the XML catalog. Figure 15.3 J2EE Schema Entry Added to XML Catalog Tip: In this section you added a location for a schema system identifier to the XML catalog. There is only one step you need to change in order to add a catalog entry specifying a location for a schema’s public identifier (its namespace). Simply use the public element instead of the system element and the publicId attribute instead of the systemId attribute as follows: Adding a Catalog of Resources to the XML Catalog The method of adding an entry to the XML catalog that you used in the previous section can be used to add many entries to the catalog. For each entry you simply provide a new extension element of the appropriate type. So, you can use this method to add the rest of the J2EE schemas and DTDs to the XML catalog. The method for adding individual resources to the XML catalog works well in many situations. However, one notable limitation is that it restricts the catalog you create to Eclipse. This restricts who you can share your catalog with and how others can make use of it. WTP is not the only project that has an XML catalog implementation. This type of facility is fairly common in tools that handle XML artifacts. To facilitate sharing of catalogs among various tools, the OASIS standards body created an XML catalog standard [XMLCatalogs], which specifies how to define an XML catalog representation in an XML file. (See Example 15.5 for an example.) This standard allows you to create XML catalogs that can be used in any tool that supports the OASIS standard. As you’ve probably guessed by now, WTP sup- ports the OASIS standard. Example 15.5 Listing of OASIS XML Catalog File <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <system uri="web-app_2_4.xsd" systemId="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"/> <system uri="j2ee_1_4.xsd" systemId="j2ee_1_4.xsd"/> <system uri="jsp_2_0.xsd" systemId="jsp_2_0.xsd"/> <system uri="j2ee_web_services_client_1_1.xsd" systemId= "http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd"/> <public uri="web-app_2_3.dtd” publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"/> <public uri="web-app_2_2.dtd" publicId="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"/> </catalog> 654 CHAPTER 15 • Customizing Resource Resolution <public publicId="http://java.sun.com/xml/ns/j2ee" uri="j2eeschemas/web-app_2_4.xsd"/> You can also add entries to the catalog for DTD public and system identifiers using the same method used for a schema by replacing the values of the publicId and systemId attributes with DTD public and system identifiers. For your J2EE catalog to be reusable within your organization, you will create the OASIS XML catalog shown in Example 15.5 and contribute it to the WTP XML catalog. Before you create your J2EE OASIS XML catalog, you need to download the rest of the J2EE schemas and DTDs. The J2EE 1.4 schemas are listed at http://java.sun.com/xml/ns/j2ee/ You’ve already downloaded web-app_2_4.xsd, and http://www.w3.org/2001/xml.xsd is already bundled with WTP. The rest of the schemas that you need for a J2EE 1.4 Web application are jsp_2_0.xsd, j2ee_1_4.xsd, and j2ee_web_services_client_1_1.xsd, which is listed as http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd Download these schemas and place them in the j2eeschemas folder in your plug-in. Next you need the J2EE 1.3 DTD, web-app_2_3.dtd, which is available from http://java.sun.com/dtd/ Download this file and place it in the j2eeschemas folder. The last resource you need to obtain is the J2EE 1.2 DTD, web-app_2_2.dtd, which is available from http://java.sun.com/j2ee/dtds/ Download this file as well and place it in the j2eeschemas folder. Contributing Resources to the XML Catalog 655 Note: The J2EE schema and DTD pages contain listings for many other schemas besides those that you have downloaded. These other schemas and DTDs are used for other parts of the J2EE specification and are not needed for your immediate pur- pose, although depending on your use you may find it beneficial to place these in your catalog as well. Now that you have all of your required resources you can create your OASIS XML catalog. Create a new XML file in the j2eeschemas folder named j2eeschemacatalog.xml to hold your catalog entries. Add the entries in the cata- log (see Example 15.5 previously). The OASIS XML catalog standard and the WTP XML catalog extension point are very similar by design, so your OASIS catalog entries will be similar to the entry that you contributed in the previous section (although, unlike the extension point, WTP does not contain a GUI to create OASIS XML catalogs). With your J2EE OASIS XML catalog complete, all that’s left is to contribute it to WTP. Contributing an OASIS XML catalog to the WTP XML catalog is very similar to contributing an individual entry. Open your plug-in manifest to the Extensions tab. Right click on the existing catalogContribution and select New ᭤ nextCatalog. Enter the location j2eeschemas/j2eeschemacatalog.xml for the catalog or select your catalog with the Browse button. Save your plug-in manifest and you’re done. Change to the plugin.xml source view to view your extension (see Example 15.6). Example 15.6 Listing of nextCatalog Extension <extension id="j2eeCatalog" name="J2EE Catalog" point="org.eclipse.wst.xml.core.catalogContributions"> <catalogContribution> <system systemId="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" uri="j2eeschemas/web-app_2_4.xsd"/> <nextCatalog catalog="j2eeschemas/j2eeschemacatalog.xml"/> </catalogContribution> </extension> You’ve made it to the fun part. Try out your changes by launching a new runtime workspace. Once the new workspace is up, open the XML Catalog pref- erences page. The preferences page should now contain a catalog entry that you can expand to reveal the entries contained within that catalog (see Figure 15.4). This demonstrates another benefit of using OASIS XML catalogs. Using these catalogs allows you to group related entries together in the WTP XML Catalog preferences page. Exit the preferences page and return to your dynamic Web project that dis- played an error after you completed the previous section. Validate your project by right clicking on it and selecting Validate. The error is removed as the required schemas can now be resolved by the XML catalog. Try creating new J2EE 1.3 and 1.2 Web projects by changing the Dynamic Web Module facet on page two of the New Dynamic Web Project wizard. 656 CHAPTER 15 • Customizing Resource Resolution Note: At the time of writing this book, there was a bug in WTP that resulted in all of the entries within an OASIS catalog being displayed with an error marker, and this may result in those entries not being used in resource resolution. Implementing a Custom Resource Resolution Strategy There are many ways in which a resource can be resolved. In the previous section you contributed resources to the XML catalog. The XML catalog is a resource resolution strategy that allows you to contribute individual resources. In order to customize the resource resolution employed by WTP’s tools, you need to add a strategy to the URI resolution framework, which provides the facility to imple- ment any strategy you need. (We’ll discuss this framework in detail in the next section.) The second part of your task is to include your company’s proprietary schemas in WTP. Here’s a little more background about your task. Your company uses schemas to define the grammar for many types of XML documents, including those that hold employee information. An example of an employee information document is shown in Example 15.7 and the correspon- ding schema is shown in Example 15.8. These schemas are used by employees to author XML documents. There is already a process in place within your com- pany that automatically downloads the latest version of your company schemas Implementing a Custom Resource Resolution Strategy 657 Figure 15.4 J2EE OASIS Catalog Entry Added to XML Catalog onto all employee machines and stores them in C:\schemas. (Yes, all employees of your company use Windows.) This process was put in place to ensure that every employee has up-to-date copies of all of the company’s schemas. Management wants the latest version of these schemas incorporated into WTP. The benefits of including your company’s schemas in WTP are the same as those of including the J2EE schemas and DTDs. Your company wants all employees to be able to use content assistance and validation in order to mini- mize the amount of mistakes in these important documents. As the schemas may change and new schemas may be added to the collection, the XML catalog is not suitable for this task. To incorporate your company’s schemas in WTP, you will create a custom URI resolver and contribute it to the URI resolution framework. In the next two sections we’ll start with an overview of the URI resolution framework and then you’ll implement your custom URI resolver. Example 15.7 Listing of a Sample Employee XML Document <?xml version="1.0" encoding="UTF-8"?> <tns:employee xmlns:tns="http://www.leagueplanet.com/employee/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.leagueplanet.com/employee/employee.xsd"> <id>11111111</id> <firstname>Lawrence</firstname> <surname>Mandel</surname> <busaddress> <street>8200 Warden Ave</street> <city>Markham</city> <state>Ontario</state> <zipcode>L6G1C7</zipcode> <country>Canada</country> </busaddress> <position>Software Developer</position> <department>Eclipse Web Tools</department> <company>IBM</company> </tns:employee> Example 15.8 Listing of employee.xsd <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.leagueplanet.com/employee/" xmlns:tns="http://www.leagueplanet.com/employee/"> <element name="employee" type="tns:employeeInfo"/> <complexType name="employeeInfo"> <sequence> <element name="id" type="int"/> <element name="firstname" type="string"/> <element name="surname" type="string"/> <element name="busaddress" type="tns:address"/> <element name="position" type="string"/> 658 CHAPTER 15 • Customizing Resource Resolution [...]... the Web Tools Platform 2.0 Plan Wiki at http://wiki .eclipse. org/index.php /Web_ Tools_ Platform_ 2.0_Plan 677 678 CHAPTER 17 • The Road Ahead Each of these items will be discussed in more detail below: ❍ Migration to the Eclipse Data Tools Platform Project ❍ Maturation of the Eclipse JavaServer Faces Tools Incubator Project ❍ Maturation of the Eclipse Dali JPA Tools Incubator Project ❍ Maturation of the Eclipse. .. more, see http://www.sap.com /platform/ netweaver/components/developerstudio W4T Eclipse W4T Eclipse differs from the other tools presented in this section W4T Eclipse provides a visual development environment for Java Web applications This Java Web Tools 673 commercial product from Innoopract does not focus on the Java Web technologies in use, but instead aims to simplify Java Web development To that end,... the tools that you need, we will present the tools in this chapter by the language that they support In the following sections we will cover Web development tools for Java, Perl, PHP, Python, and Ruby Java Web Tools Given Eclipse s Java heritage it should come as no surprise that there are a number of Java Web application development tools for Eclipse In this section we’ll cover nine different tools. .. integrated Web browser for testing your Web application’s Perl scripts within Eclipse For more, see http://e-p-i-c.sourceforge.net PHP Web Tools PHP is the second “P” in the LAMP stack In this section we’ll highlight two PHP projects that you can use in Eclipse Eclipse PHP Development Tools Project The Eclipse PHP Development Tools project is a fully featured PHP IDE for developing PHP-based Web applications. .. development focus is not on specific technologies, W4T Eclipse and the W4 Toolkit are built on Java standards such as Java beans and servlets W4T Eclipse also includes support for Hibernate and EJB based applications For more, see http://www.innoopract.com/w4teclipse Figure 16.2 The W4T Eclipse Perspective 674 CHAPTER 16 • Other Web Tools Based on Eclipse Perl Web Tools Perl is the original “P” in the LAMP acronym,... ❍ Maturation of the Eclipse AJAX Tools Framework Incubator Project ❍ Support for Java Enterprise Edition 5 ❍ Support for Apache Axis2 and W3C WSDL 2.0 ❍ Integration with the Eclipse PHP Tools Project ❍ Integration with the Eclipse SOA Tools Platform Project Eclipse Data Tools Platform (DTP) Project The initial charter of WTP included Data tools Although SQL is not a Web technology, WTP included it because... using Eclipse as your IDE is the extensible nature of the platform This benefit, while not listed in terms of tools that you can use, provides you with the ability to customize your IDE to suit your needs by plugging in any Eclipse tool WTP has currently limited its scope to a subset of Java Web application development tools However, because WTP is an Eclipse project, you can further customize your Web. .. deploy Web, Web services, Java, J2EE, portal, and SOA applications Although there are too Java Web Tools 671 many features to list here, some of the notable ones include XSL, EJB, JSF, Struts, and modeling support using UML Developers can also use RAD to improve their code quality with tools for automated code quality reviews and build interactive reports with Crystal Reports RAD is optimized for WebSphere... http://labs.jboss.com/portal/jbosside 672 CHAPTER 16 • Other Web Tools Based on Eclipse MyEclipse MyEclipse, a commercial Web development IDE, is only one of three IDEs discussed in this chapter that also features modeling capabilities such as UML diagram editors and UML to Java code generation MyEclipse extends WTP and adds support for a variety of Web technologies including JSF, EJB, Hibernate, and Struts... IDE to suit your additional Web development needs This chapter showcases other Eclipse- based Web tools that can help beef up your Web development IDE Some of the tools that we will cover in this chapter extend WTP, providing additional functionality for the existing tools Others do not integrate with WTP directly but can be used alongside WTP in Eclipse to create broader Web- based development coverage . J2EE 1.3 SYSTEM DOCTYPE <!DOCTYPE web- app SYSTEM "http:/ /java. sun.com/dtd /web- app_2_3.dtd"> Every J2EE Web application contains the XML file web. xml, known as the deployment descriptor. 15.11 Listing of FolderUriResolver .java package org.eclipsewtp.resourceresolution; import java. io.File; import org .eclipse. core.resources.IFile; import org .eclipse. wst.common.uriresolver URIResolverExtension; public. uri="jsp_2_0.xsd" systemId="jsp_2_0.xsd"/> <system uri="j2ee _web_ services_client_1_1.xsd" systemId= "http://www.ibm.com/webservices/xsd/j2ee _web_ services_client_1_1.xsd"/> <public uri=" ;web- app_2_3.dtd” publicId="-//Sun