📄 xmlcontainerhelperimpl.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: XMLContainerHelperImpl.java,v 1.7 2000/11/09 14:56:53 daniela Exp $package org.ozoneDB.xml.util;import java.io.IOException;import org.w3c.dom.Document;import org.w3c.dom.Node;import org.xml.sax.SAXException;import org.ozoneDB.OzoneObject;import org.ozoneDB.xml.dom.DocumentProxy;import org.ozoneDB.xml.xpath.XtXPathProcessor;import org.ozoneDB.xml.xpath.XPathProcessor;import org.ozoneDB.xml.xpath.XPathQuery;import org.ozoneDB.xml.xpath.XObject;/** * This class provides server side part of the XMLContainer. It mainly handles * storing and retrieving of parts of the underlying XML document. * {@link SAXEventChunk} is used to exchange XML data between server and client. * * * @version $Revision: 1.7 $ $Date: 2000/11/09 14:56:53 $ * @author <a href="http://www.smb-tec.com">SMB</a> */public final class XMLContainerHelperImpl extends OzoneObject implements XMLContainerHelper { private final static long serialVersionUID = 4L; private final static boolean debug = XMLContainer.debug; /** */ private static String xpathProcessorName; /** * The underlying XML document. */ private Document document; static { xpathProcessorName = XtXPathProcessor.class.getName(); } public XMLContainerHelperImpl() { if (debug) { System.out.println( "helper: ctor..." ); } } public final void onCreate() throws Exception { if (debug) { System.out.println( "helper: onCreate()..." ); } document = (Document)database().createObject( org.ozoneDB.xml.dom.DocumentImpl.class.getName() ); ((DocumentProxy)document).setContainer( this ); } public final void setDocument( Document _pdoc ) { if (debug) { System.out.println( "helper: setDocument..." ); } if (document != null) { throw new IllegalStateException( "Container helper is already assigned to a document." ); } document = _pdoc; ((DocumentProxy)document).setContainer( this ); } public final Document getDocument() { if (debug) { System.out.println( "helper: getDocument..." ); } return document; } public final SAXChunkConsumer beginInputSequence( Node _pNode ) throws Exception { if (debug) { System.out.println("helper: beginInputSequence..."); } if (_pNode == null) { _pNode = getDocument(); } SAXChunkConsumer consumer = new SAXChunkConsumer( getDocument(), _pNode ); return consumer; } public final SAXChunkConsumer putChunk( byte[] _chunkData, SAXChunkConsumer _consumer ) throws SAXException, IOException { _consumer.processChunk( _chunkData ); return _consumer; } public final void endInputSequence() throws Exception { if (debug) { System.out.println( "helper: endInputSequence..." ); } } public final SAXChunkProducer beginOutputSequence( Node _pnode, int _depth ) throws Exception { if (_pnode == null) { _pnode = getDocument(); } return new SAXChunkProducer( _pnode, _depth ); } public final SAXChunkProducer createNextChunk( SAXChunkProducer producer ) throws SAXException { producer.createNextChunk(); return producer; } public final void endOutputSequence() throws Exception { if (debug) { System.out.println( "helper: endOutputSequence..." ); } } // methods for XPath support public final static void setXPathProcessorName( String _classname ) throws ClassNotFoundException { if (_classname == null) { throw new IllegalArgumentException( "_name == null." ); } // just check if this class is available Class cl = Thread.currentThread().getContextClassLoader().loadClass( _classname ); xpathProcessorName = _classname; } public final XObject executeQuery( XPathQuery _query, Node _pNode ) throws SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException { if (_pNode == null) { _pNode = getDocument(); } // build a new processor in order to be able to handle several // requests in parallel Class cl = Thread.currentThread().getContextClassLoader().loadClass( xpathProcessorName ); XPathProcessor processor = (XPathProcessor)cl.newInstance(); return processor.execute( _query, _pNode ); } /** * Determines the absolute XPath for the given node. * @param node The W3C DOM node whose XPath is to determine. * @return The string representing the absolute XPath for this node. */ public final String xpathForNode( Node _pnode ) { if (_pnode == null) { throw new IllegalArgumentException( "_pnode == null." ); } StringBuffer xpath = new StringBuffer(); xpath = iterateBack( _pnode, xpath ); return xpath.toString(); } // internal stuff private final StringBuffer iterateBack( Node node, StringBuffer buffer ) { int nthChild = 1; String nodeName = node.getNodeName(); Node prevNode = node; while ((prevNode = prevNode.getPreviousSibling()) != null) { if (prevNode.getNodeName().equals( nodeName ) && prevNode.getNodeType() == node.getNodeType()) { nthChild++; } } if (node.getNodeType() == Node.TEXT_NODE) { nodeName = "text()"; } else if (node.getNodeType() == Node.COMMENT_NODE) { nodeName = "comment()"; } else { if (node.getNodeType() == Node.DOCUMENT_NODE) { nodeName = ""; } } buffer.insert( 0, "/" + nodeName + (nodeName.length() > 0 ? "[" + nthChild + "]" : "") ); node = node.getParentNode(); if (node != null && node.getNodeType() != Node.DOCUMENT_NODE) { buffer = iterateBack( node, buffer ); } return buffer; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -