/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of
* any nuclear facility.
*/
package com.sun.j2ee.blueprints.xmldocuments;
import java.io.*;
import java.net.URL;
import java.util.Properties;
import java.util.Locale;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.sax.*;
import javax.xml.transform.stream.*;
public final class XMLDocumentUtils {
public static final String DEFAULT_ENCODING = "UTF-8";
public static final String SCHEMAS_DIRECTORY_PATH = "/com/sun/j2ee/blueprints/xmldocuments/rsrc/schemas/";
public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
public static final String W3C_XML_SCHEMA_LOCATION_QNAME = "xsi:schemaLocation";
public static final String W3C_XML_SCHEMA_INSTANCE_NS = "http://www.w3.org/2001/XMLSchema-instance";
public static final String SAX_NS_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
private XMLDocumentUtils() {}
public static String getAttribute(Element element, String name, boolean optional) throws XMLDocumentException {
String value = element.getAttribute(name);
if (value == null && !optional) {
throw new XMLDocumentException("Attribute " + name + " of " + element.getTagName() + " expected.");
}
return value;
}
public static String getAttributeAsString(Element element, String name, boolean optional) throws XMLDocumentException {
return getAttribute(element, name, optional);
}
public static int getAttributeAsInt(Element element, String name, boolean optional) throws XMLDocumentException {
try {
return Integer.parseInt(getAttribute(element, name, optional));
} catch (NumberFormatException exception) {
throw new XMLDocumentException(element.getTagName() + "/@" + name + " attribute: value format error.", exception);
}
}
public static Element getFirstChild(Element element, String name, boolean optional) throws XMLDocumentException {
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (((Element) child).getTagName().equals(name)) {
return (Element) child;
}
break;
}
}
if (!optional) {
throw new XMLDocumentException(name + " element expected as first child of " + element.getTagName() + ".");
}
return null;
}
public static Element getChild(Element element, String name, boolean optional) throws XMLDocumentException {
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (((Element) child).getTagName().equals(name)) {
return (Element) child;
}
}
}
if (!optional) {
throw new XMLDocumentException(name + " element expected as child of " + element.getTagName() + ".");
}
return null;
}
public static Element getSibling(Element element, boolean optional) throws XMLDocumentException {
return getSibling(element, element.getTagName(), optional);
}
public static Element getSibling(Element element, String name, boolean optional) throws XMLDocumentException {
for (Node sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
if (((Element) sibling).getTagName().equals(name)) {
return (Element) sibling;
}
}
}
if (!optional) {
throw new XMLDocumentException(name + " element expected after " + element.getTagName() + ".");
}
return null;
}
public Element getNextSibling(Element element, boolean optional) throws XMLDocumentException {
return getNextSibling(element, element.getTagName(), optional);
}
public static Element getNextSibling(Element element, String name, boolean optional) throws XMLDocumentException {
for (Node sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
if (((Element) sibling).getTagName().equals(name)) {
return (Element) sibling;
}
break;
}
}
if (!optional) {
throw new XMLDocumentException(name + " element expected after " + element.getTagName() + ".");
}
return null;
}
public static String getContent(Element element, boolean optional) throws XMLDocumentException {
StringBuffer buffer = new StringBuffer();
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE) {
try {
buffer.append(((Text) child).getData());
} catch (DOMException e) {}
}
}
if (!optional && buffer.length() == 0) {
throw new XMLDocumentException(element.getTagName() + " element: content expected.");
}
return buffer.toString();
}
public static String getContentAsString(Element element, boolean optional) throws XMLDocumentException {
return getContent(element, optional);
}
public static int getContentAsInt(Element element, boolean optional) throws XMLDocumentException {
try {
return Integer.parseInt(getContent(element, optional));
} catch (NumberFormatException exception) {
throw new XMLDocumentException(element.getTagName() + " element: content format error.", exception);
}
}
public static float getContentAsFloat(Element element, boolean optional) throws XMLDocumentException {
try {
return Float.parseFloat(getContent(element, optional));
} catch (NumberFormatException exceptio
没有合适的资源?快使用搜索试试~ 我知道了~
petstore-1_3_1_02
共747个文件
java:309个
jsp:98个
xml:97个
需积分: 9 7 下载量 122 浏览量
2008-06-16
23:00:10
上传
评论
收藏 7.65MB ZIP 举报
温馨提示
petstore-1_3_1_02学习源代码
资源详情
资源评论
资源推荐
收起资源包目录
petstore-1_3_1_02 (747个子文件)
ant 1KB
antRun 124B
ant.bat 4KB
adminwsclient.bat 3KB
adminwsclient.bat 3KB
build.bat 2KB
setup.bat 2KB
build.bat 2KB
build.bat 2KB
setup.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
build.bat 2KB
antRun.bat 2KB
lcp.bat 2KB
COPYRIGHT 3KB
TPASupplierOrder.dtd 3KB
PurchaseOrder.dtd 3KB
PurchaseOrder.dtd 3KB
TPAInvoice.dtd 2KB
SupplierOrder.dtd 2KB
SupplierOrder.dtd 2KB
PopulateSQL.dtd 2KB
Invoice.dtd 2KB
ContactInfo.dtd 2KB
TPALineItem.dtd 2KB
ItemDetails.dtd 2KB
LineItem.dtd 2KB
LineItem.dtd 2KB
Profile.dtd 2KB
ContactInfo.dtd 2KB
Address.dtd 2KB
Address.dtd 2KB
Customer.dtd 2KB
Product.dtd 2KB
OrderApproval.dtd 2KB
Account.dtd 2KB
Category.dtd 2KB
CreditCard.dtd 2KB
Item.dtd 2KB
CreditCard.dtd 2KB
Mail.dtd 2KB
Mail.dtd 2KB
CategoryDetails.dtd 2KB
ProductDetails.dtd 2KB
User.dtd 2KB
CommonElements.dtd 2KB
petstore.ear 1.26MB
petstore.ear 1.26MB
petstoreadmin.ear 600KB
petstoreadmin.ear 489KB
opc.ear 335KB
supplier.ear 315KB
supplier.ear 231KB
opc.ear 180KB
splash.gif 35KB
jrat1.gif 8KB
fish4.gif 7KB
monkey.gif 7KB
banner_cats.gif 7KB
banner_reptiles.gif 6KB
banner_fish.gif 6KB
banner_birds.gif 6KB
bird4.gif 6KB
dog2.gif 6KB
banner_dogs.gif 6KB
dog1.gif 6KB
bird3.gif 6KB
bird5.gif 5KB
fish3.gif 5KB
cat2.gif 5KB
dog6.gif 5KB
bird1.gif 5KB
dog5.gif 5KB
cat3.gif 5KB
banner_logo.gif 5KB
bird6.gif 5KB
cat4.gif 5KB
lizard3.gif 5KB
fish2.gif 4KB
dog3.gif 4KB
logo-topbar.gif 4KB
cat1.gif 3KB
fish_icon.gif 3KB
birds_icon.gif 3KB
cats_icon.gif 3KB
frog1.gif 3KB
dogs_icon.gif 3KB
lizard2.gif 3KB
lizard1.gif 3KB
bird2.gif 3KB
dog4.gif 3KB
reptiles_icon.gif 2KB
duke4.gif 2KB
共 747 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
lineonshow
- 粉丝: 0
- 资源: 52
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0